Skip to content

Commit

Permalink
Add CLI to run any Python program based on argparse
Browse files Browse the repository at this point in the history
Implements issue #519.
  • Loading branch information
pawamoy committed Feb 4, 2022
1 parent a451f52 commit 6787cac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
25 changes: 13 additions & 12 deletions gooey/__main__.py
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()
18 changes: 18 additions & 0 deletions gooey/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''The command line interface.'''

import sys
from importlib import import_module

from gooey import Gooey


def main(args=None):
args = args or sys.argv[1:]
module_path, function_name = args[0].split(':')
if len(args) > 1:
if args[1] == '--':
del args[1]
sys.argv = ['gooey', *args[1:]]
module = import_module(module_path)
function = getattr(module, function_name)
return Gooey(function)()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
install_requires=deps,
include_package_data=True,
dependency_links = ["http://www.wxpython.org/download.php"],
entry_points={'console_scripts': ['gooey = gooey.cli:main']},
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
Expand Down

0 comments on commit 6787cac

Please sign in to comment.