-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conquer the land of arguing snakes #788
Changes from all commits
474dce6
1bbfbb1
de9f8df
2694a78
cf77dba
6341340
b1267c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
# ''' | ||
# Delegates arguments to the main Gooey runner | ||
# | ||
# For use when run directly from command line with the -m (module) flag: | ||
# | ||
# e.g. $ python -m gooey | ||
# | ||
# ''' | ||
# | ||
# from gooey import application | ||
# | ||
# application.main() | ||
''' | ||
Delegates arguments to the main Gooey runner. | ||
|
||
For use when run directly from command line with the -m (module) flag: | ||
|
||
e.g. $ python -m gooey | ||
|
||
''' | ||
|
||
from gooey.cli import main | ||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'''The command line interface.''' | ||
|
||
import sys | ||
from importlib import import_module | ||
try: | ||
from importlib.metadata import entry_points | ||
except ImportError: | ||
from importlib_metadata import entry_points | ||
|
||
from gooey import Gooey | ||
|
||
|
||
def main(args=None): | ||
args = args or sys.argv[1:] | ||
if not args: | ||
# without args we assume we want to run gooey on gooey itself | ||
# TODO: rewrite using argparse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running Gooey on itself requires rewriting this function with an argparse parser. Let me know if this is something you'd like 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave it up to you ^_^ I'd be fine going sans additional configuration for the initial release of this -- let it "bake" a bit and see if people need the functionality. On the flip side, if you want to throw a parser in there so people can control things that's fine, too. You may be able to even generate a options for all of the params directly from the type definition by looking through its |
||
script_name = "gooey" | ||
else: | ||
script_name = args[0] | ||
scripts = {script.name: script for script in entry_points().get('console_scripts')} | ||
if script_name in scripts: | ||
# a valid script was passed | ||
script = scripts[script_name] | ||
module_path = script.module | ||
function_name = script.attr | ||
prog = script_name | ||
elif ':' in script_name: | ||
# the path to a function was passed | ||
module_path, function_name = args[0].split(':') | ||
prog = module_path.split('.', 1)[0] | ||
pawamoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else: | ||
print('usage: gooey [SCRIPT | MODULE:FUNCTION] [-- SCRIPT_ARGS...]', file=sys.stderr) | ||
sys.exit(1) | ||
if len(args) > 1: | ||
if args[1] == '--': | ||
del args[1] | ||
sys.argv = [prog, *args[1:]] | ||
module = import_module(module_path) | ||
function = getattr(module, function_name) | ||
return Gooey(function, use_cmd_args=True)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain a bit about these different versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importlib.metadata
is included in the standard library since Python 3.8 only.Since you support lower versions, the
importlib-metadata
package is required (it's a simple backport).Therefore, we must handle both cases in the code since the import path is not the same (
importlib.metadata
vs.importlib_metadata
).