Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement jmp driver list command for listing locally installed drivers #258

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

NickCao
Copy link
Collaborator

@NickCao NickCao commented Feb 6, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new driver command interface in the Jumpstarter CLI, enabling users to list available drivers and view version information.
    • Expanded driver support across the platform with enhanced integration for various driver types such as CAN, Composite, DUTLink, Network, OpenDAL, Power, Raspberry Pi, and SDWire.
    • Added new entry points for additional drivers, enhancing the extensibility of the Jumpstarter framework.
  • Documentation

    • Updated the documentation with a dedicated section on the Jumpstarter Driver CLI.

Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request introduces a new asynchronous CLI for the Jumpstarter driver, adding a dedicated driver command group with commands such as list_drivers and version. The updates include documentation changes, new tests for the CLI commands, and proper logging configuration. The integration of the driver commands into the main Jumpstarter CLI is accomplished by updating the command registration in the respective packages. Additionally, several driver packages now expose new entry points via their pyproject.toml files, and the workspace configuration is adjusted to include the new CLI driver module.

Changes

File(s) Change Summary
packages/jumpstarter-cli-driver/README.md Added a new "Jumpstarter Driver CLI" section.
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/__init__.py
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver_test.py
Introduced a new asynchronous CLI command group using asyncclick with commands list_drivers and version, complete with logging configuration and asynchronous tests.
packages/jumpstarter-cli-driver/pyproject.toml Added project metadata, dependencies (including jumpstarter-cli-common and asyncclick), a dev dependency group, and a script entry point (jmp-driver).
packages/jumpstarter-cli/jumpstarter_cli/__init__.py
packages/jumpstarter-cli/pyproject.toml
Integrated the driver module into the main Jumpstarter CLI command group and added jumpstarter-cli-driver to the dependencies.
packages/jumpstarter-driver-*/pyproject.toml (can, composite, dutlink, network, opendal, power, raspberrypi, sdwire) Added new entry points for various drivers and adapters (e.g., Can, Composite, Dutlink, TcpNetwork, Opendal, MockPower, DigitalInput, SDWire) under the respective namespaces.
pyproject.toml (root) Added an entry in [tool.uv.sources] to include jumpstarter-cli-driver as part of the workspace.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as Jumpstarter CLI
    participant DC as Driver Command Group
    participant EP as Entry Points & Table Builder

    U->>CLI: Run "jmp driver list_drivers"
    CLI->>DC: Execute driver command group
    DC->>EP: Retrieve available driver entry points
    EP-->>DC: Return driver data table
    DC->>CLI: Output formatted driver list
    CLI-->>U: Display driver list result
Loading

Suggested reviewers

  • mangelajo
  • kirkbrauer
  • bennyz

Poem

Oh, how I hop through lines of code,
A bunny with a joyful load!
CLI commands now dance in tune,
With drivers shining like the moon 🌙.
In our garden of change, I nibble a carrot byte!
Hop on, let's code through day and night!
~ Your coding bunny 🐰

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

@kirkbrauer
Copy link
Contributor

Humm, I'm not sure how these import semantics look. A bit too confusing I think...

@NickCao NickCao changed the title Entry point PoC Implement jmp driver list command for listing locally installed drivers Feb 10, 2025
@NickCao NickCao marked this pull request as ready for review February 10, 2025 17:58
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: 2

🧹 Nitpick comments (5)
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py (1)

7-8: Remove unnecessary async.

The list_drivers function is marked as async but doesn't perform any asynchronous operations. Consider removing the async keyword to improve clarity.

-@click.command("list")
-async def list_drivers():
+@click.command("list")
+def list_drivers():
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/__init__.py (1)

10-17: Enhance command group docstring.

The current docstring could be more descriptive to help users understand the command's purpose and available subcommands.

 @click.group(cls=AliasedGroup)
 @opt_log_level
 def driver(log_level: Optional[str]):
-    """Jumpstarter driver CLI tool"""
+    """
+    Jumpstarter driver CLI tool.
+
+    Commands:
+      list    List locally installed drivers
+      version Show version information
+    """
packages/jumpstarter-cli-driver/pyproject.toml (1)

26-28: Script Entry Point with Import Consideration

