|
35 | 35 | from easybuild.tools.build_log import EasyBuildError |
36 | 36 | from easybuild.tools.config import build_option, PYTHONPATH, EBPYTHONPREFIXES |
37 | 37 | from easybuild.tools.modules import get_software_root |
| 38 | +from easybuild.tools.filetools import search_file |
38 | 39 |
|
39 | 40 |
|
40 | 41 | class PythonBundle(Bundle): |
@@ -123,6 +124,19 @@ def make_module_extra(self, *args, **kwargs): |
123 | 124 | self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that") |
124 | 125 | use_ebpythonprefixes = True |
125 | 126 |
|
| 127 | + # Check if the installdir or sources contain any .pth files. For them to work correctly, |
| 128 | + # Python needs these files to be in the sitedir path. While this typically works system-wide |
| 129 | + # or in a venv, having Python modules in separate directories is unusual, and only having |
| 130 | + # $PYTHONPATH will ignore these files. |
| 131 | + # Our sitecustomize.py adds paths in $EBPYTHONPREFIXES to the sitedir path though, allowing |
| 132 | + # these .pth files to work as expected. See: https://docs.python.org/3/library/site.html#module-site |
| 133 | + # .pth files always should be in the site folder, so most of the path is fixed. |
| 134 | + # Try the installation directory first |
| 135 | + if self.installdir and search_file([self.installdir], r".*\.pth$", silent=True): |
| 136 | + self.log.info("Found path configuration file in installation directory. " |
| 137 | + "Enabling $EBPYTHONPREFIXES...") |
| 138 | + use_ebpythonprefixes = True |
| 139 | + |
126 | 140 | if self.multi_python or use_ebpythonprefixes: |
127 | 141 | path = '' # EBPYTHONPREFIXES are relative to the install dir |
128 | 142 | if path not in self.module_generator.added_paths_per_key[EBPYTHONPREFIXES]: |
|
0 commit comments