forked from LagrangeDev/lagrange-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdm_build.py
35 lines (28 loc) · 783 Bytes
/
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
27
28
29
30
31
32
33
34
35
"""
PDM Build Script
auto bump version to lagrange/version.py
2024/3/18
"""
import subprocess
import shutil
from pdm.backend.hooks import Context
git = shutil.which("git")
rev = ""
def pdm_build_hook_enabled(_context: Context) -> bool:
global rev
if not git:
return False
with subprocess.Popen(
[git, "rev-parse", "--short", "HEAD"],
stdout=subprocess.PIPE,
) as proc:
rev = proc.stdout.read().strip().decode()
if rev is None:
return False
return True
def pdm_build_initialize(context: Context):
ver = context.config.metadata.get("version")
with open("lagrange/version.py", "w") as f:
if ver is None:
ver = "0.0.0"
f.write(f"__version__ = '{ver}{'-' if rev else ''}{rev}'\n")