summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2019-04-12 22:26:48 +0200
committerPeter Scheibel <scheibel1@llnl.gov>2019-04-18 18:41:22 -0700
commit76b5af6bf364fac0bab99d327527128f0e04f62e (patch)
treef9039cb63a5127d4f10802ebc2e3f4da00ab1620
parentbbb5d616625a7fd2b8360921e9cbfbc5b994f67b (diff)
downloadspack-76b5af6bf364fac0bab99d327527128f0e04f62e.tar.gz
spack-76b5af6bf364fac0bab99d327527128f0e04f62e.tar.bz2
spack-76b5af6bf364fac0bab99d327527128f0e04f62e.tar.xz
spack-76b5af6bf364fac0bab99d327527128f0e04f62e.zip
Used functools.wrap for the decorator + reordered imports
-rw-r--r--lib/spack/spack/repo.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py
index 48ab51fd4f..fcc76af37c 100644
--- a/lib/spack/spack/repo.py
+++ b/lib/spack/spack/repo.py
@@ -5,15 +5,17 @@
import abc
import collections
-import os
-import stat
-import shutil
+import contextlib
import errno
-import sys
+import functools
import inspect
+import os
import re
+import shutil
+import stat
+import sys
import traceback
-from contextlib import contextmanager
+
from six import string_types, add_metaclass
try:
@@ -80,10 +82,11 @@ NOT_PROVIDED = object()
_package_prepend = 'from spack.pkgkit import *'
-def _autospec(function):
- """Decorator that automatically converts the argument of a single-arg
- function to a Spec."""
-
+def autospec(function):
+ """Decorator that automatically converts the first argument of a
+ function to a Spec.
+ """
+ @functools.wraps(function)
def converter(self, spec_like, *args, **kwargs):
if not isinstance(spec_like, spack.spec.Spec):
spec_like = spack.spec.Spec(spec_like)
@@ -551,14 +554,14 @@ class RepoPath(object):
return self._patch_index
- @_autospec
+ @autospec
def providers_for(self, vpkg_spec):
providers = self.provider_index.providers_for(vpkg_spec)
if not providers:
raise UnknownPackageError(vpkg_spec.name)
return providers
- @_autospec
+ @autospec
def extensions_for(self, extendee_spec):
return [p for p in self.all_packages() if p.extends(extendee_spec)]
@@ -634,7 +637,7 @@ class RepoPath(object):
# that can operate on packages that don't exist yet.
return self.first_repo()
- @_autospec
+ @autospec
def get(self, spec, new=False):
"""Find a repo that contains the supplied spec's package.
@@ -646,7 +649,7 @@ class RepoPath(object):
"""Find a class for the spec's package and return the class object."""
return self.repo_for_pkg(pkg_name).get_pkg_class(pkg_name)
- @_autospec
+ @autospec
def dump_provenance(self, spec, path):
"""Dump provenance information for a spec to a particular path.
@@ -868,7 +871,7 @@ class Repo(object):
tty.die("Error reading %s when opening %s"
% (self.config_file, self.root))
- @_autospec
+ @autospec
def get(self, spec):
if not self.exists(spec.name):
raise UnknownPackageError(spec.name)
@@ -891,7 +894,7 @@ class Repo(object):
sys.excepthook(*sys.exc_info())
raise FailedConstructorError(spec.fullname, *sys.exc_info())
- @_autospec
+ @autospec
def dump_provenance(self, spec, path):
"""Dump provenance information for a spec to a particular path.
@@ -948,14 +951,14 @@ class Repo(object):
"""Index of patches and packages they're defined on."""
return self.index['patches']
- @_autospec
+ @autospec
def providers_for(self, vpkg_spec):
providers = self.provider_index.providers_for(vpkg_spec)
if not providers:
raise UnknownPackageError(vpkg_spec.name)
return providers
- @_autospec
+ @autospec
def extensions_for(self, extendee_spec):
return [p for p in self.all_packages() if p.extends(extendee_spec)]
@@ -964,14 +967,14 @@ class Repo(object):
if spec.namespace and spec.namespace != self.namespace:
raise UnknownNamespaceError(spec.namespace)
- @_autospec
+ @autospec
def dirname_for_package_name(self, spec):
"""Get the directory name for a particular package. This is the
directory that contains its package.py file."""
self._check_namespace(spec)
return os.path.join(self.packages_path, spec.name)
- @_autospec
+ @autospec
def filename_for_package_name(self, spec):
"""Get the filename for the module we should load for a particular
package. Packages for a Repo live in
@@ -1205,7 +1208,7 @@ def set_path(repo):
return append
-@contextmanager
+@contextlib.contextmanager
def swap(repo_path):
"""Temporarily use another RepoPath."""
global path