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. - Upload via
twine(with--dry-runby default). - Simple Typer-based CLI.
Installation
pip install .
# or
pip install sage-pypi-publisher
CLI
Quick Start
Interactive Mode (Recommended) - Build and get prompted to upload:
sage-pypi-publisher build .
# After build completes, you'll be asked:
# - "是否立即上传到 PYPI?" (Upload to PyPI?)
# - "是否执行真实上传?" (Execute real upload?)
One-Command Build & Upload:
# Test on TestPyPI first (dry-run)
sage-pypi-publisher build . --upload -r testpypi
# Real upload to PyPI
sage-pypi-publisher build . --upload -r pypi --no-dry-run
# Public mode (source code)
sage-pypi-publisher build . --upload -r pypi --no-dry-run --mode public
All Commands
sage-pypi-publisher --help
# 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
# Build (auto-detects pure Python vs C/C++ extensions)
sage-pypi-publisher build /path/to/pkg
# Build with upload (interactive prompts)
sage-pypi-publisher build /path/to/pkg --upload -r testpypi
# Build with auto-upload (no prompts)
sage-pypi-publisher build /path/to/pkg --upload -r pypi --no-dry-run
# 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
from pathlib import Path
from pypi_publisher.compiler import BytecodeCompiler
compiler = BytecodeCompiler(Path("/path/to/pkg"))
compiled = compiler.compile_package()
wheel = compiler.build_wheel(compiled)
compiler.upload_wheel(wheel, repository="testpypi", dry_run=True)
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.
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 Distributions
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.1.8.7.tar.gz.
File metadata
- Download URL: isage_pypi_publisher-0.1.8.7.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45447a35f76c7fbb7cb64e77a4a8ae09155fad31ea91ef829c5e8795a68810d6
|
|
| MD5 |
8c3cebb960c4dd876971d0a85120f20e
|
|
| BLAKE2b-256 |
728694079f7f31be699748663c0a78563c9fc5f816bb464f6dcd8e490a8c8775
|
File details
Details for the file isage_pypi_publisher-0.1.8.7-py2.py3-none-any.whl.
File metadata
- Download URL: isage_pypi_publisher-0.1.8.7-py2.py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
432523ada94d4f71f485e0c786066105e241278fda27e85209cce493b86e2123
|
|
| MD5 |
0e62acca265435525d24ce37b08ef97b
|
|
| BLAKE2b-256 |
f8ba7d51382f4d47c8ffa861ff395546470cb37f8ebcaba737d454b8a62877d9
|
File details
Details for the file isage_pypi_publisher-0.1.8.7-cp311-none-any.whl.
File metadata
- Download URL: isage_pypi_publisher-0.1.8.7-cp311-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: CPython 3.11
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be9305fd43341b35a558d7277ff25978ef0cebb8cf43039fc90b7419db9880b
|
|
| MD5 |
dc3eda73ab66145b7a6bfff40364b2fd
|
|
| BLAKE2b-256 |
889353da0b50a2ba268df46503d344312f30e97ba684ea6ec2317b63b90d3e59
|