Skip to content

Commit 9f3cf6a

Browse files
committed
Exclude base python installations themselves from automatic PYTHONPATH
1 parent 4ed16be commit 9f3cf6a

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

easybuild/framework/easyblock.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,21 +1438,30 @@ def make_module_extra(self, altroot=None, altversion=None):
14381438
value, type(value))
14391439
lines.append(self.module_generator.append_paths(key, value, allow_abs=self.cfg['allow_append_abs_path']))
14401440

1441-
# Add automatic PYTHONPATH or EBPYTHONPREFIXES if they aren't already present
1442-
python_paths = [path[len(self.installdir)+1:]
1443-
for path in glob.glob(f'{self.installdir}/lib*/python*/site-packages')
1444-
if re.match(self.installdir + r'/lib(64)?/python\d+\.\d+/site-packages', path)]
1445-
use_ebpythonprefixes = get_software_root('Python') and build_option('prefer_ebpythonprefixes') and \
1446-
self.cfg['prefer_ebpythonprefixes']
1447-
1448-
if len(python_paths) > 1 and not use_ebpythonprefixes:
1449-
raise EasyBuildError('Multiple python paths requires EBPYTHONPREFIXES: ' + ', '.join(python_paths))
1450-
elif python_paths:
1451-
# Add paths unless they were already added
1452-
if use_ebpythonprefixes and '' not in self.module_generator.added_paths_per_key['EBPYTHONPREFIXES']:
1453-
lines.append(self.module_generator.prepend_paths('EBPYTHONPREFIXES', ''))
1454-
elif python_paths[0] not in self.module_generator.added_paths_per_key['PYTHONPATH']:
1455-
lines.append(self.module_generator.prepend_paths('PYTHONPATH', python_paths))
1441+
# Add automatic PYTHONPATH or EBPYTHONPREFIXES if they aren't already present and python paths exist
1442+
if self.name not in ['Python', 'Miniconda', 'Anaconda']: # nothing extra needed for base python installations
1443+
# Exclude symlinks lib -> lib64 or vice verse to avoid duplicates
1444+
python_paths = []
1445+
if not os.path.islink(f'{self.installdir}/lib'):
1446+
python_paths += [path[len(self.installdir)+1:]
1447+
for path in glob.glob(f'{self.installdir}/lib/python*/site-packages')
1448+
if re.match(self.installdir + r'/lib/python\d+\.\d+/site-packages', path)]
1449+
if not os.path.islink(f'{self.installdir}/lib64'):
1450+
python_paths += [path[len(self.installdir)+1:]
1451+
for path in glob.glob(f'{self.installdir}/lib64/python*/site-packages')
1452+
if re.match(self.installdir + r'/lib64/python\d+\.\d+/site-packages', path)]
1453+
1454+
use_ebpythonprefixes = get_software_root('Python') and build_option('prefer_ebpythonprefixes') and \
1455+
self.cfg['prefer_ebpythonprefixes']
1456+
1457+
if len(python_paths) > 1 and not use_ebpythonprefixes:
1458+
raise EasyBuildError('Multiple python paths requires EBPYTHONPREFIXES: ' + ', '.join(python_paths))
1459+
elif python_paths:
1460+
# Add paths unless they were already added
1461+
if use_ebpythonprefixes and '' not in self.module_generator.added_paths_per_key['EBPYTHONPREFIXES']:
1462+
lines.append(self.module_generator.prepend_paths('EBPYTHONPREFIXES', ''))
1463+
elif python_paths[0] not in self.module_generator.added_paths_per_key['PYTHONPATH']:
1464+
lines.append(self.module_generator.prepend_paths('PYTHONPATH', python_paths))
14561465

14571466
modloadmsg = self.cfg['modloadmsg']
14581467
if modloadmsg:

0 commit comments

Comments
 (0)