The project.scripts entry (jmp-driver = "jumpstarter_cli_driver:driver") correctly exposes the CLI command. However, given past comments about confusing import semantics, please double-check that the driver callable in the jumpstarter_cli_driver module is imported and documented unambiguously. A clarifying docstring or inline comment could help other developers understand the resolution of the import.

packages/jumpstarter-driver-dutlink/pyproject.toml (1)

25-30: New Dutlink Driver Entry Points

The newly added entry points for Dutlink, DutlinkSerial, DutlinkStorageMux, and DutlinkPower under [project.entry-points."jumpstarter.drivers"] are set up correctly. Please verify that the corresponding classes in jumpstarter_driver_dutlink.driver are implemented as intended.

pyproject.toml (1)

10-10: New Workspace Entry Addition: Ensure Consistent Module Integration

The new entry jumpstarter-cli-driver = { workspace = true } is correctly added in the [tool.uv.sources] section. This aligns with the existing workspace configuration and integrates the new jumpstarter-cli-driver module as intended for the CLI enhancements introduced in this PR. Please ensure that the module itself follows the same import and dependency patterns as the other CLI modules to avoid any potential confusion regarding import semantics.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c653ff9 and c71747f.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • packages/jumpstarter-cli-driver/README.md (1 hunks)
  • packages/jumpstarter-cli-driver/jumpstarter_cli_driver/__init__.py (1 hunks)
  • packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py (1 hunks)
  • packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver_test.py (1 hunks)
  • packages/jumpstarter-cli-driver/pyproject.toml (1 hunks)
  • packages/jumpstarter-cli/jumpstarter_cli/__init__.py (2 hunks)
  • packages/jumpstarter-cli/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-can/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-composite/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-dutlink/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-network/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-opendal/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-power/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-raspberrypi/pyproject.toml (1 hunks)
  • packages/jumpstarter-driver-sdwire/pyproject.toml (1 hunks)
  • pyproject.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/jumpstarter-cli-driver/README.md
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
🔇 Additional comments (19)
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver_test.py (1)

18-20: LGTM!

The fixture correctly configures the anyio backend to use asyncio.

packages/jumpstarter-cli/jumpstarter_cli/__init__.py (2)

5-5: LGTM!

The import follows the established pattern and is correctly placed with other similar imports.


15-15: LGTM!

The command registration follows the established pattern and is correctly placed with other similar registrations.

packages/jumpstarter-driver-sdwire/pyproject.toml (1)

18-20: Ensure Consistency in the SDWire Entry Point.
The new entry point SDWire = "jumpstarter_driver_sdwire.driver:SDWire" is added correctly. Please verify that the module path and class name exactly match the implementation and that the naming convention is consistent with other driver entry points within the project.

packages/jumpstarter-driver-opendal/pyproject.toml (1)

18-20: Validate the New Opendal Adapter Entry Point.
The entry point Opendal = "jumpstarter_driver_opendal.adapters:OpendalAdapter" is properly defined under [project.entry-points."jumpstarter.adapters"]. Confirm that this mapping correctly reflects the module structure and that it adheres to the project’s naming conventions used for adapters.

packages/jumpstarter-driver-composite/pyproject.toml (1)

17-19: Confirm the Composite Driver Entry Point Integration.
The addition of the Composite entry point with the mapping Composite = "jumpstarter_driver_composite.driver:Composite" is straightforward and appears correct. Ensure the module and class names are accurate and that this new driver aligns with the overall entry point naming scheme applied in the project.

packages/jumpstarter-driver-power/pyproject.toml (1)

18-20: Review the MockPower Driver Entry Point.
The new entry point MockPower = "jumpstarter_driver_power.driver:MockPower" under the [project.entry-points."jumpstarter.drivers"] section is well defined. Please double-check that the naming style is consistent with similar drivers in the ecosystem and that the referenced class exists in the specified module.

packages/jumpstarter-driver-raspberrypi/pyproject.toml (1)

18-21: Confirm the Dual Entry Points for Raspberry Pi Drivers.
The new entry points DigitalInput and DigitalOutput mapping to jumpstarter_driver_raspberrypi.driver:DigitalInput and jumpstarter_driver_raspberrypi.driver:DigitalOutput are added correctly. This dual entry point setup provides a clear separation of functionality. It would be beneficial to ensure accompanying documentation (or in-code comments) clearly explains their usage to avoid any potential confusion regarding import semantics.

