Skip to content

Commit d87145d

Browse files
vstinnerGlyphack
authored andcommitted
pythongh-109615: Fix support test_copy_python_src_ignore() (python#109958)
Fix the test when run on an installed Python: use "abs_srcdir" of sysconfig, and skip the test if the Python source code cannot be found. * Tools/patchcheck/patchcheck.py, Tools/freeze/test/freeze.py and Lib/test/libregrtest/utils.py now first try to get "abs_srcdir" from sysconfig, before getting "srcdir" from sysconfig. * test.pythoninfo logs sysconfig "abs_srcdir".
1 parent 7ffa11f commit d87145d

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

Lib/test/libregrtest/utils.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,13 @@ 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-
# gh-74470: On Windows, only srcdir is available. Using
359-
# abs_builddir mostly matters on UNIX when building Python
360-
# out of the source tree, especially when the source tree
361-
# is read only.
362-
tmp_dir = sysconfig.get_config_var('srcdir')
358+
tmp_dir = sysconfig.get_config_var('abs_srcdir')
359+
if not tmp_dir:
360+
# gh-74470: On Windows, only srcdir is available. Using
361+
# abs_builddir mostly matters on UNIX when building
362+
# Python out of the source tree, especially when the
363+
# source tree is read only.
364+
tmp_dir = sysconfig.get_config_var('srcdir')
363365
tmp_dir = os.path.join(tmp_dir, 'build')
364366
else:
365367
# WASI platform

Lib/test/pythoninfo.py

+1
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ def collect_sysconfig(info_add):
520520
'SHELL',
521521
'SOABI',
522522
'abs_builddir',
523+
'abs_srcdir',
523524
'prefix',
524525
'srcdir',
525526
):

Lib/test/test_support.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,13 @@ def test_set_memlimit(self):
802802
support.real_max_memuse = old_real_max_memuse
803803

804804
def test_copy_python_src_ignore(self):
805-
src_dir = sysconfig.get_config_var('srcdir')
805+
src_dir = sysconfig.get_config_var('abs_srcdir')
806+
if not src_dir:
807+
src_dir = sysconfig.get_config_var('srcdir')
806808
src_dir = os.path.abspath(src_dir)
809+
if not os.path.exists(src_dir):
810+
self.skipTest(f"cannot access Python source code directory:"
811+
f" {src_dir!r}")
807812

808813
ignored = {'.git', '__pycache__'}
809814

Tools/freeze/test/freeze.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
from test import support
88

99

10+
def get_python_source_dir():
11+
src_dir = sysconfig.get_config_var('abs_srcdir')
12+
if not src_dir:
13+
src_dir = sysconfig.get_config_var('srcdir')
14+
return os.path.abspath(src_dir)
15+
16+
1017
TESTS_DIR = os.path.dirname(__file__)
1118
TOOL_ROOT = os.path.dirname(TESTS_DIR)
12-
SRCDIR = os.path.abspath(sysconfig.get_config_var('srcdir'))
19+
SRCDIR = get_python_source_dir()
1320

1421
MAKE = shutil.which('make')
1522
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')

Tools/patchcheck/patchcheck.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111
import untabify
1212

1313

14+
def get_python_source_dir():
15+
src_dir = sysconfig.get_config_var('abs_srcdir')
16+
if not src_dir:
17+
src_dir = sysconfig.get_config_var('srcdir')
18+
return os.path.abspath(src_dir)
19+
20+
1421
# Excluded directories which are copies of external libraries:
1522
# don't check their coding style
1623
EXCLUDE_DIRS = [
1724
os.path.join('Modules', '_decimal', 'libmpdec'),
1825
os.path.join('Modules', 'expat'),
1926
os.path.join('Modules', 'zlib'),
2027
]
21-
SRCDIR = sysconfig.get_config_var('srcdir')
28+
SRCDIR = get_python_source_dir()
2229

2330

2431
def n_files_str(count):

0 commit comments

Comments
 (0)