From b601fd08caf21b5fc11e6998a5ebd20a04ac57ad Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sun, 17 Aug 2014 01:41:32 -0700 Subject: Bugfixes for csh environment modules. --- lib/spack/spack/cmd/module.py | 15 +++++++++------ lib/spack/spack/modules.py | 27 ++++++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index af5a68923b..4f6de18532 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -52,14 +52,16 @@ def setup_parser(subparser): 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 there, and print out the name that the user + should type to use that package's module. + """ specs = spack.cmd.parse_specs(spec_array) if len(specs) > 1: tty.die("You can only pass one spec.") spec = specs[0] - if not spack.db.exists(spec.name): - tty.die("No such package: %s" % spec.name) - if mtype not in 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) mt = module_types[mtype] - mod = mt(spec.package) + mod = mt(specs[0].package) 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(): diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index 596308f801..3f56208f5b 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -157,7 +157,14 @@ class EnvModule(object): def file_name(self): """Subclasses should implement this to return the name of the file 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): @@ -172,9 +179,12 @@ class Dotkit(EnvModule): @property def file_name(self): - spec = self.pkg.spec - return join_path(Dotkit.path, spec.architecture, - spec.format('$_$@$%@$+$#.dk')) + return join_path(Dotkit.path, self.pkg.spec.architecture, + self.pkg.spec.format('$_$@$%@$+$#.dk')) + + @property + def use_name(self): + return self.pkg.spec.format('$_$@$%@$+$#') def _write(self, dk_file): @@ -206,9 +216,12 @@ class TclModule(EnvModule): @property def file_name(self): - spec = self.pkg.spec - return join_path(TclModule.path, spec.architecture, - spec.format('$_$@$%@$+$#')) + return join_path(TclModule.path, self.pkg.spec.architecture, self.use_name) + + + @property + def use_name(self): + return self.pkg.spec.format('$_$@$%@$+$#') def _write(self, m_file): -- cgit v1.2.3-60-g2f50