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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatch_env_plus-1.0.1.tar.gz.
File metadata
- Download URL: hatch_env_plus-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f8aa5437746b9557384df264a0335d5fa0975661f84272780272fc5bc64da8d
|
|
| MD5 |
65f1a91b25b310613a32c6986c147d24
|
|
| BLAKE2b-256 |
0a6b070354f08443b23970eea07f3b0a4107690c990c8ee8b3a8f7d96d7b9918
|
Provenance
The following attestation bundles were made for hatch_env_plus-1.0.1.tar.gz:
Publisher:
publish.yml on jenskeiner/hatch-env-plus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_env_plus-1.0.1.tar.gz -
Subject digest:
3f8aa5437746b9557384df264a0335d5fa0975661f84272780272fc5bc64da8d - Sigstore transparency entry: 919097369
- Sigstore integration time:
-
Permalink:
jenskeiner/hatch-env-plus@1c397aa5ba040592af7f5552f72a99a03d1308a1 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/jenskeiner
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1c397aa5ba040592af7f5552f72a99a03d1308a1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hatch_env_plus-1.0.1-py3-none-any.whl.
File metadata
- Download URL: hatch_env_plus-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7bfb376a8574c5c64b39ef75cd6698c6db7d16b34f785828cddbd99e7da2fd3
|
|
| MD5 |
e9f66101c88adaf197d19e4e38ef3c82
|
|
| BLAKE2b-256 |
7b9fad46e83914b2b0c006f57cdaba4af642e030845660915957ed60026b8d46
|
Provenance
The following attestation bundles were made for hatch_env_plus-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on jenskeiner/hatch-env-plus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_env_plus-1.0.1-py3-none-any.whl -
Subject digest:
b7bfb376a8574c5c64b39ef75cd6698c6db7d16b34f785828cddbd99e7da2fd3 - Sigstore transparency entry: 919097370
- Sigstore integration time:
-
Permalink:
jenskeiner/hatch-env-plus@1c397aa5ba040592af7f5552f72a99a03d1308a1 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/jenskeiner
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1c397aa5ba040592af7f5552f72a99a03d1308a1 -
Trigger Event:
release
-
Statement type: