Skip to content

Commit

Permalink
rpc-server: use
Browse files Browse the repository at this point in the history
* use rpc-server which runs invenio commands
  • Loading branch information
utnapischtim committed Mar 1, 2025
1 parent 79de4ce commit c1343db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions invenio_cli/helpers/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# 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.

"""Invenio-cli configuration file."""

from configparser import ConfigParser
from functools import cached_property
from pathlib import Path

from ..errors import InvenioCLIConfigError
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 26 additions & 2 deletions invenio_cli/helpers/package_managers.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit c1343db

Please sign in to comment.