From d664176c8fb5ae503b3b168d9ade85d3fd189608 Mon Sep 17 00:00:00 2001 From: Alex Bucknall Date: Thu, 19 Feb 2026 13:31:18 +0000 Subject: [PATCH] Use setuptools-scm for automatic version management Replace manual version management with setuptools-scm which derives the version from git tags at build time. This eliminates the need for a workflow to push version updates back to main (which required a PAT). - Add setuptools-scm as build dependency - Make version field dynamic in pyproject.toml - Update publish workflow to use setuptools-scm - Remove update-version.yml workflow Co-Authored-By: Claude Opus 4.5 --- .github/workflows/python-publish.yml | 10 ++++------ .github/workflows/update-version.yml | 29 ---------------------------- pyproject.toml | 6 ++++-- 3 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/update-version.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 2658f61..a5e9620 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,10 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Extract version from tag - run: echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV - - name: Set version from tag - run: sed -i "s/^version = \".*\"/version = \"$TAG_VERSION\"/" pyproject.toml + with: + fetch-depth: 0 # setuptools-scm needs full git history - name: Set up Python uses: actions/setup-python@v5 with: @@ -24,10 +22,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build twine + pip install build twine setuptools-scm - name: Verify version run: | - PACKAGE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") + PACKAGE_VERSION=$(python -m setuptools_scm) echo "Publishing version: $PACKAGE_VERSION" - name: Build and publish env: diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml deleted file mode 100644 index 1c8da88..0000000 --- a/.github/workflows/update-version.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Update Version - -on: - push: - tags: - - v* - -jobs: - update-version: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - with: - ref: main - token: ${{ secrets.NOTE_PYTHON_PUSH }} - - name: Extract version from tag - run: echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV - - name: Update pyproject.toml version - run: sed -i "s/^version = \".*\"/version = \"$TAG_VERSION\"/" pyproject.toml - - name: Commit and push version update - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git diff --exit-code pyproject.toml && echo "Version already up to date" && exit 0 - git add pyproject.toml - git commit -m "Bump version to $TAG_VERSION" - git push origin main diff --git a/pyproject.toml b/pyproject.toml index 697746a..67d0160 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["setuptools>=61.0"] +requires = ["setuptools>=61.0", "setuptools-scm"] build-backend = "setuptools.build_meta" [project] name = "note-python" -version = "2.1.4" +dynamic = ["version"] description = "Cross-platform Python Library for the Blues Wireless Notecard" authors = [ {name = "Blues Inc.", email = "support@blues.com"}, @@ -35,5 +35,7 @@ Repository = "https://github.com/blues/note-python" [tool.setuptools] packages = ["notecard"] +[tool.setuptools_scm] + [tool.pytest.ini_options] addopts = "--ignore=test/hitl/"