We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
numexpr can't be installed as an extension
The reason is two-fold:

As an extension this is not executed:

https://github.com/easybuilders/easybuild-easyblocks/blob/develop/easybuild/easyblocks/n/numexpr.py#L59

And therefore the variable is not defined, it is built without VML, and it would fail on the sanity check.

With that fixed, there is another more convoluted issue. The sanity check executed follows this order:

1. Sanity check in `numexpr.py`
2. Sanity check in `pythonpackage`
3. Sanity check in `extensioneasyblock`
4. Sanity check in `easyblock`
5. Sanity check in `extensioneasyblock` again
6. And finally sanity check in `easyblock` again, where it fails

5 and 6 happens due to this condition:

https://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/framework/extensioneasyblock.py#L154

Without the `custom_commands` it works just fine. But that should be ok.

The log does not help much, but shows that there is a weird issue (sanity checked passed, and then failed):

```
== 2020-03-26 20:57:10,714 run.py:200 DEBUG run_cmd: running cmd python -c 'import numexpr; assert(numexpr.use_vml)' (in /gpfs/software/juwels/stages/Devel-2019a/software/Jupyter/2019a-gcccoremkl-8.3.0-2019.3.199-devel2-Python-3.6.8)
== 2020-03-26 20:57:10,715 run.py:219 INFO running cmd: python -c 'import numexpr; assert(numexpr.use_vml)'
== 2020-03-26 20:57:11,196 run.py:536 DEBUG cmd "python -c 'import numexpr; assert(numexpr.use_vml)'" exited with exit code 0 and output:

== 2020-03-26 20:57:11,196 run.py:570 DEBUG Using default regular expression: (?<![(,-]|\w)(?:error|segmentation fault|failed)(?![(,-]|\.?\w)
== 2020-03-26 20:57:11,197 easyblock.py:2574 INFO sanity check command python -c 'import numexpr; assert(numexpr.use_vml)' ran successfully! (output: )
== 2020-03-26 20:57:11,198 easyblock.py:2595 DEBUG Skipping RPATH sanity check
== 2020-03-26 20:57:11,198 easyblock.py:2601 DEBUG Sanity check passed!
== 2020-03-26 20:57:11,198 extensioneasyblock.py:160 INFO Sanity check for numexpr successful!
== 2020-03-26 20:57:11,199 easyblock.py:2473 WARNING failing sanity check for 'numexpr' extension: (see log for details)
== 2020-03-26 20:57:11,199 easyblock.py:2479 WARNING extensions sanity check failed for 1 extensions:
```

The funny bit. If I wrap this condition https://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/framework/easyblock.py#L2622 like this:

```
         print("before extension easyblock failed message: "+str(self.sanity_check_fail_msgs))
         # also run sanity check for extensions (unless we are an extension ourselves)
         if not extension:
             self._sanity_check_step_extensions()
         print("after extension easyblock failed message: "+str(self.sanity_check_fail_msgs))
```

I get this output:

```
before extension easyblock failed message: []
after extension easyblock failed message: []
after extension easyblock failed message: ['extensions sanity check failed for 1 extensions: numexpr', "failing sanity check for 'numexpr' extension: (see log for details)"]
```

