Skip to content

Commit

Permalink
python module: stop using distutils schemes on sufficiently new Debian
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eli-schwartz authored and dnicolodi committed Sep 8, 2023
1 parent 432518e commit 944fa91
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions mesonbuild/scripts/python_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,29 @@ def get_distutils_paths(scheme=None, prefix=None):
# default scheme to a custom one pointing to /usr/local and replacing
# site-packages with dist-packages.
# See https://github.com/mesonbuild/meson/issues/8739.
# XXX: We should be using sysconfig, but Debian only patches distutils.
#
# We should be using sysconfig, but before 3.10.3, Debian only patches distutils.
# So we may end up falling back.

def get_install_paths():
import distutils.command.install
if 'deb_system' in distutils.command.install.INSTALL_SCHEMES:
paths = get_distutils_paths(scheme='deb_system')
install_paths = get_distutils_paths(scheme='deb_system', prefix='')
if sys.version_info >= (3, 10):
scheme = sysconfig.get_default_scheme()
else:
paths = sysconfig.get_paths()
empty_vars = {'base': '', 'platbase': '', 'installed_base': ''}
install_paths = sysconfig.get_paths(vars=empty_vars)
scheme = sysconfig._get_default_scheme()

if sys.version_info >= (3, 10, 3):
if 'deb_system' in sysconfig.get_scheme_names():
scheme = 'deb_system'
else:
import distutils.command.install
if 'deb_system' in distutils.command.install.INSTALL_SCHEMES:
paths = get_distutils_paths(scheme='deb_system')
install_paths = get_distutils_paths(scheme='deb_system', prefix='')
return paths, install_paths

paths = sysconfig.get_paths(scheme=scheme)
empty_vars = {'base': '', 'platbase': '', 'installed_base': ''}
install_paths = sysconfig.get_paths(scheme=scheme, vars=empty_vars)
return paths, install_paths

def links_against_libpython():
Expand Down

0 comments on commit 944fa91

Please sign in to comment.