summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-03-18 14:40:53 +0100
committeralalazo <massimiliano.culpo@googlemail.com>2016-03-18 14:40:53 +0100
commitec8cc2b52839007f0825815c8cfdee8f9a8629a6 (patch)
treeff602c223664f79f46c18139ae6b65ad414bbefe /var
parent82ba0c6c07406a2accc8f50e4619d5379b24aca1 (diff)
downloadspack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.tar.gz
spack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.tar.bz2
spack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.tar.xz
spack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.zip
PYTHONPATH : python patches methods for its extensions
Diffstat (limited to 'var')
-rw-r--r--var/spack/repos/builtin/packages/py-nose/package.py6
-rw-r--r--var/spack/repos/builtin/packages/python/package.py34
2 files changed, 34 insertions, 6 deletions
diff --git a/var/spack/repos/builtin/packages/py-nose/package.py b/var/spack/repos/builtin/packages/py-nose/package.py
index e817b8eb51..4fee99098e 100644
--- a/var/spack/repos/builtin/packages/py-nose/package.py
+++ b/var/spack/repos/builtin/packages/py-nose/package.py
@@ -1,12 +1,12 @@
from spack import *
-from spack.package import PythonExtension
-class PyNose(PythonExtension):
+
+class PyNose(Package):
"""nose extends the test loading and running features of unittest,
making it easier to write, find and run tests."""
homepage = "https://pypi.python.org/pypi/nose"
- url = "https://pypi.python.org/packages/source/n/nose/nose-1.3.4.tar.gz"
+ url = "https://pypi.python.org/packages/source/n/nose/nose-1.3.4.tar.gz"
version('1.3.4', '6ed7169887580ddc9a8e16048d38274d')
version('1.3.6', '0ca546d81ca8309080fc80cb389e7a16')
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
index d46e1068b6..c445d26369 100644
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -1,11 +1,14 @@
+import functools
+import glob
+import inspect
import os
import re
from contextlib import closing
-from llnl.util.lang import match_predicate
-from spack.util.environment import *
-from spack import *
import spack
+from llnl.util.lang import match_predicate
+from spack import *
+from spack.util.environment import *
class Python(Package):
@@ -111,6 +114,31 @@ class Python(Package):
else:
module.python = Executable(join_path(spec.prefix.bin, 'python'))
+ # The code below patches the any python extension to have good defaults for `setup_dependent_environment` and
+ # `setup_environment` only if the extension didn't override any of these functions explicitly.
+ def _setup_env(self, env):
+ site_packages = glob.glob(join_path(self.spec.prefix.lib, "python*/site-packages"))
+ if site_packages:
+ env.prepend_path('PYTHONPATH', site_packages[0])
+
+ def _setup_denv(self, env, extension_spec):
+ pass
+
+ pkg_cls = type(ext_spec.package) # Retrieve the type we may want to patch
+ if 'python' in pkg_cls.extendees:
+ # List of overrides we are interested in
+ interesting_overrides = ['setup_environment', 'setup_dependent_environment']
+ overrides_found = [
+ (name, defining_cls) for name, _, defining_cls, _, in inspect.classify_class_attrs(pkg_cls)
+ if
+ name in interesting_overrides and # The attribute has the right name
+ issubclass(defining_cls, Package) and defining_cls is not Package # and is an actual override
+ ]
+ if not overrides_found:
+ # If no override were found go on patching
+ pkg_cls.setup_environment = functools.wraps(Package.setup_environment)(_setup_env)
+ pkg_cls.setup_dependent_environment = functools.wraps(Package.setup_dependent_environment)(_setup_denv)
+
# Add variables for lib/pythonX.Y and lib/pythonX.Y/site-packages dirs.
module.python_lib_dir = os.path.join(ext_spec.prefix, self.python_lib_dir)
module.python_include_dir = os.path.join(ext_spec.prefix, self.python_include_dir)