Checklist for maintainers: build artifacts, upload to TestPyPI, then PyPI.
- Python 3.10+ (aligned with
requires-pythoninpyproject.toml). - Editable install with dev tools:
pip install -e ".[dev]"(includesbuild,twine,pytest,ruff). - Accounts on PyPI and TestPyPI.
- API tokens for uploads (recommended: API token per project, not account password).
From the repository root:
bash scripts/build_dist.shThis runs python -m build, then twine check dist/*, and lists dist/.
Equivalent manual steps:
rm -rf dist/ build/
python -m build
twine check dist/*Configure credentials (pick one):
~/.pypircwith atestpypirepository section, or- Environment variables:
TWINE_USERNAME=__token__andTWINE_PASSWORD=<testpypi-api-token>.
Upload:
twine upload --repository testpypi dist/*Smoke-install from TestPyPI (use the version you uploaded):
pip install -i https://test.pypi.org/simple/ trading-crab-lib==0.1.0(TestPyPI may not have all dependencies mirrored; a full runtime check is often done against PyPI deps plus the TestPyPI package.)
twine upload dist/*Use PyPI API token (TWINE_USERNAME=__token__, TWINE_PASSWORD=<pypi-token>) or ~/.pypirc pypi section.
Yanking vs deleting: Prefer yanking a bad release so consumers pinning exact versions see the yank; deleting a release is discouraged and may break mirrors.
PyPI supports Trusted Publishers (e.g. GitHub Actions OIDC) so CI can upload without a long-lived PyPI password. See the official guide: Trusted publishers.
No OIDC workflow is checked into this repository by default; use the appendix below if you add publishing to CI.
The distribution name is trading-crab-lib. If that name is already taken on PyPI, choose a new [project].name in pyproject.toml (and update imports/docs accordingly) or confirm ownership of the existing project. Validating on TestPyPI first is recommended.
To keep pinned actions secure and maintainable, run this checklist on a schedule (recommended: monthly, or at least once per quarter):
- Review
.github/workflows/*.ymlfor pinneduses: owner/repo@<sha>refs. - Resolve the latest commit SHA for each intended major tag/branch (for example
v4,v5,release/v1). - Update workflow
uses:lines to new SHAs and keep an inline comment with the corresponding tag/branch. - Open a PR titled
chore(ci): refresh pinned GitHub Action SHAs. - Confirm CI passes after the refresh.
- If behavior changes, pin back to the previous known-good SHA and investigate release notes.
Suggested PR checklist:
-
actions/checkoutpinned to latestv4commit -
actions/setup-pythonpinned to latestv5commit -
actions/upload-artifactpinned to latestv4commit -
actions/download-artifactpinned to latestv4commit -
pypa/gh-action-pypi-publishpinned to latestrelease/v1commit
This snippet is not active in-repo; copy to .github/workflows/publish-pypi.yml and configure a pypi environment + Trusted Publisher on PyPI.
name: Publish to PyPI
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install build twine
- run: python -m build
- run: twine check dist/*
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/After enabling Trusted Publishing for this repo on pypi.org, uploads use OIDC instead of stored tokens in GitHub Secrets.