Python bytecode compiler and PyPI publishing toolkit for monorepos
Project description
sage-pypi-publisher
A tiny toolkit to compile Python packages to bytecode, build wheels, and publish to PyPI/TestPyPI. Extracted from SAGE's internal sage-dev tooling and made standalone.
Features
- Copy a package tree and compile
.py→.pyc(keeps__init__.pyand_version.py). - Auto-adjust
pyproject.toml/MANIFEST.into include compiled artifacts and binary extensions. - Build wheels with
python -m build. - 🚀 NEW: Smart
--for-pypimode - one command for perfect PyPI publishing! - NEW: Universal wheel support - one wheel works on all Python 3.x versions!
- NEW: Source distribution (sdist) support - users can install from source on any version
- Upload via
twine(with--dry-runby default). - Simple Typer-based CLI.
Solving the Multi-Version Problem
Problem: Your package declares support for Python 3.8-3.12, but you only upload a wheel for Python 3.11. Users on other versions can't install it!
Solution: sage-pypi-publisher now uses Smart Mode by default 🎯
# That's it! No extra flags needed - smart mode is automatic
sage-pypi-publisher build . --upload --no-dry-run
What happens automatically:
- ✅ Pure Python packages: Builds universal wheel (py3-none-any) that works on ALL Python 3.x versions!
- ✅ Packages with C extensions: Builds for current Python + provides source code for others
- ✅ Always includes source distribution (sdist) as fallback
- ✅ No need to build wheels for each Python version separately!
Why this works:
- Universal wheel (py3-none-any): One file works on Python 3.8, 3.9, 3.10, 3.11, 3.12, and future versions!
- Source distribution: If universal wheel doesn't work, users can compile from source
- Zero configuration: Works perfectly out of the box!
Installation
pip install .
# or
pip install sage-pypi-publisher
CLI
Quick Start
🎯 Simplest Usage (Smart Mode - Default!)
# Just build - automatically chooses best strategy!
sage-pypi-publisher build .
# Build and upload to TestPyPI
sage-pypi-publisher build . --upload -r testpypi
# Build and upload to PyPI (production)
sage-pypi-publisher build . --upload --no-dry-run -r pypi
What Smart Mode Does (Automatically):
- 🔍 Detects if your package is pure Python or has C extensions
- 📦 Pure Python → builds universal wheel (works on ALL Python 3.x!)
- 🔧 C extensions → builds for current Python version
- 📚 Always includes source distribution (sdist)
- ✅ Perfect for packages declaring Python 3.8+ support!
Manual Control (Advanced):
# Disable smart mode (old behavior - current Python only)
sage-pypi-publisher build . --no-for-pypi
# Force universal wheel
sage-pypi-publisher build . --universal
# Force specific mode
sage-pypi-publisher build . --mode public
All Commands
sage-pypi-publisher --help
# 🎯 Simplest: Build with smart mode (default!)
sage-pypi-publisher build .
# Build and upload to PyPI
sage-pypi-publisher build . --upload --no-dry-run
# Compile only (bytecode mode by default)
sage-pypi-publisher compile /path/to/pkg -o /tmp/out
# Compile in public mode (keep source)
sage-pypi-publisher compile /path/to/pkg -o /tmp/out --mode public
# Disable smart mode (old behavior)
sage-pypi-publisher build /path/to/pkg --no-for-pypi
# Force universal wheel (manual override)
sage-pypi-publisher build /path/to/pkg --universal
# Force manylinux build for C/C++ extensions
sage-pypi-publisher build /path/to/pkg --force-manylinux
# Upload an existing wheel
sage-pypi-publisher upload dist/yourpkg-0.1.0-py3-none-any.whl -r pypi --no-dry-run
Build Modes
--mode private(default): Compile to.pycbytecode (保密模式 - protects source code)--mode public: Keep.pysource files (公开模式 - open source)- Aliases:
bytecode=private,source=public
Python API
Basic Usage
fromPyPI Publishing Options
**Smart Mode (Default) 🎯**
- **Enabled automatically** - no flags needed!
- Pure Python → universal wheel + sdist
- C extensions → current Python wheel + sdist
- Use `--no-for-pypi` to disable
**Manual Override:**
- **`--universal`**: Force universal wheel (py3-none-any) - only works for pure Python packages
- **`--sdist`**: Add source distribution (.tar.gz)
- **`--no-for-pypi`**: Disable smart mode, build for current Python only
**Why NOT build wheels for each Python version?**
You might wonder: "Why not build cp38, cp39, cp310, cp311, cp312 wheels separately?"
**Technical limitation**: To build a wheel for Python 3.10, you need Python 3.10 installed and running. You can't build a true Python 3.10 wheel from Python 3.11 environment.
**Better solution**:
- Pure Python packages → Use universal wheel (py3-none-any) - ONE wheel for ALL versions!
- C extensions → Provide source distribution (sdist) so users can compile for their Python version
- For production C extensions with multiple versions → Use `cibuildwheel` in CI/CD
wheeUniversal Wheel (Recommended for Pure Python)
```python
from pathlib import Path
from pypi_publisher.compiler import BytecodeCompiler
# For pure Python packages
compiler = BytecodeCompiler(Path("/path/to/pkg"), mode="public")
compiled = compiler.compile_package()
# Build universal wheel (works on ALL Python 3.x)
universal_wheel = compiler.build_universal_wheel(compiled)
# Build source distribution
sdist = compiler.build_sdist(compiled)
# Upload both
for artifact in [universal_wheel, sdist]:
compiler.upload_wheel(artiface_package()
# Build source distribution
sdist = compiler.build_sdist(compiled)
compiler.upload_wheel(sdist, repository="pypi", dry_run=False)
Git Hooks
sage-pypi-publisher provides intelligent git hooks to simplify version management and PyPI publishing.
Installation
sage-pypi-publisher install-hooks .
Features
- Auto-detection: Detects version changes in
pyproject.tomlon push. - Interactive Update: Prompts to update version if forgotten.
- Auto-Publish: Builds and uploads to PyPI automatically upon confirmation.
- Smart Build: Detects C/C++ extensions for manylinux wheels.
Notes
- Requires
python -m buildandtwineavailable. - No backward compatibility with
sage-devCLI; PyPI commands have been removed from SAGE. - Designed to be monorepo-friendly but works with any package path that contains
pyproject.toml.
Test commit
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file isage_pypi_publisher-0.2.1.1.tar.gz.
File metadata
- Download URL: isage_pypi_publisher-0.2.1.1.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efbfec5f4cc07adbb61c76f98f1c7870befbe33c52e34c7300e043dbe82c1093
|
|
| MD5 |
c1108719d85f73c07d30723624462b88
|
|
| BLAKE2b-256 |
d6feb044ccb268607277a1183d2f429d7de3767a2d7608f8c420564f164a34b0
|
File details
Details for the file isage_pypi_publisher-0.2.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: isage_pypi_publisher-0.2.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 30.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
669ae837a0dd5d5dc9eebca1e780147687e0663e3eda0d84e0797ca44eac7886
|
|
| MD5 |
8e30fb2e4243edf40aba1a06fabc5233
|
|
| BLAKE2b-256 |
163e65fb9ab932a8c1d26138591bafb9ffb4b69adbc41f208b312abc84e4334c
|