|
42 | 42 |
|
43 | 43 | import easybuild.tools.environment as env |
44 | 44 | from easybuild.base import fancylogger |
45 | | -from easybuild.easyblocks.python import EBPYTHONPREFIXES, EXTS_FILTER_PYTHON_PACKAGES |
| 45 | +from easybuild.easyblocks.python import EXTS_FILTER_PYTHON_PACKAGES |
46 | 46 | from easybuild.framework.easyconfig import CUSTOM |
47 | 47 | from easybuild.framework.easyconfig.default import DEFAULT_CONFIG |
48 | 48 | from easybuild.framework.easyconfig.templates import PYPI_SOURCE |
49 | 49 | from easybuild.framework.extensioneasyblock import ExtensionEasyBlock |
50 | 50 | from easybuild.tools.build_log import EasyBuildError, print_msg |
51 | | -from easybuild.tools.config import build_option |
| 51 | +from easybuild.tools.config import build_option, PYTHONPATH, EBPYTHONPREFIXES |
52 | 52 | from easybuild.tools.filetools import change_dir, mkdir, remove_dir, symlink, which |
53 | 53 | from easybuild.tools.modules import get_software_root |
54 | 54 | from easybuild.tools.run import run_shell_cmd, subprocess_popen_text |
@@ -1162,15 +1162,27 @@ def make_module_extra(self, *args, **kwargs): |
1162 | 1162 | txt = '' |
1163 | 1163 |
|
1164 | 1164 | # update $EBPYTHONPREFIXES rather than $PYTHONPATH |
1165 | | - # if this Python package was installed for multiple Python versions |
1166 | | - if self.multi_python: |
1167 | | - txt += self.module_generator.prepend_paths(EBPYTHONPREFIXES, '') |
| 1165 | + # if this Python package was installed for multiple Python versions, or if we prefer it; |
| 1166 | + # note: although EasyBuild framework also has logic for this in EasyBlock.make_module_extra, |
| 1167 | + # we retain full control here, since the logic is slightly different |
| 1168 | + use_ebpythonprefixes = False |
| 1169 | + runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)] |
| 1170 | + |
| 1171 | + if 'Python' in runtime_deps: |
| 1172 | + self.log.info("Found Python runtime dependency, so considering $EBPYTHONPREFIXES...") |
| 1173 | + if build_option('prefer_python_search_path') == EBPYTHONPREFIXES: |
| 1174 | + self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that") |
| 1175 | + use_ebpythonprefixes = True |
| 1176 | + |
| 1177 | + if self.multi_python or use_ebpythonprefixes: |
| 1178 | + path = '' # EBPYTHONPREFIXES are relative to the install dir |
| 1179 | + txt += self.module_generator.prepend_paths(EBPYTHONPREFIXES, path) |
1168 | 1180 | elif self.require_python: |
1169 | 1181 | self.set_pylibdirs() |
1170 | 1182 | for path in self.all_pylibdirs: |
1171 | 1183 | fullpath = os.path.join(self.installdir, path) |
1172 | 1184 | # only extend $PYTHONPATH with existing, non-empty directories |
1173 | 1185 | if os.path.exists(fullpath) and os.listdir(fullpath): |
1174 | | - txt += self.module_generator.prepend_paths('PYTHONPATH', path) |
| 1186 | + txt += self.module_generator.prepend_paths(PYTHONPATH, path) |
1175 | 1187 |
|
1176 | 1188 | return super(PythonPackage, self).make_module_extra(txt, *args, **kwargs) |
0 commit comments