-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathhatch_build.py
More file actions
26 lines (21 loc) · 943 Bytes
/
hatch_build.py
File metadata and controls
26 lines (21 loc) · 943 Bytes
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 subprocess
from pathlib import Path
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomBuildHook(BuildHookInterface):
def initialize(self, version: str, build_data: dict) -> None:
# Always read from metadata — the `version` parameter receives the build
# target name ("editable", "standard", "wheel") rather than the actual
# version in most install modes.
version = self.metadata.version
try:
commit = subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"],
stderr=subprocess.DEVNULL,
text=True,
).strip()
except Exception:
commit = "unknown"
version_file = (
Path(self.root) / "src" / "expb" / "cli" / "version" / "_version.py"
)
version_file.write_text(f'__version__ = "{version}"\n__commit__ = "{commit}"\n')