Merge pull request #552 from epfl-scitas/features/env_objects_flying_around
enhancement proposal : customization of module files
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
from spack import *
|
||||
import os
|
||||
|
||||
|
||||
class Mpich(Package):
|
||||
"""MPICH is a high performance and widely portable implementation of
|
||||
the Message Passing Interface (MPI) standard."""
|
||||
@@ -46,14 +47,23 @@ class Mpich(Package):
|
||||
provides('mpi@:3.0', when='@3:')
|
||||
provides('mpi@:1.3', when='@1:')
|
||||
|
||||
def setup_dependent_environment(self, module, spec, dep_spec):
|
||||
"""For dependencies, make mpicc's use spack wrapper."""
|
||||
os.environ['MPICH_CC'] = os.environ['CC']
|
||||
os.environ['MPICH_CXX'] = os.environ['CXX']
|
||||
os.environ['MPICH_F77'] = os.environ['F77']
|
||||
os.environ['MPICH_F90'] = os.environ['FC']
|
||||
os.environ['MPICH_FC'] = os.environ['FC']
|
||||
def setup_environment(self, env):
|
||||
env.set_env('MPICH_CC', self.compiler.cc)
|
||||
env.set_env('MPICH_CXX', self.compiler.cxx)
|
||||
env.set_env('MPICH_F77', self.compiler.f77)
|
||||
env.set_env('MPICH_F90', self.compiler.fc)
|
||||
env.set_env('MPICH_FC', self.compiler.fc)
|
||||
|
||||
def setup_dependent_environment(self, env, dependent_spec):
|
||||
env.set_env('MPICH_CC', spack_cc)
|
||||
env.set_env('MPICH_CXX', spack_cxx)
|
||||
env.set_env('MPICH_F77', spack_f77)
|
||||
env.set_env('MPICH_F90', spack_f90)
|
||||
env.set_env('MPICH_FC', spack_fc)
|
||||
|
||||
def modify_module(self, module, spec, dep_spec):
|
||||
"""For dependencies, make mpicc's use spack wrapper."""
|
||||
# FIXME : is this necessary ? Shouldn't this be part of a contract with MPI providers?
|
||||
module.mpicc = join_path(self.prefix.bin, 'mpicc')
|
||||
|
||||
def install(self, spec, prefix):
|
||||
|
@@ -123,7 +123,7 @@ def set_network_type(self, spec, configure_args):
|
||||
count += 1
|
||||
if count > 1:
|
||||
raise RuntimeError('network variants are mutually exclusive (only one can be selected at a time)')
|
||||
|
||||
network_options = []
|
||||
# From here on I can suppose that only one variant has been selected
|
||||
if self.enabled(Mvapich2.PSM) in spec:
|
||||
network_options = ["--with-device=ch3:psm"]
|
||||
|
@@ -1,5 +1,4 @@
|
||||
from spack import *
|
||||
import sys
|
||||
|
||||
class NetlibScalapack(Package):
|
||||
"""ScaLAPACK is a library of high-performance linear algebra routines for parallel distributed memory machines"""
|
||||
@@ -41,11 +40,10 @@ def install(self, spec, prefix):
|
||||
make()
|
||||
make("install")
|
||||
|
||||
def setup_dependent_environment(self, module, spec, dependent_spec):
|
||||
def modify_module(self, module, spec, dependent_spec):
|
||||
lib_dsuffix = '.dylib' if sys.platform == 'darwin' else '.so'
|
||||
lib_suffix = lib_dsuffix if '+shared' in spec['scalapack'] else '.a'
|
||||
|
||||
spec['scalapack'].fc_link = '-L%s -lscalapack' % spec['scalapack'].prefix.lib
|
||||
spec['scalapack'].cc_link = spec['scalapack'].fc_link
|
||||
spec['scalapack'].libraries = [join_path(spec['scalapack'].prefix.lib,
|
||||
'libscalapack%s' % lib_suffix)]
|
||||
spec['scalapack'].libraries = [join_path(spec['scalapack'].prefix.lib, 'libscalapack%s' % lib_suffix)]
|
||||
|
@@ -41,12 +41,17 @@ class Openmpi(Package):
|
||||
def url_for_version(self, version):
|
||||
return "http://www.open-mpi.org/software/ompi/v%s/downloads/openmpi-%s.tar.bz2" % (version.up_to(2), version)
|
||||
|
||||
def setup_dependent_environment(self, module, spec, dep_spec):
|
||||
"""For dependencies, make mpicc's use spack wrapper."""
|
||||
os.environ['OMPI_CC'] = 'cc'
|
||||
os.environ['OMPI_CXX'] = 'c++'
|
||||
os.environ['OMPI_FC'] = 'f90'
|
||||
os.environ['OMPI_F77'] = 'f77'
|
||||
def setup_environment(self, env):
|
||||
env.set_env('OMPI_CC', self.compiler.cc)
|
||||
env.set_env('OMPI_CXX', self.compiler.cxx)
|
||||
env.set_env('OMPI_FC', self.compiler.fc)
|
||||
env.set_env('OMPI_F77', self.compiler.f77)
|
||||
|
||||
def setup_dependent_environment(self, env, dependent_spec):
|
||||
env.set_env('OMPI_CC', spack_cc)
|
||||
env.set_env('OMPI_CXX', spack_cxx)
|
||||
env.set_env('OMPI_FC', spack_fc)
|
||||
env.set_env('OMPI_F77', spack_f77)
|
||||
|
||||
def install(self, spec, prefix):
|
||||
config_args = ["--prefix=%s" % prefix,
|
||||
|
@@ -1,11 +1,12 @@
|
||||
from spack import *
|
||||
|
||||
|
||||
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')
|
||||
|
@@ -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):
|
||||
@@ -89,13 +92,21 @@ def python_include_dir(self):
|
||||
def site_packages_dir(self):
|
||||
return os.path.join(self.python_lib_dir, 'site-packages')
|
||||
|
||||
def setup_dependent_environment(self, env, extension_spec):
|
||||
# Set PYTHONPATH to include site-packages dir for the extension and any other python extensions it depends on.
|
||||
python_paths = []
|
||||
for d in extension_spec.traverse():
|
||||
if d.package.extends(self.spec):
|
||||
python_paths.append(os.path.join(d.prefix, self.site_packages_dir))
|
||||
env.set_env('PYTHONPATH', ':'.join(python_paths))
|
||||
|
||||
def setup_dependent_environment(self, module, spec, ext_spec):
|
||||
"""Called before python modules' install() methods.
|
||||
def modify_module(self, module, spec, ext_spec):
|
||||
"""
|
||||
Called before python modules' install() methods.
|
||||
|
||||
In most cases, extensions will only need to have one line::
|
||||
|
||||
python('setup.py', 'install', '--prefix=%s' % prefix)
|
||||
python('setup.py', 'install', '--prefix=%s' % prefix)
|
||||
"""
|
||||
# Python extension builds can have a global python executable function
|
||||
if self.version >= Version("3.0.0") and self.version < Version("4.0.0"):
|
||||
@@ -103,6 +114,31 @@ def setup_dependent_environment(self, module, spec, ext_spec):
|
||||
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)
|
||||
@@ -111,15 +147,6 @@ def setup_dependent_environment(self, module, spec, ext_spec):
|
||||
# Make the site packages directory if it does not exist already.
|
||||
mkdirp(module.site_packages_dir)
|
||||
|
||||
# Set PYTHONPATH to include site-packages dir for the
|
||||
# extension and any other python extensions it depends on.
|
||||
python_paths = []
|
||||
for d in ext_spec.traverse():
|
||||
if d.package.extends(self.spec):
|
||||
python_paths.append(os.path.join(d.prefix, self.site_packages_dir))
|
||||
os.environ['PYTHONPATH'] = ':'.join(python_paths)
|
||||
|
||||
|
||||
# ========================================================================
|
||||
# Handle specifics of activating and deactivating python modules.
|
||||
# ========================================================================
|
||||
|
@@ -55,11 +55,8 @@ class Qt(Package):
|
||||
depends_on("mesa", when='@4:+mesa')
|
||||
depends_on("libxcb")
|
||||
|
||||
|
||||
def setup_dependent_environment(self, module, spec, dep_spec):
|
||||
"""Dependencies of Qt find it using the QTDIR environment variable."""
|
||||
os.environ['QTDIR'] = self.prefix
|
||||
|
||||
def setup_environment(self, env):
|
||||
env.set_env['QTDIR'] = self.prefix
|
||||
|
||||
def patch(self):
|
||||
if self.spec.satisfies('@4'):
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from spack import *
|
||||
import spack
|
||||
import os
|
||||
|
||||
|
||||
class Ruby(Package):
|
||||
"""A dynamic, open source programming language with a focus on
|
||||
@@ -15,11 +14,20 @@ class Ruby(Package):
|
||||
|
||||
def install(self, spec, prefix):
|
||||
configure("--prefix=%s" % prefix)
|
||||
|
||||
make()
|
||||
make("install")
|
||||
|
||||
def setup_dependent_environment(self, module, spec, ext_spec):
|
||||
def setup_dependent_environment(self, env, extension_spec):
|
||||
# Set GEM_PATH to include dependent gem directories
|
||||
ruby_paths = []
|
||||
for d in extension_spec.traverse():
|
||||
if d.package.extends(self.spec):
|
||||
ruby_paths.append(d.prefix)
|
||||
env.set_env('GEM_PATH', concatenate_paths(ruby_paths))
|
||||
# The actual installation path for this gem
|
||||
env.set_env('GEM_HOME', extension_spec.prefix)
|
||||
|
||||
def modify_module(self, module, spec, ext_spec):
|
||||
"""Called before ruby modules' install() methods. Sets GEM_HOME
|
||||
and GEM_PATH to values appropriate for the package being built.
|
||||
|
||||
@@ -31,11 +39,4 @@ def setup_dependent_environment(self, module, spec, ext_spec):
|
||||
module.ruby = Executable(join_path(spec.prefix.bin, 'ruby'))
|
||||
module.gem = Executable(join_path(spec.prefix.bin, 'gem'))
|
||||
|
||||
# Set GEM_PATH to include dependent gem directories
|
||||
ruby_paths = []
|
||||
for d in ext_spec.traverse():
|
||||
if d.package.extends(self.spec):
|
||||
ruby_paths.append(d.prefix)
|
||||
os.environ['GEM_PATH'] = ':'.join(ruby_paths)
|
||||
# The actual installation path for this gem
|
||||
os.environ['GEM_HOME'] = ext_spec.prefix
|
||||
|
||||
|
Reference in New Issue
Block a user