|
6 | 6 | import logging
|
7 | 7 | import os
|
8 | 8 | import sys
|
| 9 | +import sysconfig |
9 | 10 | from collections import namedtuple
|
10 | 11 | from textwrap import dedent
|
11 | 12 |
|
@@ -311,3 +312,51 @@ def test_py_info_to_system_raises(session_app_data, mocker, caplog, skip_if_test
|
311 | 312 | assert log.levelno == logging.INFO
|
312 | 313 | expected = "ignore {} due cannot resolve system due to RuntimeError('failed to detect ".format(sys.executable)
|
313 | 314 | assert expected in log.message
|
| 315 | + |
| 316 | + |
| 317 | +def test_custom_venv_install_scheme_is_prefered(mocker): |
| 318 | + # The paths in this test are Fedora paths, but we set them for nt as well, |
| 319 | + # so the test also works on Windows, despite the actual values are nonsense there. |
| 320 | + # Values were simplified to be compatible with all the supported Python versions. |
| 321 | + # Note: Since this file has from __future__ import unicode_literals, |
| 322 | + # we manually cast all the values to str() |
| 323 | + # as the original schemes are not unicode on Python 2. |
| 324 | + default_scheme = { |
| 325 | + str("stdlib"): str("{base}/lib/python{py_version_short}"), |
| 326 | + str("platstdlib"): str("{platbase}/lib/python{py_version_short}"), |
| 327 | + str("purelib"): str("{base}/local/lib/python{py_version_short}/site-packages"), |
| 328 | + str("platlib"): str("{platbase}/local/lib/python{py_version_short}/site-packages"), |
| 329 | + str("include"): str("{base}/include/python{py_version_short}"), |
| 330 | + str("platinclude"): str("{platbase}/include/python{py_version_short}"), |
| 331 | + str("scripts"): str("{base}/local/bin"), |
| 332 | + str("data"): str("{base}/local"), |
| 333 | + } |
| 334 | + venv_scheme = {key: path.replace(str("local"), str()) for key, path in default_scheme.items()} |
| 335 | + sysconfig_install_schemes = { |
| 336 | + str("posix_prefix"): default_scheme, |
| 337 | + str("nt"): default_scheme, |
| 338 | + str("venv"): venv_scheme, |
| 339 | + } |
| 340 | + if getattr(sysconfig, "get_preferred_scheme", None): |
| 341 | + sysconfig_install_schemes[sysconfig.get_preferred_scheme("prefix")] = default_scheme |
| 342 | + mocker.patch("sysconfig._INSTALL_SCHEMES", sysconfig_install_schemes) |
| 343 | + |
| 344 | + # On Python < 3.10, the distutils schemes are not derived from sysconfig schemes |
| 345 | + # So we mock them as well to assert the custom "venv" install scheme has priority |
| 346 | + distutils_scheme = { |
| 347 | + str("purelib"): str("$base/local/lib/python$py_version_short/site-packages"), |
| 348 | + str("platlib"): str("$platbase/local/lib/python$py_version_short/site-packages"), |
| 349 | + str("headers"): str("$base/include/python$py_version_short/$dist_name"), |
| 350 | + str("scripts"): str("$base/local/bin"), |
| 351 | + str("data"): str("$base/local"), |
| 352 | + } |
| 353 | + distutils_schemes = { |
| 354 | + str("unix_prefix"): distutils_scheme, |
| 355 | + str("nt"): distutils_scheme, |
| 356 | + } |
| 357 | + mocker.patch("distutils.command.install.INSTALL_SCHEMES", distutils_schemes) |
| 358 | + |
| 359 | + pyinfo = PythonInfo() |
| 360 | + pyver = "{}.{}".format(pyinfo.version_info.major, pyinfo.version_info.minor) |
| 361 | + assert pyinfo.install_path("scripts") == "bin" |
| 362 | + assert pyinfo.install_path("purelib").replace(os.sep, "/") == "lib/python{}/site-packages".format(pyver) |
0 commit comments