Note the 2 "after" with a single "before". It is late and I am tired and hungry, but that looks pretty weird to me and I am starting to believe in leprechauns

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `easybuild/easyblocks/n/numexpr.py`
Content:
```
1 ##
2 # Copyright 2019-2020 Ghent University
3 #
4 # This file is part of EasyBuild,
5 # originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
6 # with support of Ghent University (http://ugent.be/hpc),
7 # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
8 # Flemish Research Foundation (FWO) (http://www.fwo.be/en)
9 # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
10 #
11 # https://github.com/easybuilders/easybuild
12 #
13 # EasyBuild is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation v2.
16 #
17 # EasyBuild is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.
24 ##
25 """
26 EasyBuild support for building and installing numexpr, implemented as an easyblock
27 """
28 import os
29 
30 from easybuild.easyblocks.generic.pythonpackage import PythonPackage
31 from easybuild.tools.filetools import write_file
32 from easybuild.tools.modules import get_software_root
33 from easybuild.tools.systemtools import get_cpu_features
34 
35 
36 class EB_numexpr(PythonPackage):
37     """Support for building/installing numexpr."""
38 
39     @staticmethod
40     def extra_options():
41         """Override some custom easyconfig parameters specifically for numexpr."""
42         extra_vars = PythonPackage.extra_options()
43 
44         extra_vars['download_dep_fail'][0] = True
45         extra_vars['use_pip'][0] = True
46 
47         return extra_vars
48 
49     def __init__(self, *args, **kwargs):
50         """Initialisation of custom class variables for numexpr."""
51         super(EB_numexpr, self).__init__(*args, **kwargs)
52 
53         self.imkl_root = None
54 
55     def prepare_step(self, *args, **kwargs):
56         """Prepare environment for building and installing numexpr."""
57         super(EB_numexpr, self).prepare_step(*args, **kwargs)
58 
59         self.imkl_root = get_software_root('imkl')
60 
61     def configure_step(self):
62         """Custom configuration procedure for numexpr."""
63         super(EB_numexpr, self).configure_step()
64 
65         # if Intel MKL is available, set up site.cfg such that the right VML library is used;
66         # this makes a *big* difference in terms of performance;
67         # see also https://github.com/pydata/numexpr/blob/master/site.cfg.example
68         if self.imkl_root:
69 
70             # figure out which VML library to link to
71             cpu_features = get_cpu_features()
72             if 'avx512f' in cpu_features:
73                 mkl_vml_lib = 'mkl_vml_avx512'
74             elif 'avx2' in cpu_features:
75                 mkl_vml_lib = 'mkl_vml_avx2'
76             elif 'avx' in cpu_features:
77                 mkl_vml_lib = 'mkl_vml_avx'
78             else:
79                 # use default kernels as fallback for non-AVX systems
80                 mkl_vml_lib = 'mkl_vml_def'
81 
82             mkl_libs = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_def', mkl_vml_lib, 'mkl_rt', 'iomp5']
83 
84             mkl_lib_dirs = [
85                 os.path.join(self.imkl_root, 'mkl', 'lib', 'intel64'),
86                 os.path.join(self.imkl_root, 'lib', 'intel64'),
87             ]
88 
89             site_cfg_txt = '\n'.join([
90                 "[mkl]",
91                 "include_dirs = %s" % os.path.join(self.imkl_root, 'mkl', 'include'),
92                 "library_dirs = %s" % ':'.join(mkl_lib_dirs),
93                 "mkl_libs = %s" % ', '.join(mkl_libs),
94             ])
95             write_file('site.cfg', site_cfg_txt)
96 
97     def sanity_check_step(self):
98         """Custom sanity check for numexpr."""
99 
100         custom_commands = []
101 
102         # if Intel MKL is available, make sure VML is used
103         if self.imkl_root:
104             custom_commands.append("python -c 'import numexpr; assert(numexpr.use_vml)'")
105 
106         super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)
107
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/easybuild/easyblocks/n/numexpr.py b/easybuild/easyblocks/n/numexpr.py
--- a/easybuild/easyblocks/n/numexpr.py
+++ b/easybuild/easyblocks/n/numexpr.py
@@ -52,16 +52,12 @@
 
         self.imkl_root = None
 
-    def prepare_step(self, *args, **kwargs):
-        """Prepare environment for building and installing numexpr."""
-        super(EB_numexpr, self).prepare_step(*args, **kwargs)
-
-        self.imkl_root = get_software_root('imkl')
-
     def configure_step(self):
         """Custom configuration procedure for numexpr."""
         super(EB_numexpr, self).configure_step()
 
+        self.imkl_root = get_software_root('imkl')
+
         # if Intel MKL is available, set up site.cfg such that the right VML library is used;
         # this makes a *big* difference in terms of performance;
         # see also https://github.com/pydata/numexpr/blob/master/site.cfg.example
@@ -103,4 +99,4 @@
         if self.imkl_root:
             custom_commands.append("python -c 'import numexpr; assert(numexpr.use_vml)'")
 
-        super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)
+        return super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)

{"golden_diff": "diff --git a/easybuild/easyblocks/n/numexpr.py b/easybuild/easyblocks/n/numexpr.py\n--- a/easybuild/easyblocks/n/numexpr.py\n+++ b/easybuild/easyblocks/n/numexpr.py\n@@ -52,16 +52,12 @@\n \n         self.imkl_root = None\n \n-    def prepare_step(self, *args, **kwargs):\n-        \"\"\"Prepare environment for building and installing numexpr.\"\"\"\n-        super(EB_numexpr, self).prepare_step(*args, **kwargs)\n-\n-        self.imkl_root = get_software_root('imkl')\n-\n     def configure_step(self):\n         \"\"\"Custom configuration procedure for numexpr.\"\"\"\n         super(EB_numexpr, self).configure_step()\n \n+        self.imkl_root = get_software_root('imkl')\n+\n         # if Intel MKL is available, set up site.cfg such that the right VML library is used;\n         # this makes a *big* difference in terms of performance;\n         # see also https://github.com/pydata/numexpr/blob/master/site.cfg.example\n@@ -103,4 +99,4 @@\n         if self.imkl_root:\n             custom_commands.append(\"python -c 'import numexpr; assert(numexpr.use_vml)'\")\n \n-        super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)\n+        return super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)\n", "issue": "numexpr can't be installed as an extension\nThe reason is two-fold:\r\n\r\nAs an extension this is not executed:\r\n\r\nhttps://github.com/easybuilders/easybuild-easyblocks/blob/develop/easybuild/easyblocks/n/numexpr.py#L59\r\n\r\nAnd therefore the variable is not defined, it is built without VML, and it would fail on the sanity check.\r\n\r\nWith that fixed, there is another more convoluted issue. The sanity check executed follows this order:\r\n\r\n1. Sanity check in `numexpr.py`\r\n2. Sanity check in `pythonpackage`\r\n3. Sanity check in `extensioneasyblock`\r\n4. Sanity check in `easyblock`\r\n5. Sanity check in `extensioneasyblock` again\r\n6. And finally sanity check in `easyblock` again, where it fails\r\n\r\n5 and 6 happens due to this condition:\r\n\r\nhttps://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/framework/extensioneasyblock.py#L154\r\n\r\nWithout the `custom_commands` it works just fine. But that should be ok.\r\n\r\nThe log does not help much, but shows that there is a weird issue (sanity checked passed, and then failed):\r\n\r\n```\r\n== 2020-03-26 20:57:10,714 run.py:200 DEBUG run_cmd: running cmd python -c 'import numexpr; assert(numexpr.use_vml)' (in /gpfs/software/juwels/stages/Devel-2019a/software/Jupyter/2019a-gcccoremkl-8.3.0-2019.3.199-devel2-Python-3.6.8)\r\n== 2020-03-26 20:57:10,715 run.py:219 INFO running cmd: python -c 'import numexpr; assert(numexpr.use_vml)'\r\n== 2020-03-26 20:57:11,196 run.py:536 DEBUG cmd \"python -c 'import numexpr; assert(numexpr.use_vml)'\" exited with exit code 0 and output:\r\n\r\n== 2020-03-26 20:57:11,196 run.py:570 DEBUG Using default regular expression: (?<![(,-]|\\w)(?:error|segmentation fault|failed)(?![(,-]|\\.?\\w)\r\n== 2020-03-26 20:57:11,197 easyblock.py:2574 INFO sanity check command python -c 'import numexpr; assert(numexpr.use_vml)' ran successfully! (output: )\r\n== 2020-03-26 20:57:11,198 easyblock.py:2595 DEBUG Skipping RPATH sanity check\r\n== 2020-03-26 20:57:11,198 easyblock.py:2601 DEBUG Sanity check passed!\r\n== 2020-03-26 20:57:11,198 extensioneasyblock.py:160 INFO Sanity check for numexpr successful!\r\n== 2020-03-26 20:57:11,199 easyblock.py:2473 WARNING failing sanity check for 'numexpr' extension: (see log for details)\r\n== 2020-03-26 20:57:11,199 easyblock.py:2479 WARNING extensions sanity check failed for 1 extensions:\r\n```\r\n\r\nThe funny bit. If I wrap this condition https://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/framework/easyblock.py#L2622 like this:\r\n\r\n```\r\n         print(\"before extension easyblock failed message: \"+str(self.sanity_check_fail_msgs))\r\n         # also run sanity check for extensions (unless we are an extension ourselves)\r\n         if not extension:\r\n             self._sanity_check_step_extensions()\r\n         print(\"after extension easyblock failed message: \"+str(self.sanity_check_fail_msgs))\r\n```\r\n\r\nI get this output:\r\n\r\n```\r\nbefore extension easyblock failed message: []\r\nafter extension easyblock failed message: []\r\nafter extension easyblock failed message: ['extensions sanity check failed for 1 extensions: numexpr', \"failing sanity check for 'numexpr' extension: (see log for details)\"]\r\n```\r\n\r\nNote the 2 \"after\" with a single \"before\". It is late and I am tired and hungry, but that looks pretty weird to me and I am starting to believe in leprechauns\n", "before_files": [{"content": "##\n# Copyright 2019-2020 Ghent University\n#\n# This file is part of EasyBuild,\n# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),\n# with support of Ghent University (http://ugent.be/hpc),\n# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),\n# Flemish Research Foundation (FWO) (http://www.fwo.be/en)\n# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).\n#\n# https://github.com/easybuilders/easybuild\n#\n# EasyBuild is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation v2.\n#\n# EasyBuild is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.\n##\n\"\"\"\nEasyBuild support for building and installing numexpr, implemented as an easyblock\n\"\"\"\nimport os\n\nfrom easybuild.easyblocks.generic.pythonpackage import PythonPackage\nfrom easybuild.tools.filetools import write_file\nfrom easybuild.tools.modules import get_software_root\nfrom easybuild.tools.systemtools import get_cpu_features\n\n\nclass EB_numexpr(PythonPackage):\n    \"\"\"Support for building/installing numexpr.\"\"\"\n\n    @staticmethod\n    def extra_options():\n        \"\"\"Override some custom easyconfig parameters specifically for numexpr.\"\"\"\n        extra_vars = PythonPackage.extra_options()\n\n        extra_vars['download_dep_fail'][0] = True\n        extra_vars['use_pip'][0] = True\n\n        return extra_vars\n\n    def __init__(self, *args, **kwargs):\n        \"\"\"Initialisation of custom class variables for numexpr.\"\"\"\n        super(EB_numexpr, self).__init__(*args, **kwargs)\n\n        self.imkl_root = None\n\n    def prepare_step(self, *args, **kwargs):\n        \"\"\"Prepare environment for building and installing numexpr.\"\"\"\n        super(EB_numexpr, self).prepare_step(*args, **kwargs)\n\n        self.imkl_root = get_software_root('imkl')\n\n    def configure_step(self):\n        \"\"\"Custom configuration procedure for numexpr.\"\"\"\n        super(EB_numexpr, self).configure_step()\n\n        # if Intel MKL is available, set up site.cfg such that the right VML library is used;\n        # this makes a *big* difference in terms of performance;\n        # see also https://github.com/pydata/numexpr/blob/master/site.cfg.example\n        if self.imkl_root:\n\n            # figure out which VML library to link to\n            cpu_features = get_cpu_features()\n            if 'avx512f' in cpu_features:\n                mkl_vml_lib = 'mkl_vml_avx512'\n            elif 'avx2' in cpu_features:\n                mkl_vml_lib = 'mkl_vml_avx2'\n            elif 'avx' in cpu_features:\n                mkl_vml_lib = 'mkl_vml_avx'\n            else:\n                # use default kernels as fallback for non-AVX systems\n                mkl_vml_lib = 'mkl_vml_def'\n\n            mkl_libs = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_def', mkl_vml_lib, 'mkl_rt', 'iomp5']\n\n            mkl_lib_dirs = [\n                os.path.join(self.imkl_root, 'mkl', 'lib', 'intel64'),\n                os.path.join(self.imkl_root, 'lib', 'intel64'),\n            ]\n\n            site_cfg_txt = '\\n'.join([\n                \"[mkl]\",\n                \"include_dirs = %s\" % os.path.join(self.imkl_root, 'mkl', 'include'),\n                \"library_dirs = %s\" % ':'.join(mkl_lib_dirs),\n                \"mkl_libs = %s\" % ', '.join(mkl_libs),\n            ])\n            write_file('site.cfg', site_cfg_txt)\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for numexpr.\"\"\"\n\n        custom_commands = []\n\n        # if Intel MKL is available, make sure VML is used\n        if self.imkl_root:\n            custom_commands.append(\"python -c 'import numexpr; assert(numexpr.use_vml)'\")\n\n        super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)\n", "path": "easybuild/easyblocks/n/numexpr.py"}], "after_files": [{"content": "##\n# Copyright 2019-2020 Ghent University\n#\n# This file is part of EasyBuild,\n# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),\n# with support of Ghent University (http://ugent.be/hpc),\n# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),\n# Flemish Research Foundation (FWO) (http://www.fwo.be/en)\n# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).\n#\n# https://github.com/easybuilders/easybuild\n#\n# EasyBuild is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation v2.\n#\n# EasyBuild is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.\n##\n\"\"\"\nEasyBuild support for building and installing numexpr, implemented as an easyblock\n\"\"\"\nimport os\n\nfrom easybuild.easyblocks.generic.pythonpackage import PythonPackage\nfrom easybuild.tools.filetools import write_file\nfrom easybuild.tools.modules import get_software_root\nfrom easybuild.tools.systemtools import get_cpu_features\n\n\nclass EB_numexpr(PythonPackage):\n    \"\"\"Support for building/installing numexpr.\"\"\"\n\n    @staticmethod\n    def extra_options():\n        \"\"\"Override some custom easyconfig parameters specifically for numexpr.\"\"\"\n        extra_vars = PythonPackage.extra_options()\n\n        extra_vars['download_dep_fail'][0] = True\n        extra_vars['use_pip'][0] = True\n\n        return extra_vars\n\n    def __init__(self, *args, **kwargs):\n        \"\"\"Initialisation of custom class variables for numexpr.\"\"\"\n        super(EB_numexpr, self).__init__(*args, **kwargs)\n\n        self.imkl_root = None\n\n    def configure_step(self):\n        \"\"\"Custom configuration procedure for numexpr.\"\"\"\n        super(EB_numexpr, self).configure_step()\n\n        self.imkl_root = get_software_root('imkl')\n\n        # if Intel MKL is available, set up site.cfg such that the right VML library is used;\n        # this makes a *big* difference in terms of performance;\n        # see also https://github.com/pydata/numexpr/blob/master/site.cfg.example\n        if self.imkl_root:\n\n            # figure out which VML library to link to\n            cpu_features = get_cpu_features()\n            if 'avx512f' in cpu_features:\n                mkl_vml_lib = 'mkl_vml_avx512'\n            elif 'avx2' in cpu_features:\n                mkl_vml_lib = 'mkl_vml_avx2'\n            elif 'avx' in cpu_features:\n                mkl_vml_lib = 'mkl_vml_avx'\n            else:\n                # use default kernels as fallback for non-AVX systems\n                mkl_vml_lib = 'mkl_vml_def'\n\n            mkl_libs = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_def', mkl_vml_lib, 'mkl_rt', 'iomp5']\n\n            mkl_lib_dirs = [\n                os.path.join(self.imkl_root, 'mkl', 'lib', 'intel64'),\n                os.path.join(self.imkl_root, 'lib', 'intel64'),\n            ]\n\n            site_cfg_txt = '\\n'.join([\n                \"[mkl]\",\n                \"include_dirs = %s\" % os.path.join(self.imkl_root, 'mkl', 'include'),\n                \"library_dirs = %s\" % ':'.join(mkl_lib_dirs),\n                \"mkl_libs = %s\" % ', '.join(mkl_libs),\n            ])\n            write_file('site.cfg', site_cfg_txt)\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for numexpr.\"\"\"\n\n        custom_commands = []\n\n        # if Intel MKL is available, make sure VML is used\n        if self.imkl_root:\n            custom_commands.append(\"python -c 'import numexpr; assert(numexpr.use_vml)'\")\n\n        return super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)\n", "path": "easybuild/easyblocks/n/numexpr.py"}]}