Skip to content

Commit 6a39ef1

Browse files
jpakkanenirbheek
authored andcommitted
Only use Debian path fixing on old distros.
Cherry-picked from #10886 Final version will probably look different when merged.
1 parent e168c3d commit 6a39ef1

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

run_meson_command_tests.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,44 @@
1919
import unittest
2020
import subprocess
2121
import zipapp
22+
import sysconfig
2223
from pathlib import Path
2324

2425
from mesonbuild.mesonlib import windows_proof_rmtree, python_command, is_windows
2526
from mesonbuild.coredata import version as meson_version
2627

27-
# Handle the scheme that Debian patches in the as default
28-
import sysconfig
29-
# This function was renamed and made public in Python 3.10
30-
if hasattr(sysconfig, 'get_default_scheme'):
31-
scheme = sysconfig.get_default_scheme()
32-
else:
33-
scheme = sysconfig._get_default_scheme()
34-
if scheme == 'posix_local':
35-
scheme = 'posix_prefix'
28+
scheme = None
29+
30+
def needs_debian_path_hack():
31+
try:
32+
import setuptools
33+
return int(setuptools.__version__.split('.')[0]) < 65
34+
except ModuleNotFoundError:
35+
return False
36+
37+
if needs_debian_path_hack():
38+
# Handle the scheme that Debian patches in the as default
39+
# This function was renamed and made public in Python 3.10
40+
if hasattr(sysconfig, 'get_default_scheme'):
41+
scheme = sysconfig.get_default_scheme()
42+
else:
43+
scheme = sysconfig._get_default_scheme()
44+
if scheme == 'posix_local':
45+
scheme = 'posix_prefix'
3646

3747
def get_pypath():
38-
pypath = sysconfig.get_path('purelib', scheme=scheme, vars={'base': ''})
48+
if scheme:
49+
pypath = sysconfig.get_path('purelib', scheme=scheme, vars={'base': ''})
50+
else:
51+
pypath = sysconfig.get_path('purelib', vars={'base': ''})
3952
# Ensure that / is the path separator and not \, then strip /
4053
return Path(pypath).as_posix().strip('/')
4154

4255
def get_pybindir():
4356
# 'Scripts' on Windows and 'bin' on other platforms including MSYS
44-
return sysconfig.get_path('scripts', scheme=scheme, vars={'base': ''}).strip('\\/')
57+
if scheme:
58+
return sysconfig.get_path('scripts', scheme=scheme, vars={'base': ''}).strip('\\/')
59+
return sysconfig.get_path('scripts', vars={'base': ''}).strip('\\/')
4560

4661
class CommandTests(unittest.TestCase):
4762
'''

0 commit comments

Comments
 (0)