Skip to content

Commit

Permalink
pyproject: use .dev{distance}, not +{node}, for non-release builds.
Browse files Browse the repository at this point in the history
At the moment this uses a git URL for pdm-backend because required PDM
functionality (pdm-project/pdm-backend#217) is not released yet.
  • Loading branch information
whitequark committed Apr 13, 2024
1 parent 8bf4f77 commit 4d6eec4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions pdm_build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import os
from datetime import datetime
from pdm.backend.hooks.version import SCMVersion
from pdm.backend._vendor.packaging.version import Version


# This is done in a PDM build hook without specifying `dynamic = [..., "version"]` to put all
# of the static metadata into pyproject.toml. Tools other than PDM will not execute this script
# and will use the generic version of the documentation URL (which redirects to /latest).
def format_version(version: SCMVersion) -> str:
major, minor, patch = (int(n) for n in str(version.version).split(".")[:3])
dirty = f"+{datetime.utcnow():%Y%m%d.%H%M%S}" if version.dirty else ""
if version.distance is None:
return f"{major}.{minor}.{patch}{dirty}"
else:
return f"{major}.{minor}.{patch}.dev{version.distance}{dirty}"


def pdm_build_initialize(context):
version = Version(context.config.metadata["version"])

# This is done in a PDM build hook without specifying `dynamic = [..., "version"]` to put all
# of the static metadata into pyproject.toml. Tools other than PDM will not execute this script
# and will use the generic version of the documentation URL (which redirects to /latest).
if version.is_prerelease:
url_version = "latest"
else:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[tool.pdm.version]
source = "scm"
version_format = "pdm_build:format_version"

[project]
dynamic = ["version"]
Expand Down Expand Up @@ -39,7 +40,7 @@ amaranth-rpc = "amaranth.rpc:main"
# Build system configuration

[build-system]
requires = ["pdm-backend"]
requires = ["pdm-backend @ git+https://github.com/pdm-project/pdm-backend"]
build-backend = "pdm.backend"

[tool.pdm]
Expand Down

0 comments on commit 4d6eec4

Please sign in to comment.