gen_devcontainer_json.py 2.05 KB
Newer Older
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
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""
Script to generate devcontainer.json files for different frameworks using Jinja2 template.
"""

from datetime import datetime
from pathlib import Path

from jinja2 import Environment, FileSystemLoader


def main():
    """Generate devcontainer.json files for different frameworks."""
    # Define the frameworks to generate
    frameworks = ["vllm", "sglang", "trtllm"]

    # Get the current directory (where this script is located)
    script_dir = Path(__file__).parent

    # Setup Jinja2 environment
    env = Environment(loader=FileSystemLoader(script_dir))
    template = env.get_template("devcontainer.json.j2")

    # Generate devcontainer.json for each framework
    for framework in frameworks:
        # Create the target directory
        target_dir = script_dir / framework
        target_dir.mkdir(exist_ok=True)

        # Render the template with framework-specific values
        current_year = datetime.now().year
        rendered_content = template.render(
            framework=framework, current_year=current_year
        )

        # Add auto-generated warning to the beginning of the file
        warning_comment = """// AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
// This file was generated from devcontainer.json.j2
// To make changes, edit the .j2 template and run gen_devcontainer_json.py
"""

        # Insert warning after the opening brace
        lines = rendered_content.split("\n")
        if lines[0].strip() == "{":
            lines.insert(1, warning_comment.rstrip())
            rendered_content = "\n".join(lines)

        # Write the rendered content to the target file
        target_file = target_dir / "devcontainer.json"
        with open(target_file, "w") as f:
            f.write(rendered_content)

        print(f"Generated {target_file}")

    print(
        f"Successfully generated devcontainer.json files for: {', '.join(frameworks)}"
    )


if __name__ == "__main__":
    main()