Skip to content

Commit c3b5011

Browse files
authored
Merge pull request #6 from boegel/ebpythonprefixes2
take into account `multi_deps` when determining whether to use `$PYTHONPATH` or `$EBPYTHONPREFIXES` + remove `force_pythonpath` easyconfig parameter
2 parents 835e63c + 11f132e commit c3b5011

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

easybuild/framework/easyblock.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,12 +1401,24 @@ def make_module_pythonpath(self):
14011401
candidate_paths = (os.path.relpath(path, self.installdir) for path in glob.glob(python_subdir_pattern))
14021402
python_paths = [path for path in candidate_paths if re.match(r'lib/python\d+\.\d+/site-packages', path)]
14031403

1404+
# determine whether Python is a runtime dependency;
1405+
# if so, we assume it was installed with EasyBuild, and hence is aware of $EBPYTHONPREFIXES
14041406
runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)]
1405-
use_ebpythonprefixes = all([
1406-
'Python' in runtime_deps,
1407-
build_option('prefer_python_search_path') == EBPYTHONPREFIXES,
1408-
not self.cfg['force_pythonpath']
1409-
])
1407+
1408+
# don't use $EBPYTHONPREFIXES unless we can and it's preferred or necesary (due to use of multi_deps)
1409+
use_ebpythonprefixes = False
1410+
multi_deps = self.cfg['multi_deps']
1411+
1412+
if 'Python' in runtime_deps:
1413+
self.log.info("Found Python runtime dependency, so considering $EBPYTHONPREFIXES...")
1414+
1415+
if build_option('prefer_python_search_path') == EBPYTHONPREFIXES:
1416+
self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that")
1417+
use_ebpythonprefixes = True
1418+
1419+
elif multi_deps and 'Python' in multi_deps:
1420+
self.log.info("Python is listed in 'multi_deps', so using $EBPYTHONPREFIXES instead of $PYTHONPATH")
1421+
use_ebpythonprefixes = True
14101422

14111423
if python_paths:
14121424
# add paths unless they were already added

easybuild/framework/easyconfig/default.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
'patches': [[], "List of patches to apply", BUILD],
116116
'prebuildopts': ['', 'Extra options pre-passed to build command.', BUILD],
117117
'preconfigopts': ['', 'Extra options pre-passed to configure.', BUILD],
118-
'force_pythonpath': [False, "Force use of PYTHONPATH for python seearch path when possible.", BUILD],
119118
'preinstallopts': ['', 'Extra prefix options for installation.', BUILD],
120119
'pretestopts': ['', 'Extra prefix options for test.', BUILD],
121120
'postinstallcmds': [[], 'Commands to run after the install step.', BUILD],

test/framework/toy_build.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,15 +4242,16 @@ def test_toy_python(self):
42424242
"""
42434243
Test whether $PYTHONPATH or $EBPYTHONPREFIXES are set correctly.
42444244
"""
4245-
# generate fake Python module that we can use as runtime dependency for toy
4245+
# generate fake Python modules that we can use as runtime dependency for toy
42464246
# (required condition for use of $EBPYTHONPREFIXES)
42474247
fake_mods_path = os.path.join(self.test_prefix, 'modules')
4248-
fake_python_mod = os.path.join(fake_mods_path, 'Python', '3.6')
4249-
if get_module_syntax() == 'Lua':
4250-
fake_python_mod += '.lua'
4251-
write_file(fake_python_mod, '')
4252-
else:
4253-
write_file(fake_python_mod, '#%Module')
4248+
for pyver in ('2.7', '3.6'):
4249+
fake_python_mod = os.path.join(fake_mods_path, 'Python', pyver)
4250+
if get_module_syntax() == 'Lua':
4251+
fake_python_mod += '.lua'
4252+
write_file(fake_python_mod, '')
4253+
else:
4254+
write_file(fake_python_mod, '#%Module')
42544255
self.modtool.use(fake_mods_path)
42554256

42564257
test_ecs = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs')
@@ -4284,22 +4285,22 @@ def test_toy_python(self):
42844285
self.assertTrue(pythonpath_regex.search(toy_mod_txt),
42854286
f"Pattern '{pythonpath_regex.pattern}' found in: {toy_mod_txt}")
42864287

4287-
test_ec_txt += "\ndependencies = [('Python', '3.6', '', SYSTEM)]"
4288-
write_file(test_ec, test_ec_txt)
4288+
# if Python is listed as runtime dependency, then $EBPYTHONPREFIXES is used if it's preferred
4289+
write_file(test_ec, test_ec_txt + "\ndependencies = [('Python', '3.6', '', SYSTEM)]")
42894290
self.run_test_toy_build_with_output(ec_file=test_ec, extra_args=args)
42904291
toy_mod_txt = read_file(toy_mod)
42914292

42924293
ebpythonprefixes_regex = re.compile('^prepend.path.*EBPYTHONPREFIXES.*root', re.M)
42934294
self.assertTrue(ebpythonprefixes_regex.search(toy_mod_txt),
42944295
f"Pattern '{ebpythonprefixes_regex.pattern}' found in: {toy_mod_txt}")
42954296

4296-
test_ec_txt += "\nforce_pythonpath = True"
4297-
write_file(test_ec, test_ec_txt)
4297+
# if Python is listed in multi_deps, then $EBPYTHONPREFIXES is used, even if it's not explicitely preferred
4298+
write_file(test_ec, test_ec_txt + "\nmulti_deps = {'Python': ['2.7', '3.6']}")
42984299
self.run_test_toy_build_with_output(ec_file=test_ec)
42994300
toy_mod_txt = read_file(toy_mod)
43004301

4301-
self.assertTrue(pythonpath_regex.search(toy_mod_txt),
4302-
f"Pattern '{pythonpath_regex.pattern}' found in: {toy_mod_txt}")
4302+
self.assertTrue(ebpythonprefixes_regex.search(toy_mod_txt),
4303+
f"Pattern '{ebpythonprefixes_regex.pattern}' found in: {toy_mod_txt}")
43034304

43044305

43054306
def suite():

0 commit comments

Comments
 (0)