3.7 KiB
3.7 KiB
Building and Publishing Guide
This guide explains how to build and publish the microscopy-object-detection package.
Prerequisites
pip install build twine
Building the Package
1. Clean Previous Builds
rm -rf build/ dist/ *.egg-info
2. Build Distribution Archives
python -m build
This will create both wheel (.whl) and source distribution (.tar.gz) in the dist/ directory.
3. Verify the Build
ls dist/
# Should show:
# microscopy_object_detection-1.0.0-py3-none-any.whl
# microscopy_object_detection-1.0.0.tar.gz
Testing the Package Locally
Install in Development Mode
pip install -e .
Install from Built Package
pip install dist/microscopy_object_detection-1.0.0-py3-none-any.whl
Test the Installation
# Test CLI
microscopy-detect --version
# Test GUI launcher
microscopy-detect-gui
Publishing to PyPI
1. Configure PyPI Credentials
Create or update ~/.pypirc:
[pypi]
username = __token__
password = pypi-YOUR-API-TOKEN-HERE
2. Upload to Test PyPI (Recommended First)
python -m twine upload --repository testpypi dist/*
Then test installation:
pip install --index-url https://test.pypi.org/simple/ microscopy-object-detection
3. Upload to PyPI
python -m twine upload dist/*
Version Management
Update version in multiple files:
setup.py: Updateversionparameterpyproject.toml: Updateversionfieldsrc/__init__.py: Update__version__variable
Git Tags
After publishing, tag the release:
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
Package Structure
The built package includes:
- All Python source files in
src/ - Configuration files in
config/ - Database schema file (
src/database/schema.sql) - Documentation files (README.md, LICENSE, etc.)
- Entry points for CLI and GUI
Troubleshooting
Import Errors
If you get import errors, ensure:
- All
__init__.pyfiles are present - Package structure follows the setup configuration
- Dependencies are listed in
requirements.txt
Missing Files
If files are missing in the built package:
- Check
MANIFEST.inincludes the required patterns - Check
pyproject.tomlpackage-data configuration - Rebuild with
python -m build --no-isolationfor debugging
Version Conflicts
If version conflicts occur:
- Ensure version is consistent across all files
- Clear build artifacts and rebuild
- Check for cached installations:
pip list | grep microscopy
CI/CD Integration
GitHub Actions Example
name: Build and Publish
on:
release:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
pip install build twine
- name: Build package
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*
Best Practices
- Version Bumping: Use semantic versioning (MAJOR.MINOR.PATCH)
- Testing: Always test on Test PyPI before publishing to PyPI
- Documentation: Update README.md and CHANGELOG.md for each release
- Git Tags: Tag releases in git for easy reference
- Dependencies: Keep requirements.txt updated and specify version ranges