packages/jumpstarter-driver-can/pyproject.toml (1)

19-23: Entry Points for CAN Drivers Added

The new entry points under [project.entry-points."jumpstarter.drivers"] for Can, IsoTpPython, and IsoTpSocket are formatted correctly. Please ensure that the corresponding driver classes within jumpstarter_driver_can.driver exist and conform to the naming conventions expected by the CLI listing mechanism.

packages/jumpstarter-cli/pyproject.toml (1)

16-16: New CLI Driver Dependency Added

The addition of "jumpstarter-cli-driver" in the dependencies list integrates the new driver CLI functionality into the main CLI. Verify that this dependency harmonizes with existing components and does not introduce any ambiguous import paths.

packages/jumpstarter-cli-driver/pyproject.toml (7)

1-12: New Project Metadata Configuration

The metadata—including name, dynamic, readme, license, and requires-python—is correctly defined for this new package. Consider adding a brief project description later to better clarify the package’s purpose.


13-16: Dependencies Specification

The dependencies list (with "jumpstarter-cli-common" and "asyncclick>=8.1.7.2") is appropriate for supporting asynchronous CLI operations.


18-25: Development Dependency Group Defined

The dependency-groups section for dev dependencies is well established, ensuring robust testing support.


29-31: Wheel Packaging Configuration

The wheel build target configuration correctly includes the package jumpstarter_cli_driver, ensuring proper distribution.


32-35: VCS URLs for Metadata

The URLs for Homepage and source_archive are appropriately set, facilitating traceability to the source repository.


36-39: Version Control Integration

Sourcing the version from the VCS with the specified raw options is an effective approach. Make sure the relative path ('../../') is accurate with the repository structure.


40-42: Build System Configuration

The build system requirements using hatchling and hatch-vcs are correctly specified.

packages/jumpstarter-driver-network/pyproject.toml (2)

19-24: Network Driver Entry Points Configured

The entry points for network drivers (TcpNetwork, UdpNetwork, UnixNetwork, and EchoNetwork) under the "jumpstarter.drivers" group are correctly declared. Ensure that each mapped class in jumpstarter_driver_network.driver exists and follows the project’s naming conventions.


25-30: Adapter Entry Points for Network Adapters

The adapter entry points (TcpPortforward, UnixPortforward, Pexpect, and Novnc) under the "jumpstarter.adapters" group are properly defined. Confirm that the target classes in jumpstarter_driver_network.adapters are imported correctly and clear in their purpose.

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: 0

🧹 Nitpick comments (2)
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py (2)

1-5: Add docstring to clarify import semantics.

Given the feedback about confusing import semantics, consider adding a module docstring explaining the purpose of each import:

+"""
+Driver listing functionality for the Jumpstarter CLI.
+
+Imports:
+- entry_points: Used to discover installed Jumpstarter drivers
+- asyncclick: Async variant of Click for CLI command handling
+- make_table: Utility for formatting driver information as a table
+"""
 from importlib.metadata import entry_points
 
 import asyncclick as click
 from jumpstarter_cli_common import make_table

13-13: Consider more robust value formatting.

The current string replacement might be fragile if the value contains multiple colons.

-        click.echo(make_table(["NAME", "TYPE"], [{"NAME": e.name, "TYPE": e.value.replace(":", ".")} for e in drivers]))
+        click.echo(make_table(["NAME", "TYPE"], [{"NAME": e.name, "TYPE": e.value.split(":", 1)[0]} for e in drivers]))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c71747f and fc7df88.

📒 Files selected for processing (1)
  • packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py (1)
Learnt from: NickCao
PR: jumpstarter-dev/jumpstarter#258
File: packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py:9-13
Timestamp: 2025-02-10T18:05:02.169Z
Learning: The `importlib.metadata.entry_points()` function is designed to never raise exceptions and safely returns an empty iterator when no entry points are found, making explicit error handling unnecessary.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (1)
packages/jumpstarter-cli-driver/jumpstarter_cli_driver/driver.py (1)

7-12: LGTM! Clean implementation of driver discovery.

The command implementation is well-structured with good empty state handling. The use of entry_points() for driver discovery is appropriate and safe, as it never raises exceptions.

@NickCao NickCao merged commit 37b6476 into main Feb 11, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants