Skip to content

Commit

Permalink
Extracted method for resolving python lib dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Feb 12, 2024
1 parent 2b8bf7b commit 22aadd3
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,31 @@ def initialize_options(self):
self.user = None
self.parallel = None

@staticmethod
def _python_lib_dir(sysconfig):
"""
Resolve Python's library directory for building extensions
that rely on a shared Python library.
See python/cpython#44264 and python/cpython#48686
"""
if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
return

if sysconfig.python_build:
yield '.'
return

if sys.platform == 'zos':
# On z/OS, a user is not required to install Python to
# a predetermined path, but can use Python portably
installed_dir = sysconfig.get_config_var('base')
lib_dir = sysconfig.get_config_var('platlibdir')
yield os.path.join(installed_dir, lib_dir)
else:
# building third party extensions
yield sysconfig.get_config_var('LIBDIR')

def finalize_options(self): # noqa: C901
from distutils import sysconfig

Expand Down Expand Up @@ -231,23 +256,7 @@ def finalize_options(self): # noqa: C901
# building python standard extensions
self.library_dirs.append('.')

# For building extensions with a shared Python library,
# Python's library directory must be appended to library_dirs
# See Issues: #1600860, #4366
if sysconfig.get_config_var('Py_ENABLE_SHARED'):
if not sysconfig.python_build:
if sys.platform == 'zos':
# On z/OS, a user is not required to install Python to
# a predetermined path, but can use Python portably
installed_dir = sysconfig.get_config_var('base')
lib_dir = sysconfig.get_config_var('platlibdir')
self.library_dirs.append(os.path.join(installed_dir, lib_dir))
else:
# building third party extensions
self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
else:
# building python standard extensions
self.library_dirs.append('.')
self.library_dirs.extend(self._python_lib_dir(sysconfig))

# The argument parsing will result in self.define being a string, but
# it has to be a list of 2-tuples. All the preprocessor symbols
Expand Down

0 comments on commit 22aadd3

Please sign in to comment.