Skip to content
Snippets Groups Projects
Commit 5a9ef130 authored by Todd Gamblin's avatar Todd Gamblin
Browse files

Make EnvModule class use spec instead of package, fix using module of non-present package.

- Using the spec doesn't require the package to be there.
- Restore ability to use non-present packages (which was broken)
parent 8cc22981
Branches
Tags
No related merge requests found
...@@ -57,14 +57,14 @@ def module_find(mtype, spec_array): ...@@ -57,14 +57,14 @@ def module_find(mtype, spec_array):
of type <mtype> there, and print out the name that the user of type <mtype> there, and print out the name that the user
should type to use that package's module. should type to use that package's module.
""" """
if mtype not in module_types:
tty.die("Invalid module type: '%s'. Options are %s." % (mtype, comma_or(module_types)))
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 mtype not in module_types:
tty.die("Invalid module type: '%s'. Options are " + comma_and(module_types))
specs = [s for s in spack.db.installed_package_specs() if s.satisfies(spec)] specs = [s for s in spack.db.installed_package_specs() if s.satisfies(spec)]
if len(specs) == 0: if len(specs) == 0:
tty.die("No installed packages match spec %s" % spec) tty.die("No installed packages match spec %s" % spec)
...@@ -76,10 +76,9 @@ def module_find(mtype, spec_array): ...@@ -76,10 +76,9 @@ def module_find(mtype, spec_array):
sys.exit(1) sys.exit(1)
mt = module_types[mtype] mt = module_types[mtype]
mod = mt(specs[0].package) mod = mt(specs[0])
if not os.path.isfile(mod.file_name): if not os.path.isfile(mod.file_name):
tty.error( mod.file_name) tty.die("No %s module is installed for %s." % (mtype, spec))
tty.die("No %s module is installed for package %s." % (mtype, spec))
print mod.use_name print mod.use_name
...@@ -96,7 +95,7 @@ def module_refresh(): ...@@ -96,7 +95,7 @@ def module_refresh():
mkdirp(cls.path) mkdirp(cls.path)
for spec in specs: for spec in specs:
tty.debug(" Writing file for %s." % spec) tty.debug(" Writing file for %s." % spec)
cls(spec.package).write() cls(spec).write()
......
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
def post_install(pkg): def post_install(pkg):
dk = spack.modules.Dotkit(pkg) dk = spack.modules.Dotkit(pkg.spec)
dk.write() dk.write()
def post_uninstall(pkg): def post_uninstall(pkg):
dk = spack.modules.Dotkit(pkg) dk = spack.modules.Dotkit(pkg.spec)
dk.remove() dk.remove()
...@@ -88,7 +88,7 @@ def __init__(cls, name, bases, dict): ...@@ -88,7 +88,7 @@ def __init__(cls, name, bases, dict):
module_types[cls.name] = cls module_types[cls.name] = cls
def __init__(self, pkg=None): def __init__(self, spec=None):
# category in the modules system # category in the modules system
# TODO: come up with smarter category names. # TODO: come up with smarter category names.
self.category = "spack" self.category = "spack"
...@@ -100,7 +100,7 @@ def __init__(self, pkg=None): ...@@ -100,7 +100,7 @@ def __init__(self, pkg=None):
# dict pathname -> list of directories to be prepended to in # dict pathname -> list of directories to be prepended to in
# the module file. # the module file.
self._paths = None self._paths = None
self.pkg = pkg self.spec = spec
@property @property
...@@ -114,22 +114,22 @@ def add_path(path_name, directory): ...@@ -114,22 +114,22 @@ def add_path(path_name, directory):
# Add paths if they exist. # Add paths if they exist.
for var, directory in [ for var, directory in [
('PATH', self.pkg.prefix.bin), ('PATH', self.spec.prefix.bin),
('MANPATH', self.pkg.prefix.man), ('MANPATH', self.spec.prefix.man),
('MANPATH', self.pkg.prefix.share_man), ('MANPATH', self.spec.prefix.share_man),
('LD_LIBRARY_PATH', self.pkg.prefix.lib), ('LD_LIBRARY_PATH', self.spec.prefix.lib),
('LD_LIBRARY_PATH', self.pkg.prefix.lib64)]: ('LD_LIBRARY_PATH', self.spec.prefix.lib64)]:
if os.path.isdir(directory): if os.path.isdir(directory):
add_path(var, directory) add_path(var, directory)
# short description is just the package + version # short description is just the package + version
# TODO: maybe packages can optionally provide it. # TODO: maybe packages can optionally provide it.
self.short_description = self.pkg.spec.format("$_ $@") self.short_description = self.spec.format("$_ $@")
# long description is the docstring with reduced whitespace. # long description is the docstring with reduced whitespace.
if self.pkg.__doc__: if self.spec.package.__doc__:
self.long_description = re.sub(r'\s+', ' ', self.pkg.__doc__) self.long_description = re.sub(r'\s+', ' ', self.spec.package.__doc__)
return self._paths return self._paths
...@@ -179,12 +179,12 @@ class Dotkit(EnvModule): ...@@ -179,12 +179,12 @@ class Dotkit(EnvModule):
@property @property
def file_name(self): def file_name(self):
return join_path(Dotkit.path, self.pkg.spec.architecture, return join_path(Dotkit.path, self.spec.architecture,
self.pkg.spec.format('$_$@$%@$+$#.dk')) self.spec.format('$_$@$%@$+$#.dk'))
@property @property
def use_name(self): def use_name(self):
return self.pkg.spec.format('$_$@$%@$+$#') return self.spec.format('$_$@$%@$+$#')
def _write(self, dk_file): def _write(self, dk_file):
...@@ -207,7 +207,7 @@ def _write(self, dk_file): ...@@ -207,7 +207,7 @@ def _write(self, dk_file):
dk_file.write("dk_alter %s %s\n" % (var, directory)) dk_file.write("dk_alter %s %s\n" % (var, directory))
# Let CMake find this package. # Let CMake find this package.
dk_file.write("dk_alter CMAKE_PREFIX_PATH %s\n" % self.pkg.prefix) dk_file.write("dk_alter CMAKE_PREFIX_PATH %s\n" % self.spec.prefix)
class TclModule(EnvModule): class TclModule(EnvModule):
...@@ -216,12 +216,12 @@ class TclModule(EnvModule): ...@@ -216,12 +216,12 @@ class TclModule(EnvModule):
@property @property
def file_name(self): def file_name(self):
return join_path(TclModule.path, self.pkg.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 self.pkg.spec.format('$_$@$%@$+$#') return self.spec.format('$_$@$%@$+$#')
def _write(self, m_file): def _write(self, m_file):
...@@ -244,4 +244,4 @@ def _write(self, m_file): ...@@ -244,4 +244,4 @@ def _write(self, m_file):
for directory in dirs: for directory in dirs:
m_file.write("prepend-path %s \"%s\"\n" % (var, directory)) m_file.write("prepend-path %s \"%s\"\n" % (var, directory))
m_file.write("prepend-path CMAKE_PREFIX_PATH \"%s\"\n" % self.pkg.prefix) m_file.write("prepend-path CMAKE_PREFIX_PATH \"%s\"\n" % self.spec.prefix)
...@@ -33,7 +33,9 @@ def comma_list(sequence, article=''): ...@@ -33,7 +33,9 @@ def comma_list(sequence, article=''):
return sequence[0] return sequence[0]
else: else:
out = ', '.join(str(s) for s in sequence[:-1]) out = ', '.join(str(s) for s in sequence[:-1])
out += ', ' if len(sequence) != 2:
out += ',' # oxford comma
out += ' '
if article: if article:
out += article + ' ' out += article + ' '
out += str(sequence[-1]) out += str(sequence[-1])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment