This document outlines the steps needed to release a new version to PyPI.
-
Update version number in the following files:
setup.py
scrape_cli/__init__.py
-
Update the CHANGELOG:
- Add a new section for the upcoming version.
- Document all significant changes.
- Include the release date.
-
Install Dependencies:
- Ensure all dependencies are installed properly:
pip install -r requirements.txt
- Ensure all dependencies are installed properly:
-
Activate the virtual environment (if not already activated):
source venv/bin/activate # Linux/MacOS
-
Clean previous builds:
rm -rf build/ dist/ *.egg-info
-
Build the distribution packages:
python3 -m build
-
Verify the built distributions:
twine check dist/*
-
Local Installation Test (optional but recommended):
- Install the built package locally to verify it:
pip install dist/<package-name>.tar.gz
- Install the built package locally to verify it:
-
Upload the distribution packages to PyPI:
twine upload dist/*
-
Verify Installation:
pip install <package-name>
-
Tag the Release in Git:
git tag -a <version> -m "Release <version>" git push origin <version>
-
Create a GitHub Release:
- Go to the releases page on GitHub.
- Create a new release using the version tag.
- Add release notes summarizing the changes.
- Announce the release if needed.
-
Update Documentation:
- Update relevant parts of the documentation.
- Post announcements in channels such as Slack or mailing lists (if applicable).
-
Remove the release from PyPI if issues are found:
twine delete <package-name> <version>
-
Revert the Git Tag:
git tag -d <version> git push origin :refs/tags/<version>
To save time and reduce the chance of manual errors, consider using a script like the one below for automation:
#!/bin/bash
set -e
# Activate the virtual environment
source venv/bin/activate
# Clean previous builds
rm -rf build/ dist/ *.egg-info
# Build the package
python3 -m build
# Check the build
twine check dist/*
# Upload to PyPI
twine upload dist/*
# Tag the release
git tag -a $1 -m "Release $1"
git push origin $1
This script simplifies many of the steps and ensures that all commands run in sequence.