From 19422819da1d1ae9a8c3aa57fc790fa32844fa1d Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 28 Dec 2023 07:49:41 -0500 Subject: [PATCH] app_deploy: add support for pip environment vars Signed-off-by: Eric Callahan --- moonraker/components/update_manager/app_deploy.py | 10 +++++++++- moonraker/components/update_manager/common.py | 1 + moonraker/components/update_manager/update_manager.py | 8 ++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/moonraker/components/update_manager/app_deploy.py b/moonraker/components/update_manager/app_deploy.py index ffe7567..464ab1b 100644 --- a/moonraker/components/update_manager/app_deploy.py +++ b/moonraker/components/update_manager/app_deploy.py @@ -169,6 +169,7 @@ class AppDeploy(BaseDeploy): else: self.log_info("Unable to locate pip executable") self.venv_args = config.get('venv_args', None) + self.pip_env_vars = config.getdict("pip_environment_variables", None) def _configure_dependencies( self, config: ConfigHelper, node_only: bool = False @@ -411,11 +412,18 @@ class AppDeploy(BaseDeploy): else: reqs = [req.replace("\"", "'") for req in requirements] args = " ".join([f"\"{req}\"" for req in reqs]) + env: Optional[Dict[str, str]] = None + if self.pip_env_vars is not None: + self.log_info( + f"Running Pip with environment variables: {self.pip_env_vars}" + ) + env = dict(os.environ) + env.update(self.pip_env_vars) self.notify_status("Updating python packages...") try: await self.cmd_helper.run_cmd( f"{self.pip_cmd} install {args}", timeout=1200., notify=True, - retries=3 + retries=3, env=env, log_stderr=True ) except Exception: self.log_exc("Error updating python requirements") diff --git a/moonraker/components/update_manager/common.py b/moonraker/components/update_manager/common.py index 4ed9289..0d5971a 100644 --- a/moonraker/components/update_manager/common.py +++ b/moonraker/components/update_manager/common.py @@ -32,6 +32,7 @@ BASE_CONFIG: Dict[str, Dict[str, str]] = { "system_dependencies": "scripts/system-dependencies.json", "host_repo": "arksine/moonraker", "virtualenv": sys.exec_prefix, + "pip_environment_variables": "SKIP_CYTHON=Y", "path": str(source_info.source_path()), "managed_services": "moonraker" }, diff --git a/moonraker/components/update_manager/update_manager.py b/moonraker/components/update_manager/update_manager.py index 4c5651b..caec8ef 100644 --- a/moonraker/components/update_manager/update_manager.py +++ b/moonraker/components/update_manager/update_manager.py @@ -582,10 +582,14 @@ class CommandHelper: retries: int = 1, env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None, - sig_idx: int = 1 + sig_idx: int = 1, + log_stderr: bool = False ) -> None: cb = self.notify_update_response if notify else None - scmd = self.build_shell_command(cmd, callback=cb, env=env, cwd=cwd) + log_stderr |= self.server.is_verbose_enabled() + scmd = self.build_shell_command( + cmd, callback=cb, env=env, cwd=cwd, log_stderr=log_stderr + ) for _ in range(retries): if await scmd.run(timeout=timeout, sig_idx=sig_idx): break