-
Notifications
You must be signed in to change notification settings - Fork 47
rpc-server: use #387
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
Closed
Closed
rpc-server: use #387
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,49 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2025 TU Wien. | ||
| # Copyright (C) 2025 Graz University of Technology. | ||
| # | ||
| # Invenio-Cli is free software; you can redistribute it and/or modify it | ||
| # under the terms of the MIT License; see LICENSE file for more details. | ||
|
|
||
| """Wrappers around various package managers to be used under the hood.""" | ||
|
|
||
| import atexit | ||
| import os | ||
| from abc import ABC | ||
| from subprocess import Popen | ||
| from typing import List | ||
|
|
||
| from .process import run_cmd | ||
|
|
||
|
|
||
| class PythonPackageManager(ABC): | ||
| """Interface for creating tool-specific Python package management commands.""" | ||
|
|
||
| name: str = None | ||
| lock_file_name: str = None | ||
| rpc_server_is_running: bool = False | ||
| rpc_server: Popen = None | ||
| run_prefix: List = [] | ||
|
|
||
| def __init__(self): | ||
| """Construct.""" | ||
| self.rpc_server = Popen( | ||
| self.run_prefix + ["invenio", "rpc-server", "start", "--port", "5001"] | ||
| ) | ||
| atexit.register(self.cleanup) | ||
| while True: | ||
| response = run_cmd( | ||
| self.run_prefix + ["rpc-server", "ping", "--port", "5001"] | ||
| ) | ||
| if "pong" in response.output: | ||
| self.rpc_server_is_running = True | ||
| break | ||
|
|
||
| def cleanup(self): | ||
| """Cleanup.""" | ||
| if self.rpc_server: | ||
| self.rpc_server.terminate() | ||
|
|
||
| def run_command(self, *command: str) -> List[str]: | ||
| """Generate command to run the given command in the managed environment.""" | ||
|
|
@@ -60,6 +87,24 @@ class Pipenv(PythonPackageManager): | |
|
|
||
| name = "pipenv" | ||
| lock_file_name = "Pipfile.lock" | ||
| run_prefix = ["pipenv", "run"] | ||
|
|
||
| def send_command(self, *command): | ||
| """Send command to rpc server, default to run_command.""" | ||
| if self.rpc_server_is_running: | ||
| # [1:] remove "invenio" from commands | ||
| return [ | ||
| self.name, | ||
| "run", | ||
| "rpc-server", | ||
| "send", | ||
| "--port", | ||
| "5001", | ||
| "--plain", | ||
| *command[1:], | ||
| ] | ||
| else: | ||
| self.run_command(*command) | ||
|
|
||
| def run_command(self, *command): | ||
| """Generate command to run the given command in the managed environment.""" | ||
|
|
@@ -117,6 +162,25 @@ class UV(PythonPackageManager): | |
|
|
||
| name = "uv" | ||
| lock_file_name = "uv.lock" | ||
| run_prefix = ["uv", "run", "--no-sync"] | ||
|
|
||
| def send_command(self, *command): | ||
| """Send command to rpc server, default to run_command.""" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is almost a duplicate. maybe it is possible to reduce code with using super().send_command(..) |
||
| if self.rpc_server_is_running: | ||
| # [1:] remove "invenio" from commands | ||
| return [ | ||
| self.name, | ||
| "run", | ||
| "--no-sync", | ||
| "rpc-server", | ||
| "send", | ||
| "--port", | ||
| "5001", | ||
| "--plain", | ||
| *command[1:], | ||
| ] | ||
| else: | ||
| return self.run_command(*command) | ||
|
|
||
| def run_command(self, *command): | ||
| """Generate command to run the given command in the managed environment.""" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is untested