Skip to content

Commit d53d10b

Browse files
eli-schwartzrobtaylor
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 732533a commit d53d10b

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

mesonbuild/scripts/python_info.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
del sys.path[0]
1414

1515
import json, os, sysconfig
16-
import distutils.command.install
1716

1817
def get_distutils_paths(scheme=None, prefix=None):
1918
import distutils.dist
@@ -37,15 +36,32 @@ def get_distutils_paths(scheme=None, prefix=None):
3736
# default scheme to a custom one pointing to /usr/local and replacing
3837
# site-packages with dist-packages.
3938
# See https://github.com/mesonbuild/meson/issues/8739.
40-
# XXX: We should be using sysconfig, but Debian only patches distutils.
39+
#
40+
# We should be using sysconfig, but before 3.10.3, Debian only patches distutils.
41+
# So we may end up falling back.
4142

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

5066
def links_against_libpython():
5167
from distutils.core import Distribution, Extension

0 commit comments

Comments
 (0)