Python/Managing Packages

From Dev Wiki
Jump to navigation Jump to search
ToDo: Document initially setting up a third-party package.


Editing/Debugging a Package

It's always possible to edit a Python package on your local machine.


First, if not already done, find the repo (such as on github) where the package is hosted, and clone it down to the local machine.
Next, you can either go into the package folder and edit it as-is (just like any other git project), or you can cd into a different Python application that uses the package as a dependency. Then from there, run:

pip install develop <location_to_local_package>

This command will change the pip pointers to look at the local instance of the repository, instead of the normal pypi version that pip checks out by default.


Pushing a New Version

1) Install/update required dependencies for uploading to pypi:

pip install --upgrade build
pip install --upgrade twine


2) Update all internal project references, regarding current project version. At minimum, this will probably be the files:

  • docs/source/conf.py
  • pyproject.toml
  • setup.cfg

May be additional files to update, depending on the actual project setup and internal documentation.

Ex: If previous version was 1.0.0 and you're uploading a bug fix release, then you might update all references to say 1.0.1.


3) As an optional step, first merge changes into the main/master branch, and push to GitHub/BitBucket/GitLab/etc. Then verify ReadTheDocs pulled and built new docs successfully.


4) As another optional step, give a meaningful version name as a git tag. See Programming/Git#Tag_Commands.


5) Build project files to finally push to pypi:

python -m build

After running this command, there should be a dist folder at project root. Double check that the version listed in the file names seems correct, compared to what was done in step #2 above.


6) Finally push the new project version files to pypi:

python -m twine upload dist/*


At this point, the project should be updated on Pypi. Verify everything has successfully uploaded, and the new version can now be pulled down.