Skip to main content

Setuptools extension for CalVer package versions

Project description

CalVer

The calver package is a setuptools extension for automatically defining your Python package version as a calendar version.

Usage

First, ensure calver is present during the project's build step by specifying it as one of the build requirements:

pyproject.toml:

[build-system]
requires = ["setuptools>=42", "calver"]

To enable generating the version automatically based on the date, add the following to setup.py:

setup.py:

from setuptools import setup

setup(
    ...
    use_calver=True,
    setup_requires=['calver'],
    ...
)

You can test that it is working with:

$ python setup.py --version
2020.6.16

Configuration

By default, when setting use_calver=True, it uses the following to generate the version string:

>>> import datetime
>>> datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y.%m.%d")
2020.6.16

You can override the format string by passing it instead of True:

setup.py:

from setuptools import setup

setup(
    ...
    use_calver="%Y.%m.%d.%H.%M",
    setup_requires=['calver'],
    ...
)

You can override the current date/time by passing the environment variable SOURCE_DATE_EPOCH, which should be a Unix timestamp in seconds. This is useful for reproducible builds (see https://reproducible-builds.org/docs/source-date-epoch/):

env SOURCE_DATE_EPOCH=1743428011000 python setup.py --version

You can override this entirely by passing a callable instead, which will be called with no arguments at build time:

setup.py:

import datetime
from setuptools import setup

def long_now_version():
    now = datetime.datetime.now(tz=datetime.timezone.utc)
    return now.strftime("%Y").zfill(5) + "." + now.strftime("%m.%d")

setup(
    ...
    use_calver=long_now_version,
    setup_requires=['calver'],
    ...
)

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

calver-2025.4.17.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

calver-2025.4.17-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file calver-2025.4.17.tar.gz.

File metadata

  • Download URL: calver-2025.4.17.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for calver-2025.4.17.tar.gz
Algorithm Hash digest
SHA256 460702737d620f5c3d4175450485180a1b7f7a422c5db0e6af3e655c7395ec7e
MD5 b02f51c61083eb5bd1b84218ec2fffd3
BLAKE2b-256 4f1e6cdde2a9cbd1bd2fad6fab0d005b1c10b4161823656ddb19ccc3adcbd5af

See more details on using hashes here.

Provenance

The following attestation bundles were made for calver-2025.4.17.tar.gz:

Publisher: release.yml on di/calver

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

File details

Details for the file calver-2025.4.17-py3-none-any.whl.

File metadata

  • Download URL: calver-2025.4.17-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.12.9

File hashes

Hashes for calver-2025.4.17-py3-none-any.whl
Algorithm Hash digest
SHA256 82f0efe7f71c28167af5ed9712e0d9d6272eb0817acbbf852b8b2404666a0cf2
MD5 543b5bd222dc7d2d69fec4a5eb08d499
BLAKE2b-256 4b6870db15cada0c4c3a17c6e44d906e13e32ee7467b133a04bc555d91aded16

See more details on using hashes here.

Provenance

The following attestation bundles were made for calver-2025.4.17-py3-none-any.whl:

Publisher: release.yml on di/calver

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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page