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)
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)
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)
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'))
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'))
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)
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' )
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' )
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)
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'))
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'))
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')
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')