-
Notifications
You must be signed in to change notification settings - Fork 29
Rules for writing executable scripts
nietky edited this page Oct 15, 2012
·
1 revision
Executable scripts must have this structure at a minimum:
#!/usr/bin/env python
def main():
# do stuff with sys.argv, etc.
if __name__ == '__main__':
main() # this should be the only statement in this block
The filename should follow the rules for Python module names, e.g. such that for a script called mtpy/utils/my_script.py you can do
>>> import mtpy.utils.my_script
This rules out dashes in filenames.
Then you must add a new entry to this part of setup.py:
setup_kwargs['entry_points'] = {'console_scripts': [
# ...
'my_script = mtpy.utils.my_script:main', # << Add your new script
# ...]}
and that's it.