diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e88564c..3f5b61d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,10 @@ on: push: tags: ["v*"] workflow_dispatch: + inputs: + version: + description: "Version to build (e.g. 1.2.3, without the v prefix)" + required: true jobs: build: @@ -14,6 +18,17 @@ jobs: python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 + - name: Set version from tag + shell: bash + run: | + VERSION="${{ github.event.inputs.version || github.ref_name }}" + VERSION="${VERSION#v}" + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version: '$VERSION'. Provide a semver version via the workflow_dispatch input or push a v* tag." + exit 1 + fi + sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml + rm -f Cargo.toml.bak - uses: dtolnay/rust-toolchain@1.85.0 - uses: PyO3/maturin-action@v1 with: @@ -28,6 +43,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set version from tag + shell: bash + run: | + VERSION="${{ github.event.inputs.version || github.ref_name }}" + VERSION="${VERSION#v}" + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version: '$VERSION'. Provide a semver version via the workflow_dispatch input or push a v* tag." + exit 1 + fi + sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml + rm -f Cargo.toml.bak - uses: PyO3/maturin-action@v1 with: command: sdist diff --git a/pyproject.toml b/pyproject.toml index d59c0c3..1e90735 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "rustypca" -version = "0.1.0" +dynamic = ["version"] description = "Probabilistic PCA with missing value support using Rust and PyO3" readme = {file = "README.md", content-type = "text/markdown"} license = {file = "LICENSE"} diff --git a/rustypca/__init__.py b/rustypca/__init__.py index 8d0d2ce..fda937c 100644 --- a/rustypca/__init__.py +++ b/rustypca/__init__.py @@ -1,6 +1,12 @@ """Probabilistic Principal Component Analysis with missing value support.""" +from importlib.metadata import PackageNotFoundError, version + from ._rustypca import PPCA __all__ = ["PPCA"] -__version__ = "0.1.0" + +try: + __version__ = version("rustypca") +except PackageNotFoundError: + __version__ = "unknown"