Skip to content

Commit 9b2c112

Browse files
authored
Merge pull request #53 from etowahadams/etowahadams/pypi
feat: Publish to PyPI
2 parents c82cafb + 63d6178 commit 9b2c112

8 files changed

Lines changed: 304 additions & 100 deletions

File tree

.github/workflows/wheels.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ on:
1414
- 'pyproject.toml'
1515
- '.github/workflows/wheels.yml'
1616
workflow_dispatch:
17+
inputs:
18+
publish_target:
19+
description: "Publish target (manual runs only)"
20+
required: true
21+
default: "none"
22+
type: choice
23+
options:
24+
- none
25+
- testpypi
1726

1827
jobs:
1928
build_wheels:
@@ -25,9 +34,9 @@ jobs:
2534
include:
2635
- os: ubuntu-latest
2736
cibw_archs: "x86_64"
28-
- os: macos-latest
37+
- os: macos-14
2938
cibw_archs: "x86_64"
30-
- os: macos-latest
39+
- os: macos-14
3140
cibw_archs: "arm64"
3241

3342
steps:
@@ -122,7 +131,7 @@ jobs:
122131
strategy:
123132
fail-fast: false
124133
matrix:
125-
os: [ubuntu-latest, macos-latest]
134+
os: [ubuntu-latest, macos-14]
126135
python-version: ['3.9', '3.10', '3.11', '3.12']
127136

