Repository: easybuilders/easybuild-easyblocks

Issue:
PythonPackage is not compatible with --sanity-check-only
Using `--sanity-check-only` on something that was installed with the `PythonPackage` (or `PythonBundle`, or a derivative) easyblock fails with:

```
== FAILED: Installation ended unsuccessfully (build directory: /tmp/easybuild_build/pygmo/2.16.1/foss-2020b): build failed (first 300 chars): cmd "pip --version" exited with exit code 127 and output:
/bin/bash: pip: command not found
 (took 0 secs)
```

The problem is that the module (which is already installed) only gets loaded later, when the parent `sanity_check_step` is being called.


Discussion:

Resolving patch:
diff --git a/easybuild/easyblocks/generic/pythonpackage.py b/easybuild/easyblocks/generic/pythonpackage.py
--- a/easybuild/easyblocks/generic/pythonpackage.py
+++ b/easybuild/easyblocks/generic/pythonpackage.py
@@ -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,
@@ -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 = []
 
@@ -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:


Test patch: