Exemple #1
0
def install(name, keep_prefix=False, keep_stage=False, ignore_deps=False, environs=None, compiler=None):
    _init_spack()
    from spack import repo, installed_db
    from spack.cmd import parse_specs
    from os import environ
    if not isinstance(name, str):
        results = [], []
        for pkg in name:
            a, b = install(pkg, keep_prefix=keep_prefix, keep_stage=keep_stage,
                           ignore_deps=ignore_deps, environs=environs,
                           compiler=compiler)
            results[0].extend(a)
            results[1].extend(b)
        return results
    if environs is not None:
        environ.update(environs)
    if compiler is not None:
        names = name.split()
        names.insert(1, "%" + compiler.rstrip().lstrip())
        name = ' '.join(names)
    specs = parse_specs(name, concretize=True)
    packages = [repo.get(spec) for spec in specs]
    new_pkgs = [u for u in packages if not u.installed]
    for package in new_pkgs:
        with installed_db.write_transaction():
            package.do_install(
                keep_prefix=keep_prefix,
                keep_stage=keep_stage,
                ignore_deps=ignore_deps
            )
    return [p.name for p in new_pkgs if p.installed], \
        [p.name for p in new_pkgs if not p.installed]
Exemple #2
0
def extensions(parser, args):
    if not args.spec:
        tty.die("extensions requires a package spec.")

    # Checks
    spec = cmd.parse_specs(args.spec)
    if len(spec) > 1:
        tty.die("Can only list extensions for one package.")

    if not spec[0].package.extendable:
        tty.die("%s is not an extendable package." % spec[0].name)

    env = ev.get_env(args, 'extensions')
    spec = cmd.disambiguate_spec(spec[0], env)

    if not spec.package.extendable:
        tty.die("%s does not have extensions." % spec.short_spec)

    if args.show in ("packages", "all"):
        # List package names of extensions
        extensions = spack.repo.path.extensions_for(spec)
        if not extensions:
            tty.msg("%s has no extensions." % spec.cshort_spec)
        else:
            tty.msg(spec.cshort_spec)
            tty.msg("%d extensions:" % len(extensions))
            colify(ext.name for ext in extensions)

    if args.view:
        target = args.view
    else:
        target = spec.prefix

    view = YamlFilesystemView(target, spack.store.layout)

    if args.show in ("installed", "all"):
        # List specs of installed extensions.
        installed = [
            s.spec for s in spack.store.db.installed_extensions_for(spec)]

        if args.show == "all":
            print
        if not installed:
            tty.msg("None installed.")
        else:
            tty.msg("%d installed:" % len(installed))
            cmd.display_specs(installed, args)

    if args.show in ("activated", "all"):
        # List specs of activated extensions.
        activated = view.extensions_layout.extension_map(spec)
        if args.show == "all":
            print
        if not activated:
            tty.msg("None activated.")
        else:
            tty.msg("%d activated:" % len(activated))
            cmd.display_specs(activated.values(), args)
Exemple #3
0
def package_prefix(specs):
    """ Return package prefix """
    _init_spack()
    from spack.cmd import parse_specs
    packages = parse_specs(specs, concretize=True)
    if len(packages) == 0:
        raise RuntimeError("No package found")
    elif len(packages) > 1:
        raise RuntimeError("Specs correspond to more than one package")
    return packages[0].prefix
Exemple #4
0
def package_prefix(specs):
    """ Return package prefix """
    _init_spack()
    from spack.cmd import parse_specs
    packages = parse_specs(specs, concretize=True)
    if len(packages) == 0:
        raise RuntimeError("No package found")
    elif len(packages) > 1:
        raise RuntimeError("Specs correspond to more than one package")
    return packages[0].prefix
Exemple #5
0
def is_installed(name, compiler=None):
    _init_spack()
    from spack import repo
    from spack.cmd import parse_specs
    names = [name] if isinstance(name, str) else name
    for name in names:
        if compiler is not None:
            name = name.split()
            name.insert(1, "%" + compiler.rstrip().lstrip())
            name = ' '.join(name)
        specs = parse_specs(name, concretize=True)
        for spec in specs:
           a = repo.get(spec)
           if not a.installed:
               return False
    return True
Exemple #6
0
def is_installed(name, compiler=None):
    _init_spack()
    from spack import repo
    from spack.cmd import parse_specs
    names = [name] if isinstance(name, str) else name
    for name in names:
        if compiler is not None:
            name = name.split()
            name.insert(1, "%" + compiler.rstrip().lstrip())
            name = ' '.join(name)
        specs = parse_specs(name, concretize=True)
        for spec in specs:
            a = repo.get(spec)
            if not a.installed:
                return False
    return True
Exemple #7
0
def module_name(name, compiler=None):
    """ Figures out module name(s) from specs """
    _init_spack()
    from spack.modules import module_types
    from spack.store import db as installed_db
    mt = module_types['tcl']

    if compiler is not None:
        names = name.split()
        names.insert(1, "%" + compiler.rstrip().lstrip())
        name = ' '.join(names)

    specs = parse_specs(name, concretize=True, normalize=True)
    result = []
    for spec in specs:
        mods = {pkg.dag_hash(): pkg for pkg in installed_db.query(spec)}
        if spec.dag_hash() not in mods:
            raise Exception("Could not find package %s" % spec)
        result.append(mt(mods[spec.dag_hash()]).layout.use_name)
    return result
