6
6
executable name.
7
7
"""
8
8
9
+ from __future__ import annotations
10
+
9
11
import os
12
+ import platform
10
13
import subprocess
11
14
import sys
12
15
16
+ from typing import Mapping
17
+
13
18
from ._log import log
14
19
from .debug import DEBUG
15
20
from .errors import DistutilsExecError
@@ -22,6 +27,21 @@ def _debug(cmd):
22
27
return cmd if DEBUG else cmd [0 ]
23
28
24
29
30
+ def _inject_macos_ver (env : Mapping [str :str ] | None ) -> Mapping [str :str ] | None :
31
+ if platform .system () != 'Darwin' :
32
+ return env
33
+
34
+ from distutils .util import MACOSX_VERSION_VAR , get_macosx_target_ver
35
+
36
+ target_ver = get_macosx_target_ver ()
37
+ update = {MACOSX_VERSION_VAR : target_ver } if target_ver else {}
38
+ return {** _resolve (env ), ** update }
39
+
40
+
41
+ def _resolve (env : Mapping [str :str ] | None ) -> Mapping [str :str ]:
42
+ return os .environ if env is None else env
43
+
44
+
25
45
def spawn (cmd , search_path = True , verbose = False , dry_run = False , env = None ):
26
46
"""Run another program, specified as a command list 'cmd', in a new process.
27
47
@@ -47,17 +67,8 @@ def spawn(cmd, search_path=True, verbose=False, dry_run=False, env=None):
47
67
if executable is not None :
48
68
cmd [0 ] = executable
49
69
50
- env = env if env is not None else dict (os .environ )
51
-
52
- if sys .platform == 'darwin' :
53
- from distutils .util import MACOSX_VERSION_VAR , get_macosx_target_ver
54
-
55
- macosx_target_ver = get_macosx_target_ver ()
56
- if macosx_target_ver :
57
- env [MACOSX_VERSION_VAR ] = macosx_target_ver
58
-
59
70
try :
60
- subprocess .check_call (cmd , env = env )
71
+ subprocess .check_call (cmd , env = _inject_macos_ver ( env ) )
61
72
except OSError as exc :
62
73
raise DistutilsExecError (
63
74
f"command { _debug (cmd )!r} failed: { exc .args [- 1 ]} "
0 commit comments