示例#1
0
文件: main.py 项目: FNALssi/spack
def setup_main_options(args):
    """Configure spack globals based on the basic options."""
    # Set up environment based on args.
    tty.set_verbose(args.verbose)
    tty.set_debug(args.debug)
    tty.set_stacktrace(args.stacktrace)

    # debug must be set first so that it can even affect behvaior of
    # errors raised by spack.config.
    if args.debug:
        spack.error.debug = True
        spack.util.debug.register_interrupt_handler()
        spack.config.set('config:debug', True, scope='command_line')

    if args.timestamp:
        tty.set_timestamp(True)

    # override lock configuration if passed on command line
    if args.locks is not None:
        spack.util.lock.check_lock_safety(spack.paths.prefix)
        spack.config.set('config:locks', False, scope='command_line')

    if args.mock:
        rp = spack.repo.RepoPath(spack.paths.mock_packages_path)
        spack.repo.set_path(rp)

    # If the user asked for it, don't check ssl certs.
    if args.insecure:
        tty.warn("You asked for --insecure. Will NOT check SSL certificates.")
        spack.config.set('config:verify_ssl', False, scope='command_line')

    # when to use color (takes always, auto, or never)
    color.set_color_when(args.color)
示例#2
0
文件: main.py 项目: matzke1/spack
def setup_main_options(args):
    """Configure spack globals based on the basic options."""
    # Set up environment based on args.
    tty.set_verbose(args.verbose)
    tty.set_debug(args.debug)
    tty.set_stacktrace(args.stacktrace)

    # debug must be set first so that it can even affect behvaior of
    # errors raised by spack.config.
    if args.debug:
        spack.error.debug = True
        spack.util.debug.register_interrupt_handler()
        spack.config.set('config:debug', True, scope='command_line')

    # override lock configuration if passed on command line
    if args.locks is not None:
        spack.util.lock.check_lock_safety(spack.paths.prefix)
        spack.config.set('config:locks', False, scope='command_line')

    if args.mock:
        rp = spack.repo.RepoPath(spack.paths.mock_packages_path)
        spack.repo.set_path(rp)

    # If the user asked for it, don't check ssl certs.
    if args.insecure:
        tty.warn("You asked for --insecure. Will NOT check SSL certificates.")
        spack.config.set('config:verify_ssl', False, scope='command_line')

    # when to use color (takes always, auto, or never)
    tty.color.set_color_when(args.color)
示例#3
0
def setup_main_options(args):
    """Configure spack globals based on the basic options."""
    # Assign a custom function to show warnings
    warnings.showwarning = send_warning_to_tty

    # Set up environment based on args.
    tty.set_verbose(args.verbose)
    tty.set_debug(args.debug)
    tty.set_stacktrace(args.stacktrace)

    # debug must be set first so that it can even affect behavior of
    # errors raised by spack.config.

    if args.debug:
        spack.error.debug = True
        spack.util.debug.register_interrupt_handler()
        spack.config.set('config:debug', True, scope='command_line')
        spack.util.environment.tracing_enabled = True

    if args.show_cores != "off":
        # minimize_cores defaults to true, turn it off if we're showing full core
        # but don't want to wait to minimize it.
        spack.solver.asp.full_cores = True
        if args.show_cores == 'full':
            spack.solver.asp.minimize_cores = False

    if args.timestamp:
        tty.set_timestamp(True)

    # override lock configuration if passed on command line
    if args.locks is not None:
        if args.locks is False:
            spack.util.lock.check_lock_safety(spack.paths.prefix)
        spack.config.set('config:locks', args.locks, scope='command_line')

    if args.mock:
        rp = spack.repo.RepoPath(spack.paths.mock_packages_path)
        spack.repo.set_path(rp)

    # If the user asked for it, don't check ssl certs.
    if args.insecure:
        tty.warn("You asked for --insecure. Will NOT check SSL certificates.")
        spack.config.set('config:verify_ssl', False, scope='command_line')

    # Use the spack config command to handle parsing the config strings
    for config_var in (args.config_vars or []):
        spack.config.add(fullpath=config_var, scope="command_line")

    # when to use color (takes always, auto, or never)
    color.set_color_when(args.color)
