Skip to content

Commit 8ac20e5

Browse files
authored
[3.11] gh-109615: Fix support test_copy_python_src_ignore() (#109958) (#109962)
gh-109615: Fix support test_copy_python_src_ignore() (#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". (cherry picked from commit b89ed9d)
1 parent 2423168 commit 8ac20e5

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

Lib/test/libregrtest/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,13 @@ def set_temp_dir(self):
731731
if sysconfig.is_python_build():
732732
self.tmp_dir = sysconfig.get_config_var('abs_builddir')
733733
if self.tmp_dir is None:
734-
# gh-74470: On Windows, only srcdir is available. Using
735-
# abs_builddir mostly matters on UNIX when building Python
736-
# out of the source tree, especially when the source tree
737-
# is read only.
738-
self.tmp_dir = sysconfig.get_config_var('srcdir')
734+
self.tmp_dir = sysconfig.get_config_var('abs_srcdir')
735+
if not self.tmp_dir:
736+
# gh-74470: On Windows, only srcdir is available. Using
737+
# abs_builddir mostly matters on UNIX when building
738+
# Python out of the source tree, especially when the
739+
# source tree is read only.
740+
self.tmp_dir = sysconfig.get_config_var('srcdir')
739741
self.tmp_dir = os.path.join(self.tmp_dir, 'build')
740742
else:
741743
self.tmp_dir = tempfile.gettempdir()

Lib/test/pythoninfo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ def collect_sysconfig(info_add):
524524
'Py_NOGIL',
525525
'SHELL',
526526
'SOABI',
527+
'abs_builddir',
528+
'abs_srcdir',
527529
'prefix',
530+
'srcdir',
528531
):
529532
value = sysconfig.get_config_var(name)
530533
if name == 'ANDROID_API_LEVEL' and not value:

Lib/test/test_support.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,13 @@ def recursive_function(depth):
779779
#self.assertEqual(available, 2)
780780

781781
def test_copy_python_src_ignore(self):
782-
src_dir = sysconfig.get_config_var('srcdir')
782+
src_dir = sysconfig.get_config_var('abs_srcdir')
783+
if not src_dir:
784+
src_dir = sysconfig.get_config_var('srcdir')
783785
src_dir = os.path.abspath(src_dir)
786+
if not os.path.exists(src_dir):
787+
self.skipTest(f"cannot access Python source code directory:"
788+
f" {src_dir!r}")
784789

785790
ignored = {'.git', '__pycache__'}
786791

Tools/freeze/test/freeze.py

Lines changed: 8 additions & 1 deletion
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/scripts/patchcheck.py

Lines changed: 8 additions & 1 deletion
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 = [os.path.join('Modules', '_ctypes', 'libffi_osx'),
1724
os.path.join('Modules', '_ctypes', 'libffi_msvc'),
1825
os.path.join('Modules', '_decimal', 'libmpdec'),
1926
os.path.join('Modules', 'expat'),
2027
os.path.join('Modules', 'zlib')]
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)