From c1343db4cd6f0fd9ba39adaa171616539a12290d Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Sat, 1 Mar 2025 20:07:50 +0100 Subject: [PATCH] rpc-server: use * use rpc-server which runs invenio commands --- invenio_cli/helpers/cli_config.py | 5 +++-- invenio_cli/helpers/package_managers.py | 28 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/invenio_cli/helpers/cli_config.py b/invenio_cli/helpers/cli_config.py index 46e1092..0c06e73 100644 --- a/invenio_cli/helpers/cli_config.py +++ b/invenio_cli/helpers/cli_config.py @@ -3,7 +3,7 @@ # Copyright (C) 2019-2024 CERN. # Copyright (C) 2019-2020 Northwestern University. # Copyright (C) 2021 Esteban J. G. Gabancho. -# Copyright (C) 2024 Graz University of Technology. +# Copyright (C) 2024-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. @@ -11,6 +11,7 @@ """Invenio-cli configuration file.""" from configparser import ConfigParser +from functools import cached_property from pathlib import Path from ..errors import InvenioCLIConfigError @@ -62,7 +63,7 @@ def __init__(self, project_dir="./"): with open(self.private_config_path) as cfg_file: self.private_config.read_file(cfg_file) - @property + @cached_property def python_package_manager(self) -> PythonPackageManager: """Get python packages manager.""" manager_name = self.config[CLIConfig.CLI_SECTION].get( diff --git a/invenio_cli/helpers/package_managers.py b/invenio_cli/helpers/package_managers.py index a961e63..77d13fe 100644 --- a/invenio_cli/helpers/package_managers.py +++ b/invenio_cli/helpers/package_managers.py @@ -1,6 +1,7 @@ # -*- 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. @@ -11,12 +12,15 @@ from abc import ABC 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 def run_command(self, *command: str) -> List[str]: """Generate command to run the given command in the managed environment.""" @@ -61,9 +65,19 @@ class Pipenv(PythonPackageManager): name = "pipenv" lock_file_name = "Pipfile.lock" + def __init__(self): + """Construct.""" + response = run_cmd([self.name, "run", "rpc-server", "ping"]) + if "pong" in response.output: + self.rpc_server_is_running = True + def run_command(self, *command): """Generate command to run the given command in the managed environment.""" - return [self.name, "run", *command] + if self.rpc_server_is_running: + # [1:] remove "invenio" from commands + return [self.name, "run", "rpc-server", "send", *command[1:]] + else: + return [self.name, "run", *command] def editable_dev_install(self, *packages): """Install the local packages as editable, but ignore it for locking.""" @@ -118,10 +132,20 @@ class UV(PythonPackageManager): name = "uv" lock_file_name = "uv.lock" + def __init__(self): + """Construct.""" + response = run_cmd([self.name, "run", "--no-sync", "rpc-server", "ping"]) + if "pong" in response.output: + self.rpc_server_is_running = True + def run_command(self, *command): """Generate command to run the given command in the managed environment.""" # "--no-sync" is used to not override locally installed editable packages - return [self.name, "run", "--no-sync", *command] + if self.rpc_server_is_running: + # [1:] remove "invenio" from commands + return [self.name, "run", "--no-sync", "rpc-server", "send", *command[1:]] + else: + return [self.name, "run", "--no-sync", *command] def editable_dev_install(self, *packages): """Install the local packages as editable, but ignore it for locking."""