示例#4
0
文件: cdash.py 项目: havogt/spack
    def __init__(self, args):
        Reporter.__init__(self, args)
        tty.set_verbose(args.verbose)
        self.success = True
        self.template_dir = os.path.join('reports', 'cdash')
        self.cdash_upload_url = args.cdash_upload_url

        if self.cdash_upload_url:
            self.buildid_regexp = re.compile("<buildId>([0-9]+)</buildId>")
        self.phase_regexp = re.compile(r"Executing phase: '(.*)'")

        self.authtoken = None
        if 'SPACK_CDASH_AUTH_TOKEN' in os.environ:
            tty.verbose("Using CDash auth token from environment")
            self.authtoken = os.environ.get('SPACK_CDASH_AUTH_TOKEN')

        if getattr(args, 'spec', ''):
            packages = args.spec
        elif getattr(args, 'specs', ''):
            packages = args.specs
        else:
            packages = []
            for file in args.specfiles:
                with open(file, 'r') as f:
                    s = spack.spec.Spec.from_yaml(f)
                    packages.append(s.format())
        self.install_command = ' '.join(packages)
        self.base_buildname = args.cdash_build or self.install_command
        self.site = args.cdash_site or socket.gethostname()
        self.osname = platform.system()
        self.endtime = int(time.time())
        if args.cdash_buildstamp:
            self.buildstamp = args.cdash_buildstamp
        else:
            buildstamp_format = "%Y%m%d-%H%M-{0}".format(args.cdash_track)
            self.buildstamp = time.strftime(buildstamp_format,
                                            time.localtime(self.endtime))
        self.buildIds = OrderedDict()
        self.revision = ''
        git = which('git')
        with working_dir(spack.paths.spack_root):
            self.revision = git('rev-parse', 'HEAD', output=str).strip()
        self.multiple_packages = False
示例#5
0
def setup_main_options(args):
    """Configure spack globals based on the basic options."""
    # Set up environment based on args.
    tty.set_verbose(args.verbose)
    tty.set_debug(args.debug)
    tty.set_stacktrace(args.stacktrace)
    spack.debug = args.debug

    if spack.debug:
        import spack.util.debug as debug
        debug.register_interrupt_handler()

    if args.mock:
        from spack.repository import RepoPath
        spack.repo.swap(RepoPath(spack.mock_packages_path))

    # If the user asked for it, don't check ssl certs.
    if args.insecure:
        tty.warn("You asked for --insecure. Will NOT check SSL certificates.")
        spack.insecure = True
示例#6
0
def setup_main_options(args):
    """Configure pymod globals based on the basic options."""
    # Set up environment based on args.
    tty.set_verbose(args.verbose)
    tty.set_debug(args.debug)
    #    tty.set_trace(args.trace)

    # debug must be set first so that it can even affect behavior of
    # errors raised by pymod.config.
    if args.debug:
        # pymod.error.debug = True
        pymod.config.set("debug", True, scope="command_line")

    if args.dryrun:
        pymod.config.set("dryrun", True, scope="command_line")

    if args.shell != pymod.config.get("default_shell"):
        pymod.shell.set_shell(args.shell)

    # when to use color (takes always, auto, or never)
    color.set_color_when(args.color)
