Fix usage of PythonPackage.test outside of PythonPackage (#20555)
This commit is contained in:
parent
f0cafd21ce
commit
ba70f90ee0
@ -6,10 +6,10 @@
|
||||
import inspect
|
||||
import os
|
||||
|
||||
from llnl.util.filesystem import working_dir, join_path
|
||||
from spack.build_systems.python import PythonPackage
|
||||
from llnl.util.filesystem import find, working_dir, join_path
|
||||
from spack.directives import depends_on, extends
|
||||
from spack.package import PackageBase, run_after
|
||||
import llnl.util.tty as tty
|
||||
|
||||
|
||||
class SIPPackage(PackageBase):
|
||||
@ -44,7 +44,44 @@ class SIPPackage(PackageBase):
|
||||
depends_on('qt')
|
||||
depends_on('py-sip')
|
||||
|
||||
import_modules = PythonPackage.import_modules
|
||||
@property
|
||||
def import_modules(self):
|
||||
"""Names of modules that the Python package provides.
|
||||
|
||||
These are used to test whether or not the installation succeeded.
|
||||
These names generally come from running:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>> import setuptools
|
||||
>> setuptools.find_packages()
|
||||
|
||||
in the source tarball directory. If the module names are incorrectly
|
||||
detected, this property can be overridden by the package.
|
||||
|
||||
Returns:
|
||||
list: list of strings of module names
|
||||
"""
|
||||
modules = []
|
||||
|
||||
# Python libraries may be installed in lib or lib64
|
||||
# See issues #18520 and #17126
|
||||
for lib in ['lib', 'lib64']:
|
||||
root = os.path.join(self.prefix, lib, 'python{0}'.format(
|
||||
self.spec['python'].version.up_to(2)), 'site-packages')
|
||||
# Some Python libraries are packages: collections of modules
|
||||
# distributed in directories containing __init__.py files
|
||||
for path in find(root, '__init__.py', recursive=True):
|
||||
modules.append(path.replace(root + os.sep, '', 1).replace(
|
||||
os.sep + '__init__.py', '').replace('/', '.'))
|
||||
# Some Python libraries are modules: individual *.py files
|
||||
# found in the site-packages directory
|
||||
for path in find(root, '*.py', recursive=False):
|
||||
modules.append(path.replace(root + os.sep, '', 1).replace(
|
||||
'.py', '').replace('/', '.'))
|
||||
|
||||
tty.debug('Detected the following modules: {0}'.format(modules))
|
||||
return modules
|
||||
|
||||
def python(self, *args, **kwargs):
|
||||
"""The python ``Executable``."""
|
||||
@ -101,7 +138,16 @@ def install_args(self):
|
||||
|
||||
# Testing
|
||||
|
||||
test = PythonPackage.test
|
||||
def test(self):
|
||||
"""Attempts to import modules of the installed package."""
|
||||
|
||||
# Make sure we are importing the installed modules,
|
||||
# not the ones in the source directory
|
||||
for module in self.import_modules:
|
||||
self.run_test(inspect.getmodule(self).python.path,
|
||||
['-c', 'import {0}'.format(module)],
|
||||
purpose='checking import of {0}'.format(module),
|
||||
work_dir='spack-test')
|
||||
|
||||
run_after('install')(PackageBase._run_default_install_time_test_callbacks)
|
||||
|
||||
|
@ -20,6 +20,7 @@ class Gdal(AutotoolsPackage):
|
||||
list_depth = 1
|
||||
|
||||
maintainers = ['adamjstewart']
|
||||
import_modules = ['osgeo', 'osgeo.utils']
|
||||
|
||||
version('3.2.1', sha256='6c588b58fcb63ff3f288eb9f02d76791c0955ba9210d98c3abd879c770ae28ea')
|
||||
version('3.2.0', sha256='b051f852600ffdf07e337a7f15673da23f9201a9dbb482bd513756a3e5a196a6')
|
||||
@ -562,5 +563,13 @@ def darwin_fix(self):
|
||||
fix_darwin_install_name(self.prefix.lib)
|
||||
|
||||
def test(self):
|
||||
"""Attempts to import modules of the installed package."""
|
||||
|
||||
if '+python' in self.spec:
|
||||
PythonPackage.test(self)
|
||||
# Make sure we are importing the installed modules,
|
||||
# not the ones in the source directory
|
||||
for module in self.import_modules:
|
||||
self.run_test(self.spec['python'].command.path,
|
||||
['-c', 'import {0}'.format(module)],
|
||||
purpose='checking import of {0}'.format(module),
|
||||
work_dir='spack-test')
|
||||
|
@ -15,6 +15,7 @@ class PyTensorflow(Package, CudaPackage):
|
||||
url = "https://github.com/tensorflow/tensorflow/archive/v2.3.1.tar.gz"
|
||||
|
||||
maintainers = ['adamjstewart', 'aweits']
|
||||
import_modules = ['tensorflow']
|
||||
|
||||
version('2.4.1', sha256='f681331f8fc0800883761c7709d13cda11942d4ad5ff9f44ad855e9dc78387e0')
|
||||
version('2.4.0', sha256='26c833b7e1873936379e810a39d14700281125257ddda8cd822c89111db6f6ae')
|
||||
@ -298,9 +299,6 @@ class PyTensorflow(Package, CudaPackage):
|
||||
|
||||
phases = ['configure', 'build', 'install']
|
||||
|
||||
import_modules = PythonPackage.import_modules
|
||||
test = PythonPackage.test
|
||||
|
||||
# https://www.tensorflow.org/install/source
|
||||
def setup_build_environment(self, env):
|
||||
spec = self.spec
|
||||
@ -790,3 +788,14 @@ def install(self, spec, prefix):
|
||||
setup_py('install', '--prefix={0}'.format(prefix),
|
||||
'--single-version-externally-managed', '--root=/')
|
||||
remove_linked_tree(tmp_path)
|
||||
|
||||
def test(self):
|
||||
"""Attempts to import modules of the installed package."""
|
||||
|
||||
# Make sure we are importing the installed modules,
|
||||
# not the ones in the source directory
|
||||
for module in self.import_modules:
|
||||
self.run_test(self.spec['python'].command.path,
|
||||
['-c', 'import {0}'.format(module)],
|
||||
purpose='checking import of {0}'.format(module),
|
||||
work_dir='spack-test')
|
||||
|
Loading…
Reference in New Issue
Block a user