-
Notifications
You must be signed in to change notification settings - Fork 175
/
pdm_build.py
26 lines (21 loc) · 1.05 KB
/
pdm_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from datetime import datetime
from pdm.backend.hooks.version import SCMVersion
from pdm.backend._vendor.packaging.version import Version
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:
url_version = f"v{version}"
context.config.metadata["urls"]["Documentation"] += url_version