modules : removed dead code

This commit is contained in:
alalazo 2016-03-16 16:23:02 +01:00
parent 597727f8be
commit ac762e95a6

View File

@ -22,14 +22,12 @@
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
"""This module contains code for creating environment modules, which """
can include dotkits, tcl modules, lmod, and others. This module contains code for creating environment modules, which can include dotkits, tcl modules, lmod, and others.
The various types of modules are installed by post-install hooks and The various types of modules are installed by post-install hooks and removed after an uninstall by post-uninstall hooks.
removed after an uninstall by post-uninstall hooks. This class This class consolidates the logic for creating an abstract description of the information that module systems need.
consolidates the logic for creating an abstract description of the Currently that includes a number of directories to be appended to paths in the user's environment:
information that module systems need. Currently that includes a
number of directories to be appended to paths in the user's environment:
* /bin directories to be appended to PATH * /bin directories to be appended to PATH
* /lib* directories for LD_LIBRARY_PATH * /lib* directories for LD_LIBRARY_PATH
@ -37,26 +35,23 @@
* /man* and /share/man* directories for MANPATH * /man* and /share/man* directories for MANPATH
* the package prefix for CMAKE_PREFIX_PATH * the package prefix for CMAKE_PREFIX_PATH
This module also includes logic for coming up with unique names for This module also includes logic for coming up with unique names for the module files so that they can be found by the
the module files so that they can be found by the various various shell-support files in $SPACK/share/spack/setup-env.*.
shell-support files in $SPACK/share/spack/setup-env.*.
Each hook in hooks/ implements the logic for writing its specific type Each hook in hooks/ implements the logic for writing its specific type of module file.
of module file.
""" """
__all__ = ['EnvModule', 'Dotkit', 'TclModule']
import os import os
import os.path import os.path
import re import re
import shutil import shutil
import textwrap import textwrap
from glob import glob
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack
from spack.environment import *
from llnl.util.filesystem import join_path, mkdirp from llnl.util.filesystem import join_path, mkdirp
from spack.environment import *
__all__ = ['EnvModule', 'Dotkit', 'TclModule']
# Registry of all types of modules. Entries created by EnvModule's metaclass # Registry of all types of modules. Entries created by EnvModule's metaclass
module_types = {} module_types = {}
@ -79,34 +74,35 @@ def print_help():
"") "")
class PathInspector(object):
dirname2varname = {
'bin': ('PATH',),
'man': ('MANPATH',),
'lib': ('LIBRARY_PATH', 'LD_LIBRARY_PATH'),
'lib64': ('LIBRARY_PATH', 'LD_LIBRARY_PATH'),
'include': ('CPATH',),
'pkgconfig': ('PKG_CONFIG_PATH',)
}
def __call__(self, env, directory, names):
for name in names:
variables = PathInspector.dirname2varname.get(name, None)
if variables is None:
continue
absolute_path = join_path(os.path.abspath(directory), name)
for variable in variables:
env.prepend_path(variable, absolute_path)
def inspect_path(path): def inspect_path(path):
class PathInspector(object):
dirname2varname = {
'bin': ('PATH',),
'man': ('MANPATH',),
'lib': ('LIBRARY_PATH', 'LD_LIBRARY_PATH'),
'lib64': ('LIBRARY_PATH', 'LD_LIBRARY_PATH'),
'include': ('CPATH',),
'pkgconfig': ('PKG_CONFIG_PATH',)
}
def __call__(self, env, directory, names):
for name in names:
variables = PathInspector.dirname2varname.get(name, None)
if variables is None:
continue
absolute_path = join_path(os.path.abspath(directory), name)
for variable in variables:
env.prepend_path(variable, absolute_path)
env, inspector = EnvironmentModifications(), PathInspector() env, inspector = EnvironmentModifications(), PathInspector()
os.path.walk(path, inspector, env) os.path.walk(path, inspector, env)
env.prepend_path('CMAKE_PREFIX_PATH', path)
return env return env
class EnvModule(object): class EnvModule(object):
name = 'env_module' name = 'env_module'
formats = {}
class __metaclass__(type): class __metaclass__(type):
def __init__(cls, name, bases, dict): def __init__(cls, name, bases, dict):
@ -119,9 +115,6 @@ def __init__(self, spec=None):
# TODO: come up with smarter category names. # TODO: come up with smarter category names.
self.category = "spack" self.category = "spack"
# dict pathname -> list of directories to be prepended to in
# the module file.
self._paths = None
self.spec = spec self.spec = spec
self.pkg = spec.package # Just stored for convenience self.pkg = spec.package # Just stored for convenience
@ -136,44 +129,21 @@ def __init__(self, spec=None):
if self.spec.package.__doc__: if self.spec.package.__doc__:
self.long_description = re.sub(r'\s+', ' ', self.spec.package.__doc__) self.long_description = re.sub(r'\s+', ' ', self.spec.package.__doc__)
@property # @property
def paths(self): # def paths(self):
if self._paths is None: # # Add python path unless it's an actual python installation
self._paths = {} # # TODO : is there a better way to do this?
# # FIXME : add PYTHONPATH to every python package
def add_path(path_name, directory): # if self.spec.name != 'python':
path = self._paths.setdefault(path_name, []) # site_packages = glob(join_path(self.spec.prefix.lib, "python*/site-packages"))
path.append(directory) # if site_packages:
# add_path('PYTHONPATH', site_packages[0])
# Add paths if they exist. #
for var, directory in [ # # FIXME : Same for GEM_PATH
('PATH', self.spec.prefix.bin), # if self.spec.package.extends(spack.spec.Spec('ruby')):
('MANPATH', self.spec.prefix.man), # add_path('GEM_PATH', self.spec.prefix)
('MANPATH', self.spec.prefix.share_man), #
('LIBRARY_PATH', self.spec.prefix.lib), # return self._paths
('LIBRARY_PATH', self.spec.prefix.lib64),
('LD_LIBRARY_PATH', self.spec.prefix.lib),
('LD_LIBRARY_PATH', self.spec.prefix.lib64),
('CPATH', self.spec.prefix.include),
('PKG_CONFIG_PATH', join_path(self.spec.prefix.lib, 'pkgconfig')),
('PKG_CONFIG_PATH', join_path(self.spec.prefix.lib64, 'pkgconfig'))]:
if os.path.isdir(directory):
add_path(var, directory)
# Add python path unless it's an actual python installation
# TODO : is there a better way to do this?
# FIXME : add PYTHONPATH to every python package
if self.spec.name != 'python':
site_packages = glob(join_path(self.spec.prefix.lib, "python*/site-packages"))
if site_packages:
add_path('PYTHONPATH', site_packages[0])
# FIXME : Same for GEM_PATH
if self.spec.package.extends(spack.spec.Spec('ruby')):
add_path('GEM_PATH', self.spec.prefix)
return self._paths
def write(self): def write(self):
"""Write out a module file for this object.""" """Write out a module file for this object."""
@ -181,14 +151,9 @@ def write(self):
if not os.path.exists(module_dir): if not os.path.exists(module_dir):
mkdirp(module_dir) mkdirp(module_dir)
# If there are no paths, no need for a dotkit. # Environment modifications guessed by inspecting the installation prefix
if not self.paths:
return
# Construct the changes that needs to be done on the environment for
env = inspect_path(self.spec.prefix) env = inspect_path(self.spec.prefix)
# FIXME : move the logic to inspection # Package-specific environment modifications
env.prepend_path('CMAKE_PREFIX_PATH', self.spec.prefix)
# FIXME : decide how to distinguish between calls done in the installation and elsewhere # FIXME : decide how to distinguish between calls done in the installation and elsewhere
env.extend(self.spec.package.environment_modifications(None)) env.extend(self.spec.package.environment_modifications(None))
# site_specific = ...` # site_specific = ...`
@ -196,12 +161,17 @@ def write(self):
return return
with open(self.file_name, 'w') as f: with open(self.file_name, 'w') as f:
self._write(f, env) self.write_header(f)
for line in self.process_environment_command(env):
f.write(line)
def _write(self, stream): def write_header(self, stream):
"""To be implemented by subclasses."""
raise NotImplementedError() raise NotImplementedError()
def process_environment_command(self, env):
for command in env:
# FIXME : how should we handle errors here?
yield self.formats[type(command)].format(command)
@property @property
def file_name(self): def file_name(self):
@ -225,10 +195,14 @@ class Dotkit(EnvModule):
name = 'dotkit' name = 'dotkit'
path = join_path(spack.share_path, "dotkit") path = join_path(spack.share_path, "dotkit")
formats = {
PrependPath: 'dk_alter {0.name} {0.path}\n',
SetEnv: 'dk_setenv {0.name} {0.value}\n'
}
@property @property
def file_name(self): def file_name(self):
return join_path(Dotkit.path, self.spec.architecture, return join_path(Dotkit.path, self.spec.architecture, '%s.dk' % self.use_name)
'%s.dk' % self.use_name)
@property @property
def use_name(self): def use_name(self):
@ -237,7 +211,7 @@ def use_name(self):
self.spec.compiler.version, self.spec.compiler.version,
self.spec.dag_hash()) self.spec.dag_hash())
def _write(self, dk_file, env): def write_header(self, dk_file):
# Category # Category
if self.category: if self.category:
dk_file.write('#c %s\n' % self.category) dk_file.write('#c %s\n' % self.category)
@ -251,18 +225,11 @@ def _write(self, dk_file, env):
for line in textwrap.wrap(self.long_description, 72): for line in textwrap.wrap(self.long_description, 72):
dk_file.write("#h %s\n" % line) dk_file.write("#h %s\n" % line)
# Path alterations
for var, dirs in self.paths.items():
for directory in dirs:
dk_file.write("dk_alter %s %s\n" % (var, directory))
# Let CMake find this package.
dk_file.write("dk_alter CMAKE_PREFIX_PATH %s\n" % self.spec.prefix)
class TclModule(EnvModule): class TclModule(EnvModule):
name = 'tcl' name = 'tcl'
path = join_path(spack.share_path, "modules") path = join_path(spack.share_path, "modules")
formats = { formats = {
PrependPath: 'prepend-path {0.name} \"{0.path}\"\n', PrependPath: 'prepend-path {0.name} \"{0.path}\"\n',
SetEnv: 'setenv {0.name} \"{0.value}\"\n' SetEnv: 'setenv {0.name} \"{0.value}\"\n'
@ -272,7 +239,6 @@ class TclModule(EnvModule):
def file_name(self): def file_name(self):
return join_path(TclModule.path, self.spec.architecture, self.use_name) return join_path(TclModule.path, self.spec.architecture, self.use_name)
@property @property
def use_name(self): def use_name(self):
return "%s-%s-%s-%s-%s" % (self.spec.name, self.spec.version, return "%s-%s-%s-%s-%s" % (self.spec.name, self.spec.version,
@ -280,19 +246,7 @@ def use_name(self):
self.spec.compiler.version, self.spec.compiler.version,
self.spec.dag_hash()) self.spec.dag_hash())
def process_environment_command(self, env): def write_header(self, module_file):
for command in env:
# FIXME : how should we handle errors here?
yield self.formats[type(command)].format(command)
def _write(self, module_file, env):
"""
Writes a TCL module file for this package
Args:
module_file: module file stream
env: list of environment modifications to be written in the module file
"""
# TCL Modulefile header # TCL Modulefile header
module_file.write('#%Module1.0\n') module_file.write('#%Module1.0\n')
# TODO : category ? # TODO : category ?
@ -306,30 +260,3 @@ def _write(self, module_file, env):
doc = re.sub(r'"', '\"', self.long_description) doc = re.sub(r'"', '\"', self.long_description)
module_file.write("puts stderr \"%s\"\n" % doc) module_file.write("puts stderr \"%s\"\n" % doc)
module_file.write('}\n\n') module_file.write('}\n\n')
# Environment modifications
for line in self.process_environment_command(env):
module_file.write(line)
# FIXME : REMOVE
# def _write(self, m_file):
# # TODO: cateogry?
# m_file.write('#%Module1.0\n')
#
# # Short description
# if self.short_description:
# m_file.write('module-whatis \"%s\"\n\n' % self.short_description)
#
# # Long description
# if self.long_description:
# m_file.write('proc ModulesHelp { } {\n')
# doc = re.sub(r'"', '\"', self.long_description)
# m_file.write("puts stderr \"%s\"\n" % doc)
# m_file.write('}\n\n')
#
# # Path alterations
# for var, dirs in self.paths.items():
# for directory in dirs:
# m_file.write("prepend-path %s \"%s\"\n" % (var, directory))
#
# m_file.write("prepend-path CMAKE_PREFIX_PATH \"%s\"\n" % self.spec.prefix)