Skip to content

Commit

Permalink
app_deploy: add support for pip environment vars
Browse files Browse the repository at this point in the history
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
  • Loading branch information
Arksine committed Dec 28, 2023
1 parent f7d5f11 commit 1942281
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion moonraker/components/update_manager/app_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def _configure_virtualenv(self, config: ConfigHelper) -> None:
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
Expand Down Expand Up @@ -411,11 +412,18 @@ async def _update_python_requirements(
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")
Expand Down
1 change: 1 addition & 0 deletions moonraker/components/update_manager/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"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"
},
Expand Down
8 changes: 6 additions & 2 deletions moonraker/components/update_manager/update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,14 @@ async def run_cmd(
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
Expand Down

0 comments on commit 1942281

Please sign in to comment.