-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhatch_build.py
More file actions
31 lines (26 loc) · 1.09 KB
/
hatch_build.py
File metadata and controls
31 lines (26 loc) · 1.09 KB
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
"""Hatchling build hook to embed git commit at build time."""
import subprocess
from pathlib import Path
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomBuildHook(BuildHookInterface):
"""Build hook to capture git commit hash."""
def initialize(self, version, build_data):
"""Run before the build starts."""
# Get git commit hash
try:
result = subprocess.run(
["git", "rev-parse", "--short=7", "HEAD"],
capture_output=True,
text=True,
timeout=5,
check=False,
)
if result.returncode == 0:
commit = result.stdout.strip()
if commit:
# Write commit to a file that will be included in the package
version_file = Path(self.root) / "dropkit" / "_version.txt"
version_file.write_text(commit)
print(f"Embedded git commit: {commit}")
except Exception as e:
print(f"Warning: Could not capture git commit: {e}")