summaryrefslogtreecommitdiff
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
parent82ba0c6c07406a2accc8f50e4619d5379b24aca1 (diff)
downloadspack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.tar.gz
spack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.tar.bz2
spack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.tar.xz
spack-ec8cc2b52839007f0825815c8cfdee8f9a8629a6.zip
PYTHONPATH : python patches methods for its extensions
-rw-r--r--lib/spack/spack/build_environment.py4
-rw-r--r--lib/spack/spack/cmd/uninstall.py12
-rw-r--r--lib/spack/spack/directory_layout.py2
-rw-r--r--lib/spack/spack/modules.py12
-rw-r--r--lib/spack/spack/package.py10
-rw-r--r--var/spack/repos/builtin/packages/py-nose/package.py6
-rw-r--r--var/spack/repos/builtin/packages/python/package.py34
7 files changed, 53 insertions, 27 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 68477145fe..c51fa58477 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -282,9 +282,11 @@ def setup_package(pkg):
for mod in modules:
set_module_variables_for_package(pkg, mod)
- # Allow dependencies to set up environment as well.
+ # Allow dependencies to modify the module
for dependency_spec in pkg.spec.traverse(root=False):
dependency_spec.package.modify_module(pkg.module, dependency_spec, pkg.spec)
+ # Allow dependencies to set up environment as well
+ for dependency_spec in pkg.spec.traverse(root=False):
dependency_spec.package.setup_dependent_environment(env, pkg.spec)
# TODO : implement validation
#validate(env)
diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py
index d01aa2136b..2fab8f6f2a 100644
--- a/lib/spack/spack/cmd/uninstall.py
+++ b/lib/spack/spack/cmd/uninstall.py
@@ -79,7 +79,7 @@ def uninstall(parser, args):
try:
# should work if package is known to spack
pkgs.append(s.package)
- except spack.repository.UnknownPackageError, e:
+ except spack.repository.UnknownPackageError as e:
# The package.py file has gone away -- but still
# want to uninstall.
spack.Package(s).do_uninstall(force=True)
@@ -94,11 +94,11 @@ def uninstall(parser, args):
for pkg in pkgs:
try:
pkg.do_uninstall(force=args.force)
- except PackageStillNeededError, e:
+ except PackageStillNeededError as e:
tty.error("Will not uninstall %s" % e.spec.format("$_$@$%@$#", color=True))
- print
- print "The following packages depend on it:"
+ print()
+ print("The following packages depend on it:")
display_specs(e.dependents, long=True)
- print
- print "You can use spack uninstall -f to force this action."
+ print()
+ print("You can use spack uninstall -f to force this action.")
sys.exit(1)
diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py
index 39ee4e203d..da8f1aa1bc 100644
--- a/lib/spack/spack/directory_layout.py
+++ b/lib/spack/spack/directory_layout.py
@@ -150,7 +150,7 @@ class DirectoryLayout(object):
if os.path.exists(path):
try:
shutil.rmtree(path)
- except exceptions.OSError, e:
+ except exceptions.OSError as e:
raise RemoveFailedError(spec, path, e)
path = os.path.dirname(path)
diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py
index d192bbe004..7303844229 100644
--- a/lib/spack/spack/modules.py
+++ b/lib/spack/spack/modules.py
@@ -119,13 +119,13 @@ class EnvModule(object):
module_types[cls.name] = cls
def __init__(self, spec=None):
+ self.spec = spec
+ self.pkg = spec.package # Just stored for convenience
+
# category in the modules system
# TODO: come up with smarter category names.
self.category = "spack"
- self.spec = spec
- self.pkg = spec.package # Just stored for convenience
-
# short description default is just the package + version
# packages can provide this optional attribute
self.short_description = spec.format("$_ $@")
@@ -161,6 +161,12 @@ class EnvModule(object):
# Environment modifications guessed by inspecting the installation prefix
env = inspect_path(self.spec.prefix)
+
+ # Let the extendee modify their extensions before asking for package-specific modifications
+ for extendee in self.pkg.extendees:
+ extendee_spec = self.spec[extendee]
+ extendee_spec.package.modify_module(self.pkg, extendee_spec, self.spec)
+
# Package-specific environment modifications
self.spec.package.setup_environment(env)
# TODO : implement site-specific modifications and filters
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 185e3ad2ee..72c84ec624 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1261,16 +1261,6 @@ class Package(object):
"""Get the rpath args as a string, with -Wl,-rpath, for each element."""
return " ".join("-Wl,-rpath,%s" % p for p in self.rpath)
-
-class PythonExtension(Package):
- def setup_dependent_environment(self, env, dependent_spec):
- pass
-
- def setup_environment(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 validate_package_url(url_string):
"""Determine whether spack can handle a particular URL or not."""
url = urlparse(url_string)
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)