From d6a497540d4603d3627ad45004c2dd746dc18dab Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 18 Mar 2020 16:52:01 -0700 Subject: [PATCH] fixup reporter work --- lib/spack/spack/cmd/install.py | 3 ++- lib/spack/spack/cmd/test.py | 4 +++- lib/spack/spack/report.py | 26 +++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index 510b0e310c2..659a37e6457 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -263,7 +263,8 @@ def install(parser, args, **kwargs): tty.warn("Deprecated option: --run-tests: use --test=all instead") # 1. Abstract specs from cli - reporter = spack.report.collect_info('do_install', args.log_format, args) + reporter = spack.report.collect_info( + spack.package.PackageInstaller, '_install_task', args.log_format, args) if args.log_file: reporter.filename = args.log_file diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py index fcf5f4053c2..aa6d7274593 100644 --- a/lib/spack/spack/cmd/test.py +++ b/lib/spack/spack/cmd/test.py @@ -15,6 +15,7 @@ import spack.cmd import spack.cmd.common.arguments as arguments import spack.report +import spack.package description = "run spack's tests for an install" section = "administrator" @@ -90,7 +91,8 @@ def test(parser, args): # Set up reporter setattr(args, 'package', [s.format() for s in specs_to_test]) - reporter = spack.report.collect_info('do_test', args.log_format, args) + reporter = spack.report.collect_info( + spack.package.PackageBase, 'do_test', args.log_format, args) if not reporter.filename: if args.log_file: if os.path.isabs(args.log_file): diff --git a/lib/spack/spack/report.py b/lib/spack/spack/report.py index a62f0d9ab44..703b33a82e5 100644 --- a/lib/spack/spack/report.py +++ b/lib/spack/spack/report.py @@ -36,7 +36,7 @@ def fetch_log(pkg, do_fn, dir): log_files = { - 'do_install': pkg.build_log_path, + '_install_task': pkg.build_log_path, 'do_test': os.path.join(dir, pkg.test_log_name), } try: @@ -130,7 +130,7 @@ def gather_info(do_fn): """ @functools.wraps(do_fn) def wrapper(instance, *args, **kwargs): - if isinstance(instance, PackageBase): + if isinstance(instance, spack.package.PackageBase): pkg = instance elif hasattr(args[0], 'pkg'): pkg = args[0].pkg @@ -152,12 +152,12 @@ def wrapper(instance, *args, **kwargs): start_time = time.time() value = None try: - value = _install_task(instance, *args, **kwargs) + value = do_fn(instance, *args, **kwargs) package['result'] = 'success' package['stdout'] = fetch_log(pkg, do_fn, self.dir) package['installed_from_binary_cache'] = \ pkg.installed_from_binary_cache - if do_fn.__name__ == 'do_install' and installed_on_entry: + if do_fn.__name__ == '_install_task' and installed_on_entry: return except spack.build_environment.InstallError as e: @@ -240,22 +240,25 @@ class collect_info(object): # The file 'junit.xml' is written when exiting # the context - specs = [Spec('hdf5').concretized()] - with collect_info(specs, 'junit', 'junit.xml'): + s = [Spec('hdf5').concretized()] + with collect_info(PackageBase, do_install, s, 'junit', 'a.xml'): # A report will be generated for these specs... - for spec in specs: - spec.do_install() + for spec in s: + getattr(class, function)(spec) # ...but not for this one Spec('zlib').concretized().do_install() Args: + class: class on which to wrap a function + function: function to wrap format_name (str or None): one of the supported formats - args (dict): args passed to spack install + args (dict): args passed to function Raises: ValueError: when ``format_name`` is not in ``valid_formats`` """ - def __init__(self, function, format_name, args): + def __init__(self, cls, function, format_name, args): + self.cls = cls self.function = function self.filename = None if args.cdash_upload_url: @@ -280,7 +283,8 @@ def concretization_report(self, msg): def __enter__(self): if self.format_name: # Start the collector and patch self.function on appropriate class - self.collector = InfoCollector(self.function, self.specs, self.dir) + self.collector = InfoCollector( + self.cls, self.function, self.specs, self.dir) self.collector.__enter__() def __exit__(self, exc_type, exc_val, exc_tb):