[!8] Feature/fix python with multiple versions

Merge branch 'feature/fix-python-with-multiple-versions' into 'master'

ref:spack/dune-spack\> Actually, make install already installs Python
packages, so there is no need to do it manually in a post-install hook.

Additionally, we set the DUNE_PY_DIR and DUNE_CONTROL_PATH environment
variables, so that the Python bindings work even in presence of multiple
installations.

This fixes [#8]

See merge request [spack/dune-spack!8]

  [#8]: gitlab.dune-project.org/NoneNone/issues/8
  [spack/dune-spack!8]: gitlab.dune-project.org/spack/dune-spack/merge_requests/8


Closes #8
This commit is contained in:
Dominic Kempf 2020-05-15 09:19:27 +00:00
commit 3c6941ca42
1 changed files with 22 additions and 11 deletions

View File

@ -43,6 +43,7 @@ class Dune(CMakePackage):
# Some variants for customization of Dune # Some variants for customization of Dune
variant('doc', default=False, description='Build and install documentation') variant('doc', default=False, description='Build and install documentation')
variant('python', default=False, description='Build with Python bindings')
# Variants for upstream dependencies # Variants for upstream dependencies
variant('arpack', default=True, description='Build ARnoldi PACKage library support') variant('arpack', default=True, description='Build ARnoldi PACKage library support')
@ -71,7 +72,6 @@ class Dune(CMakePackage):
variant('grid', default=True, description='Build with dune-grid module') variant('grid', default=True, description='Build with dune-grid module')
variant('istl', default=True, description='Build with dune-istl module') variant('istl', default=True, description='Build with dune-istl module')
variant('localfunctions', default=True, description='Build with dune-localfunctions module') variant('localfunctions', default=True, description='Build with dune-localfunctions module')
variant('python', default=False, description='Build with Python and dune-python')
variant('spgrid', default=False, description='Build with dune-spgrid module') variant('spgrid', default=False, description='Build with dune-spgrid module')
variant('typetree', default=False, description='Build with dune-typetree module') variant('typetree', default=False, description='Build with dune-typetree module')
variant('uggrid', default=False, description='Build with dune-uggrid module') variant('uggrid', default=False, description='Build with dune-uggrid module')
@ -174,7 +174,6 @@ class Dune(CMakePackage):
depends_on('doxygen', type='build', when='+doc') depends_on('doxygen', type='build', when='+doc')
depends_on('gawk') depends_on('gawk')
depends_on('gmp', when='+gmp') depends_on('gmp', when='+gmp')
depends_on('imagemagick', type='build', when='+doc')
depends_on('intel-tbb', when='+tbb') depends_on('intel-tbb', when='+tbb')
depends_on('lapack', when='+lapack') depends_on('lapack', when='+lapack')
depends_on('metis', when='+metis') depends_on('metis', when='+metis')
@ -182,10 +181,11 @@ class Dune(CMakePackage):
depends_on('parmetis', when='+parmetis') depends_on('parmetis', when='+parmetis')
depends_on('pkg-config', type='build') depends_on('pkg-config', type='build')
depends_on('python@3.0:', type=('build', 'run'), when='+python') depends_on('python@3.0:', type=('build', 'run'), when='+python')
depends_on('py-setuptools', type='build') depends_on('py-setuptools', type='build', when='+python')
depends_on('py-numpy', type=('build', 'run'), when='+python') depends_on('py-numpy', type=('build', 'run'), when='+python')
depends_on('py-pip', type=('build', 'run'), when='+python') depends_on('py-pip', type=('build', 'run'), when='+python')
depends_on('py-sphinx', type=('build', 'run'), when='+doc') depends_on('py-sphinx', type=('build', 'run'), when='+doc')
depends_on('py-wheel', type='build', when='+python')
depends_on('scotch+mpi', when='+ptscotch') depends_on('scotch+mpi', when='+ptscotch')
depends_on('sionlib', when='+sionlib') depends_on('sionlib', when='+sionlib')
depends_on('suite-sparse', when='+suitesparse') depends_on('suite-sparse', when='+suitesparse')
@ -194,6 +194,22 @@ class Dune(CMakePackage):
depends_on('zlib', when='+zlib') depends_on('zlib', when='+zlib')
depends_on('zoltan', when='+zoltan') depends_on('zoltan', when='+zoltan')
def setup_build_environment(self, env):
# We reset the DUNE_CONTROL_PATH here because any entries in this
# path that contain Dune modules will break the Spack build process.
env.set('DUNE_CONTROL_PATH', self.prefix)
def setup_run_environment(self, env):
# Some scripts search the DUNE_CONTROL_PATH for Dune modules (e.g. duneproject).
# We need to set it correctly in order to allow multiple simultaneous
# installations of the dune package.
env.set('DUNE_CONTROL_PATH', self.prefix)
# Additionally, we need to set the workspace for the Python bindings to something
# that is unique to this build of the dune module (it defaults to ~/.cache)
if '+python' in self.spec:
env.set('DUNE_PY_DIR', self.prefix)
def cmake_args(self): def cmake_args(self):
"""Populate cmake arguments.""" """Populate cmake arguments."""
spec = self.spec spec = self.spec
@ -213,8 +229,10 @@ class Dune(CMakePackage):
] ]
if '+python' in spec: if '+python' in spec:
if '@2.7' not in spec:
cmake_args.append('-DDUNE_ENABLE_PYTHONBINDINGS:BOOL=TRUE')
cmake_args.append('-DDUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS:BOOL=TRUE') cmake_args.append('-DDUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS:BOOL=TRUE')
cmake_args.append('-DPYTHON_INSTALL_LOCATION:STRING="system"') cmake_args.append('-DDUNE_PYTHON_INSTALL_LOCATION:STRING="system"')
return cmake_args return cmake_args
@ -269,10 +287,3 @@ class Dune(CMakePackage):
options_file = join_path(self.stage.source_path, "..", "dune.opts") options_file = join_path(self.stage.source_path, "..", "dune.opts")
installer('--builddir=%s'%self.build_directory , '--opts=%s' % options_file, 'make') installer('--builddir=%s'%self.build_directory , '--opts=%s' % options_file, 'make')
@run_after('install')
def install_python_components(self):
if '+python' in self.spec:
for package in self.python_components:
build_directory = 'dune-python/python'
with working_dir(join_path(self.build_directory,'dune-python/python')):
setup_py('install', '--prefix={0}'.format(self.prefix))