|
1 | 1 | import os
|
| 2 | +import sys |
2 | 3 | from textwrap import dedent
|
3 | 4 | from typing import Optional
|
4 | 5 |
|
@@ -203,6 +204,31 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
|
203 | 204 | assert result.stdout.strip() == "2.0", str(result)
|
204 | 205 |
|
205 | 206 |
|
| 207 | +if sys.version_info < (3, 12): |
| 208 | + BUILD_ENV_ERROR_DEBUG_CODE = r""" |
| 209 | + from distutils.sysconfig import get_python_lib |
| 210 | + print( |
| 211 | + f'imported `pkg` from `{pkg.__file__}`', |
| 212 | + file=sys.stderr) |
| 213 | + print('system sites:\n ' + '\n '.join(sorted({ |
| 214 | + get_python_lib(plat_specific=0), |
| 215 | + get_python_lib(plat_specific=1), |
| 216 | + })), file=sys.stderr) |
| 217 | + """ |
| 218 | +else: |
| 219 | + BUILD_ENV_ERROR_DEBUG_CODE = r""" |
| 220 | + from sysconfig import get_paths |
| 221 | + paths = get_paths() |
| 222 | + print( |
| 223 | + f'imported `pkg` from `{pkg.__file__}`', |
| 224 | + file=sys.stderr) |
| 225 | + print('system sites:\n ' + '\n '.join(sorted({ |
| 226 | + paths['platlib'], |
| 227 | + paths['purelib'], |
| 228 | + })), file=sys.stderr) |
| 229 | + """ |
| 230 | + |
| 231 | + |
206 | 232 | @pytest.mark.usefixtures("enable_user_site")
|
207 | 233 | def test_build_env_isolation(script: PipTestEnvironment) -> None:
|
208 | 234 | # Create dummy `pkg` wheel.
|
@@ -231,26 +257,17 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
|
231 | 257 | run_with_build_env(
|
232 | 258 | script,
|
233 | 259 | "",
|
234 |
| - r""" |
235 |
| - from distutils.sysconfig import get_python_lib |
| 260 | + f""" |
236 | 261 | import sys
|
237 | 262 |
|
238 | 263 | try:
|
239 | 264 | import pkg
|
240 | 265 | except ImportError:
|
241 | 266 | pass
|
242 | 267 | else:
|
243 |
| - print( |
244 |
| - f'imported `pkg` from `{pkg.__file__}`', |
245 |
| - file=sys.stderr) |
246 |
| - print('system sites:\n ' + '\n '.join(sorted({ |
247 |
| - get_python_lib(plat_specific=0), |
248 |
| - get_python_lib(plat_specific=1), |
249 |
| - })), file=sys.stderr) |
250 |
| - print('sys.path:\n ' + '\n '.join(sys.path), file=sys.stderr) |
| 268 | + {BUILD_ENV_ERROR_DEBUG_CODE} |
| 269 | + print('sys.path:\\n ' + '\\n '.join(sys.path), file=sys.stderr) |
251 | 270 | sys.exit(1)
|
252 |
| - """ |
253 |
| - f""" |
254 | 271 | # second check: direct check of exclusion of system site packages
|
255 | 272 | import os
|
256 | 273 |
|
|
0 commit comments