Skip to content

Commit

Permalink
Merge pull request #2828 from boegel/pythonpackage_sanity_check_load_…
Browse files Browse the repository at this point in the history
…module

load module early during PythonPackage's sanity check step via sanity_check_load_module
  • Loading branch information
akesandgren authored Dec 8, 2022
2 parents 99ee865 + 57288b6 commit 8c89bcb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions easybuild/easyblocks/generic/pythonpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,14 @@ def sanity_check_step(self, *args, **kwargs):

success, fail_msg = True, ''

# load module early ourselves rather than letting parent sanity_check_step method do so,
# since custom actions taken below require that environment is set up properly already
# (especially when using --sanity-check-only)
if not self.sanity_check_module_loaded:
extension = self.is_extension or kwargs.get('extension', False)
extra_modules = kwargs.get('extra_modules', None)
self.fake_mod_data = self.sanity_check_load_module(extension=extension, extra_modules=extra_modules)

# don't add user site directory to sys.path (equivalent to python -s)
# see https://www.python.org/dev/peps/pep-0370/;
# must be set here to ensure that it is defined when running sanity check for extensions,
Expand Down Expand Up @@ -852,9 +860,14 @@ def sanity_check_step(self, *args, **kwargs):

if not self.is_extension:
# for stand-alone Python package installations (not part of a bundle of extensions),
# we need to load the fake module file, otherwise the Python package being installed
# is not "in view", and we will overlook missing dependencies...
fake_mod_data = self.load_fake_module(purge=True)
# the (fake or real) module file must be loaded at this point,
# otherwise the Python package being installed is not "in view",
# and we will overlook missing dependencies...
loaded_modules = [x['mod_name'] for x in self.modules_tool.list()]
if self.short_mod_name not in loaded_modules:
self.log.debug("Currently loaded modules: %s", loaded_modules)
raise EasyBuildError("%s module is not loaded, this should never happen...",
self.short_mod_name)

pip_check_errors = []

Expand Down Expand Up @@ -900,9 +913,6 @@ def sanity_check_step(self, *args, **kwargs):
) % (faulty_version, '\n'.join(faulty_pkg_names))
pip_check_errors.append(msg)

if not self.is_extension:
self.clean_up_fake_module(fake_mod_data)

if pip_check_errors:
raise EasyBuildError('\n'.join(pip_check_errors))
else:
Expand Down

0 comments on commit 8c89bcb

Please sign in to comment.