hatch_build.py 1.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
#  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 = [
10
    "common",
11
12
13
14
15
16
17
    "frontend",
    "vllm",
    "sglang",
    "trtllm",
    "mocker",
    "llama_cpp",
    "planner",
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
]


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(
50
                self.root, f"components/src/dynamo/{component}/_version.py"
51
52
53
            )
            with open(version_file_path, "w") as f:
                f.write(version_content)