Skip to main content

A version source for Hatchling that reads the version from a given environment variable, but also allows for a fallback if the variable is not populated.

Project description

Hatchling Environment Variable Version Source

A Hatchling version source plugin that reads the version from an environment variable with a configurable fallback value, since the built-in env version source does not allow to define a fallback.

Installation

Add the package as a build dependency to your pyproject.toml:

[build-system]
requires = ["hatchling", "hatch-env-plus"]
build-backend = "hatchling.build"

Configuration

Configure a dynamic version source in the project section of pyproject.toml:

[project]
dynamic = ["version"]

Make sure you don't specify the version directly in the project section, or the dynamic version source may not be picked up.

Then, configure the version source:

[tool.hatch.version]
source = "env-plus"
variable = "PACKAGE_VERSION"  # optional, default shown
fallback = "0.0.0dev0"  # optional, default shown

Use the variable field to set the environment variable to use, and set fallback to the desired fallback version.

Note: An empty string, whether from the configured environment variable or from the fallback, is an undefined version.

If you explicitly set the configured environment variable to the empty string, your build will fail as no valid version is set. If you explicitly set fallback to an empty string, your build will fail when the configured environment variable is not set. This is the default behavior of Hatchling's built-in enviroment variable version source env.

Usage

Build your project with the desired version by setting the environment variable:

PACKAGE_VERSION=2.0.0 uv build
# Builds package version "2.0.0".

Leave the environment variable empty to use the default:

uv build
# Builds package version 0.0.0dev0 (or configured fallback).

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

hatch_env_plus-1.0.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

hatch_env_plus-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file hatch_env_plus-1.0.0.tar.gz.

File metadata

  • Download URL: hatch_env_plus-1.0.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hatch_env_plus-1.0.0.tar.gz
Algorithm Hash digest
SHA256 55780e71c640a4eb06e14ad052d1c4bc88a0ebf771f97abd2036271430330f06
MD5 f4473f6a3db1631a95555b17eaf9a34e
BLAKE2b-256 a620fa8ff7095a28a0ac468030dce79edd89785d6cfd3124267ff9905544c0aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_env_plus-1.0.0.tar.gz:

Publisher: publish.yml on jenskeiner/hatch-env-plus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hatch_env_plus-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hatch_env_plus-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hatch_env_plus-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69462014fb2cef0f8df2bd598ccc3b6b3c62e22ac8ab2ec7f2888eb19a8d5fe4
MD5 b439414b01389d934140d671a5d6f0ba
BLAKE2b-256 6ceedc416c6c24ed16fda2a074a8bbcb9da74d676638a7d874239fefa730c91e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_env_plus-1.0.0-py3-none-any.whl:

Publisher: publish.yml on jenskeiner/hatch-env-plus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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