package.py : hdf5 and lzo have examples of run_tests

This commit is contained in:
alalazo 2016-07-13 09:21:49 +02:00
parent 97c2224cd6
commit 5cc59507f7
3 changed files with 41 additions and 22 deletions

View file

@ -96,25 +96,35 @@ def __get__(self, instance, owner):
phase = getattr(instance, self.name) phase = getattr(instance, self.name)
@functools.wraps(phase) @functools.wraps(phase)
def phase_wrapper(spec, prefix): def phase_wrapper(spec, prefix):
# Check instance attributes at the beginning of a phase
self._on_phase_start(instance)
# Execute phase pre-conditions, # Execute phase pre-conditions,
# and give them the chance to fail # and give them the chance to fail
for check in self.preconditions: for check in self.preconditions:
check(instance) check(instance) # Do something sensible at some point
# Do something sensible at some point
phase(spec, prefix) phase(spec, prefix)
# Execute phase sanity_checks, # Execute phase sanity_checks,
# and give them the chance to fail # and give them the chance to fail
for check in self.sanity_checks: for check in self.sanity_checks:
check(instance) check(instance)
if getattr(instance, 'last_phase', None) == self.name: # Check instance attributes at the end of a phase
raise StopIteration('Stopping at \'{0}\' phase'.format(self.name)) self._on_phase_exit(instance)
return phase_wrapper return phase_wrapper
def _on_phase_start(self, instance):
pass
def _on_phase_exit(self, instance):
# If a phase has a matching last_phase attribute,
# stop the installation process raising a StopIteration
if getattr(instance, 'last_phase', None) == self.name:
raise StopIteration('Stopping at \'{0}\' phase'.format(self.name))
class PackageMeta(type): class PackageMeta(type):
"""Conveniently transforms attributes to permit extensible phases """Conveniently transforms attributes to permit extensible phases
Iterates over the attribute 'phase' and creates / updates private Iterates over the attribute 'phases' and creates / updates private
InstallPhase attributes in the class that is being initialized InstallPhase attributes in the class that is being initialized
""" """
phase_fmt = '_InstallPhase_{0}' phase_fmt = '_InstallPhase_{0}'
@ -156,14 +166,25 @@ def _append_checks(check_name):
def _register_checks(cls, check_type, *args): def _register_checks(cls, check_type, *args):
def _register_sanity_checks(func): def _register_sanity_checks(func):
attr_name = PackageMeta.phase_fmt.format(check_type) attr_name = PackageMeta.phase_fmt.format(check_type)
sanity_checks = getattr(meta, attr_name) check_list = getattr(meta, attr_name)
for item in args: for item in args:
checks = sanity_checks.setdefault(item, []) checks = check_list.setdefault(item, [])
checks.append(func) checks.append(func)
setattr(meta, attr_name, sanity_checks) setattr(meta, attr_name, check_list)
return func return func
return _register_sanity_checks return _register_sanity_checks
@staticmethod
def on_package_attributes(**attrs):
def _execute_under_condition(func):
@functools.wraps(func)
def _wrapper(instance):
# If all the attributes have the value we require, then execute
if all([getattr(instance, key, None) == value for key, value in attrs.items()]):
func(instance)
return _wrapper
return _execute_under_condition
@classmethod @classmethod
def precondition(cls, *args): def precondition(cls, *args):
return cls._register_checks('preconditions', *args) return cls._register_checks('preconditions', *args)
@ -181,6 +202,9 @@ def sanity_check(cls, *args):
if all([not hasattr(x, 'precondition') for x in bases]): if all([not hasattr(x, 'precondition') for x in bases]):
attr_dict['precondition'] = precondition attr_dict['precondition'] = precondition
if all([not hasattr(x, 'on_package_attributes') for x in bases]):
attr_dict['on_package_attributes'] = on_package_attributes
# Preconditions # Preconditions
_append_checks('preconditions') _append_checks('preconditions')
# Sanity checks # Sanity checks

View file

@ -29,8 +29,8 @@
class Hdf5(AutotoolsPackage): class Hdf5(AutotoolsPackage):
"""HDF5 is a data model, library, and file format for storing and managing """HDF5 is a data model, library, and file format for storing and managing
data. It supports an unlimited variety of datatypes, and is designed for data. It supports an unlimited variety of datatypes, and is designed for
flexible and efficient I/O and for high volume and complex data. flexible and efficient I/O and for high volume and complex data.
""" """
homepage = "http://www.hdfgroup.org/HDF5/" homepage = "http://www.hdfgroup.org/HDF5/"
@ -54,9 +54,9 @@ class Hdf5(AutotoolsPackage):
variant('szip', default=False, description='Enable szip support') variant('szip', default=False, description='Enable szip support')
variant('threadsafe', default=False, description='Enable thread-safe capabilities') variant('threadsafe', default=False, description='Enable thread-safe capabilities')
depends_on("mpi", when='+mpi') depends_on('mpi', when='+mpi')
depends_on("szip", when='+szip') depends_on('szip', when='+szip')
depends_on("zlib") depends_on('zlib')
@AutotoolsPackage.precondition('configure') @AutotoolsPackage.precondition('configure')
def validate(self): def validate(self):
@ -140,15 +140,9 @@ def configure_args(self):
]) ])
return ["--with-zlib=%s" % spec['zlib'].prefix] + extra_args return ["--with-zlib=%s" % spec['zlib'].prefix] + extra_args
#configure(
# "--prefix=%s" % prefix,
# "--with-zlib=%s" % spec['zlib'].prefix,
# *extra_args)
#make()
#make("install")
#self.check_install(spec)
@AutotoolsPackage.sanity_check('install') @AutotoolsPackage.sanity_check('install')
@AutotoolsPackage.on_package_attributes(run_tests=True)
def check_install(self): def check_install(self):
"Build and run a small program to test the installed HDF5 library" "Build and run a small program to test the installed HDF5 library"
spec = self.spec spec = self.spec

View file

@ -44,6 +44,7 @@ def configure_args(self):
] ]
@AutotoolsPackage.sanity_check('build') @AutotoolsPackage.sanity_check('build')
@AutotoolsPackage.on_package_attributes(run_tests=True)
def check(self): def check(self):
if self.extra_args.get('build-tests', False): make('check')
make('check') make('test')