示例#1
0
 def test_package_filename(self):
     repo = Repo(spack.mock_packages_path)
     filename = repo.filename_for_package_name('mpich')
     self.assertEqual(
         filename,
         join_path(spack.mock_packages_path, 'packages', 'mpich',
                   'package.py'))
示例#2
0
def edit_package(name, repo_path, namespace, force=False):
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something's wrong.  '%s' is not a file!" % path)
        if not os.access(path, os.R_OK | os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    elif not force:
        tty.die("No package '%s'.  Use spack create, or supply -f/--force "
                "to edit a new file." % spec.name)
    else:
        mkdirp(os.path.dirname(path))
        with open(path, "w") as pkg_file:
            pkg_file.write(
                package_template.substitute(name=spec.name,
                                            class_name=mod_to_class(
                                                spec.name)))

    spack.editor(path)
示例#3
0
文件: edit.py 项目: Exteris/spack
def edit_package(name, repo_path, namespace, force=False):
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something's wrong.  '%s' is not a file!" % path)
        if not os.access(path, os.R_OK|os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    elif not force:
        tty.die("No package '%s'.  Use spack create, or supply -f/--force "
                "to edit a new file." % spec.name)
    else:
        mkdirp(os.path.dirname(path))
        with open(path, "w") as pkg_file:
            pkg_file.write(
                package_template.substitute(
                    name=spec.name, class_name=mod_to_class(spec.name)))

    spack.editor(path)
示例#4
0
def edit_package(name, repo_path, namespace):
    """Opens the requested package file in your favorite $EDITOR.

    :param str name: The name of the package
    :param str repo_path: The path to the repository containing this package
    :param str namespace: A valid namespace registered with Spack
    """
    # Find the location of the package
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something is wrong. '{0}' is not a file!".format(path))
        if not os.access(path, os.R_OK | os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    else:
        tty.die("No package for '{0}' was found.".format(spec.name),
                "  Use `spack create` to create a new package")

    spack.editor(path)
示例#5
0
 def test_nonexisting_package_filename(self):
     repo = Repo(spack.mock_packages_path)
     filename = repo.filename_for_package_name('some-nonexisting-package')
     self.assertEqual(
         filename,
         join_path(spack.mock_packages_path, 'packages',
                   'some-nonexisting-package', 'package.py'))
示例#6
0
def edit_package(name, repo_path, namespace):
    """Opens the requested package file in your favorite $EDITOR.

    Args:
        name (str): The name of the package
        repo_path (str): The path to the repository containing this package
        namespace (str): A valid namespace registered with Spack
    """
    # Find the location of the package
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something is wrong. '{0}' is not a file!".format(path))
        if not os.access(path, os.R_OK | os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    else:
        tty.die("No package for '{0}' was found.".format(spec.name),
                "  Use `spack create` to create a new package")

    spack.editor(path)
示例#7
0
def test_package_filename(builtin_mock):
    repo = Repo(spack.mock_packages_path)
    filename = repo.filename_for_package_name('mpich')
    assert filename == join_path(
        spack.mock_packages_path,
        'packages',
        'mpich',
        'package.py'
    )
示例#8
0
def test_nonexisting_package_filename():
    repo = Repo(spack.mock_packages_path)
    filename = repo.filename_for_package_name('some-nonexisting-package')
    assert filename == join_path(
        spack.mock_packages_path,
        'packages',
        'some-nonexisting-package',
        'package.py'
    )
示例#9
0
def find_repository(spec, args):
    # figure out namespace for spec
    if spec.namespace and args.namespace and spec.namespace != args.namespace:
        tty.die("Namespaces '%s' and '%s' do not match." % (spec.namespace,
                                                            args.namespace))

    if not spec.namespace and args.namespace:
        spec.namespace = args.namespace

    # Figure out where the new package should live.
    repo_path = args.repo
    if repo_path is not None:
        try:
            repo = Repo(repo_path)
            if spec.namespace and spec.namespace != repo.namespace:
                tty.die("Can't create package with namespace %s in repo with "
                        "namespace %s" % (spec.namespace, repo.namespace))
        except RepoError as e:
            tty.die(str(e))
    else:
        if spec.namespace:
            repo = spack.repo.get_repo(spec.namespace, None)
            if not repo:
                tty.die("Unknown namespace: %s" % spec.namespace)
        else:
            repo = spack.repo.first_repo()

    # Set the namespace on the spec if it's not there already
    if not spec.namespace:
        spec.namespace = repo.namespace

    return repo
示例#10
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_config('repos', 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.update_config('repos', repos, args.scope)
    tty.msg("Added repo with namespace '%s'." % repo.namespace)
示例#11
0
def repo_remove(args):
    """Remove a repository from Spack's configuration."""
    repos = spack.config.get_config('repos', args.scope)
    path_or_namespace = args.path_or_namespace

    # If the argument is a path, remove that repository from config.
    canon_path = canonicalize_path(path_or_namespace)
    for repo_path in repos:
        repo_canon_path = canonicalize_path(repo_path)
        if canon_path == repo_canon_path:
            repos.remove(repo_path)
            spack.config.update_config('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 == path_or_namespace:
                repos.remove(path)
                spack.config.update_config('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" % path_or_namespace)
示例#12
0
文件: flake8.py 项目: nvarini1/spack
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.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)
示例#13
0
def repo_exists(path, scope=None, prefix=None):
    """ Checks whether input is a known repo """
    _init_spack()
    from spack.repository import Repo
    from spack.config import get_config
    from os.path import join

    cannon = repo_path(path)
    repos = get_config('repos', defaults('scope', scope))

    repo = Repo(cannon)
    return repo.root in repos or path in repos
示例#14
0
def repo_list(args):
    """Show registered repositories and their namespaces."""
    roots = spack.config.get_config('repos', 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))
示例#15
0
def get_repository(args, name):
    """Returns a Repo object that will allow us to determine the path where
    the new package file should be created.

    Args:
        args (argparse.Namespace): The arguments given to ``spack create``
        name (str): The name of the package to create

    Returns:
        Repo: A Repo object capable of determining the path to the package file
    """
    spec = Spec(name)
    # Figure out namespace for spec
    if spec.namespace and args.namespace and spec.namespace != args.namespace:
        tty.die("Namespaces '{0}' and '{1}' do not match.".format(
            spec.namespace, args.namespace))

    if not spec.namespace and args.namespace:
        spec.namespace = args.namespace

    # Figure out where the new package should live
    repo_path = args.repo
    if repo_path is not None:
        repo = Repo(repo_path)
        if spec.namespace and spec.namespace != repo.namespace:
            tty.die("Can't create package with namespace {0} in repo with "
                    "namespace {0}".format(spec.namespace, repo.namespace))
    else:
        if spec.namespace:
            repo = spack.repo.get_repo(spec.namespace, None)
            if not repo:
                tty.die("Unknown namespace: '{0}'".format(spec.namespace))
        else:
            repo = spack.repo.first_repo()

    # Set the namespace on the spec if it's not there already
    if not spec.namespace:
        spec.namespace = repo.namespace

    return repo
示例#16
0
def add_repo(path, prefix=None, scope=None):
    """ Adds path to spack repos """
    _init_spack()

    from collections import namedtuple
    from spack.repository import Repo
    from spack.config import get_config, update_config
    from spack.cmd import default_list_scope

    cannon = repo_path(path, prefix)
    repos = get_config('repos', defaults('scope', scope))
    if not repos:
        repos = []

    repo = Repo(cannon)

    if repo.root in repos or path in repos:
        return False

    repos.insert(0, cannon)
    update_config('repos', repos, defaults('scope', scope))
    return True
示例#17
0
文件: packages.py 项目: zepx/spack
def test_package_filename(builtin_mock):
    repo = Repo(spack.mock_packages_path)
    filename = repo.filename_for_package_name('mpich')
    assert filename == join_path(spack.mock_packages_path, 'packages', 'mpich',
                                 'package.py')
示例#18
0
文件: packages.py 项目: Exteris/spack
 def test_nonexisting_package_filename(self):
     repo = Repo(spack.mock_packages_path)
     filename = repo.filename_for_package_name('some-nonexisting-package')
     self.assertEqual(
         filename,
         join_path(spack.mock_packages_path, 'packages', 'some-nonexisting-package', 'package.py'))
示例#19
0
文件: packages.py 项目: Exteris/spack
 def test_package_filename(self):
     repo = Repo(spack.mock_packages_path)
     filename = repo.filename_for_package_name('mpich')
     self.assertEqual(filename,
                      join_path(spack.mock_packages_path, 'packages', 'mpich', 'package.py'))
示例#20
0
文件: packages.py 项目: zepx/spack
def test_nonexisting_package_filename():
    repo = Repo(spack.mock_packages_path)
    filename = repo.filename_for_package_name('some-nonexisting-package')
    assert filename == join_path(spack.mock_packages_path, 'packages',
                                 'some-nonexisting-package', 'package.py')