示例#7
0
def init(parser, args):
    global spackdev_base

    # Verbosity
    tty.set_verbose(args.verbose)

    if 'SPACKDEV_BASE' in os.environ:
        if args.force:
            tty.warn(
                'spack dev init: (force) removing existing SPACKDEV_* from current environment.'
            )
            for x in [x for x in os.environ if x.startswith('SPACKDEV_')]:
                del os.environ[x]
        else:
            tty.die(
                'spack dev init: current environment is already aware of a SpackDev environment ({0})'
                .format(os.environ['SPACKDEV_BASE']))

    if args.base_dir:
        if os.path.isdir(args.base_dir) or \
           os.path.exists(os.path.abspath(os.path.dirname(args.base_dir))):
            spackdev_base = os.path.abspath(args.base_dir)
        else:
            tty.die(
                'spack dev init: {0} is not a directory or its parent does not exist.'
                .format(args.base_dir))

    try:
        if (not os.path.exists(spackdev_base)):
            os.mkdir(spackdev_base)
        os.chdir(spackdev_base)
    except OSError:
        tty.die(
            'spack dev init: unable to make or change directory to {0}'.format(
                spackdev_base))

    # Save for posterity
    os.environ['SPACKDEV_BASE'] = spackdev_base

    requested = args.packages
    dag_filename = args.dag_file
    build_system = Build_system(args.generator, args.override_generator)
    os.environ['SPACKDEV_GENERATOR'] = build_system.cmake_generator

    if os.listdir(spackdev_base):
        if args.force:
            tty.warn(
                'spack dev init: (force) using non-empty directory {0}'.format(
                    spackdev_base))
            if (os.path.exists('spackdev-aux') or os.path.exists('build')
                    or os.path.exists('install') or os.path.exists('tmp')):
                if args.force:
                    tty.warn(
                        'spack dev init: (force) removing existing spackdev-aux, build and install directories from {0}'
                        .format(spackdev_base))
                    for wd in ('spackdev-aux', 'build', 'install', 'tmp'):
                        shutil.rmtree(wd, ignore_errors=True)
                else:
                    tty.die(
                        'spack dev init: cannot re-init (spackdev-aux/build/install/tmp directories exist)'
                    )
        else:
            tty.die('spack dev init: refusing to use non-empty directory {0}'.
                    format(spackdev_base))

    os.mkdir('spackdev-aux')
    filesystem.mkdirp('srcs')

    tty.msg('requested packages: {0}{1}'.\
            format(', '.join(requested),
                   ' from install tree as specified in {0}'.format(dag_filename)
                   if dag_filename else ''))
    specs = extract_specs(dag_filename if dag_filename else requested)
    additional = get_additional(requested, specs)
    if additional:
        tty.msg('additional inter-dependent packages: ' + ' '.join(additional))
    dev_packages = requested + additional
    if args.print_spec_tree:
        tty.msg('Full spec tree: \n{0}'.\
                format('\n'.join([spec.tree(cover='nodes',
                                            format='{name}{@version}{%compiler}{compiler_flags}{variants}{arch=architecture}',
                                            hashlen=7,
                                            show_types=True,
                                            status_fn=spack.spec.Spec.install_status)
                                  for spec in specs])))
        if args.print_spec_tree == 'exit':
            sys.exit(1)

    dep_specs = write_package_info(requested, additional, specs)
    package_specs = {}
    for package in dev_packages:
        spec = dev.cmd.get_package_spec(package, specs)
        if spec:
            package_specs[package] = spec[package]
        else:
            tty.die("Unable to find spec for specified package {0}".\
                    format(package))

    if not args.no_stage:
        tty.msg('stage sources for {0}'.format(dev_packages))
        dev.cmd.stage_packages(dev_packages, package_specs)

    if not args.no_dependencies:
        tty.msg('install dependencies')
        dev.cmd.install_dependencies(dev_packages=dev_packages,
                                     dep_specs=dep_specs)

    tty.msg('create wrapper scripts')
    path_fixer = create_environment(dev_packages, package_specs)

    tty.msg('generate top level CMakeLists.txt')
    write_cmakelists(dev_packages, package_specs, build_system, path_fixer)

    tty.msg('create and initialize build area')
    create_build_area(build_system, args)

    tty.msg('initialization of {0} complete;'.format(spackdev_base))
    tty.msg('source {0} to begin.'.format(
        os.path.join(spackdev_base, dev.spackdev_aux_subdir, 'env.sh')))
