diff options
author | Manuela Kuhn <36827019+manuelakuhn@users.noreply.github.com> | 2022-09-18 01:02:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-17 23:02:30 +0000 |
commit | d4c13b0f8f4534657f6148be63327c04b7b161e1 (patch) | |
tree | c4090111346994be4a81a9c8b958ab5abb56485e /lib | |
parent | 2c7c749986bd2fd32ab3dcff18917cde96c798b0 (diff) | |
download | spack-d4c13b0f8f4534657f6148be63327c04b7b161e1.tar.gz spack-d4c13b0f8f4534657f6148be63327c04b7b161e1.tar.bz2 spack-d4c13b0f8f4534657f6148be63327c04b7b161e1.tar.xz spack-d4c13b0f8f4534657f6148be63327c04b7b161e1.zip |
Add skip_import to PythonPackage and use it in py-nilearn (#32664)
* Add skip_import to PythonPackage and use it in py-nilearn
* Fix dependencies
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/docs/build_systems/pythonpackage.rst | 13 | ||||
-rw-r--r-- | lib/spack/spack/build_systems/python.py | 18 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/spack/docs/build_systems/pythonpackage.rst b/lib/spack/docs/build_systems/pythonpackage.rst index 13b59cc96e..53d0f09167 100644 --- a/lib/spack/docs/build_systems/pythonpackage.rst +++ b/lib/spack/docs/build_systems/pythonpackage.rst @@ -582,6 +582,19 @@ libraries. Make sure not to add modules/packages containing the word "test", as these likely won't end up in the installation directory, or may require test dependencies like pytest to be installed. +Instead of defining the ``import_modules`` explicity, only the subset +of module names to be skipped can be defined by using ``skip_modules``. +If a defined module has submodules, they are skipped as well, e.g., +in case the ``plotting`` modules should be excluded from the +automatically detected ``import_modules`` ``['nilearn', 'nilearn.surface', +'nilearn.plotting', 'nilearn.plotting.data']`` set: + +.. code-block:: python + + skip_modules = ['nilearn.plotting'] + +This will set ``import_modules`` to ``['nilearn', 'nilearn.surface']`` + Import tests can be run during the installation using ``spack install --test=root`` or at any time after the installation using ``spack test run``. diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py index 5cd60d774e..085feec5fe 100644 --- a/lib/spack/spack/build_systems/python.py +++ b/lib/spack/spack/build_systems/python.py @@ -138,13 +138,29 @@ class PythonPackage(PackageBase): path.replace(root + os.sep, "", 1).replace(".py", "").replace("/", ".") ) - modules = [mod for mod in modules if re.match("[a-zA-Z0-9._]+$", mod)] + modules = [ + mod + for mod in modules + if re.match("[a-zA-Z0-9._]+$", mod) and not any(map(mod.startswith, self.skip_modules)) + ] tty.debug("Detected the following modules: {0}".format(modules)) return modules @property + def skip_modules(self): + """Names of modules that should be skipped when running tests. + + These are a subset of import_modules. If a module has submodules, + they are skipped as well (meaning a.b is skipped if a is contained). + + Returns: + list: list of strings of module names + """ + return [] + + @property def build_directory(self): """The root directory of the Python package. |