Skip to content

Commit

Permalink
Configure PDM to avoid +local version suffix on clean builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Apr 5, 2024
1 parent 179c4e6 commit 4c0935d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pdm_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from datetime import datetime
from pdm.backend.hooks.version import SCMVersion


def format_version(version: SCMVersion) -> str:
major, minor = (int(n) for n in str(version.version).split(".")[:2])
dirty = f"+{datetime.utcnow():%Y%m%d.%H%M%S}" if version.dirty else ""
if version.distance is None:
return f"{major}.{minor}{dirty}"
else:
return f"{major}.{minor}.dev{version.distance}{dirty}"
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tool.pdm.version]
source = "scm"
version_format = "pdm_build:format_version"

[project]
dynamic = ["version"]
Expand All @@ -20,7 +21,8 @@ dependencies = [
]

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

[tool.pdm.build]
Expand Down

0 comments on commit 4c0935d

Please sign in to comment.