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)
This commit is contained in:
parent
8cc2298181
commit
5a9ef130ea
@ -57,14 +57,14 @@ def module_find(mtype, spec_array):
|
||||
of type <mtype> there, and print out the name that the user
|
||||
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)
|
||||
if len(specs) > 1:
|
||||
tty.die("You can only pass one spec.")
|
||||
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)]
|
||||
if len(specs) == 0:
|
||||
tty.die("No installed packages match spec %s" % spec)
|
||||
@ -76,10 +76,9 @@ def module_find(mtype, spec_array):
|
||||
sys.exit(1)
|
||||
|
||||
mt = module_types[mtype]
|
||||
mod = mt(specs[0].package)
|
||||
mod = mt(specs[0])
|
||||
if not os.path.isfile(mod.file_name):
|
||||
tty.error( mod.file_name)
|
||||
tty.die("No %s module is installed for package %s." % (mtype, spec))
|
||||
tty.die("No %s module is installed for %s." % (mtype, spec))
|
||||
|
||||
print mod.use_name
|
||||
|
||||
@ -96,7 +95,7 @@ def module_refresh():
|
||||
mkdirp(cls.path)
|
||||
for spec in specs:
|
||||
tty.debug(" Writing file for %s." % spec)
|
||||
cls(spec.package).write()
|
||||
cls(spec).write()
|
||||
|
||||
|
||||
|
||||
|
@ -26,10 +26,10 @@
|
||||
|
||||
|
||||
def post_install(pkg):
|
||||
dk = spack.modules.Dotkit(pkg)
|
||||
dk = spack.modules.Dotkit(pkg.spec)
|
||||
dk.write()
|
||||
|
||||
|
||||
def post_uninstall(pkg):
|
||||
dk = spack.modules.Dotkit(pkg)
|
||||
dk = spack.modules.Dotkit(pkg.spec)
|
||||
dk.remove()
|
||||
|
@ -88,7 +88,7 @@ def __init__(cls, name, bases, dict):
|
||||
module_types[cls.name] = cls
|
||||
|
||||
|
||||
def __init__(self, pkg=None):
|
||||
def __init__(self, spec=None):
|
||||
# category in the modules system
|
||||
# TODO: come up with smarter category names.
|
||||
self.category = "spack"
|
||||
@ -100,7 +100,7 @@ def __init__(self, pkg=None):
|
||||
# dict pathname -> list of directories to be prepended to in
|
||||
# the module file.
|
||||
self._paths = None
|
||||
self.pkg = pkg
|
||||
self.spec = spec
|
||||
|
||||
|
||||
@property
|
||||
@ -114,22 +114,22 @@ def add_path(path_name, directory):
|
||||
|
||||
# Add paths if they exist.
|
||||
for var, directory in [
|
||||
('PATH', self.pkg.prefix.bin),
|
||||
('MANPATH', self.pkg.prefix.man),
|
||||
('MANPATH', self.pkg.prefix.share_man),
|
||||
('LD_LIBRARY_PATH', self.pkg.prefix.lib),
|
||||
('LD_LIBRARY_PATH', self.pkg.prefix.lib64)]:
|
||||
('PATH', self.spec.prefix.bin),
|
||||
('MANPATH', self.spec.prefix.man),
|
||||
('MANPATH', self.spec.prefix.share_man),
|
||||
('LD_LIBRARY_PATH', self.spec.prefix.lib),
|
||||
('LD_LIBRARY_PATH', self.spec.prefix.lib64)]:
|
||||
|
||||
if os.path.isdir(directory):
|
||||
add_path(var, directory)
|
||||
|
||||
# short description is just the package + version
|
||||
# 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.
|
||||
if self.pkg.__doc__:
|
||||
self.long_description = re.sub(r'\s+', ' ', self.pkg.__doc__)
|
||||
if self.spec.package.__doc__:
|
||||
self.long_description = re.sub(r'\s+', ' ', self.spec.package.__doc__)
|
||||
|
||||
return self._paths
|
||||
|
||||
@ -179,12 +179,12 @@ class Dotkit(EnvModule):
|
||||
|
||||
@property
|
||||
def file_name(self):
|
||||
return join_path(Dotkit.path, self.pkg.spec.architecture,
|
||||
self.pkg.spec.format('$_$@$%@$+$#.dk'))
|
||||
return join_path(Dotkit.path, self.spec.architecture,
|
||||
self.spec.format('$_$@$%@$+$#.dk'))
|
||||
|
||||
@property
|
||||
def use_name(self):
|
||||
return self.pkg.spec.format('$_$@$%@$+$#')
|
||||
return self.spec.format('$_$@$%@$+$#')
|
||||
|
||||
|
||||
def _write(self, dk_file):
|
||||
@ -207,7 +207,7 @@ def _write(self, dk_file):
|
||||
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.pkg.prefix)
|
||||
dk_file.write("dk_alter CMAKE_PREFIX_PATH %s\n" % self.spec.prefix)
|
||||
|
||||
|
||||
class TclModule(EnvModule):
|
||||
@ -216,12 +216,12 @@ class TclModule(EnvModule):
|
||||
|
||||
@property
|
||||
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
|
||||
def use_name(self):
|
||||
return self.pkg.spec.format('$_$@$%@$+$#')
|
||||
return self.spec.format('$_$@$%@$+$#')
|
||||
|
||||
|
||||
def _write(self, m_file):
|
||||
@ -244,4 +244,4 @@ def _write(self, m_file):
|
||||
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.pkg.prefix)
|
||||
m_file.write("prepend-path CMAKE_PREFIX_PATH \"%s\"\n" % self.spec.prefix)
|
||||
|
@ -33,7 +33,9 @@ def comma_list(sequence, article=''):
|
||||
return sequence[0]
|
||||
else:
|
||||
out = ', '.join(str(s) for s in sequence[:-1])
|
||||
out += ', '
|
||||
if len(sequence) != 2:
|
||||
out += ',' # oxford comma
|
||||
out += ' '
|
||||
if article:
|
||||
out += article + ' '
|
||||
out += str(sequence[-1])
|
||||
|
Loading…
Reference in New Issue
Block a user