-
Notifications
You must be signed in to change notification settings - Fork 895
Expand file tree
/
Copy pathhatch_build.py
More file actions
52 lines (43 loc) · 1.76 KB
/
hatch_build.py
File metadata and controls
52 lines (43 loc) · 1.76 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import os
import subprocess
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
COMPONENTS = [
"frontend/src/dynamo/frontend",
"backends/vllm/src/dynamo/vllm",
"backends/sglang/src/dynamo/sglang",
"backends/trtllm/src/dynamo/trtllm",
"backends/mocker/src/dynamo/mocker",
"backends/llama_cpp/src/dynamo/llama_cpp",
"planner/src/dynamo/planner",
]
class VersionWriterHook(BuildHookInterface):
"""
A Hatch build hook to write the project version to a file.
"""
def initialize(self, version, build_data):
"""
This method is called before the build process begins.
"""
full_version = self.metadata.version
try:
result = subprocess.run(
["git", "rev-parse", "--short", "HEAD"],
cwd=self.root,
capture_output=True,
text=True,
check=True,
)
git_version = result.stdout.strip()
if git_version:
full_version += f"+{git_version}"
except (subprocess.CalledProcessError, FileNotFoundError):
pass
version_content = f'# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n\n# This file is auto-generated at build time\n__version__ = "{full_version}"\n'
for component in COMPONENTS:
version_file_path = os.path.join(
self.root, f"components/{component}/_version.py"
)
with open(version_file_path, "w") as f:
f.write(version_content)