Exemple #8
0
def module_name(name, compiler=None):
    """ Figures out module name(s) from specs """
    _init_spack()
    from spack.modules import module_types
    from spack.store import db as installed_db
    mt = module_types['tcl']

    if compiler is not None:
        names = name.split()
        names.insert(1, "%" + compiler.rstrip().lstrip())
        name = ' '.join(names)

    specs = parse_specs(name, concretize=True, normalize=True)
    result = []
    for spec in specs:
        mods = {pkg.dag_hash(): pkg for pkg in installed_db.query(spec)}
        if spec.dag_hash() not in mods:
            raise Exception("Could not find package %s" % spec)
        result.append(mt(mods[spec.dag_hash()]).layout.use_name)
    return result
Exemple #9
0
def install(name,
            keep_prefix=False,
            keep_stage=False,
            install_deps=True,
            environs=None,
            compiler=None):
    _init_spack()
    from spack import repo
    from spack.store import db as installed_db
    from spack.cmd import parse_specs
    from os import environ
    if not isinstance(name, str):
        results = [], []
        for pkg in name:
            a, b = install(
                pkg,
                keep_prefix=keep_prefix,
                keep_stage=keep_stage,
                install_deps=install_deps,
                environs=environs,
                compiler=compiler)
            results[0].extend(a)
            results[1].extend(b)
        return results
    if environs is not None:
        environ.update(environs)
    if compiler is not None:
        names = name.split()
        names.insert(1, "%" + compiler.rstrip().lstrip())
        name = ' '.join(names)
    specs = parse_specs(name, concretize=True)
    packages = [repo.get(spec) for spec in specs]
    new_pkgs = [u for u in packages if not u.installed]
    for package in new_pkgs:
        with installed_db.write_transaction():
            package.do_install(
                keep_prefix=keep_prefix,
                keep_stage=keep_stage,
                install_deps=install_deps)
    return [p.name for p in new_pkgs if p.installed], \
        [p.name for p in new_pkgs if not p.installed]
Exemple #10
0
def module_name(name, compiler=None):
    """ Figures out module name(s) from specs """
    _init_spack()
    from spack.modules import module_types
    from spack import installed_db
    mt = module_types['tcl']

    if compiler is not None:
        names = name.split()
        names.insert(1, "%" + compiler.rstrip().lstrip())
        name = ' '.join(names)

    specs = parse_specs(name, concretize=True, normalize=True)
    result = []
    for spec in specs:
        mods = installed_db.query(spec)
        if len(mods) == 0:
            raise ValueError("No module found for %s." % spec)
        elif len(mods) > 1:
            raise ValueError(
                "More than one module matches %s (%s)." % (spec, mods))
        result.append(mt(mods[0]).use_name)
    return result
Exemple #11
0
def extensions(parser, args):
    if not args.spec:
        # If called without arguments, list all the extendable packages
        isatty = sys.stdout.isatty()
        if isatty:
            tty.info('Extendable packages:')

        extendable_pkgs = []
        for name in spack.repo.all_package_names():
            pkg = spack.repo.get(name)
            if pkg.extendable:
                extendable_pkgs.append(name)

        colify(extendable_pkgs, indent=4)
        return

    # Checks
    spec = cmd.parse_specs(args.spec)
    if len(spec) > 1:
        tty.die("Can only list extensions for one package.")

    if not spec[0].package.extendable:
        tty.die("%s is not an extendable package." % spec[0].name)

    env = ev.active_environment()
    spec = cmd.disambiguate_spec(spec[0], env)

    if not spec.package.extendable:
        tty.die("%s does not have extensions." % spec.short_spec)

    if args.show in ("packages", "all"):
        # List package names of extensions
        extensions = spack.repo.path.extensions_for(spec)
        if not extensions:
            tty.msg("%s has no extensions." % spec.cshort_spec)
        else:
            tty.msg(spec.cshort_spec)
            tty.msg("%d extensions:" % len(extensions))
            colify(ext.name for ext in extensions)

    if args.view:
        target = args.view
    else:
        target = spec.prefix

    view = YamlFilesystemView(target, spack.store.layout)

    if args.show in ("installed", "all"):
        # List specs of installed extensions.
        installed = [
            s.spec for s in spack.store.db.installed_extensions_for(spec)
        ]

        if args.show == "all":
            print
        if not installed:
            tty.msg("None installed.")
        else:
            tty.msg("%d installed:" % len(installed))
            cmd.display_specs(installed, args)

    if args.show in ("activated", "all"):
        # List specs of activated extensions.
        activated = view.extensions_layout.extension_map(spec)
        if args.show == "all":
            print
        if not activated:
            tty.msg("None activated.")
        else:
            tty.msg("%d activated:" % len(activated))
            cmd.display_specs(activated.values(), args)
Exemple #12
0
def parse_specs(specs, concretize=False, normalize=False):
    """ Converts spec to module name """
    _init_spack()
    from spack.cmd import parse_specs
    return parse_specs(specs, concretize=concretize, normalize=normalize)
Exemple #13
0
def parse_specs(specs, concretize=False, normalize=False):
    """ Converts spec to module name """
    _init_spack()
    from spack.cmd import parse_specs
    return parse_specs(specs, concretize=concretize, normalize=normalize)