summaryrefslogtreecommitdiff
path: root/lib/spack/spack/repo.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/spack/repo.py')
-rw-r--r--lib/spack/spack/repo.py34
1 files changed, 4 insertions, 30 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py
index ec09262541..980fb0cbab 100644
--- a/lib/spack/spack/repo.py
+++ b/lib/spack/spack/repo.py
@@ -29,10 +29,8 @@ import shutil
import errno
import sys
import inspect
-import imp
import re
import traceback
-import tempfile
import json
from contextlib import contextmanager
from six import string_types
@@ -54,11 +52,13 @@ import spack.config
import spack.caches
import spack.error
import spack.spec
+import spack.util.imp as simp
from spack.provider_index import ProviderIndex
from spack.util.path import canonicalize_path
from spack.util.naming import NamespaceTrie, valid_module_name
from spack.util.naming import mod_to_class, possible_spack_module_names
+
#: Super-namespace for all packages.
#: Package modules are imported as spack.pkg.<namespace>.<pkg-name>.
repo_namespace = 'spack.pkg'
@@ -994,9 +994,8 @@ class Repo(object):
fullname = "%s.%s" % (self.full_namespace, pkg_name)
try:
- with import_lock():
- with prepend_open(file_path, text=_package_prepend) as f:
- module = imp.load_source(fullname, file_path, f)
+ module = simp.load_source(fullname, file_path,
+ prepend=_package_prepend)
except SyntaxError as e:
# SyntaxError strips the path from the filename so we need to
# manually construct the error message in order to give the
@@ -1147,31 +1146,6 @@ def set_path(repo):
@contextmanager
-def import_lock():
- imp.acquire_lock()
- yield
- imp.release_lock()
-
-
-@contextmanager
-def prepend_open(f, *args, **kwargs):
- """Open a file for reading, but prepend with some text prepended
-
- Arguments are same as for ``open()``, with one keyword argument,
- ``text``, specifying the text to prepend.
- """
- text = kwargs.get('text', None)
-
- with open(f, *args) as f:
- with tempfile.NamedTemporaryFile(mode='w+') as tf:
- if text:
- tf.write(text + '\n')
- tf.write(f.read())
- tf.seek(0)
- yield tf.file
-
-
-@contextmanager
def swap(repo_path):
"""Temporarily use another RepoPath."""
global path