-
Notifications
You must be signed in to change notification settings - Fork 5
/
hatch_build.py
37 lines (28 loc) · 1.13 KB
/
hatch_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
36
37
import os
import subprocess
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
def get_git_rev():
try:
new_cwd = os.path.abspath(os.path.dirname(__file__))
rev_raw = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=new_cwd)
return rev_raw.decode("utf8").strip()
except Exception:
return "unknown"
def write_baked_revision(dest_dir):
baked_dest = os.path.join(dest_dir, '_baked_revision.py')
os.makedirs(dest_dir, exist_ok=True)
with open(baked_dest, "w") as f:
f.write(r'revision = "%s"' % get_git_rev())
class CustomBuildHook(BuildHookInterface):
PLUGIN_NAME = 'custom'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def initialize(self, version, build_data):
here = os.path.abspath(os.path.dirname(__file__))
if not os.path.exists(os.path.join(here, '.git')):
return # not running from git
if self.target_name not in ["wheel", "sdist"]:
return # something else
write_baked_revision(
os.path.join(here, "src", "libertem_live")
)