def analyze_spec(spec, analyzers=None, outdir=None, monitor=None, overwrite=False): """ Do an analysis for a spec, optionally adding monitoring. We also allow the user to specify a custom output directory. analyze_spec(spec, args.analyzers, args.outdir, monitor) Args: spec (spack.spec.Spec): spec object of installed package analyzers (list): list of analyzer (keys) to run monitor (spack.monitor.SpackMonitorClient): a monitor client overwrite (bool): overwrite result if already exists """ analyzers = analyzers or list(spack.analyzers.analyzer_types.keys()) # Load the build environment from the spec install directory, and send # the spec to the monitor if it's not known if monitor: monitor.load_build_environment(spec) monitor.new_configuration([spec]) for name in analyzers: # Instantiate the analyzer with the spec and outdir analyzer = spack.analyzers.get_analyzer(name)(spec, outdir) # Run the analyzer to get a json result - results are returned as # a dictionary with a key corresponding to the analyzer type, so # we can just update the data result = analyzer.run() # Send the result. We do them separately because: # 1. each analyzer might have differently organized output # 2. the size of a result can be large analyzer.save_result(result, overwrite)
def test_spack_monitor_new_configuration(mock_monitor_request, install_mockery): monitor = get_client(host="hostname") spec = spack.spec.Spec("dttop") spec.concretize() response = monitor.new_configuration([spec]) # The response is a lookup of specs assert "dttop" in response
def install(parser, args, **kwargs): if args.help_cdash: parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, epilog=textwrap.dedent('''\ environment variables: SPACK_CDASH_AUTH_TOKEN authentication token to present to CDash ''')) arguments.add_cdash_args(parser, True) parser.print_help() return # The user wants to monitor builds using github.com/spack/spack-monitor if args.use_monitor: monitor = spack.monitor.get_client( host=args.monitor_host, prefix=args.monitor_prefix, disable_auth=args.monitor_disable_auth, tags=args.monitor_tags, save_local=args.monitor_save_local, ) reporter = spack.report.collect_info(spack.package.PackageInstaller, '_install_task', args.log_format, args) if args.log_file: reporter.filename = args.log_file if args.run_tests: tty.warn("Deprecated option: --run-tests: use --test=all instead") def get_tests(specs): if args.test == 'all' or args.run_tests: return True elif args.test == 'root': return [spec.name for spec in specs] else: return False # Parse cli arguments and construct a dictionary # that will be passed to the package installer update_kwargs_from_args(args, kwargs) if not args.spec and not args.specfiles: # if there are no args but an active environment # then install the packages from it. env = ev.active_environment() if env: tests = get_tests(env.user_specs) kwargs['tests'] = tests if not args.only_concrete: with env.write_transaction(): concretized_specs = env.concretize(tests=tests) ev.display_specs(concretized_specs) # save view regeneration for later, so that we only do it # once, as it can be slow. env.write(regenerate=False) specs = env.all_specs() if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs # Tell the monitor about the specs if args.use_monitor and specs: monitor.new_configuration(specs) tty.msg("Installing environment {0}".format(env.name)) with reporter('build'): env.install_all(**kwargs) tty.debug("Regenerating environment views for {0}".format( env.name)) with env.write_transaction(): # write env to trigger view generation and modulefile # generation env.write() return else: msg = "install requires a package argument or active environment" if 'spack.yaml' in os.listdir(os.getcwd()): # There's a spack.yaml file in the working dir, the user may # have intended to use that msg += "\n\n" msg += "Did you mean to install using the `spack.yaml`" msg += " in this directory? Try: \n" msg += " spack env activate .\n" msg += " spack install\n" msg += " OR\n" msg += " spack --env . install" tty.die(msg) if args.no_checksum: spack.config.set('config:checksum', False, scope='command_line') if args.deprecated: spack.config.set('config:deprecated', True, scope='command_line') # 1. Abstract specs from cli abstract_specs = spack.cmd.parse_specs(args.spec) tests = get_tests(abstract_specs) kwargs['tests'] = tests try: specs = spack.cmd.parse_specs(args.spec, concretize=True, tests=tests) except SpackError as e: tty.debug(e) reporter.concretization_report(e.message) raise # 2. Concrete specs from yaml files for file in args.specfiles: with open(file, 'r') as f: if file.endswith('yaml') or file.endswith('yml'): s = spack.spec.Spec.from_yaml(f) else: s = spack.spec.Spec.from_json(f) concretized = s.concretized() if concretized.dag_hash() != s.dag_hash(): msg = 'skipped invalid file "{0}". ' msg += 'The file does not contain a concrete spec.' tty.warn(msg.format(file)) continue abstract_specs.append(s) specs.append(concretized) if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs with reporter('build'): if args.overwrite: installed = list( filter(lambda x: x, map(spack.store.db.query_one, specs))) if not args.yes_to_all: display_args = { 'long': True, 'show_flags': True, 'variants': True } if installed: tty.msg('The following package specs will be ' 'reinstalled:\n') spack.cmd.display_specs(installed, **display_args) not_installed = list( filter(lambda x: x not in installed, specs)) if not_installed: tty.msg('The following package specs are not installed and' ' the --overwrite flag was given. The package spec' ' will be newly installed:\n') spack.cmd.display_specs(not_installed, **display_args) # We have some specs, so one of the above must have been true answer = tty.get_yes_or_no('Do you want to proceed?', default=False) if not answer: tty.die('Reinstallation aborted.') # overwrite all concrete explicit specs from this build kwargs['overwrite'] = [spec.dag_hash() for spec in specs] # Update install_args with the monitor args, needed for build task kwargs.update({ "monitor_disable_auth": args.monitor_disable_auth, "monitor_keep_going": args.monitor_keep_going, "monitor_host": args.monitor_host, "use_monitor": args.use_monitor, "monitor_prefix": args.monitor_prefix, }) # If we are using the monitor, we send configs. and create build # The full_hash is the main package id, the build_hash for others if args.use_monitor and specs: monitor.new_configuration(specs) install_specs(args, kwargs, zip(abstract_specs, specs))