示例#8
0
文件: install.py 项目: t-brown/spack
def install(parser, args, **kwargs):
    # TODO: unify args.verbose?
    tty.set_verbose(args.verbose or args.install_verbose)

    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,
            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

    def get_tests(specs):
        if args.test == 'all':
            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 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)

            else:
                msg = '{0} environment has no specs to install'.format(
                    env.name)
                tty.msg(msg)

            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)

        # Tell spack monitor about it
        if args.use_monitor and abstract_specs:
            monitor.failed_concretization(abstract_specs)
        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_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 dag_hash is the main package id
        if args.use_monitor and specs:
            monitor.new_configuration(specs)
        install_specs(args, kwargs, zip(abstract_specs, specs))
示例#9
0
文件: init.py 项目: FNALssi/spack-dev
def init(parser, args):
    # Verbosity
    tty.set_verbose(args.verbose)

    # Non-trivial exclusivity checks
    if args.resume:
        if args.packages or args.dag_file:
            _init_subparser.error(
                '--resume is incompatible with --dag-file or non-option arguments PACKAGES'
            )

    # Initialize the spack dev area.
    init_spackdev_base(args)

    # Specify the build system in the environment (may be used by
    # recipes during spec concretization).
    build_system = Build_system(args.generator, args.override_generator)
    os.environ['SPACKDEV_GENERATOR'] = build_system.cmake_generator

    (requested, additional, dev_package_info, specs, dep_specs)\
        = get_package_info(args)

    dev_packages = requested + additional

    # Identify specs and set staging path for development packages.
    dev_package_specs = {}
    for package in dev_packages:
        spec = dev.cmd.get_package_spec(package, specs)
        if spec:
            dev_package_specs[package] = spec[package]
            # Set the package's path to be passed to the stage object
            # when it is created.
            spec.package.path = spack_stage_top()
        else:
            tty.die('Unable to find spec for specified package {0}'.\
                    format(package))

    # Print development package spec tree(s) if desired.
    if args.print_spec_tree:
        print_spec_tree(dev_packages, specs)
        if args.print_spec_tree == 'exit':
            sys.exit(1)

    # Stage development packages if selected.
    if not args.no_stage:
        tty.msg('stage sources for {0}'.format(dev_packages))
        dev.cmd.stage_packages(dev_package_info, dev_package_specs)

    # Exit now if we're not installing dependencies.
    if args.no_dependencies:
        tty.msg(
            'Dependencies will not be built, SpackDev environment is incomplete.'
        )
        tty.msg(
            'Use spack dev --resume to complete initialization of SpackDev environment.'
        )
        sys.exit(1)

    # Continue with the rest of the initialization process.
    tty.msg('install dependencies')
    dev.cmd.install_dependencies(dev_package_info=dev_package_info,
                                 dep_specs=dep_specs)

    # Create tool wrappers.
    global_wrappers_dir = create_cmd_links(specs)

    # Create the environment files.
    tty.msg('create environment files.')
    path_fixer = PathFixer(spack.store.root, spack_stage_top())
    path_fixer.set_packages(*dev_packages)
    create_environment(dev_packages, dev_package_specs, path_fixer,
                       global_wrappers_dir)

    # Generate the top level CMakeLists.txt.
    tty.msg('generate top level CMakeLists.txt')
    write_cmakelists(dev_packages, dev_package_specs, build_system, path_fixer)

    # Initialize the build area.
    tty.msg('initialize build area')
    init_build_area(build_system, args)

    # Done.
    tty.msg('initialization of {0} complete;'.format(spackdev_base))
    tty.msg('source {0} to begin.'.format(
        os.path.join(spackdev_base, dev.spackdev_aux_env_subdir, 'env.sh')))