Skip to content

Commit fab3dad

Browse files
Clean up get_config_var().
1 parent a8e2cf0 commit fab3dad

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

Tools/freeze/test/freeze.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UnsupportedError(Exception):
2222
"""The operation isn't supported."""
2323

2424

25-
def _run_cmd(cmd, cwd=None, verbose=True, showcmd=True):
25+
def _run_cmd(cmd, cwd=None, verbose=True, showcmd=True, showerr=True):
2626
if showcmd:
2727
print(f'# {" ".join(shlex.quote(a) for a in cmd)}')
2828
proc = subprocess.run(
@@ -32,7 +32,8 @@ def _run_cmd(cmd, cwd=None, verbose=True, showcmd=True):
3232
text=True,
3333
)
3434
if proc.returncode != 0:
35-
print(proc.stderr, file=sys.stderr)
35+
if showerr:
36+
print(proc.stderr, file=sys.stderr)
3637
proc.check_returncode()
3738
return proc.stdout
3839

@@ -102,18 +103,19 @@ def get_config_var(build, name, *, fail=True):
102103
else:
103104
builddir = build
104105
python = os.path.join(builddir, 'python')
105-
if not os.path.isfile(python):
106-
return get_makefile_var(builddir, 'CONFIG_ARGS', fail=fail)
107106

108-
try:
109-
text = _run_cmd(
110-
[python, '-c',
111-
'import sysconfig', 'print(sysconfig.get_config_var("CONFIG_ARGS"))'],
112-
showcmd=False,
113-
)
114-
return text
115-
except subprocess.CalledProcessError:
116-
return get_makefile_var(builddir, 'CONFIG_ARGS', fail=fail)
107+
if os.path.isfile(python):
108+
try:
109+
text = _run_cmd(
110+
[python, '-c',
111+
f'import sysconfig; print(sysconfig.get_config_var("{name}"))'],
112+
showcmd=False,
113+
showerr=False,
114+
)
115+
return text
116+
except subprocess.CalledProcessError:
117+
pass
118+
return get_makefile_var(builddir, name, fail=fail)
117119

118120

119121
def get_configure_args(build, *, fail=True):

0 commit comments

Comments
 (0)