https://github.com/yaythomas/python-cli-pypa-build-example
Example of how to create & package a Python CLI application using the PyPA build tool.
https://github.com/yaythomas/python-cli-pypa-build-example
build cli packaging python
Last synced: about 1 year ago
JSON representation
Example of how to create & package a Python CLI application using the PyPA build tool.
- Host: GitHub
- URL: https://github.com/yaythomas/python-cli-pypa-build-example
- Owner: yaythomas
- License: apache-2.0
- Created: 2021-08-26T15:32:10.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-26T16:12:22.000Z (almost 5 years ago)
- Last Synced: 2025-04-01T03:41:31.883Z (about 1 year ago)
- Topics: build, cli, packaging, python
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Use PyPA build to create Python CLI applications
This repo is a deliberately simple example of how to create & package Python CLI
applications using the [PyPA setuptools build
tool](https://setuptools.readthedocs.io/).
## how to create a CLI package with Python
Sample code that we're going to deploy is in `mypackage/mymodule.py`.
The configuration telling the build tool what to package is in `setup.cfg`.
To create a package, do the following:
```console
# create a venv for build & packaging tools
$ python3 -m venv .env/build
# activate the venv
$ . .env/build/bin/activate
# install the setuptools build tool to the new environment
$ pip install build
# run build on the current directory
$ python -m build
# previous step will create a .tar.gaz & a .whl in ./dist
$ ls ./dist
mypackage-0.0.5-py3-none-any.whl
mypackage-0.0.5.tar.gz
```
## How to test deploying your Python package
To deploy your packaged CLI application, do the following:
```console
# create a fresh clean venv to test deployment
$ python3 -m venv .env/deploy
# activate the venv
$ . .env/deploy/bin/activate
# install the wheel we built using pip
$ pip install dist/mypackage-0.0.5-py3-none-any.whl
# the CLI entrypoints listed in setup.cfg are now in .env the /bin dir
$ ls .env/deploy/bin
my-application
another-application
# you can run your freshly deployed CLI app
$ my-application
hello from my_function
$ another-application
hello from another_function
```
You specify the names your app deploy as - `my-application` and
`another-application` - in `setup.cfg`.