From bc1d2b13fbc316be6f60d39855cf4010f5b024ba Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Mon, 30 Sep 2024 16:19:28 +0200 Subject: [PATCH] don't use force_pythonpath + clarify why we're keeping logic on $PYTHONPATH vs $EBPYTHONPREFIXES in PythonBundle + PythonPackage easyblocks --- easybuild/easyblocks/generic/pythonbundle.py | 13 +++++++++---- easybuild/easyblocks/generic/pythonpackage.py | 15 +++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/easybuild/easyblocks/generic/pythonbundle.py b/easybuild/easyblocks/generic/pythonbundle.py index 18a0fb70817..76729c41052 100644 --- a/easybuild/easyblocks/generic/pythonbundle.py +++ b/easybuild/easyblocks/generic/pythonbundle.py @@ -147,11 +147,16 @@ def make_module_extra(self, *args, **kwargs): txt = super(Bundle, self).make_module_extra(*args, **kwargs) # update $EBPYTHONPREFIXES rather than $PYTHONPATH - # if this Python package was installed for multiple Python versions - # or if we prefer it + # if this Python package was installed for multiple Python versions, or if we prefer it + use_ebpythonprefixes = False runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)] - use_ebpythonprefixes = 'Python' in runtime_deps and \ - build_option('prefer_python_search_path') == EBPYTHONPREFIXES and not self.cfg['force_pythonpath'] + + if 'Python' in runtime_deps: + self.log.info("Found Python runtime dependency, so considering $EBPYTHONPREFIXES...") + if build_option('prefer_python_search_path') == EBPYTHONPREFIXES: + self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that") + use_ebpythonprefixes = True + if self.multi_python or use_ebpythonprefixes: path = '' # EBPYTHONPREFIXES are relative to the install dir if path not in self.module_generator.added_paths_per_key[EBPYTHONPREFIXES]: diff --git a/easybuild/easyblocks/generic/pythonpackage.py b/easybuild/easyblocks/generic/pythonpackage.py index 916f8545f8c..1b9a8ea5174 100644 --- a/easybuild/easyblocks/generic/pythonpackage.py +++ b/easybuild/easyblocks/generic/pythonpackage.py @@ -1162,11 +1162,18 @@ def make_module_extra(self, *args, **kwargs): txt = '' # update $EBPYTHONPREFIXES rather than $PYTHONPATH - # if this Python package was installed for multiple Python versions - # or if we prefer it + # if this Python package was installed for multiple Python versions, or if we prefer it; + # note: although EasyBuild framework also has logic for this in EasyBlock.make_module_extra, + # we retain full control here, since the logic is slightly different + use_ebpythonprefixes = False runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)] - use_ebpythonprefixes = 'Python' in runtime_deps and \ - build_option('prefer_python_search_path') == EBPYTHONPREFIXES and not self.cfg['force_pythonpath'] + + if 'Python' in runtime_deps: + self.log.info("Found Python runtime dependency, so considering $EBPYTHONPREFIXES...") + if build_option('prefer_python_search_path') == EBPYTHONPREFIXES: + self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that") + use_ebpythonprefixes = True + if self.multi_python or use_ebpythonprefixes: path = '' # EBPYTHONPREFIXES are relative to the install dir txt += self.module_generator.prepend_paths(EBPYTHONPREFIXES, path)