scripts-fabq/notes/pip_packaging.md
Fabrice Quenneville 7124708173 Added pip packaging notes and guide for Debian
- Included instructions for required tools, building the package, and uploading to Test PyPI and Live PyPI.
- Added comments for clarity in the notes.

Added notes on user commands and font directories in Linux notes

- Included commands to run commands as a specific user, change user shells, and switch to a user with a specific shell.
- Added instructions for managing local and global font directories.
2024-10-21 03:19:21 -04:00

3.3 KiB

Pip packaging

Table of Contents

Required Tools

Ensure that you have the necessary tools (python3-setuptools, python3-wheel, and twine) installed on your Debian system. You can install them using apt:

apt update
apt install python3-setuptools python3-wheel twine

Credentials

Check if your credentials for PyPI and Test PyPI are stored in ~/.pypirc:

cat ~/.pypirc

Ensure you have the correct tokens and repository configurations in this file if you plan to use token-based authentication for uploads.

Build the package

Navigate to your project directory (where setup.py is located) and build the distribution files. This will generate both a source distribution and a wheel.

python3 setup.py sdist bdist_wheel

The above command will create a dist/ folder containing .tar.gz and .whl files.

Upload package

Upload to Test PyPI

To upload your package to Test PyPI (a test environment that mirrors the real PyPI), use the following command:

twine upload --repository-url https://test.pypi.org/legacy/ dist/*

You can also specify a particular version of your package:

twine upload --repository-url https://test.pypi.org/legacy/ dist/MediaCurator-0.0.10*

You can also specify the repository from ~/.pypirc:

twine upload --repository testpypi dist/MediaCurator-0.0.10*

You will be prompted to enter your Test PyPI username and password.

Note:

If you're having trouble remembering your credentials, you can create or manage your account at Test PyPI.

Install the Package from Test PyPI

To test the package installation from Test PyPI, you can use the following command:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mediacurator

This command first checks Test PyPI for the package and falls back to the official PyPI for dependencies.

Upload to Live PyPI

Once you are confident everything works, you can upload the package to the real PyPI using:

twine upload dist/*

You can also specify the version:

twine upload dist/MediaCurator-0.0.10*

You can also specify the repository-url:

twine upload --repository-url https://test.pypi.org/legacy/ dist/MediaCurator-0.0.10*

You can also specify the repository from ~/.pypirc:

twine upload --repository mediacurator dist/MediaCurator-0.0.10*

Ensure your PyPI token is configured or provide it directly during the upload:

twine upload -u __token__ -p <your-testpypi-token> dist/MediaCurator-0.0.10*

You will need your credentials for your PyPI account, which you can create/manage at PyPI.


Notes

  • Ensure your version numbers are updated in setup.py before uploading a new package version.
  • Always test your package thoroughly using Test PyPI before uploading to the live PyPI to avoid breaking releases.