This guide covers how to build and publish the SerialTalk package to PyPI.
- Python 3.7 or higher
- Git
-
Clone the repository:
git clone https://github.com/antonvh/SerialTalk.git cd SerialTalk -
Create a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install in development mode:
pip install -e ".[dev]"
chmod +x build.sh
./build.sh-
Install build tools:
pip install build twine
-
Clean previous builds:
rm -rf dist/ build/ *.egg-info -
Build the package:
python -m build
This creates both source distribution (.tar.gz) and wheel (.whl) files in the dist/ directory.
Install the built package locally:
pip install dist/serialtalk-1.0.0-py3-none-any.whl-
Create accounts on:
-
Create API tokens:
-
Configure credentials in
~/.pypirc:[distutils] index-servers = pypi testpypi [pypi] username = __token__ password = pypi-YOUR-API-TOKEN-HERE [testpypi] repository = https://test.pypi.org/legacy/ username = __token__ password = pypi-YOUR-TEST-API-TOKEN-HERE
python -m twine upload --repository testpypi dist/*Test the installation:
pip install --index-url https://test.pypi.org/simple/ serialtalkpython -m twine upload dist/*The version is defined in three places and must be kept in sync:
pyproject.toml- Main version for PyPIserialtalk/__init__.py-__version__variablepackage.json- Version for mip (MicroPython)
To release a new version:
-
Update the version number in all three files
-
Commit the changes:
git add pyproject.toml serialtalk/__init__.py package.json git commit -m "Bump version to X.Y.Z" git tag vX.Y.Z git push origin main --tags -
Build and publish as described above
SerialTalk/
├── serialtalk/ # Main package directory
│ ├── __init__.py # Package initialization with version info
│ ├── serialtalk.py # Core SerialTalk class
│ ├── auto.py # Auto-detection for platforms
│ ├── sockets.py # Socket communication
│ └── ... # Platform-specific modules
├── pyproject.toml # Modern Python package metadata
├── setup.py # Backwards compatibility setup
├── package.json # MicroPython mip metadata
├── MANIFEST.in # Additional files to include
├── LICENSE # MIT License
├── README.md # User documentation
└── docs/ # Sphinx documentation
pytestFormat code with Black:
black serialtalk/Check code style:
flake8 serialtalk/cd docs
make htmlDocumentation will be in docs/_build/html/.
Consider setting up GitHub Actions for:
- Automated testing on multiple Python versions
- Automated publishing on tagged releases
- Documentation building and deployment
For issues and questions:
- GitHub Issues: https://github.com/antonvh/SerialTalk/issues
- Email: anton@antonsmindstorms.com