app_deploy: add support for pip environment vars

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-12-28 07:49:41 -05:00
parent f7d5f11cf8
commit 19422819da
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
3 changed files with 16 additions and 3 deletions

View File

@ -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")

View File

@ -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"
},

View File

@ -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