From 6d7976cd57e1f352287869e9ff46e4b3aa3fe333 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 13 Nov 2021 10:13:25 -0500 Subject: [PATCH 1/2] Allow overrides of _multiarch_addendum and _sysconfig_name_tmpl, supporting the patches used by pkgsrc. Fixes #16. --- distutils/__init__.py | 7 ++++--- distutils/sysconfig.py | 33 ++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/distutils/__init__.py b/distutils/__init__.py index 0ba5e44a..8fd493b4 100644 --- a/distutils/__init__.py +++ b/distutils/__init__.py @@ -15,9 +15,10 @@ try: - # Allow Debian (only) to customize system behavior. - # Ref pypa/distutils#2. This hook is deprecated and - # no other environments should use it. + # Allow Debian and pkgsrc (only) to customize system + # behavior. Ref pypa/distutils#2 and pypa/distutils#16. + # This hook is deprecated and no other environments + # should use it. importlib.import_module('_distutils_system_mod') except ImportError: pass diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 1c025892..e5b2177c 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -279,14 +279,23 @@ def get_config_h_filename(): return os.path.join(inc_dir, 'pyconfig.h') +_makefile_tmpl = 'config-{python_ver}{build_flags}{multiarch}' + + def get_makefile_filename(): """Return full pathname of installed Makefile from the Python build.""" if python_build: return os.path.join(_sys_home or project_base, "Makefile") lib_dir = get_python_lib(plat_specific=0, standard_lib=1) - config_file = 'config-{}{}'.format(get_python_version(), build_flags) - if hasattr(sys.implementation, '_multiarch'): - config_file += '-%s' % sys.implementation._multiarch + multiarch = ( + '-%s' % sys.implementation._multiarch + if hasattr(sys.implementation, '_multiarch') else '' + ) + config_file = _makefile_tmpl.format( + python_ver=get_python_version(), + build_flags=build_flags, + multiarch=multiarch, + ) return os.path.join(lib_dir, config_file, 'Makefile') @@ -458,15 +467,21 @@ def expand_makefile_vars(s, vars): _config_vars = None + +_sysconfig_name_tmpl = '_sysconfigdata_{abi}_{platform}_{multiarch}' + + def _init_posix(): """Initialize the module as appropriate for POSIX systems.""" # _sysconfigdata is generated at build time, see the sysconfig module - name = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME', - '_sysconfigdata_{abi}_{platform}_{multiarch}'.format( - abi=sys.abiflags, - platform=sys.platform, - multiarch=getattr(sys.implementation, '_multiarch', ''), - )) + name = os.environ.get( + '_PYTHON_SYSCONFIGDATA_NAME', + _sysconfig_name_tmpl.format( + abi=sys.abiflags, + platform=sys.platform, + multiarch=getattr(sys.implementation, '_multiarch', ''), + ), + ) try: _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0) except ImportError: From 39539509f009e5e77fa578e969badf591fe15e42 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 17 Nov 2021 21:04:24 -0500 Subject: [PATCH 2/2] Add comments to help protect these interfaces from refactoring without consideration. --- distutils/sysconfig.py | 1 + 1 file changed, 1 insertion(+) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index e5b2177c..9f980d6a 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -279,6 +279,7 @@ def get_config_h_filename(): return os.path.join(inc_dir, 'pyconfig.h') +# Allow this value to be patched by pkgsrc. Ref pypa/distutils#16. _makefile_tmpl = 'config-{python_ver}{build_flags}{multiarch}'