File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ from datetime import datetime
3
+ from pdm .backend .hooks .version import SCMVersion
1
4
from pdm .backend ._vendor .packaging .version import Version
2
5
3
6
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
+
7
16
def pdm_build_initialize (context ):
8
17
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).
9
22
if version .is_prerelease :
10
23
url_version = "latest"
11
24
else :
Original file line number Diff line number Diff line change 2
2
3
3
[tool .pdm .version ]
4
4
source = " scm"
5
+ version_format = " pdm_build:format_version"
5
6
6
7
[project ]
7
8
dynamic = [" version" ]
@@ -39,7 +40,7 @@ amaranth-rpc = "amaranth.rpc:main"
39
40
# Build system configuration
40
41
41
42
[build-system ]
42
- requires = [" pdm-backend" ]
43
+ requires = [" pdm-backend @ git+https://github.com/pdm-project/pdm-backend " ]
43
44
build-backend = " pdm.backend"
44
45
45
46
[tool .pdm ]
You can’t perform that action at this time.
0 commit comments