Skip to content

Conversation

@grahamking
Copy link
Contributor

@grahamking grahamking commented Aug 14, 2025

Version looks like this 0.4.0+3a3f5bf2 if you have git, 0.4.0 otherwise.

The --version flag should work on all components except sglang, because that handles arguments differently.

All components (including sglang) have the expected __version__ attribute at the top level.

Summary by CodeRabbit

  • New Features

    • Added a --version flag to frontend, planner, and multiple backends (vLLM, TRT-LLM, sglang, llama.cpp, mocker) to display component versions via the CLI.
  • Chores

    • Enhanced build process to auto-generate per-component version metadata used by the CLI.
    • Updated ignore rules to exclude generated version artifacts.
    • Minor formatting cleanups with no impact on behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Adds per-component version generation via a Hatch build hook that writes _version.py files, exposes version at package level across components, and introduces a --version CLI flag for multiple backends and tools. Also updates pyproject.toml to register the hook and adjusts .gitignore and some headers.

Changes

Cohort / File(s) Summary
Build and packaging
hatch_build.py, pyproject.toml, .gitignore
Adds custom Hatch build hook to generate components’ _version.py (with optional git short hash). Registers hook in pyproject. Ignores generated _version.py; minor formatting tweak.
Version export in packages
components/backends/*/src/dynamo/*/__init__.py (llama_cpp, mocker, sglang, trtllm, vllm), components/frontend/src/dynamo/frontend/__init__.py, components/planner/src/dynamo/planner/__init__.py
Imports and re-exports __version__ from ._version to package namespace; SPDX/header adjustments where noted.
CLI: --version flags
.../llama_cpp/main.py, .../mocker/main.py, .../trtllm/utils/trtllm_utils.py, .../vllm/args.py, components/frontend/src/dynamo/frontend/main.py, components/planner/src/dynamo/planner/utils/planner_core.py
Adds argparse --version option printing component-specific version strings; imports __version__ from corresponding package; no other logic changes.
Header updates only
subset within files above
License/SPDX header additions/removals/formatting; no behavioral impact.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant Hatch as Hatch Build
  participant Hook as VersionWriterHook
  participant FS as Filesystem

  Dev->>Hatch: build
  Hatch->>Hook: initialize(version, build_data)
  Hook->>Hook: compute full_version (+ git short hash if available)
  loop for each component
    Hook->>FS: write components/.../_version.py (__version__ = full_version)
  end
  Hook-->>Hatch: done
  Hatch-->>Dev: build artifacts
Loading
sequenceDiagram
  participant User
  participant CLI as Component CLI
  participant Pkg as dynamo.<component> (__init__)
  User->>CLI: run ... --version
  CLI->>Pkg: import __version__
  CLI-->>User: print "Dynamo <Component> {__version__}" and exit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

A rabbit taps the version drum,
Hatch writes notes that softly hum.
Each backend chirps “--version” bright,
Numbers twinkle in the night.
Commit-kissed strings, concise and clear—
We hop along, new prints to cheer. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (13)
.gitignore (1)

95-95: Remove duplicate .build/ ignore

.build/ is already ignored at Line 90. Keep a single occurrence to avoid noise.

Apply this diff:

-# Local build artifacts for devcontainer
-.build/
+# Local build artifacts for devcontainer
hatch_build.py (1)

47-52: Ensure directory exists and write with explicit encoding

A small hardening: make sure parent directories exist to future-proof against path changes, and specify UTF-8 encoding.

Apply this diff:

         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:
+            os.makedirs(os.path.dirname(version_file_path), exist_ok=True)
+            with open(version_file_path, "w", encoding="utf-8") as f:
                 f.write(version_content)
components/backends/vllm/src/dynamo/vllm/args.py (1)

15-16: Avoid importing package init just to read version; fetch distribution version via importlib.metadata instead

This decouples CLI version reporting from package import-time behavior and avoids potential issues if _version.py isn’t present yet.

Apply this diff:

-from dynamo.vllm import __version__
+from importlib.metadata import version as _pkg_version
-    parser.add_argument(
-        "--version", action="version", version=f"Dynamo Backend VLLM {__version__}"
-    )
+    parser.add_argument(
+        "--version",
+        action="version",
+        version=f"Dynamo Backend VLLM {_pkg_version('ai-dynamo')}",
+    )

Optionally, if you prefer to avoid calling _pkg_version in an f-string, compute once:

version_str = _pkg_version("ai-dynamo")
parser.add_argument("--version", action="version", version=f"Dynamo Backend VLLM {version_str}")

Also applies to: 63-65

components/backends/vllm/src/dynamo/vllm/__init__.py (1)

