|
19 | 19 | import unittest
|
20 | 20 | import subprocess
|
21 | 21 | import zipapp
|
| 22 | +import sysconfig |
22 | 23 | from pathlib import Path
|
23 | 24 |
|
24 | 25 | from mesonbuild.mesonlib import windows_proof_rmtree, python_command, is_windows
|
25 | 26 | from mesonbuild.coredata import version as meson_version
|
26 | 27 |
|
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' |
36 | 46 |
|
37 | 47 | 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': ''}) |
39 | 52 | # Ensure that / is the path separator and not \, then strip /
|
40 | 53 | return Path(pypath).as_posix().strip('/')
|
41 | 54 |
|
42 | 55 | def get_pybindir():
|
43 | 56 | # '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('\\/') |
45 | 60 |
|
46 | 61 | class CommandTests(unittest.TestCase):
|
47 | 62 | '''
|
|
0 commit comments