Bugfixes for csh environment modules.

This commit is contained in:
Todd Gamblin 2014-08-17 01:41:32 -07:00
parent 22bec329c1
commit b601fd08ca
5 changed files with 81 additions and 30 deletions

View file

@ -52,14 +52,16 @@ def setup_parser(subparser):
def module_find(mtype, spec_array): def module_find(mtype, spec_array):
"""Look at all installed packages and see if the spec provided
matches any. If it does, check whether there is a module file
of type <mtype> there, and print out the name that the user
should type to use that package's module.
"""
specs = spack.cmd.parse_specs(spec_array) specs = spack.cmd.parse_specs(spec_array)
if len(specs) > 1: if len(specs) > 1:
tty.die("You can only pass one spec.") tty.die("You can only pass one spec.")
spec = specs[0] spec = specs[0]
if not spack.db.exists(spec.name):
tty.die("No such package: %s" % spec.name)
if mtype not in module_types: if mtype not in module_types:
tty.die("Invalid module type: '%s'. Options are " + comma_and(module_types)) tty.die("Invalid module type: '%s'. Options are " + comma_and(module_types))
@ -74,11 +76,12 @@ def module_find(mtype, spec_array):
sys.exit(1) sys.exit(1)
mt = module_types[mtype] mt = module_types[mtype]
mod = mt(spec.package) mod = mt(specs[0].package)
if not os.path.isfile(mod.file_name): if not os.path.isfile(mod.file_name):
tty.die("No dotkit is installed for package %s." % spec) tty.error( mod.file_name)
tty.die("No %s module is installed for package %s." % (mtype, spec))
print mod.file_name print mod.use_name
def module_refresh(): def module_refresh():

View file

@ -157,7 +157,14 @@ def _write(self, stream):
def file_name(self): def file_name(self):
"""Subclasses should implement this to return the name of the file """Subclasses should implement this to return the name of the file
where this module lives.""" where this module lives."""
return self.pkg.spec.format('$_$@$%@$+$=$#') raise NotImplementedError()
@property
def use_name(self):
"""Subclasses should implement this to return the name the
module command uses to refer to the package."""
raise NotImplementedError()
def remove(self): def remove(self):
@ -172,9 +179,12 @@ class Dotkit(EnvModule):
@property @property
def file_name(self): def file_name(self):
spec = self.pkg.spec return join_path(Dotkit.path, self.pkg.spec.architecture,
return join_path(Dotkit.path, spec.architecture, self.pkg.spec.format('$_$@$%@$+$#.dk'))
spec.format('$_$@$%@$+$#.dk'))
@property
def use_name(self):
return self.pkg.spec.format('$_$@$%@$+$#')
def _write(self, dk_file): def _write(self, dk_file):
@ -206,9 +216,12 @@ class TclModule(EnvModule):
@property @property
def file_name(self): def file_name(self):
spec = self.pkg.spec return join_path(TclModule.path, self.pkg.spec.architecture, self.use_name)
return join_path(TclModule.path, spec.architecture,
spec.format('$_$@$%@$+$#'))
@property
def use_name(self):
return self.pkg.spec.format('$_$@$%@$+$#')
def _write(self, m_file): def _write(self, m_file):

View file

