diff options
Diffstat (limited to 'lib/spack/spack/repo.py')
-rw-r--r-- | lib/spack/spack/repo.py | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index b735866321..b103ac1caf 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -1260,23 +1260,6 @@ def set_path(repo): @contextlib.contextmanager -def swap(repo_path): - """Temporarily use another RepoPath.""" - global path - - # swap out _path for repo_path - saved = path - remove_from_meta = set_path(repo_path) - - yield - - # restore _path and sys.meta_path - if remove_from_meta: - sys.meta_path.remove(repo_path) - path = saved - - -@contextlib.contextmanager def additional_repository(repository): """Adds temporarily a repository to the default one. @@ -1288,6 +1271,34 @@ def additional_repository(repository): path.remove(repository) +@contextlib.contextmanager +def use_repositories(*paths_and_repos): + """Use the repositories passed as arguments within the context manager. + + Args: + *paths_and_repos: paths to the repositories to be used, or + already constructed Repo objects + + Returns: + Corresponding RepoPath object + """ + global path + + # Construct a temporary RepoPath object from + temporary_repositories = RepoPath(*paths_and_repos) + + # Swap the current repository out + saved = path + remove_from_meta = set_path(temporary_repositories) + + yield temporary_repositories + + # Restore _path and sys.meta_path + if remove_from_meta: + sys.meta_path.remove(temporary_repositories) + path = saved + + class RepoError(spack.error.SpackError): """Superclass for repository-related errors.""" |