Skip to content

Commit 7e0013f

Browse files
eli-schwartzdnicolodi
authored andcommitted
python module: stop using distutils schemes on sufficiently new Debian
Since 3.10.3, Debian finally started patching sysconfig with custom paths, instead of just distutils. This means we can now go use that instead. It reduces our reliance on the deprecated distutils module. Partial fix for mesonbuild#7702.
1 parent b598a2a commit 7e0013f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

mesonbuild/scripts/python_info.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,29 @@ def get_distutils_paths(scheme=None, prefix=None):
3737
# default scheme to a custom one pointing to /usr/local and replacing
3838
# site-packages with dist-packages.
3939
# See https://github.com/mesonbuild/meson/issues/8739.
40-
# XXX: We should be using sysconfig, but Debian only patches distutils.
40+
#
41+
# We should be using sysconfig, but before 3.10.3, Debian only patches distutils.
42+
# So we may end up falling back.
4143

4244
def get_install_paths():
43-
import distutils.command.install
44-
if 'deb_system' in distutils.command.install.INSTALL_SCHEMES:
45-
paths = get_distutils_paths(scheme='deb_system')
46-
install_paths = get_distutils_paths(scheme='deb_system', prefix='')
45+
if sys.version_info >= (3, 10):
46+
scheme = sysconfig.get_default_scheme()
4747
else:
48-
paths = sysconfig.get_paths()
49-
empty_vars = {'base': '', 'platbase': '', 'installed_base': ''}
50-
install_paths = sysconfig.get_paths(vars=empty_vars)
48+
scheme = sysconfig._get_default_scheme()
49+
50+
if sys.version_info >= (3, 10, 3):
51+
if 'deb_system' in sysconfig.get_scheme_names():
52+
scheme = 'deb_system'
53+
else:
54+
import distutils.command.install
55+
if 'deb_system' in distutils.command.install.INSTALL_SCHEMES:
56+
paths = get_distutils_paths(scheme='deb_system')
57+
install_paths = get_distutils_paths(scheme='deb_system', prefix='')
58+
return paths, install_paths
59+
60+
paths = sysconfig.get_paths(scheme=scheme)
61+
empty_vars = {'base': '', 'platbase': '', 'installed_base': ''}
62+
install_paths = sysconfig.get_paths(scheme=scheme, vars=empty_vars)
5163
return paths, install_paths
5264

5365
def links_against_libpython():

0 commit comments

Comments
 (0)