@ -22,14 +22,28 @@
# avoids the need to come up with a user-friendly naming scheme for # avoids the need to come up with a user-friendly naming scheme for
# spack dotfiles. # spack dotfiles.
######################################################################## ########################################################################
# accumulate initial flags for main spack command
set _sp_flags = ""
while ( $#_sp_args > 0 )
if ( "$_sp_args[1]" !~ "-*" ) break
set _sp_flags = "$_sp_flags $_sp_args[1]"
shift _sp_args
end
# h and V flags don't require further output parsing.
if ( "$_sp_flags" =~ *h* || "$_sp_flags" =~ *V* ) then
\spack $_sp_flags $_sp_args
goto _sp_end
endif
# Set up args -- we want a subcommand and a spec. # Set up args -- we want a subcommand and a spec.
set _sp_subcommand=""; set _sp_subcommand=""
set _sp_spec=""; set _sp_spec=""
[ $#_sp_args -gt 0 ] && set _sp_subcommand = ($_sp_args[1]); [ $#_sp_args -gt 0 ] && set _sp_subcommand = ($_sp_args[1])
[ $#_sp_args -gt 1 ] && set _sp_spec = ($_sp_args[2-]); [ $#_sp_args -gt 1 ] && set _sp_spec = ($_sp_args[2-])
# Figure out what type of module we're running here. # Figure out what type of module we're running here.
set _sp_modtype = ""; set _sp_modtype = ""
switch ($_sp_subcommand) switch ($_sp_subcommand)
case use: case use:
case unuse: case unuse:
@ -48,12 +62,12 @@ case unload:
case use: case use:
case unuse: case unuse:
set _sp_modtype = dotkit set _sp_modtype = dotkit
set _sp_sh_cmd = $_sp_subcommand set _sp_sh_cmd = ( "`alias $_sp_subcommand'" )
breaksw breaksw
case load: case load:
case unload: case unload:
set _sp_modtype = tcl set _sp_modtype = tcl
set _sp_sh_cmd = ( module $_sp_subcommand ) set _sp_sh_cmd = ( "`alias module`" $_sp_subcommand )
breaksw breaksw
endsw endsw
@ -61,11 +75,17 @@ case unload:
# spec using 'spack module find', then use the appropriate module # spec using 'spack module find', then use the appropriate module
# tool's commands to add/remove the result from the environment. # tool's commands to add/remove the result from the environment.
# If spack module command comes back with an error, do nothing. # If spack module command comes back with an error, do nothing.
if { set _sp_full_spec = `command spack module find $_sp_modtype $_sp_spec` } then set _sp_full_spec = ""
echo $_sp_sh_cmd $_sp_module_args $_sp_full_spec if { set _sp_full_spec = `\spack module find $_sp_modtype $_sp_spec` } then
$_sp_sh_cmd $_sp_module_args $_sp_full_spec
endif endif
breaksw
default: default:
command spack $_sp_args \spack $_sp_args
breaksw
endsw endsw
unset _sp_args _sp_full_spec _sp_modtype _sp_module_args _sp_sh_cmd _sp_spec _sp_subcommand _sp_end:
unset _sp_args _sp_full_spec _sp_modtype _sp_module_args
unset _sp_sh_cmd _sp_spec _sp_subcommand _sp_flags

View file

@ -40,7 +40,8 @@ if ($?SPACK_ROOT) then
alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/spack_pathadd.csh' alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/spack_pathadd.csh'
# Set up modules and dotkit search paths in the user environment # Set up modules and dotkit search paths in the user environment
_spack_pathadd DK_NODE "$_spack_share_dir/dotkit" # TODO: fix SYS_TYPE to something non-LLNL-specific
_spack_pathadd MODULEPATH "$_spack_share_dir/modules" _spack_pathadd DK_NODE "$_spack_share_dir/dotkit/$SYS_TYPE"
_spack_pathadd MODULEPATH "$_spack_share_dir/modules/$SYS_TYPE"
_spack_pathadd PATH "$SPACK_ROOT/bin" _spack_pathadd PATH "$SPACK_ROOT/bin"
endif endif

View file

@ -56,6 +56,19 @@
# spack dotfiles. # spack dotfiles.
######################################################################## ########################################################################
function spack { function spack {
# accumulate initial flags for main spack command
_sp_flags=""
while [[ "$1" =~ ^- ]]; do
_sp_flags="$_sp_flags $1"
shift
done
# h and V flags don't require further output parsing.
if [[ "$_sp_flags" =~ *h* || "$_sp_flags" =~ *V* ]]; then
command spack $_sp_flags "$@"
return
fi
_sp_subcommand=$1; shift _sp_subcommand=$1; shift
_sp_spec="$@" _sp_spec="$@"
@ -88,13 +101,13 @@ function spack {
# spec using 'spack module find', then use the appropriate module # spec using 'spack module find', then use the appropriate module
# tool's commands to add/remove the result from the environment. # tool's commands to add/remove the result from the environment.
# If spack module command comes back with an error, do nothing. # If spack module command comes back with an error, do nothing.
if _sp_full_spec=$(command spack module find $_sp_modtype $_sp_spec); then if _sp_full_spec=$(command spack $_sp_flags module find $_sp_modtype $_sp_spec); then
$_sp_sh_cmd $_sp_module_args $_sp_full_spec $_sp_sh_cmd $_sp_module_args $_sp_full_spec
fi fi
return return
;; ;;
*) *)
command spack $_sp_subcommand $_sp_spec command spack $_sp_flags $_sp_subcommand $_sp_spec
esac esac
} }
@ -145,6 +158,7 @@ fi
_sp_share_dir="$(dirname $_sp_source_file)" _sp_share_dir="$(dirname $_sp_source_file)"
_sp_prefix="$(dirname $(dirname $_sp_share_dir))" _sp_prefix="$(dirname $(dirname $_sp_share_dir))"
_spack_pathadd DK_NODE "$_sp_share_dir/dotkit" # TODO: fix SYS_TYPE to something non-LLNL-specific
_spack_pathadd MODULEPATH "$_sp_share_dir/modules" _spack_pathadd DK_NODE "$_sp_share_dir/dotkit/$SYS_TYPE"
_spack_pathadd MODULEPATH "$_sp_share_dir/modules/$SYS_TYPE"
_spack_pathadd PATH "$_sp_prefix/bin" _spack_pathadd PATH "$_sp_prefix/bin"