128137
steps:
@@ -144,12 +153,17 @@ jobs:
144153
echo "=== Available wheels ==="
145154
ls -la wheelhouse/*.whl
146155
156+
# Determine the distribution name from the wheel filenames (PEP 427)
157+
# e.g. kalign_test-3.4.5-...whl -> kalign-test
158+
DIST_NAME="$(ls wheelhouse/*.whl | head -n 1 | xargs basename | cut -d- -f1 | tr '_' '-')"
159+
echo "=== Detected dist name: ${DIST_NAME} ==="
160+
147161
echo "=== Installing wheel ==="
148-
pip install --find-links wheelhouse/ kalign --force-reinstall
162+
pip install --find-links wheelhouse/ "${DIST_NAME}" --force-reinstall
149163
150164
# Check what got installed
151165
echo "=== Checking installed packages ==="
152-
pip list | grep kalign || true
166+
pip list | grep -E 'kalign' || true
153167
154168
# Check the kalign module structure
155169
echo "=== Checking kalign module ==="
@@ -209,6 +223,10 @@ jobs:
209223
needs: [build_wheels, build_sdist, test_install]
210224
runs-on: ubuntu-latest
211225
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
226+
permissions:
227+
id-token: write
228+
environment:
229+
name: pypi
212230

213231
steps:
214232
- name: Download all artifacts
@@ -218,9 +236,30 @@ jobs:
218236
merge-multiple: true
219237
path: dist/
220238

221-
- name: Publish to PyPI
239+
- name: Publish to PyPI (trusted publishing)
240+
uses: pypa/gh-action-pypi-publish@release/v1
241+
with:
242+
packages_dir: dist/
243+
244+
upload_testpypi:
245+
name: Upload to TestPyPI
246+
needs: [build_wheels, build_sdist, test_install]
247+
runs-on: ubuntu-latest
248+
if: github.event_name == 'workflow_dispatch' && inputs.publish_target == 'testpypi'
249+
250+
steps:
251+
- name: Download all artifacts
252+
uses: actions/download-artifact@v4
253+
with:
254+
pattern: cibw-*
255+
merge-multiple: true
256+
path: dist/
257+
258+
- name: Publish to TestPyPI (API token)
222259
uses: pypa/gh-action-pypi-publish@release/v1
223260
with:
224261
user: __token__
225-
password: ${{ secrets.PYPI_API_TOKEN }}
226-
packages_dir: dist/
262+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
263+
packages_dir: dist/
264+
repository-url: https://test.pypi.org/legacy/
265+
verbose: true

README-python.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ For bioinformatics ecosystem integration:
3232
```bash
3333
pip install kalign[biopython] # + Biopython integration
3434
pip install kalign[skbio] # + scikit-bio integration
35-
pip install kalign[all] # Everything
3635
pip install kalign[io] # I/O helpers with Biopython
36+
pip install kalign[analysis] # + pandas + matplotlib analysis/visualization helpers
37+
pip install kalign[all] # Biopython + scikit-bio + pandas + matplotlib
3738
```
3839

3940
## Quick Start
@@ -66,7 +67,7 @@ ATCGATC-ATCG
6667

6768
- **[📖 Quick Start Guide](python-docs/python-quickstart.md)** - Get up and running in minutes
6869
- **[🔧 API Reference](python-docs/python-api.md)** - Complete function documentation
69-
- **[🌐 Ecosystem Integration](python-docs/python-ecosystem.md)** - Biopython, scikit-bio, pandas integration
70+
- **[🌐 Ecosystem Integration](python-docs/python-ecosystem.md)** - Biopython, scikit-bio, pandas, and matplotlib integration
7071
- **[⚡ Performance Tuning](python-docs/python-performance.md)** - Optimization and benchmarking
7172
- **[🛠️ Troubleshooting Guide](python-docs/python-troubleshooting.md)** - Common issues and solutions
7273

@@ -580,4 +581,4 @@ See the [LICENSE](../COPYING) file for details.
580581

581582
---
582583

583-
**Made with ❤️ by the Kalign community** | **Star ⭐ us on GitHub if you find Kalign useful!**
584+
**Made with ❤️ by the Kalign community** | **Star ⭐ us on GitHub if you find Kalign useful!**

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,48 @@ cmake -DBUILD_PYTHON_MODULE=ON ..
243243
make
244244
```
245245

246+
### Cutting a New Python Release (PyPI)
247+
248+
This repo is set up to publish to PyPI from GitHub Actions on version tags (`v*`) via `.github/workflows/wheels.yml`.
249+
250+
1) Bump versions
251+
- Update the Python package version in `pyproject.toml` (`[project].version`).
252+
- Update the C/C++ library version in `CMakeLists.txt` (`KALIGN_LIBRARY_VERSION_{MAJOR,MINOR,PATCH}`).
253+
- (Optional but recommended) Add an entry to `ChangeLog`.
254+
255+
2) Sanity check locally (recommended)
256+
```bash
257+
python -m venv .venv
258+
source .venv/bin/activate
259+
python -m pip install -U pip build twine
260+
python -m build
261+
twine check dist/*
262+
```
263+
264+
3) Configure trusted publishing on PyPI
265+
- Add this GitHub repo/workflow as a trusted publisher in the PyPI project settings.
266+
- Configure it to match the workflow/environment used in `.github/workflows/wheels.yml` (environment `pypi`).
267+
268+
4) Tag and push
269+
```bash
270+
git tag vX.Y.Z
271+
git push origin vX.Y.Z
272+
```
273+
274+
That tag push triggers the wheel + sdist build, install tests, and then uploads to PyPI.
275+
276+
#### Testing publishing on TestPyPI (optional)
277+
278+
If you want to test the publishing pipeline without uploading to the real PyPI project, this repo also supports a manual TestPyPI publish:
279+
280+
1) Create a TestPyPI API token and add it as the GitHub secret `TEST_PYPI_API_TOKEN`.
281+
2) Run the GitHub Actions workflow **Build Python Wheels** manually and set `publish_target = testpypi`.
282+
283+
To install from TestPyPI while resolving dependencies from PyPI:
284+
```bash
285+
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple <package-name>
286+
```
287+
246288
## Performance
247289

248290
### Benchmark Results

pyproject.toml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ build-backend = "scikit_build_core.build"
1010
name = "kalign"
1111
version = "3.4.5"
1212
description = "Python wrapper for the Kalign multiple sequence alignment engine"
13-
readme = "README.md"
14-
license = {text = "GPL-3.0-or-later"}
13+
readme = "README-python.md"
14+
license = "GPL-3.0-or-later"
15+
license-files = ["COPYING"]
1516
authors = [
1617
{name = "Timo Lassmann", email = "timo.lassmann@telethonkids.org.au"}
1718
]
@@ -30,7 +31,6 @@ keywords = [
3031
classifiers = [
3132
"Development Status :: 5 - Production/Stable",
3233
"Intended Audience :: Science/Research",
33-
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
3434
"Operating System :: OS Independent",
3535
"Programming Language :: C",
3636
"Programming Language :: C++",
@@ -46,12 +46,7 @@ classifiers = [
4646
]
4747
requires-python = ">=3.9"
4848
dependencies = [
49-
"biopython>=1.85",
50-
"matplotlib>=3.9.4",
5149
"numpy>=1.19.0",
52-
"pandas>=2.3.0",
53-
"rich>=14.0.0",
54-
"scikit-bio>=0.6.3",
5550
]
5651

5752
[project.scripts]
@@ -62,7 +57,8 @@ kalign = "kalign.cli:main"
6257
biopython = ["biopython>=1.85"]
6358
skbio = ["scikit-bio>=0.6.3"]
6459
io = ["biopython>=1.85"] # For I/O helper functions
65-
all = ["biopython>=1.85", "scikit-bio>=0.6.3"]
60+
analysis = ["pandas>=2.3.0", "matplotlib>=3.9.4"]
61+
all = ["biopython>=1.85", "scikit-bio>=0.6.3", "pandas>=2.3.0", "matplotlib>=3.9.4"]
6662

6763
# Development dependencies
6864
dev = [

python-docs/python-quickstart.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ pip install kalign[biopython]
3131
# For scikit-bio integration
3232
pip install kalign[skbio]
3333

34-
# For everything
34+
# For file I/O helpers (Biopython-backed)
35+
pip install kalign[io]
36+
37+
# For pandas + matplotlib analysis/visualization helpers
38+
pip install kalign[analysis]
39+
40+
# For all optional ecosystem integrations
3541
pip install kalign[all]
3642
```
3743

@@ -597,7 +603,7 @@ aligned, stats, outliers = quality_control_alignment(sequences, ids)
597603

598604
Now that you're familiar with the basics, explore these advanced topics:
599605

600-
1. **[Ecosystem Integration Guide](python-ecosystem.md)** - Deep dive into Biopython and scikit-bio integration
606+
1. **[Ecosystem Integration Guide](python-ecosystem.md)** - Deep dive into Biopython, scikit-bio, pandas, and matplotlib integration
601607
2. **[Performance Tuning Guide](python-performance.md)** - Optimize for large-scale alignments
602608
3. **[API Reference](python-api.md)** - Complete function documentation
603609
4. **[Troubleshooting Guide](python-troubleshooting.md)** - Common issues and solutions
@@ -623,4 +629,4 @@ help(kalign.align)
623629
help(kalign.utils.alignment_stats)
624630
```
625631

626-
Happy aligning! 🧬✨
632+
Happy aligning! 🧬✨

python-kalign/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313
from . import _core, io, utils
1414

15-
__version__ = "3.4.5"
15+
try:
16+
from importlib.metadata import PackageNotFoundError, version as _dist_version
17+
18+
__version__ = _dist_version("kalign")
19+
except Exception:
20+
__version__ = "3.4.5"
1621
__author__ = "Timo Lassmann"
1722
__email__ = "timo.lassmann@telethonkids.org.au"
1823

0 commit comments

Comments
 (0)