def find(module_type, specs, args): """Retrieve paths or use names of module files""" single_spec = one_spec_or_raise(specs) if args.recurse_dependencies: dependency_specs_to_retrieve = list( single_spec.traverse(root=False, order='post', cover='nodes', deptype=('link', 'run'))) else: dependency_specs_to_retrieve = [] try: modules = [ spack.modules.common.get_module(module_type, spec, args.full_path, required=False) for spec in dependency_specs_to_retrieve ] modules.append( spack.modules.common.get_module(module_type, single_spec, args.full_path, required=True)) except spack.modules.common.ModuleNotFoundError as e: tty.die(e.message) if not all(modules): tty.warn(_missing_modules_warning) modules = list(x for x in modules if x) print(' '.join(modules))
def module_str(specs): modules = [] for x in specs: writer = spack.modules.module_types[module_type](x) if args.full_path: modules.append(writer.layout.filename) else: modules.append(writer.layout.use_name) return ' '.join(modules)
def loads(module_type, specs, args, out=sys.stdout): """Prompt the list of modules associated with a list of specs""" # Get a comprehensive list of specs if args.recurse_dependencies: specs_from_user_constraint = specs[:] specs = [] # FIXME : during module file creation nodes seem to be visited # FIXME : multiple times even if cover='nodes' is given. This # FIXME : work around permits to get a unique list of spec anyhow. # FIXME : (same problem as in spack/modules.py) seen = set() seen_add = seen.add for spec in specs_from_user_constraint: specs.extend([ item for item in spec.traverse(order='post', cover='nodes') if not (item in seen or seen_add(item)) ]) module_cls = spack.modules.module_types[module_type] modules = list() for spec in specs: if os.path.exists(module_cls(spec).layout.filename): modules.append((spec, module_cls(spec).layout.use_name)) elif spec.package.installed_upstream: tty.debug("Using upstream module for {0}".format(spec)) module = spack.modules.common.upstream_module(spec, module_type) modules.append((spec, module.use_name)) module_commands = { 'tcl': 'module load ', 'lmod': 'module load ', 'dotkit': 'use ' } d = { 'command': '' if not args.shell else module_commands[module_type], 'prefix': args.prefix } exclude_set = set(args.exclude) prompt_template = '{comment}{exclude}{command}{prefix}{name}' for spec, mod in modules: d['exclude'] = '## ' if spec.name in exclude_set else '' d['comment'] = '' if not args.shell else '# {0}\n'.format( spec.format()) d['name'] = mod out.write(prompt_template.format(**d)) out.write('\n')