From b0352ba5c5b1c7222c206f581ac51d61c18f611d Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Wed, 23 Oct 2024 20:12:05 +1000 Subject: [PATCH] Adjust subprocess env passing --- src/venvstacks/_util.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/venvstacks/_util.py b/src/venvstacks/_util.py index 0f3ed15..2b70e92 100644 --- a/src/venvstacks/_util.py +++ b/src/venvstacks/_util.py @@ -8,7 +8,7 @@ from contextlib import contextmanager from pathlib import Path -from typing import Any, Generator +from typing import Any, Generator, Mapping WINDOWS_BUILD = hasattr(os, "add_dll_directory") @@ -78,15 +78,16 @@ def get_env_python(env_path: Path) -> Path: def run_python_command_unchecked( - # Narrow list/dict type specs here due to the way `subprocess.run` params are typed + # Narrow list type spec here due to the way `subprocess.run` params are typed command: list[str], *, - env: dict[str, str] | None = None, + env: Mapping[str, str] | None = None, **kwds: Any, ) -> subprocess.CompletedProcess[str]: - if env is None: - env = os.environ.copy() - env.update(_SUBPROCESS_PYTHON_CONFIG) + run_env = os.environ.copy() + if env is not None: + run_env.update(env) + run_env.update(_SUBPROCESS_PYTHON_CONFIG) result: subprocess.CompletedProcess[str] = subprocess.run( command, env=env, text=True, **kwds ) @@ -94,7 +95,7 @@ def run_python_command_unchecked( def run_python_command( - # Narrow list/dict type specs here due to the way `subprocess.run` params are typed + # Narrow list type spec here due to the way `subprocess.run` params are typed command: list[str], **kwds: Any, ) -> subprocess.CompletedProcess[str]: