Skip to main content

CI friendly setuptools-scm hooks

Project description

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.
  • Environment Variable Overrides: Allows specifying a version directly via an environment variable, useful for specific CI/CD scenarios.
  • pyproject.toml Integration: All custom versioning logic and configurations are managed declaratively in your pyproject.toml file, leveraging pyprojectr for robust parsing.

This allows for consistent and predictable versioning across different development stages and CI environments, making it easier to track builds and releases.

How to Use it as a Developer

To integrate setuptools-scmx into your project, follow these steps:

1. Installation

First, ensure setuptools-scmx and its dependencies are installed. You typically add it to your build-system.requires in pyproject.toml.

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

[project]
name = "your-project-name"
dynamic = ["version"]
# ... other project metadata

2. Configure setuptools-scm

In your pyproject.toml, configure setuptools-scm to use a custom version_scheme and local_scheme. You will point version_scheme to the entry point provided by setuptools-scmx.

# pyproject.toml
[tool.setuptools_scm]
version_scheme = "setuptools_scmx:version_scheme" # Use the custom scheme
local_scheme = "no-local-version" # Or 'node-and-date' as per your preference

3. Configure setuptools-scmx

Define your custom branch-aware versioning rules and other schemes under [tool.setuptools-scmx].

# pyproject.toml
[tool.setuptools-scmx]
scheme = "branch-scheme" # This tells setuptools-scmx to use the branch-aware logic

[tool.setuptools-scmx.branch-scheme]
labels = [
  # Branches 'main' and 'master' will get a '.rc' label
  { name = "rc", branches = ["main", "master"] },
  # The 'develop' branch will get a '.dev' label
  { name = "dev", branches = ["develop"] },
  # Branches starting with 'feature/' will get an '.alpha' label
  { name = "alpha", branches = ["feature/.*"] }, # Example: feature/new-feature -> 1.2.3.alpha.4
  # The 'hotfix' branch will get a '.post' label
  { name = "post", branches = ["hotfix"] },
]

# You can also define environment variable based schemes
[tool.setuptools-scmx.env-schemes]
# If the environment variable SCMX_VERSION_OVERRIDE is set, its value will be used as the version.
custom = { version = "SCMX_VERSION_OVERRIDE" }

Explanation of [tool.setuptools-scmx.branch-scheme.labels]

Each entry in the labels list defines a rule:

  • name: The string to append to the version number (e.g., rc, dev, alpha, post). This should generally conform to PEP 440 pre-release identifiers.
  • branches: A list of branch name regexes or exact branch names to match. If the current Git branch matches any of these, the corresponding label will be used.

Note: The setuptools-scmx project's own pyproject.toml uses a simpler labels configuration for demonstration purposes.

Explanation of [tool.setuptools-scmx.env-schemes]

This section allows you to define version schemes that are activated by the presence and value of environment variables.

  • custom: This is a user-defined name for the scheme.
  • version = "ENV_VAR_NAME": If the environment variable ENV_VAR_NAME is set, its value will be used as the project's version, overriding any Git-based versioning. This is particularly useful in CI/CD pipelines where you might want to force a specific build version.

Versioning Behavior Examples:

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

  • On a Tag (git checkout 1.0.0):

    • Version: 1.0.0 (exact)
  • On main branch:

    • Version: 1.0.1.rc.5 (next version 1.0.1, label rc, distance 5)
  • On develop branch:

    • Version: 1.0.1.dev.5 (next version 1.0.1, label dev, distance 5)
  • On feature/my-new-feature branch:

    • Version: 1.0.1.alpha.5 (next version 1.0.1, label alpha, distance 5)
  • On hotfix branch:

    • Version: 1.0.1.post.5 (next version 1.0.1, label post, distance 5)
  • On an unmapped branch (e.g., bugfix/issue-123):

    • Version: 1.0.1.bugfix-issue-123.5 (next version 1.0.1, normalized branch name as label, distance 5)
  • With SCMX_VERSION_OVERRIDE="2.0.0-beta.1" environment variable set:

    • Version: 2.0.0-beta.1 (overrides Git-based versioning)

This setup provides a powerful and flexible way to manage your project's versioning in a CI/CD environment.

Project details


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.2.tar.gz (31.0 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.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for setuptools_scmx-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1ddba7373211f47b3a5cb39e0a538837509b4b4ec528df2b8b43965c33514d5b
MD5 60835b9c598c381bc6601a8c07e45d3e
BLAKE2b-256 64aa3f1e1db7e842b930770dc0224fc1e464a4cad4149738e51c64e4c72cacdb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for setuptools_scmx-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c4947bf1161e2ccd1be06990be3012efa5a084beb7c05631bd48976b65c4cb3e
MD5 7e9b9aba8752f33f6d972e66af286691
BLAKE2b-256 7cfc571db8714502b9586127b9c9929f3c5d7c7f82934073d7025ac65dc5ae29

See more details on using hashes here.

Supported by

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