Skip to main content

setuptools-scmx

Project Description

setuptools-scmx is a Python package designed to extend setuptools-scm with CI-friendly versioning schemes. It provides flexible, configuration-driven version management tailored for continuous integration and delivery workflows, allowing developers to define custom versioning logic based on Git branch names and tags directly within pyproject.toml.

What it Does

This package enhances the standard setuptools-scm functionality by introducing:

  • Custom Versioning Schemes: Define how your project's version is determined based on its Git state.
  • Branch-Aware Versioning: Differentiate version numbers based on the current Git branch (e.g., main, develop, feature/xyz).
  • Exact Tag Versions: Ensures that builds from Git tags always result in the exact tag version, without any additional suffixes.
  • CI Platform Integration: Built-in support for GitHub Actions, GitLab CI, and Jenkins environment variables.
  • Environment Variable Overrides: Allows specifying a version directly via an environment variable, with support for regex-based extraction.
  • pyproject.toml Integration: All custom versioning logic and configurations are managed declaratively in your pyproject.toml file, leveraging pyprojectr for robust parsing.

How to Use it as a Developer

1. Installation

Add setuptools-scmx to your build-system.requires in pyproject.toml.

# pyproject.toml
[build-system]
requires = [
    "setuptools>=80",
    "setuptools-scm[toml]",
    "setuptools-scmx",
]
build-backend = "setuptools.build_meta"

[project]
name = "your-project-name"
dynamic = ["version"]

2. Configure setuptools-scm

Configure setuptools-scm to use the setuptools_scmx entry point.

# pyproject.toml
[tool.setuptools_scm]
version_scheme = "setuptools_scmx:version_scheme"
local_scheme = "no-local-version"

3. Configure setuptools-scmx

Define your rules under [tool.setuptools-scmx].

# pyproject.toml
[tool.setuptools-scmx]
scheme = "branch-scheme" # Required to enable branch-aware logic
env_scheme = "github"    # Optional: 'custom' (default), 'github', 'gitlab', 'jenkins'

[tool.setuptools-scmx.branch-scheme]
labels = [
  { name = "rc", branches = ["main", "master"] },
  { name = "dev", branches = ["develop"] },
  { name = "alpha", branches = ["feature/.*"] },
  { name = "post", branches = ["hotfix"] },
]

Supported Labels

The name field in labels supports standard PEP 440 pre-release identifiers:

  • rc, beta, alpha, dev, post

CI & Environment Schemes

setuptools-scmx can automatically detect branch and build information from CI environments.

env_scheme Source Platform Automatic Branch Detection Automatic Build Number
github GitHub Actions GITHUB_REF_NAME GITHUB_RUN_ID
gitlab GitLab CI CI_COMMIT_REF_NAME CI_JOB_ID
jenkins Jenkins BRANCH_NAME BUILD_NUMBER
custom Any Manual via env-schemes.custom Manual via env-schemes.custom

Advanced Environment Configuration

You can customize how versions are extracted from environment variables.

[tool.setuptools-scmx.env-schemes.custom]
version = "SCMX_VERSION_OVERRIDE"
# If true (default), extracts version using the regex below
extract_version_with_regex = true
# Default regex extracts digits and dots (e.g., "1.2.3" from "v1.2.3-beta")
version_regex = "([\\d.]+)"

Environment Variables

  • SCMX_PYPROJECT_PATH: Path to the pyproject.toml file (defaults to pyproject.toml in the current directory). Useful for monorepos.
  • SCMX_VERSION_OVERRIDE: Default variable used by the custom scheme to force a specific version.

Versioning Behavior Examples

Assuming the last tag is 1.0.0 and there are 5 commits since (distance=5):

  • On a Tag: 1.0.0
  • On main branch: 1.0.1.rc.5
  • On develop branch: 1.0.1.dev.5
  • On feature/xyz: 1.0.1.alpha.5
  • On hotfix branch: 1.0.1.post.5
  • On an unmapped branch (bugfix/123): 1.0.1+bugfix-123.5
  • With SCMX_VERSION_OVERRIDE="2.0.0": 2.0.0 (overrides Git state)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

setuptools_scmx-0.1.4.tar.gz (56.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

setuptools_scmx-0.1.4-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file setuptools_scmx-0.1.4.tar.gz.

File metadata

  • Download URL: setuptools_scmx-0.1.4.tar.gz
  • Upload date:
  • Size: 56.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for setuptools_scmx-0.1.4.tar.gz
Algorithm Hash digest
SHA256 47df3fcc3ed3cea908597fd5983468db1598cf631a6147e63a3c424b329a529c
MD5 f692e5f858ab2c844489fa2a65d9c4ae
BLAKE2b-256 f0fffd172db1e169d4fcf1617ee6b1a42c9bea7297a0f6db0afadd651e7912af

See more details on using hashes here.

File details

Details for the file setuptools_scmx-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for setuptools_scmx-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fb925f395b6eaf320561b80eeddfd7f60318780a9e48d7e6edfa5d40473731d9
MD5 37e840d295760767d204501f8277ecfa
BLAKE2b-256 d6ef273c4e120121ca6fe54e9257a7a8cc56e3ab723c9066f14d10c0138e4cc7

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5

2 files

This release

0.1.4 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page