Beispiel #1
0
def repo_add(args):
    """Add a package source to Spack's configuration."""
    path = args.path

    # real_path is absolute and handles substitution.
    canon_path = canonicalize_path(path)

    # check if the path exists
    if not os.path.exists(canon_path):
        tty.die("No such file or directory: %s" % path)

    # Make sure the path is a directory.
    if not os.path.isdir(canon_path):
        tty.die("Not a Spack repository: %s" % path)

    # Make sure it's actually a spack repository by constructing it.
    repo = Repo(canon_path)

    # If that succeeds, finally add it to the configuration.
    repos = spack.config.get('repos', scope=args.scope)
    if not repos:
        repos = []

    if repo.root in repos or path in repos:
        tty.die("Repository is already registered with Spack: %s" % path)

    repos.insert(0, canon_path)
    spack.config.set('repos', repos, args.scope)
    tty.msg("Added repo with namespace '%s'." % repo.namespace)
Beispiel #2
0
def repo_remove(args):
    """Remove a repository from Spack's configuration."""
    repos = spack.config.get('repos', scope=args.scope)
    namespace_or_path = args.namespace_or_path

    # If the argument is a path, remove that repository from config.
    canon_path = canonicalize_path(namespace_or_path)
    for repo_path in repos:
        repo_canon_path = canonicalize_path(repo_path)
        if canon_path == repo_canon_path:
            repos.remove(repo_path)
            spack.config.set('repos', repos, args.scope)
            tty.msg("Removed repository %s" % repo_path)
            return

    # If it is a namespace, remove corresponding repo
    for path in repos:
        try:
            repo = Repo(path)
            if repo.namespace == namespace_or_path:
                repos.remove(path)
                spack.config.set('repos', repos, args.scope)
                tty.msg("Removed repository %s with namespace '%s'." %
                        (repo.root, repo.namespace))
                return
        except RepoError:
            continue

    tty.die("No repository with path or namespace: %s" % namespace_or_path)
Beispiel #3
0
def flake8_package():
    """Flake8 only checks files that have been modified.
    This fixture makes a small change to the ``flake8``
    mock package, yields the filename, then undoes the
    change on cleanup.
    """
    repo = Repo(spack.paths.mock_packages_path)
    filename = repo.filename_for_package_name('flake8')
    package = FileFilter(filename)

    # Make the change
    package.filter("state = 'unmodified'", "state = 'modified'", string=True)

    yield filename

    # Undo the change
    package.filter("state = 'modified'", "state = 'unmodified'", string=True)
Beispiel #4
0
def flake8_package():
    """Flake8 only checks files that have been modified.
    This fixture makes a small change to the ``flake8``
    mock package, yields the filename, then undoes the
    change on cleanup.
    """
    repo = Repo(spack.paths.mock_packages_path)
    filename = repo.filename_for_package_name('flake8')
    package = FileFilter(filename)

    # Make the change
    package.filter("state = 'unmodified'", "state = 'modified'", string=True)

    yield filename

    # Undo the change
    package.filter("state = 'modified'", "state = 'unmodified'", string=True)
Beispiel #5
0
def repo_list(args):
    """Show registered repositories and their namespaces."""
    roots = spack.config.get('repos', scope=args.scope)
    repos = []
    for r in roots:
        try:
            repos.append(Repo(r))
        except RepoError:
            continue

    msg = "%d package repositor" % len(repos)
    msg += "y." if len(repos) == 1 else "ies."
    tty.msg(msg)

    if not repos:
        return

    max_ns_len = max(len(r.namespace) for r in repos)
    for repo in repos:
        fmt = "%%-%ds%%s" % (max_ns_len + 4)
        print(fmt % (repo.namespace, repo.root))
import spack.store
import spack.config
import spack.caches
from spack.repo import Repo, RepoError
from spack.modules.common import root_path as module_root
from spack.util.path import canonicalize_path

printp = pprint.PrettyPrinter(indent=4).pprint

template_dirs = spack.config.get('config:template_dirs')
template_dirs = [canonicalize_path(x) for x in template_dirs]
repo_roots = spack.config.get('repos')
repos = []
for repo_root in repo_roots:
    try:
        repos.append(Repo(repo_root))
    except RepoError:
        continue
settings = {
    'install_root': spack.store.store.root,
    'template_dirs': template_dirs,
    'module_roots': {k: module_root(k, 'default')
                     for k in ('tcl', 'lmod')},
    'misc_cache': spack.caches.misc_cache.root,
    'source_cache': spack.caches.fetch_cache.root,
    'mirrors': dict(spack.config.get('mirrors')),
    'repos': repos,
}

printp(settings)