@@ -28,7 +28,8 @@ def platform_program_file_extension() -> str:
2828def run_command_sync (
2929 args : Sequence [str | PathLike [str ]],
3030 cwd : str | PathLike [str ] | None = None ,
31- extra_env : dict [str , str ] | None = None ,
31+ env : dict [str , str ] | None = None , # used as is, without merging with process envs
32+ extra_env : dict [str , str ] | None = None , # merged with envs obtained from current process
3233 extra_paths : list [str ] | None = None ,
3334 * ,
3435 shell : bool = is_windows ,
@@ -43,19 +44,21 @@ def run_command_sync(
4344 if extra_paths is None :
4445 extra_paths = []
4546 try :
46- env = None
47- if extra_env or extra_paths :
48- env = os .environ .copy ()
47+ final_env = None
48+ if env :
49+ final_env = env
50+ elif extra_env or extra_paths :
51+ final_env = os .environ .copy ()
4952 if extra_env :
50- env .update (extra_env )
53+ final_env .update (extra_env )
5154 if extra_paths :
52- env ['PATH' ] = os .path .pathsep .join (extra_paths ) + os .path .pathsep + env ['PATH' ]
55+ final_env ['PATH' ] = os .path .pathsep .join (extra_paths ) + os .path .pathsep + final_env ['PATH' ]
5356 startupinfo = None
5457 if is_windows :
5558 startupinfo = subprocess .STARTUPINFO ()
5659 startupinfo .dwFlags |= subprocess .SW_HIDE | subprocess .STARTF_USESHOWWINDOW
5760 output = subprocess .check_output ( # noqa: S603
58- args , cwd = cwd , shell = shell , stderr = subprocess .STDOUT , env = env , startupinfo = startupinfo )
61+ args , cwd = cwd , shell = shell , stderr = subprocess .STDOUT , env = final_env , startupinfo = startupinfo )
5962 return (decode_bytes (output ).strip (), None )
6063 except subprocess .CalledProcessError as error :
6164 return ('' , decode_bytes (error .output ).strip ())
0 commit comments