Skip to content

Commit 3fbed68

Browse files
committed
pyproject: use .dev{distance}, not +{node}, for non-release builds.
At the moment this uses a git URL for pdm-backend because required PDM functionality (pdm-project/pdm-backend#217) is not released yet.
1 parent 8bf4f77 commit 3fbed68

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.github/workflows/main.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ jobs:
132132
steps:
133133
- name: Check out source code
134134
uses: actions/checkout@v4
135+
with:
136+
fetch-depth: 0
135137
- name: Set up PDM
136138
uses: pdm-project/setup-pdm@v4
137139
with:
@@ -260,4 +262,4 @@ jobs:
260262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
261263
with:
262264
tag_name: ${{ github.ref_name }}
263-
release_name: ${{ steps.metadata.outputs.name }}
265+
release_name: ${{ steps.metadata.outputs.name }}

pdm_build.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
import os
2+
from datetime import datetime
3+
from pdm.backend.hooks.version import SCMVersion
14
from pdm.backend._vendor.packaging.version import Version
25

36

4-
# This is done in a PDM build hook without specifying `dynamic = [..., "version"]` to put all
5-
# of the static metadata into pyproject.toml. Tools other than PDM will not execute this script
6-
# and will use the generic version of the documentation URL (which redirects to /latest).
7+
def format_version(version: SCMVersion) -> str:
8+
major, minor, patch = (int(n) for n in str(version.version).split(".")[:3])
9+
dirty = f"+{datetime.utcnow():%Y%m%d.%H%M%S}" if version.dirty else ""
10+
if version.distance is None:
11+
return f"{major}.{minor}.{patch}{dirty}"
12+
else:
13+
return f"{major}.{minor}.{patch}.dev{version.distance}{dirty}"
14+
15+
716
def pdm_build_initialize(context):
817
version = Version(context.config.metadata["version"])
18+
19+
# This is done in a PDM build hook without specifying `dynamic = [..., "version"]` to put all
20+
# of the static metadata into pyproject.toml. Tools other than PDM will not execute this script
21+
# and will use the generic version of the documentation URL (which redirects to /latest).
922
if version.is_prerelease:
1023
url_version = "latest"
1124
else:

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[tool.pdm.version]
44
source = "scm"
5+
version_format = "pdm_build:format_version"
56

67
[project]
78
dynamic = ["version"]
@@ -39,7 +40,7 @@ amaranth-rpc = "amaranth.rpc:main"
3940
# Build system configuration
4041

4142
[build-system]
42-
requires = ["pdm-backend"]
43+
requires = ["pdm-backend @ git+https://github.com/pdm-project/pdm-backend@885bc8d9b75d068a34b2df86c6324c5fdf5c0cc8"]
4344
build-backend = "pdm.backend"
4445

4546
[tool.pdm]

0 commit comments

Comments
 (0)