Projects
How to specify cli scripts in a pyproject file
Using poetry
If you use poetry, assuming your project is organized as in this example
[tool.poetry]
name = "packagename"
version = "0.1.0"
description = ""
authors = ["finswimmer <finswimmer@example.org>"]
[tool.poetry.scripts]
cli-script = "packagename.cli:main"
[tool.poetry.dependencies]
python = "^3.6"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"
Simply call
poetry install --only-root
Where your project should be organized as
packagename
├── packagename
│ ├── __init__.py
│ └── cli.py
├── tests
│ ├── __init__.py
│ └── test_packagename.py
└── pyproject.toml
And the content of the script should resemble this:
#!/usr/bin/env python
def main():
print("Hello world")
if __name__ == '__main__':
main()
With setup tools
If your project is simple, for example like this,
yourprojectdir/
setup.py
scripts/
myscript.sh
you may only need to create or append to your setup.py
the following:
from setuptools import setup
# you may need setuptools instead of distutils
setup(
scripts = [
'scripts/myscript.sh'
]
)
Then in the shell type
python setup.py install
Source: https://stackoverflow.com/questions/874521/python-install-script-to-system