Consider the following Python project skeleton:
proj/
├── foo
│ └── __init__.py
├── README.md
└── scripts
└── run.py
In this case f
There are multiple ways to achieve this. Both require creating a python package by adding a setup.py (building on @matejcik's answer).
Option 1 (recommended): entry_point
+ console_scripts
register a function in your project as the entry point to script execution (ie: proj:foo:cli:run
).
Option 2: scripts
: Use this keyword argument in the setup()
method to reference the path to your script (ie: `bin/script.py).
I recommend using a CLI library/framework like Click so that your codebase is only concerned with maintaining application specific business logic rather than CLI robust framework feature logic. Also, click recommends using entry_point
+ console_scripts
method of script integration due to cross-platform compatibility.
Setup Tools - Automatic script creation: https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation
Setup Tools - keyword arguments: https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords
Click GitHub: https://github.com/pallets/click/
Click Setuptools integration: https://click.palletsprojects.com/en/master/setuptools/