-
Notifications
You must be signed in to change notification settings - Fork 0
Publishing a Python Package
src
- package1
- package2
- ...
pyproject.toml
setup.cfg
- pyproject.toml: defines required setuptool, wheel version for pip
- setup.cfg: defines how to build the package including entry scripts (<script-path>:<func-name>), packages directory (src), packages, other metadata.
- e.g., https://github.com/joeyshi12/diff-eq-solver/blob/master/setup.cfg
- you can alternatively use a
setup.pyfile instead
Register an account on https://pypi.org/ and create an API token in account settings.
Create a pypi config file in the home directory $HOME/.pypirc with the following content:
[pypi]
username = __token__
password = pypi-<your-api-token>
Build the package by running pip install . in the same directory as setup.cfg.
Running the command with the -e indicates the package will be installed in editable mode, so
changes in the main project code will always be reflected in the installed package (useful for developing).
A minimal distributable build zip file can be made using python -m build --sdist. This can be installed with
pip install build if missing.
Upload your package with twine upload dist/*. This can be installed with pip install twine if missing.
Note: once a package is uploaded, it cannot be reuploaded until the version number is updated in setup.cfg.
Developed by Joey Shi