Skip to content

Commit 01423cb

Browse files
authored
Improves the ability to build in CI (GH-5728)
1 parent d6ff8a7 commit 01423cb

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

Lib/test/support/script_helper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def interpreter_requires_environment():
3636
"""
3737
global __cached_interp_requires_environment
3838
if __cached_interp_requires_environment is None:
39+
# If PYTHONHOME is set, assume that we need it
40+
if 'PYTHONHOME' in os.environ:
41+
__cached_interp_requires_environment = True
42+
return True
43+
3944
# Try running an interpreter with -E to see if it works or not.
4045
try:
4146
subprocess.check_call([sys.executable, '-E',
@@ -166,7 +171,9 @@ def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
166171
kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
167172
object.
168173
"""
169-
cmd_line = [sys.executable, '-E']
174+
cmd_line = [sys.executable]
175+
if not interpreter_requires_environment():
176+
cmd_line.append('-E')
170177
cmd_line.extend(args)
171178
# Under Fedora (?), GNU readline can output junk on stderr when initialized,
172179
# depending on the TERM setting. Setting TERM=vt100 is supposed to disable

Lib/test/test_cmd_line.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def test_verbose(self):
6363
rc, out, err = assert_python_ok('-vv')
6464
self.assertNotIn(b'stack overflow', err)
6565

66+
@unittest.skipIf(interpreter_requires_environment(),
67+
'Cannot run -E tests when PYTHON env vars are required.')
6668
def test_xoptions(self):
6769
def get_xoptions(*args):
6870
# use subprocess module directly because test.support.script_helper adds
@@ -278,11 +280,7 @@ def test_empty_PYTHONPATH_issue16309(self):
278280

279281
def test_displayhook_unencodable(self):
280282
for encoding in ('ascii', 'latin-1', 'utf-8'):
281-
# We are testing a PYTHON environment variable here, so we can't
282-
# use -E, -I, or script_helper (which uses them). So instead we do
283-
# poor-man's isolation by deleting the PYTHON vars from env.
284-
env = {key:value for (key,value) in os.environ.copy().items()
285-
if not key.startswith('PYTHON')}
283+
env = os.environ.copy()
286284
env['PYTHONIOENCODING'] = encoding
287285
p = subprocess.Popen(
288286
[sys.executable, '-i'],
@@ -704,6 +702,8 @@ def test_pythondevmode_env(self):
704702
self.assertEqual(proc.returncode, 0, proc)
705703

706704

705+
@unittest.skipIf(interpreter_requires_environment(),
706+
'Cannot run -I tests when PYTHON env vars are required.')
707707
class IgnoreEnvironmentTest(unittest.TestCase):
708708

709709
def run_ignoring_vars(self, predicate, **env_vars):

PCbuild/find_python.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
@if exist "%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe" (set PYTHON="%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe") & (set _Py_Python_Source=found in externals directory) & goto :found
3232

3333
@rem If HOST_PYTHON is recent enough, use that
34-
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -c "import sys; assert sys.version_info[:2] >= (3, 6)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
34+
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -Ec "import sys; assert sys.version_info[:2] >= (3, 6)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
3535

3636
@rem If py.exe finds a recent enough version, use that one
37-
@py -3.6 -V >nul 2>&1 && (set PYTHON=py -3.6) && (set _Py_Python_Source=found with py.exe) && goto :found
37+
@py -3.6 -EV >nul 2>&1 && (set PYTHON=py -3.6) && (set _Py_Python_Source=found with py.exe) && goto :found
3838

3939
@if NOT exist "%_Py_EXTERNALS_DIR%" mkdir "%_Py_EXTERNALS_DIR%"
4040
@set _Py_NUGET=%NUGET%
@@ -50,7 +50,7 @@
5050
@rem If it fails, retry with any available copy of Python
5151
@powershell.exe -Command Invoke-WebRequest %_Py_NUGET_URL% -OutFile '%_Py_NUGET%'
5252
@if errorlevel 1 (
53-
@%_Py_HOST_PYTHON% "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
53+
@%_Py_HOST_PYTHON% -E "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
5454
)
5555
)
5656
@echo Installing Python via nuget...

PCbuild/get_externals.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ for %%e in (%libraries%) do (
6565
git clone --depth 1 https://github.com/%ORG%/cpython-source-deps --branch %%e "%EXTERNALS_DIR%\%%e"
6666
) else (
6767
echo.Fetching %%e...
68-
%PYTHON% "%PCBUILD%\get_external.py" -O %ORG% %%e
68+
%PYTHON% -E "%PCBUILD%get_external.py" -O %ORG% -e "%EXTERNALS_DIR%" %%e
6969
)
7070
)
7171

@@ -84,7 +84,7 @@ for %%b in (%binaries%) do (
8484
git clone --depth 1 https://github.com/%ORG%/cpython-bin-deps --branch %%b "%EXTERNALS_DIR%\%%b"
8585
) else (
8686
echo.Fetching %%b...
87-
%PYTHON% "%PCBUILD%\get_external.py" -b -O %ORG% %%b
87+
%PYTHON% -E "%PCBUILD%get_external.py" -b -O %ORG% -e "%EXTERNALS_DIR%" %%b
8888
)
8989
)
9090

PCbuild/python.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
<BuildPath Condition="$(Configuration) == 'PGInstrument'">$(BuildPath)instrumented\</BuildPath>
4444

4545
<!-- Directories of external projects. tcltk is handled in tcltk.props -->
46-
<ExternalsDir>$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals\`))</ExternalsDir>
46+
<ExternalsDir>$(EXTERNALS_DIR)</ExternalsDir>
47+
<ExternalsDir Condition="$(ExternalsDir) == ''">$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))</ExternalsDir>
48+
<ExternalsDir Condition="!HasTrailingSlash($(ExternalsDir))">$(ExternalsDir)\</ExternalsDir>
4749
<sqlite3Dir>$(ExternalsDir)sqlite-3.21.0.0\</sqlite3Dir>
4850
<bz2Dir>$(ExternalsDir)bzip2-1.0.6\</bz2Dir>
4951
<lzmaDir>$(ExternalsDir)xz-5.2.2\</lzmaDir>

0 commit comments

Comments
 (0)