From 04c02bca03983bad4b1e6af18fe7fe3dcee5f15d Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 15 Dec 2020 17:12:59 +0100 Subject: [PATCH] Unify handling of pylibdirs and don't add duplicated PYTHONPATH in PythonBundle --- easybuild/easyblocks/generic/pythonbundle.py | 6 +-- easybuild/easyblocks/generic/pythonpackage.py | 43 +++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/easybuild/easyblocks/generic/pythonbundle.py b/easybuild/easyblocks/generic/pythonbundle.py index e036e6ad17..cf1a162893 100644 --- a/easybuild/easyblocks/generic/pythonbundle.py +++ b/easybuild/easyblocks/generic/pythonbundle.py @@ -32,7 +32,7 @@ from easybuild.easyblocks.generic.bundle import Bundle from easybuild.easyblocks.generic.pythonpackage import EBPYTHONPREFIXES, EXTS_FILTER_PYTHON_PACKAGES -from easybuild.easyblocks.generic.pythonpackage import PythonPackage, det_pylibdir, pick_python_cmd +from easybuild.easyblocks.generic.pythonpackage import PythonPackage, get_pylibdirs, pick_python_cmd from easybuild.tools.build_log import EasyBuildError from easybuild.tools.filetools import which from easybuild.tools.modules import get_software_root @@ -111,8 +111,8 @@ def prepare_step(self, *args, **kwargs): python_cmd = pick_python_cmd(req_maj_ver=req_py_majver, req_min_ver=req_py_minver) - self.pylibdir = det_pylibdir(python_cmd=python_cmd) - self.all_pylibdirs = [self.pylibdir, det_pylibdir(plat_specific=True, python_cmd=python_cmd)] + self.all_pylibdirs = get_pylibdirs(python_cmd=python_cmd) + self.pylibdir = self.all_pylibdirs[0] # if 'python' is not used, we need to take that into account in the extensions filter # (which is also used during the sanity check) diff --git a/easybuild/easyblocks/generic/pythonpackage.py b/easybuild/easyblocks/generic/pythonpackage.py index 8c1fbd3b7b..696703aaf8 100644 --- a/easybuild/easyblocks/generic/pythonpackage.py +++ b/easybuild/easyblocks/generic/pythonpackage.py @@ -177,6 +177,30 @@ def det_pylibdir(plat_specific=False, python_cmd=None): return pylibdir +def get_pylibdirs(python_cmd): + """Return a list of python library paths to use. The first entry will be the main one""" + log = fancylogger.getLogger('get_pylibdirs', fname=False) + + # pylibdir is the 'main' Python lib directory + pylibdir = det_pylibdir(python_cmd=python_cmd) + log.debug("Python library dir: %s" % pylibdir) + + # on (some) multilib systems, the platform-specific library directory for the system Python is different + # cfr. http://serverfault.com/a/88739/126446 + # so, we keep a list of different Python lib directories to take into account + all_pylibdirs = nub([pylibdir, det_pylibdir(plat_specific=True, python_cmd=python_cmd)]) + log.debug("All Python library dirs: %s" % all_pylibdirs) + + # make very sure an entry starting with lib/ is present, + # since older versions of setuptools hardcode 'lib' rather than using the value produced by + # distutils.sysconfig.get_python_lib (which may always be lib64/...) + if not any(pylibdir.startswith('lib' + os.path.sep) for pylibdir in all_pylibdirs): + pylibdir = os.path.join('lib', *pylibdir.split(os.path.sep)[1:]) + all_pylibdirs.append(pylibdir) + log.debug("No lib/ entry found in list of Python lib dirs, so added it: %s", all_pylibdirs) + return all_pylibdirs + + def det_pip_version(): """Determine version of currently active 'pip' command.""" @@ -331,23 +355,8 @@ def __init__(self, *args, **kwargs): def set_pylibdirs(self): """Set Python lib directory-related class variables.""" - # pylibdir is the 'main' Python lib directory - self.pylibdir = det_pylibdir(python_cmd=self.python_cmd) - self.log.debug("Python library dir: %s" % self.pylibdir) - - # on (some) multilib systems, the platform-specific library directory for the system Python is different - # cfr. http://serverfault.com/a/88739/126446 - # so, we keep a list of different Python lib directories to take into account - self.all_pylibdirs = nub([self.pylibdir, det_pylibdir(plat_specific=True, python_cmd=self.python_cmd)]) - self.log.debug("All Python library dirs: %s" % self.all_pylibdirs) - - # make very sure an entry starting with lib/ is present, - # since older versions of setuptools hardcode 'lib' rather than using the value produced by - # distutils.sysconfig.get_python_lib (which may always be lib64/...) - if not any(pylibdir.startswith('lib/') for pylibdir in self.all_pylibdirs): - pylibdir = os.path.join('lib', *self.pylibdir.split(os.path.sep)[1:]) - self.all_pylibdirs.append(pylibdir) - self.log.debug("No lib/ entry found in list of Python lib dirs, so added it: %s", self.all_pylibdirs) + self.all_pylibdirs = get_pylibdirs(python_cmd=self.python_cmd) + self.pylibdir = self.all_pylibdirs[0] def prepare_python(self): """Python-specific preperations."""