Skip to main content

Easy date-based versioning for Python projects

Project description

buildsys-dateversion

Easy date-based versioning for Python projects.

PyPI

Overview

buildsys-dateversion is a Python build system extension to automatically set a version string based on the current date/time as a project builds. Once enabled, your project's version number while building a source distribution or wheel will be automatically generated.

At minimum, the version string will contain the current year & month. If the generated version would clash with a version already released to PyPI, additional date/time portions are added to the string (i.e. day, hour, minute) until the clash is resolved.

buildsys-dateversion is a PEP 517 compliant build system and can be used with other PEP 517 implementations, such as setuptools and flit.

Here's an example of a sequence of version strings which may result from using buildsys-dateversion for a project:

Release is made at... Version string
2025-03-25 12:00 2025.3
2025-03-31 12:00 2025.3.31
2025-03-31 13:00 2025.3.31.13
2025-03-31 14:00 2025.3.31.14
2025-03-31 14:30 2025.3.31.14.30
2025-03-31 17:30 2025.3.31.17
2025-04-02 12:00 2025.4

Usage

Prerequisites

Your project must use pyproject.toml.

Your project's sources must contain a .py file with a line of the form:

__version__ = "0"

(The specific value for __version__ does not matter, as it will be overwritten during build, but "0" is recommended.)

Installation (setuptools)

Your pyproject.toml should look like this:

[project]
name = "myproject"
dynamic = ["version"]

[tool.setuptools.dynamic]
version = {attr = "myproject.__version__"}

[build-system]
requires = ["buildsys-dateversion"]
build-backend = "buildsys_dateversion"

(Note that buildsys-dateversion uses pip-compatible build-system defaults; this is the reason why it is not necessary to explicitly configure setuptools as a build backend or to list it in requires, as is necessary in the flit example below.)

Installation (flit)

Your pyproject.toml should look like this:

[project]
name = "myproject"
dynamic = ["version", "description"]

[build-system]
requires = ["buildsys-dateversion", "flit_core >=3.2,<4"]
build-backend = "buildsys_dateversion"

[tool.buildsys-dateversion]
# buildsys-dateversion only handles generating the version number.
# This tells it which build backend should be used for all the
# other build steps.
build-backend = "flit_core.buildapi"

Installation (other)

buildsys-dateversion is theoretically compatible with other PEP 517 build backends (though only setuptools and flit are tested). The primary requirement is that the build backend must support a dynamic version based on a __version__ attr in the project, as both setuptools and flit do.

[project]
name = "myproject"

# The chosen PEP 517 backend must support a dynamic version.
dynamic = ["version"]

[build-system]
# Require buildsys-dateversion + the build backend.
requires = ["buildsys-dateversion", "some_build_backend"]
build-backend = "buildsys_dateversion"

[tool.buildsys-dateversion]
# This should be a module implementing the PEP 517 hooks.
build-backend = "some_build_backend.hooks"

Configuration reference

The following values can be set in pyproject.toml, in the tool.buildsys-dateversion table.

[tool.buildsys-dateversion]
# Should point at a module implementing PEP 517 hooks.
# If omitted, default is "setuptools.build_meta:__legacy__"
build-backend = "some_build_backend.hooks"

# A comment added on patched __version__ lines.
version-marker = "generated by buildsys-dateversion"

# Path to the file containing __version__.
# If omitted, the file is located automatically.
version-path = "src/mymodule/__init__.py"

Caveats

Take note of the following before using this project:

  • The setting of the __version__ attribute currently relies on temporarily patching files in the source tree, which has some implications:
    • The source tree during a build must not be read-only.
    • If the build process is interrupted, the file defining __version__ might not be restored to its original state.
  • buildsys-dateversion is implemented as a PEP 517 build backend which wraps another PEP 517 build backend. However, this wrapping is not perfect and might result in subtle behavior differences from the underlying backend.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

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

buildsys_dateversion-2025.11.tar.gz (46.4 kB view details)

Uploaded Source

Built Distribution

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

buildsys_dateversion-2025.11-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file buildsys_dateversion-2025.11.tar.gz.

File metadata

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

File hashes

Hashes for buildsys_dateversion-2025.11.tar.gz
Algorithm Hash digest
SHA256 773f92e1b6fd0dd4eb5b4fa63ab1853feeaf381985b116e074bb811d122ca590
MD5 6b7195d320b3238fa1369bc75cf8f50d
BLAKE2b-256 41e7a9e617864061c9d7d6001bd4c7ffe25d1c770baee20bad27b1122d46663a

See more details on using hashes here.

Provenance

The following attestation bundles were made for buildsys_dateversion-2025.11.tar.gz:

Publisher: release.yml on rohanpm/buildsys-dateversion

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

File details

Details for the file buildsys_dateversion-2025.11-py3-none-any.whl.

File metadata

File hashes

Hashes for buildsys_dateversion-2025.11-py3-none-any.whl
Algorithm Hash digest
SHA256 1245014dd30d3a5cb673f123721b80e5b9cfe7bfeda2e378874646d313790e4e
MD5 24dd8230beeeb567c1ce9bffaad786b3
BLAKE2b-256 8eb441ab43a4f1f08d9ead2c18f6b25a852cab7b8a443c4197686ef6dd1b87b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for buildsys_dateversion-2025.11-py3-none-any.whl:

Publisher: release.yml on rohanpm/buildsys-dateversion

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