4-6: Drop redundant reassignment and add a safe fallback when _version.py is absent (editable/dev installs).

  • __version__ = __version__ is a no-op and can be removed.
  • If _version.py isn’t present (e.g., running from source without the Hatch hook), importing will raise. A small fallback keeps imports resilient.

Proposed change:

-from ._version import __version__
-
-__version__ = __version__
+try:
+    from ._version import __version__  # generated at build time by hatch hook
+except Exception:
+    __version__ = "0.0.0+unknown"

Would you like me to apply the same pattern across all component init.py files for consistency?

components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (1)

9-9: Top-level version import can fail in editable/dev installs. Consider deferring or ensuring package-level fallback.

Importing __version__ at module import time will fail if _version.py wasn’t generated yet. If you adopt the safe-fallback pattern in dynamo.trtllm.__init__, this becomes safe. Alternatively, defer the import inside cmd_line_args() to reduce import-time coupling.

If you prefer deferring, this minimal change works:

-from dynamo.trtllm import __version__
@@ def cmd_line_args():
-    parser = argparse.ArgumentParser(
+    parser = argparse.ArgumentParser(
         description="TensorRT-LLM server integrated with Dynamo LLM."
     )
+    # Defer import to avoid import-time dependency on generated _version.py
+    try:
+        from dynamo.trtllm import __version__ as _ver
+    except Exception:
+        _ver = "0.0.0+unknown"
     parser.add_argument(
-        "--version", action="version", version=f"Dynamo Backend TRTLLM {__version__}"
+        "--version", action="version", version=f"Dynamo Backend TRTLLM {_ver}"
     )
components/planner/src/dynamo/planner/utils/planner_core.py (2)

12-12: Importing version from the package is fine; ensure init stays lightweight.

If dynamo.planner.__init__ remains minimal (only version re-export), this is safe. If it grows, consider importing from . _version directly or using a safe fallback pattern in __init__ to avoid import-time surprises.


337-339: Good addition: --version flag for the planner CLI.

Conventional usage with argparse’s version action; consistent with other components.

Optional: add a short alias -V for parity with common CLIs:

-    parser.add_argument(
-        "--version", action="version", version=f"Dynamo Planner {__version__}"
-    )
+    parser.add_argument(
+        "--version", "-V", action="version", version=f"Dynamo Planner {__version__}"
+    )
components/backends/mocker/src/dynamo/mocker/main.py (2)

12-12: Top-level version import note.

Same consideration as other components: this import is fine if dynamo.mocker.__init__ is resilient when _version.py is absent. If not, consider the safe-fallback pattern in the package __init__ or defer the import within cmd_line_args().


45-47: LGTM: standard --version support via argparse.

Consistent with repo-wide pattern. Behavior is correct and self-contained.

Optional: add a -V alias:

-    parser.add_argument(
-        "--version", action="version", version=f"Dynamo Mocker {__version__}"
-    )
+    parser.add_argument(
+        "--version", "-V", action="version", version=f"Dynamo Mocker {__version__}"
+    )
components/backends/mocker/src/dynamo/mocker/__init__.py (1)

4-6: Avoid no-op reassignment and make version import resilient.

  • __version__ = __version__ doesn’t add value.
  • Provide a runtime fallback for source checkouts without generated _version.py.

Suggested change:

-from ._version import __version__
-
-__version__ = __version__
+try:
+    from ._version import __version__  # generated at build time by hatch hook
+except Exception:
+    __version__ = "0.0.0+unknown"

If you agree, I can apply the same change across all component packages for consistency.

components/frontend/src/dynamo/frontend/main.py (1)

75-77: Nice: Standard argparse --version behavior wired correctly.

action="version" will print and exit before validating other args, which is what we want for python -m dynamo.frontend --version. Format looks consistent with the project.

Optional: Consider version=f"Dynamo Frontend {__version__}" -> version=f"%(prog)s {__version__}" if you prefer the program name to reflect the actual entry point. Current explicit label is fine if that’s the intended branding.

components/backends/llama_cpp/src/dynamo/llama_cpp/main.py (1)

14-14: Prefer a relative import for version to avoid package-level coupling.

This keeps the CLI insulated from potential __init__ changes and ensures we read the generated version directly.

Apply this diff:

-from dynamo.llama_cpp import __version__
+from ._version import __version__

If you want to keep importing from the package for consistency, verify that dynamo.llama_cpp.__init__ re-exports __version__ everywhere this is used.

components/backends/llama_cpp/src/dynamo/llama_cpp/__init__.py (1)

6-6: Optionally make the re-export explicit

If you want to make the public API explicit and silence some linters about re-exports, declare all.

-__version__ = __version__
+__version__ = __version__
+__all__ = ["__version__"]
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9ddb3ef and 16be2c5.

📒 Files selected for processing (16)
  • .gitignore (2 hunks)
  • components/backends/llama_cpp/src/dynamo/llama_cpp/__init__.py (1 hunks)
  • components/backends/llama_cpp/src/dynamo/llama_cpp/main.py (2 hunks)
  • components/backends/mocker/src/dynamo/mocker/__init__.py (1 hunks)
  • components/backends/mocker/src/dynamo/mocker/main.py (2 hunks)
  • components/backends/sglang/src/dynamo/sglang/__init__.py (1 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/__init__.py (1 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (2 hunks)
  • components/backends/vllm/src/dynamo/vllm/__init__.py (1 hunks)
  • components/backends/vllm/src/dynamo/vllm/args.py (2 hunks)
  • components/frontend/src/dynamo/frontend/__init__.py (1 hunks)
  • components/frontend/src/dynamo/frontend/main.py (2 hunks)
  • components/planner/src/dynamo/planner/__init__.py (1 hunks)
  • components/planner/src/dynamo/planner/utils/planner_core.py (2 hunks)
  • hatch_build.py (1 hunks)
  • pyproject.toml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
  • GitHub Check: Build and Test - dynamo
🔇 Additional comments (6)
pyproject.toml (1)

77-79: Hatch custom build hook registration looks correct

Hook path and placement are valid for Hatchling, enabling version file generation during builds.

hatch_build.py (1)

30-44: Git hash suffix logic is sound and resilient

Gracefully appends the short commit hash when available and falls back cleanly otherwise. PEP 440 local version formatting with “+” is appropriate.

components/backends/vllm/src/dynamo/vllm/args.py (1)

63-65: Check for duplicate --version across CLIs — verify upstream vLLM doesn't register --version

Repo search found multiple local argparse --version registrations; a duplicate-option error only happens if the same parser gets two registrations (e.g., if upstream vLLM registers args on import). Confirm vLLM’s import-time behavior; if it does register --version, guard this add.

Found occurrences:

  • components/planner/src/dynamo/planner/utils/planner_core.py:338
  • components/frontend/src/dynamo/frontend/main.py:76
  • components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py:114
  • components/backends/mocker/src/dynamo/mocker/main.py:46
  • components/backends/vllm/src/dynamo/vllm/args.py:64 <-- file under review
  • components/backends/llama_cpp/src/dynamo/llama_cpp/main.py:88

Original snippet (unchanged):

    parser.add_argument(
        "--version", action="version", version=f"Dynamo Backend VLLM {__version__}"
    )

Suggested quick guard if upstream does add --version:

if "--version" not in parser._option_string_actions:
    parser.add_argument("--version", action="version", version=f"Dynamo Backend VLLM {__version__}")
components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (1)

113-115: Nice: clean argparse --version integration.

Using action="version" ensures proper printing and immediate exit, keeping CLI behavior conventional.

components/backends/llama_cpp/src/dynamo/llama_cpp/main.py (1)

87-89: LGTM: --version integrates cleanly with required args.

Argparse’s version action exits before validating --model-path, so python -m dynamo.llama_cpp --version works without extra flags. Message format matches the pattern used elsewhere.

components/backends/llama_cpp/src/dynamo/llama_cpp/__init__.py (1)

1-2: SPDX headers: LGTM

License headers look correct and consistent.

Version looks like this `0.4.0+3a3f5bf2` if you have git, `0.4.0`
otherwise.

The `--version` flag should work on all components except sglang,
because that handles arguments differently.

All components (including sglang) have the expected `__version__`
attribute at the top level.
@grahamking grahamking merged commit ccc8c62 into main Aug 15, 2025
12 of 13 checks passed
@grahamking grahamking deleted the gk-py-version branch August 15, 2025 16:23
description="llama.cpp server integrated with Dynamo LLM."
)
parser.add_argument(
"--version", action="version", version=f"Dynamo Backend llama.cpp {__version__}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, I have written many argparse CLIs, and today I learned that action="version" was a thing! Thanks @grahamking 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's neat right?! It stops parsing when it sees that, prints the version and exits, no extra code required.

I take not credit because that was Claude Code. I gave it a spec and it did the design (hatch hook that writes a _version.py) and initial draft. It's hatch hook used an old API, so I discussed it with GPT-5 which gave me the new hook and correct way to read the build version. Then Code Rabbit reviewed it and I re-worked the PR based on it's feedback to use importlib as a fallback. I beautiful symphony of human and AI.

hhzhang16 pushed a commit that referenced this pull request Aug 27, 2025
Signed-off-by: Hannah Zhang <hannahz@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants