Skip to content

Commit a57099f

Browse files
committed
pythongh-109615: Fix test_tools.test_freeze SRCDIR
* Use sysconfig to get the source directory. * Use sysconfig.get_config_var() to get CONFIG_ARGS variable.
1 parent 9dbfe2d commit a57099f

File tree

2 files changed

+14
-36
lines changed

2 files changed

+14
-36
lines changed

Lib/test/libregrtest/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
355355
if not support.is_wasi:
356356
tmp_dir = sysconfig.get_config_var('abs_builddir')
357357
if tmp_dir is None:
358-
# bpo-30284: On Windows, only srcdir is available. Using
358+
# gh-74470: On Windows, only srcdir is available. Using
359359
# abs_builddir mostly matters on UNIX when building Python
360360
# out of the source tree, especially when the source tree
361361
# is read only.

Tools/freeze/test/freeze.py

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import os
22
import os.path
3-
import re
43
import shlex
54
import shutil
65
import subprocess
6+
import sysconfig
7+
8+
9+
def get_source_dir():
10+
src_dir = sysconfig.get_config_var('abs_builddir')
11+
if src_dir is None:
12+
# gh-74470: On Windows, only srcdir is available.
13+
src_dir = sysconfig.get_config_var('srcdir')
14+
return os.path.abspath(src_dir)
715

816

917
TESTS_DIR = os.path.dirname(__file__)
1018
TOOL_ROOT = os.path.dirname(TESTS_DIR)
11-
SRCDIR = os.path.dirname(os.path.dirname(TOOL_ROOT))
19+
SRCDIR = get_source_dir()
1220

1321
MAKE = shutil.which('make')
1422
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')
@@ -75,7 +83,7 @@ def ensure_opt(args, name, value):
7583

7684

7785
def copy_source_tree(newroot, oldroot):
78-
print(f'copying the source tree into {newroot}...')
86+
print(f'copying the source tree {oldroot} into {newroot}...')
7987
if os.path.exists(newroot):
8088
if newroot == SRCDIR:
8189
raise Exception('this probably isn\'t what you wanted')
@@ -97,34 +105,6 @@ def ignore_non_src(src, names):
97105
_run_quiet([MAKE, 'clean'], newroot)
98106

99107

100-
def get_makefile_var(builddir, name):
101-
regex = re.compile(rf'^{name} *=\s*(.*?)\s*$')
102-
filename = os.path.join(builddir, 'Makefile')
103-
try:
104-
infile = open(filename, encoding='utf-8')
105-
except FileNotFoundError:
106-
return None
107-
with infile:
108-
for line in infile:
109-
m = regex.match(line)
110-
if m:
111-
value, = m.groups()
112-
return value or ''
113-
return None
114-
115-
116-
def get_config_var(builddir, name):
117-
python = os.path.join(builddir, 'python')
118-
if os.path.isfile(python):
119-
cmd = [python, '-c',
120-
f'import sysconfig; print(sysconfig.get_config_var("{name}"))']
121-
try:
122-
return _run_stdout(cmd)
123-
except subprocess.CalledProcessError:
124-
pass
125-
return get_makefile_var(builddir, name)
126-
127-
128108
##################################
129109
# freezing
130110

@@ -151,10 +131,8 @@ def prepare(script=None, outdir=None):
151131

152132
# Run configure.
153133
print(f'configuring python in {builddir}...')
154-
cmd = [
155-
os.path.join(srcdir, 'configure'),
156-
*shlex.split(get_config_var(SRCDIR, 'CONFIG_ARGS') or ''),
157-
]
134+
config_args = shlex.split(sysconfig.get_config_var(SRCDIR, 'CONFIG_ARGS') or '')
135+
cmd = [os.path.join(srcdir, 'configure'), *config_args]
158136
ensure_opt(cmd, 'cache-file', os.path.join(outdir, 'python-config.cache'))
159137
prefix = os.path.join(outdir, 'python-installation')
160138
ensure_opt(cmd, 'prefix', prefix)

0 commit comments

Comments
 (0)