From b71d430af6025cb46ac574e91e516bc5c4caf048 Mon Sep 17 00:00:00 2001 From: alalazo Date: Tue, 28 Jun 2016 17:59:34 +0200 Subject: [PATCH 01/68] module : can regenerate single module files, homogenized cli options spack module : - refresh accepts a constraint - find and refresh share common cli options - ask for confirmation before refreshing - deleting the module file tree is now optional --- lib/spack/spack/cmd/module.py | 136 ++++++++++++++++++++++------------ lib/spack/spack/modules.py | 8 +- share/spack/csh/spack.csh | 8 +- share/spack/setup-env.sh | 8 +- 4 files changed, 101 insertions(+), 59 deletions(-) diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 5292d42225..c71e615d1c 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -32,73 +32,115 @@ from spack.modules import module_types from spack.util.string import * -description = "Manipulate modules and dotkits." +from spack.cmd.uninstall import ask_for_confirmation + +description = "Manipulate module files" + + +def _add_common_arguments(subparser): + type_help = 'Type of module files' + subparser.add_argument('--module-type', help=type_help, required=True, choices=module_types) + constraint_help = 'Optional constraint to select a subset of installed packages' + subparser.add_argument('constraint', nargs='*', help=constraint_help) def setup_parser(subparser): sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='module_command') + # spack module refresh + refresh_parser = sp.add_parser('refresh', help='Regenerate all module files.') + refresh_parser.add_argument('--delete-tree', help='Delete the module file tree before refresh', action='store_true') + _add_common_arguments(refresh_parser) - sp.add_parser('refresh', help='Regenerate all module files.') - + # spack module find find_parser = sp.add_parser('find', help='Find module files for packages.') - find_parser.add_argument('module_type', - help="Type of module to find file for. [" + - '|'.join(module_types) + "]") - find_parser.add_argument('spec', - nargs='+', - help='spec to find a module file for.') + _add_common_arguments(find_parser) -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. +class MultipleMatches(Exception): + pass + + +class NoMatch(Exception): + pass + + +def module_find(mtype, specs, args): + """ + 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. """ - 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] - - specs = spack.installed_db.query(spec) if len(specs) == 0: - tty.die("No installed packages match spec %s" % spec) + raise NoMatch() if len(specs) > 1: - tty.error("Multiple matches for spec %s. Choose one:" % spec) - for s in specs: - sys.stderr.write(s.tree(color=True)) - sys.exit(1) + raise MultipleMatches() - mt = module_types[mtype] - mod = mt(specs[0]) + mod = module_types[mtype](specs.pop()) if not os.path.isfile(mod.file_name): tty.die("No %s module is installed for %s" % (mtype, spec)) print(mod.use_name) -def module_refresh(): - """Regenerate all module files for installed packages known to - spack (some packages may no longer exist).""" - specs = [s for s in spack.installed_db.query(installed=True, known=True)] +def module_refresh(name, specs, args): + """ + Regenerate all module files for installed packages known to + spack (some packages may no longer exist). + """ + # Prompt a message to the user about what is going to change + if not specs: + tty.msg('No package matches your query') + return - for name, cls in module_types.items(): - tty.msg("Regenerating %s module files." % name) - if os.path.isdir(cls.path): - shutil.rmtree(cls.path, ignore_errors=False) - mkdirp(cls.path) - for spec in specs: - cls(spec).write() + tty.msg('You are about to regenerate the {name} module files for the following specs:'.format(name=name)) + for s in specs: + print(s.format(color=True)) + ask_for_confirmation('Do you want to proceed ? ') + + cls = module_types[name] + tty.msg('Regenerating {name} module files'.format(name=name)) + if os.path.isdir(cls.path) and args.delete_tree: + shutil.rmtree(cls.path, ignore_errors=False) + mkdirp(cls.path) + for spec in specs: + cls(spec).write() + +# Qualifiers to be used when querying the db for specs +constraint_qualifiers = { + 'refresh': { + 'installed': True, + 'known': True + }, + 'find': { + } +} + +# Dictionary of callbacks based on the value of module_command +callbacks = { + 'refresh': module_refresh, + 'find': module_find +} def module(parser, args): - if args.module_command == 'refresh': - module_refresh() - - elif args.module_command == 'find': - module_find(args.module_type, args.spec) + module_type = args.module_type + # Query specs from command line + qualifiers = constraint_qualifiers[args.module_command] + specs = [s for s in spack.installed_db.query(**qualifiers)] + constraint = ' '.join(args.constraint) + if constraint: + specs = [x for x in specs if x.satisfies(constraint, strict=True)] + # Call the appropriate function + try: + callbacks[args.module_command](module_type, specs, args) + except MultipleMatches: + message = 'the constraint \'{query}\' matches multiple packages, and this is not allowed in this context' + tty.error(message.format(query=constraint)) + for s in specs: + sys.stderr.write(s.format(color=True) + '\n') + raise SystemExit(1) + except NoMatch: + message = 'the constraint \'{query}\' match no package, and this is not allowed in this context' + tty.die(message.format(query=constraint)) diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index ce46047fa3..068179c0ce 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -454,7 +454,7 @@ def remove(self): class Dotkit(EnvModule): name = 'dotkit' - + path = join_path(spack.share_path, 'dotkit') environment_modifications_formats = { PrependPath: 'dk_alter {name} {value}\n', SetEnv: 'dk_setenv {name} {value}\n' @@ -466,7 +466,7 @@ class Dotkit(EnvModule): @property def file_name(self): - return join_path(spack.share_path, "dotkit", self.spec.architecture, + return join_path(self.path, self.spec.architecture, '%s.dk' % self.use_name) @property @@ -494,7 +494,7 @@ def prerequisite(self, spec): class TclModule(EnvModule): name = 'tcl' - + path = join_path(spack.share_path, "modules") environment_modifications_formats = { PrependPath: 'prepend-path --delim "{delim}" {name} \"{value}\"\n', AppendPath: 'append-path --delim "{delim}" {name} \"{value}\"\n', @@ -514,7 +514,7 @@ class TclModule(EnvModule): @property def file_name(self): - return join_path(spack.share_path, "modules", self.spec.architecture, self.use_name) + return join_path(self.path, self.spec.architecture, self.use_name) @property def header(self): diff --git a/share/spack/csh/spack.csh b/share/spack/csh/spack.csh index d64ce8935b..5acd190449 100644 --- a/share/spack/csh/spack.csh +++ b/share/spack/csh/spack.csh @@ -74,25 +74,25 @@ case unload: # tool's commands to add/remove the result from the environment. switch ($_sp_subcommand) case "use": - set _sp_full_spec = ( "`\spack $_sp_flags module find dotkit $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type dotkit $_sp_spec`" ) if ( $? == 0 ) then use $_sp_module_args $_sp_full_spec endif breaksw case "unuse": - set _sp_full_spec = ( "`\spack $_sp_flags module find dotkit $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type dotkit $_sp_spec`" ) if ( $? == 0 ) then unuse $_sp_module_args $_sp_full_spec endif breaksw case "load": - set _sp_full_spec = ( "`\spack $_sp_flags module find tcl $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type tcl $_sp_spec`" ) if ( $? == 0 ) then module load $_sp_module_args $_sp_full_spec endif breaksw case "unload": - set _sp_full_spec = ( "`\spack $_sp_flags module find tcl $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type tcl $_sp_spec`" ) if ( $? == 0 ) then module unload $_sp_module_args $_sp_full_spec endif diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index 8aa259cf15..3975672e7b 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -105,19 +105,19 @@ function spack { # If spack module command comes back with an error, do nothing. case $_sp_subcommand in "use") - if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module find --module-type dotkit $_sp_spec); then use $_sp_module_args $_sp_full_spec fi ;; "unuse") - if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module find --module-type dotkit $_sp_spec); then unuse $_sp_module_args $_sp_full_spec fi ;; "load") - if _sp_full_spec=$(command spack $_sp_flags module find tcl $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module find --module-type tcl $_sp_spec); then module load $_sp_module_args $_sp_full_spec fi ;; "unload") - if _sp_full_spec=$(command spack $_sp_flags module find tcl $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module find --module-type tcl $_sp_spec); then module unload $_sp_module_args $_sp_full_spec fi ;; esac From 6f69c01915aad8bb2d4b242ab7e5b185adf08b7d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 27 Apr 2016 15:00:47 -0400 Subject: [PATCH 02/68] bootstrap: fall back to the default upstream URL Fixes #352. --- lib/spack/spack/cmd/bootstrap.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index bec11439b5..9fd428e6b1 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -31,6 +31,8 @@ import spack from spack.util.executable import which +_SPACK_UPSTREAM = 'https://github.com/llnl/spack' + description = "Create a new installation of spack in another prefix" def setup_parser(subparser): @@ -40,9 +42,15 @@ def setup_parser(subparser): def get_origin_url(): git_dir = join_path(spack.prefix, '.git') git = which('git', required=True) - origin_url = git( - '--git-dir=%s' % git_dir, 'config', '--get', 'remote.origin.url', - output=str) + try: + origin_url = git( + '--git-dir=%s' % git_dir, + 'config', '--get', 'remote.origin.url', + output=str) + except ProcessError: + origin_url = _SPACK_UPSTREAM + tty.warn('No git repository found; ' + 'using default upstream URL: %s' % origin_url) return origin_url.strip() From 7ec191ce0b82827013485a98db84cd66aa2ca1b4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 May 2016 10:44:01 -0400 Subject: [PATCH 03/68] bootstrap: use the currently checked out branch The `master` branch is not really where Spack development happens, so default to it, but use the user's current branch if it's there. --- lib/spack/spack/cmd/bootstrap.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 9fd428e6b1..16808b30b8 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -39,9 +39,14 @@ def setup_parser(subparser): subparser.add_argument('prefix', help="names of prefix where we should install spack") -def get_origin_url(): +def get_origin_info(): git_dir = join_path(spack.prefix, '.git') git = which('git', required=True) + try: + branch = git('symbolic-ref', '--short', 'HEAD', output=str) + except ProcessError: + branch = 'develop' + tty.warn('No branch found; using default branch: %s' % branch) try: origin_url = git( '--git-dir=%s' % git_dir, @@ -51,11 +56,11 @@ def get_origin_url(): origin_url = _SPACK_UPSTREAM tty.warn('No git repository found; ' 'using default upstream URL: %s' % origin_url) - return origin_url.strip() + return (origin_url.strip(), branch.strip()) def bootstrap(parser, args): - origin_url = get_origin_url() + origin_url, branch = get_origin_info() prefix = args.prefix tty.msg("Fetching spack from origin: %s" % origin_url) @@ -81,8 +86,9 @@ def bootstrap(parser, args): git = which('git', required=True) git('init', '--shared', '-q') git('remote', 'add', 'origin', origin_url) - git('fetch', 'origin', 'master:refs/remotes/origin/master', '-n', '-q') - git('reset', '--hard', 'origin/master', '-q') + git('fetch', 'origin', '%s:refs/remotes/origin/%s' % (branch, branch), + '-n', '-q') + git('reset', '--hard', 'origin/%s' % branch, '-q') tty.msg("Successfully created a new spack in %s" % prefix, "Run %s/bin/spack to use this installation." % prefix) From 89bf5f4045eebdc1f40561dbb70a56e170411c20 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 May 2016 10:49:24 -0400 Subject: [PATCH 04/68] bootstrap: allow using alternate remotes If you want to bootstrap from a fork, the `--remote` option may be used to select it. Also limit the branches to 'develop' and 'master' if the remote is 'origin' since those are the actual integration branches used (other branches on 'origin' are just PR branches). --- lib/spack/spack/cmd/bootstrap.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 16808b30b8..3480c96f39 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -36,10 +36,13 @@ description = "Create a new installation of spack in another prefix" def setup_parser(subparser): + subparser.add_argument( + '-r', '--remote', action='store', dest='remote', + help="name of the remote to bootstrap from", default='origin') subparser.add_argument('prefix', help="names of prefix where we should install spack") -def get_origin_info(): +def get_origin_info(remote): git_dir = join_path(spack.prefix, '.git') git = which('git', required=True) try: @@ -47,10 +50,14 @@ def get_origin_info(): except ProcessError: branch = 'develop' tty.warn('No branch found; using default branch: %s' % branch) + if remote == 'origin' and \ + branch not in ('master', 'develop'): + branch = 'develop' + tty.warn('Unknown branch found; using default branch: %s' % branch) try: origin_url = git( '--git-dir=%s' % git_dir, - 'config', '--get', 'remote.origin.url', + 'config', '--get', 'remote.%s.url' % remote, output=str) except ProcessError: origin_url = _SPACK_UPSTREAM @@ -60,10 +67,10 @@ def get_origin_info(): def bootstrap(parser, args): - origin_url, branch = get_origin_info() + origin_url, branch = get_origin_info(args.remote) prefix = args.prefix - tty.msg("Fetching spack from origin: %s" % origin_url) + tty.msg("Fetching spack from '%s': %s" % (args.remote, origin_url)) if os.path.isfile(prefix): tty.die("There is already a file at %s" % prefix) From e3e94f0ac96db3c1ddd51555fec5a2bf71b867bf Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 May 2016 10:55:14 -0400 Subject: [PATCH 05/68] bootstrap: name the current branch the same as the remote --- lib/spack/spack/cmd/bootstrap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 3480c96f39..04892e258d 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -96,6 +96,7 @@ def bootstrap(parser, args): git('fetch', 'origin', '%s:refs/remotes/origin/%s' % (branch, branch), '-n', '-q') git('reset', '--hard', 'origin/%s' % branch, '-q') + git('checkout', '-B', branch, 'origin/%s' % branch, '-q') tty.msg("Successfully created a new spack in %s" % prefix, "Run %s/bin/spack to use this installation." % prefix) From 5f720f9b7c0e507c2a0335ce9840036ad0b9262f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Jun 2016 10:51:29 -0400 Subject: [PATCH 06/68] flake8: appease the style checker --- lib/spack/spack/cmd/bootstrap.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 04892e258d..60e2bd3a11 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -23,7 +23,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import os -from subprocess import check_call import llnl.util.tty as tty from llnl.util.filesystem import join_path, mkdirp @@ -35,11 +34,14 @@ description = "Create a new installation of spack in another prefix" + def setup_parser(subparser): subparser.add_argument( '-r', '--remote', action='store', dest='remote', help="name of the remote to bootstrap from", default='origin') - subparser.add_argument('prefix', help="names of prefix where we should install spack") + subparser.add_argument( + 'prefix', + help="names of prefix where we should install spack") def get_origin_info(remote): @@ -82,7 +84,8 @@ def bootstrap(parser, args): files_in_the_way = os.listdir(prefix) if files_in_the_way: - tty.die("There are already files there! Delete these files before boostrapping spack.", + tty.die("There are already files there! " + "Delete these files before boostrapping spack.", *files_in_the_way) tty.msg("Installing:", From 1b7eedbb7df7c6dee9ab84217e75dc8ec54dcee1 Mon Sep 17 00:00:00 2001 From: alalazo Date: Thu, 30 Jun 2016 12:56:47 +0200 Subject: [PATCH 07/68] modules.yaml : added hash_length as a new keyword config : - added `hash_length` under the modules section EnvModules : - take into consideration hash_length when constructing `file_name` - added logic to warn and skip module file writing in case of file name clash --- lib/spack/spack/config.py | 5 +++++ lib/spack/spack/modules.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 84179e1469..3a66e9f2a6 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -328,6 +328,11 @@ 'anyOf': [ { 'properties': { + 'hash_length': { + 'type': 'integer', + 'minimum': 0, + 'default': 7 + }, 'whitelist': {'$ref': '#/definitions/array_of_strings'}, 'blacklist': {'$ref': '#/definitions/array_of_strings'}, 'naming_scheme': { diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index 068179c0ce..82016feb84 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -188,6 +188,7 @@ def parse_config_options(module_generator): ##### # Automatic loading loads + module_file_actions['hash_length'] = module_configuration.get('hash_length', 7) module_file_actions['autoload'] = dependencies( module_generator.spec, module_file_actions.get('autoload', 'none')) # Prerequisites @@ -295,7 +296,9 @@ def use_name(self): if constraint in self.spec: suffixes.append(suffix) # Always append the hash to make the module file unique - suffixes.append(self.spec.dag_hash()) + hash_length = configuration.pop('hash_length', 7) + if hash_length != 0: + suffixes.append(self.spec.dag_hash(length=hash_length)) name = '-'.join(suffixes) return name @@ -338,7 +341,7 @@ def blacklisted(self): return False - def write(self): + def write(self, overwrite=False): """ Writes out a module file for this object. @@ -399,6 +402,15 @@ def write(self): for line in self.module_specific_content(module_configuration): module_file_content += line + # Print a warning in case I am accidentally overwriting + # a module file that is already there (name clash) + if not overwrite and os.path.exists(self.file_name): + message = 'Module file already exists : skipping creation\n' + message += 'file : {0.file_name}\n' + message += 'spec : {0.spec}' + tty.warn(message.format(self)) + return + # Dump to file with open(self.file_name, 'w') as f: f.write(module_file_content) From ba87937fffc5843b5f32246571b79d499dafeba3 Mon Sep 17 00:00:00 2001 From: alalazo Date: Thu, 30 Jun 2016 13:44:49 +0200 Subject: [PATCH 08/68] module : added detection of file name clashes --- lib/spack/spack/cmd/module.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index c71e615d1c..4f6b4764b6 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -25,6 +25,7 @@ import os import shutil import sys +import collections import llnl.util.tty as tty import spack.cmd @@ -100,12 +101,32 @@ def module_refresh(name, specs, args): ask_for_confirmation('Do you want to proceed ? ') cls = module_types[name] + + # Detect name clashes + writers = [cls(spec) for spec in specs] + file2writer = collections.defaultdict(list) + for item in writers: + file2writer[item.file_name].append(item) + + if len(file2writer) != len(writers): + message = 'Name clashes detected in module files:\n' + for filename, writer_list in file2writer.items(): + if len(writer_list) > 1: + message += 'file : {0}\n'.format(filename) + for x in writer_list: + message += 'spec : {0}\n'.format(x.spec.format(color=True)) + message += '\n' + tty.error(message) + tty.error('Operation aborted') + raise SystemExit(1) + + # Proceed regenerating module files tty.msg('Regenerating {name} module files'.format(name=name)) if os.path.isdir(cls.path) and args.delete_tree: shutil.rmtree(cls.path, ignore_errors=False) mkdirp(cls.path) - for spec in specs: - cls(spec).write() + for x in writers: + x.write(overwrite=True) # Qualifiers to be used when querying the db for specs constraint_qualifiers = { From a770151359a9c573bfd967f79eab26670d499af0 Mon Sep 17 00:00:00 2001 From: alalazo Date: Thu, 30 Jun 2016 16:49:24 +0200 Subject: [PATCH 09/68] module : minor improvement to output formatting --- bin/spack | 2 +- lib/spack/spack/cmd/module.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/spack b/bin/spack index e9307d1485..9b1276a866 100755 --- a/bin/spack +++ b/bin/spack @@ -77,7 +77,7 @@ import llnl.util.tty as tty from llnl.util.tty.color import * import spack from spack.error import SpackError -import argparse +from external import argparse # Command parsing parser = argparse.ArgumentParser( diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 4f6b4764b6..4f0593e45e 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -95,9 +95,10 @@ def module_refresh(name, specs, args): tty.msg('No package matches your query') return - tty.msg('You are about to regenerate the {name} module files for the following specs:'.format(name=name)) + tty.msg('You are about to regenerate the {name} module files for the following specs:\n'.format(name=name)) for s in specs: print(s.format(color=True)) + print('') ask_for_confirmation('Do you want to proceed ? ') cls = module_types[name] @@ -112,10 +113,9 @@ def module_refresh(name, specs, args): message = 'Name clashes detected in module files:\n' for filename, writer_list in file2writer.items(): if len(writer_list) > 1: - message += 'file : {0}\n'.format(filename) + message += '\nfile : {0}\n'.format(filename) for x in writer_list: message += 'spec : {0}\n'.format(x.spec.format(color=True)) - message += '\n' tty.error(message) tty.error('Operation aborted') raise SystemExit(1) From 6793a54748246efcda302b1fba24239ca5e19c2d Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 30 Jun 2016 23:18:32 +0200 Subject: [PATCH 10/68] --prefix : defaults to empty string --- lib/spack/spack/cmd/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 916bb65646..0d980bc918 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -65,7 +65,7 @@ def setup_parser(subparser): help='Generate shell script (instead of input for module command)') find_parser.add_argument( - '-p', '--prefix', dest='prefix', + '-p', '--prefix', dest='prefix', default='', help='Prepend to module names when issuing module load commands') _add_common_arguments(find_parser) From fe4ef286f2887c27b7fe18a594a11eb4647c5cf3 Mon Sep 17 00:00:00 2001 From: alalazo Date: Fri, 1 Jul 2016 12:38:04 +0200 Subject: [PATCH 11/68] module : added the command 'load-list' --- lib/spack/spack/cmd/module.py | 119 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 0d980bc918..5628ab17a5 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -23,6 +23,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## from __future__ import print_function + import os import shutil import sys @@ -41,7 +42,7 @@ def _add_common_arguments(subparser): type_help = 'Type of module files' - subparser.add_argument('--module-type', help=type_help, required=True, choices=module_types) + subparser.add_argument('--module-type', help=type_help, default='tcl', choices=module_types) constraint_help = 'Optional constraint to select a subset of installed packages' subparser.add_argument('constraint', nargs='*', help=constraint_help) @@ -55,19 +56,26 @@ def setup_parser(subparser): # spack module find find_parser = sp.add_parser('find', help='Find module files for packages.') - find_parser.add_argument( + _add_common_arguments(find_parser) + + # spack module env + loadlist_parser = sp.add_parser( + 'load-list', + help='Prompt the list of modules associated with packages that satisfy a contraint' + ) + loadlist_parser.add_argument( '-r', '--dependencies', action='store_true', dest='recurse_dependencies', help='Recursively traverse dependencies for modules to load.') - find_parser.add_argument( + loadlist_parser.add_argument( '-s', '--shell', action='store_true', dest='shell', help='Generate shell script (instead of input for module command)') - find_parser.add_argument( + loadlist_parser.add_argument( '-p', '--prefix', dest='prefix', default='', help='Prepend to module names when issuing module load commands') - _add_common_arguments(find_parser) + _add_common_arguments(loadlist_parser) class MultipleMatches(Exception): @@ -78,7 +86,45 @@ class NoMatch(Exception): pass -def module_find(mtype, specs, args): +def load_list(mtype, specs, args): + + # 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 multiple + # FIXME : times even if cover='nodes' is given. This work around permits + # FIXME : to get a unique list of spec anyhow. Do we miss a merge + # FIXME : step among nodes that refer to the same package? + # 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 = module_types[mtype] + modules = [(spec, module_cls(spec).use_name) for spec in specs if os.path.exists(module_cls(spec).file_name)] + + module_commands = { + 'tcl': 'module load ', + 'dotkit': 'dotkit use ' + } + + d = { + 'command': '' if not args.shell else module_commands[mtype], + 'prefix': args.prefix + } + + prompt_template = '{comment}{command}{prefix}{name}' + for spec, mod in modules: + d['comment'] = '' if not args.shell else '# {0}\n'.format(spec.format()) + d['name'] = mod + print( prompt_template.format(**d)) + + +def find(mtype, specs, args): """ Look at all installed packages and see if the spec provided matches any. If it does, check whether there is a module file @@ -92,56 +138,12 @@ def module_find(mtype, specs, args): raise MultipleMatches() spec = specs.pop() - if not args.recurse_dependencies: - mod = module_types[mtype](spec) - if not os.path.isfile(mod.file_name): - tty.die("No %s module is installed for %s" % (mtype, spec)) + mod = module_types[mtype](spec) + if not os.path.isfile(mod.file_name): + tty.die("No %s module is installed for %s" % (mtype, spec)) + print(mod.use_name) - print(mod.use_name) - else: - - def _find_modules(spec, modules_list): - """Finds all modules and sub-modules for a spec""" - if str(spec.version) == 'system': - # No Spack module for system-installed packages - return - - if args.recurse_dependencies: - for dep in spec.dependencies.values(): - _find_modules(dep, modules_list) - - mod = module_types[mtype](spec) - if not os.path.isfile(mod.file_name): - tty.die("No %s module is installed for %s" % (mtype, spec)) - modules_list.append((spec, mod)) - # -------------------------------------- - - modules = set() # Modules we will load - seen = set() - - # ----------- Chase down modules for it and all its dependencies - modules_dups = list() - _find_modules(spec, modules_dups) - - # Remove duplicates while keeping order - modules_unique = list() - for spec, mod in modules_dups: - if mod.use_name not in seen: - modules_unique.append((spec,mod)) - seen.add(mod.use_name) - - # Output... - if args.shell: - module_cmd = {'tcl': 'module load', 'dotkit': 'dotkit use'}[mtype] - for spec, mod in modules_unique: - if args.shell: - print('# %s' % spec.format()) - print('%s %s%s' % (module_cmd, args.prefix, mod.use_name)) - else: - print(mod.use_name) - - -def module_refresh(name, specs, args): +def refresh(name, specs, args): """ Regenerate all module files for installed packages known to spack (some packages may no longer exist). @@ -191,13 +193,16 @@ def module_refresh(name, specs, args): 'known': True }, 'find': { + }, + 'load-list':{ } } # Dictionary of callbacks based on the value of module_command callbacks = { - 'refresh': module_refresh, - 'find': module_find + 'refresh': refresh, + 'find': find, + 'load-list': load_list } From f0f7b23c8a6804da6d215e15712c99a6d72e782a Mon Sep 17 00:00:00 2001 From: alalazo Date: Fri, 1 Jul 2016 14:27:55 +0200 Subject: [PATCH 12/68] module : added rm subcommand, encapsulated logic for constraints in argarse.Action subclass --- lib/spack/spack/cmd/module.py | 127 +++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 39 deletions(-) diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 5628ab17a5..6f9ede21ac 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -28,6 +28,7 @@ import shutil import sys import collections +import argparse import llnl.util.tty as tty import spack.cmd @@ -40,33 +41,76 @@ description = "Manipulate module files" +# Qualifiers to be used when querying the db for specs +constraint_qualifiers = { + 'refresh': { + 'installed': True, + 'known': True + }, + 'find': { + }, + 'load-list':{ + }, + 'rm': { + } +} + + +class ConstraintAction(argparse.Action): + qualifiers = {} + + def __call__(self, parser, namespace, values, option_string=None): + # Query specs from command line + d = self.qualifiers.get(namespace.subparser_name, {}) + specs = [s for s in spack.installed_db.query(**d)] + values = ' '.join(values) + if values: + specs = [x for x in specs if x.satisfies(values, strict=True)] + namespace.specs = specs + +# TODO : this needs better wrapping to be extracted +ConstraintAction.qualifiers.update(constraint_qualifiers) + + def _add_common_arguments(subparser): type_help = 'Type of module files' - subparser.add_argument('--module-type', help=type_help, default='tcl', choices=module_types) + subparser.add_argument('-m', '--module-type', help=type_help, default='tcl', choices=module_types) constraint_help = 'Optional constraint to select a subset of installed packages' - subparser.add_argument('constraint', nargs='*', help=constraint_help) + subparser.add_argument('constraint', nargs='*', help=constraint_help, action=ConstraintAction) def setup_parser(subparser): - sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='module_command') + sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='subparser_name') # spack module refresh refresh_parser = sp.add_parser('refresh', help='Regenerate all module files.') refresh_parser.add_argument('--delete-tree', help='Delete the module file tree before refresh', action='store_true') _add_common_arguments(refresh_parser) + refresh_parser.add_argument( + '-y', '--yes-to-all', action='store_true', dest='yes_to_all', + help='Assume "yes" is the answer to every confirmation asked to the user.' + ) # spack module find find_parser = sp.add_parser('find', help='Find module files for packages.') _add_common_arguments(find_parser) - # spack module env + # spack module rm + rm_parser = sp.add_parser('rm', help='Find module files for packages.') + _add_common_arguments(rm_parser) + rm_parser.add_argument( + '-y', '--yes-to-all', action='store_true', dest='yes_to_all', + help='Assume "yes" is the answer to every confirmation asked to the user.' + ) + + # spack module load-list loadlist_parser = sp.add_parser( 'load-list', help='Prompt the list of modules associated with packages that satisfy a contraint' ) loadlist_parser.add_argument( - '-r', '--dependencies', action='store_true', + '-d', '--dependencies', action='store_true', dest='recurse_dependencies', - help='Recursively traverse dependencies for modules to load.') + help='Recursively traverse spec dependencies') loadlist_parser.add_argument( '-s', '--shell', action='store_true', dest='shell', @@ -87,7 +131,6 @@ class NoMatch(Exception): def load_list(mtype, specs, args): - # Get a comprehensive list of specs if args.recurse_dependencies: specs_from_user_constraint = specs[:] @@ -121,7 +164,7 @@ def load_list(mtype, specs, args): for spec, mod in modules: d['comment'] = '' if not args.shell else '# {0}\n'.format(spec.format()) d['name'] = mod - print( prompt_template.format(**d)) + print(prompt_template.format(**d)) def find(mtype, specs, args): @@ -143,7 +186,29 @@ def find(mtype, specs, args): tty.die("No %s module is installed for %s" % (mtype, spec)) print(mod.use_name) -def refresh(name, specs, args): + +def rm(mtype, specs, args): + module_cls = module_types[mtype] + modules = [module_cls(spec) for spec in specs if os.path.exists(module_cls(spec).file_name)] + + if not modules: + tty.msg('No module file matches your query') + return + + # Ask for confirmation + if not args.yes_to_all: + tty.msg('You are about to remove the following module files:\n') + for s in modules: + print(s.file_name) + print('') + ask_for_confirmation('Do you want to proceed ? ') + + # Remove the module files + for s in modules: + s.remove() + + +def refresh(mtype, specs, args): """ Regenerate all module files for installed packages known to spack (some packages may no longer exist). @@ -153,13 +218,14 @@ def refresh(name, specs, args): tty.msg('No package matches your query') return - tty.msg('You are about to regenerate the {name} module files for the following specs:\n'.format(name=name)) - for s in specs: - print(s.format(color=True)) - print('') - ask_for_confirmation('Do you want to proceed ? ') + if not args.yes_to_all: + tty.msg('You are about to regenerate the {name} module files for the following specs:\n'.format(name=mtype)) + for s in specs: + print(s.format(color=True)) + print('') + ask_for_confirmation('Do you want to proceed ? ') - cls = module_types[name] + cls = module_types[mtype] # Detect name clashes writers = [cls(spec) for spec in specs] @@ -179,48 +245,31 @@ def refresh(name, specs, args): raise SystemExit(1) # Proceed regenerating module files - tty.msg('Regenerating {name} module files'.format(name=name)) + tty.msg('Regenerating {name} module files'.format(name=mtype)) if os.path.isdir(cls.path) and args.delete_tree: shutil.rmtree(cls.path, ignore_errors=False) mkdirp(cls.path) for x in writers: x.write(overwrite=True) -# Qualifiers to be used when querying the db for specs -constraint_qualifiers = { - 'refresh': { - 'installed': True, - 'known': True - }, - 'find': { - }, - 'load-list':{ - } -} - -# Dictionary of callbacks based on the value of module_command +# Dictionary of callbacks based on the value of subparser_name callbacks = { 'refresh': refresh, 'find': find, - 'load-list': load_list + 'load-list': load_list, + 'rm': rm } def module(parser, args): module_type = args.module_type - # Query specs from command line - qualifiers = constraint_qualifiers[args.module_command] - specs = [s for s in spack.installed_db.query(**qualifiers)] - constraint = ' '.join(args.constraint) - if constraint: - specs = [x for x in specs if x.satisfies(constraint, strict=True)] - # Call the appropriate function + constraint = args.constraint try: - callbacks[args.module_command](module_type, specs, args) + callbacks[args.subparser_name](module_type, args.specs, args) except MultipleMatches: message = 'the constraint \'{query}\' matches multiple packages, and this is not allowed in this context' tty.error(message.format(query=constraint)) - for s in specs: + for s in args.specs: sys.stderr.write(s.format(color=True) + '\n') raise SystemExit(1) except NoMatch: From 0e171127b99e06d05631fe6391cb20b813bc1747 Mon Sep 17 00:00:00 2001 From: alalazo Date: Fri, 1 Jul 2016 14:30:01 +0200 Subject: [PATCH 13/68] module : reverted typo introduced in a previous commit --- bin/spack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/spack b/bin/spack index 9b1276a866..e9307d1485 100755 --- a/bin/spack +++ b/bin/spack @@ -77,7 +77,7 @@ import llnl.util.tty as tty from llnl.util.tty.color import * import spack from spack.error import SpackError -from external import argparse +import argparse # Command parsing parser = argparse.ArgumentParser( From d10fceaacc7a1f8349f249c8700381f858b359b1 Mon Sep 17 00:00:00 2001 From: alalazo Date: Fri, 1 Jul 2016 23:06:07 +0200 Subject: [PATCH 14/68] spack commands : refactoring of cli arguments and common utiities. Implemented suggestions on `spack module loads` - Common cli arguments now are in their own module - Moved utilities that can be reused by different commands into spack.cmd.__init__.py - Modifications to `spack module loads` --- lib/spack/spack/cmd/__init__.py | 101 ++++++++++++++++- lib/spack/spack/cmd/common/__init__.py | 24 ++++ lib/spack/spack/cmd/common/arguments.py | 88 +++++++++++++++ lib/spack/spack/cmd/find.py | 85 +------------- lib/spack/spack/cmd/module.py | 142 +++++++++--------------- lib/spack/spack/cmd/uninstall.py | 20 +--- lib/spack/spack/test/cmd/find.py | 6 +- lib/spack/spack/util/pattern.py | 6 + 8 files changed, 272 insertions(+), 200 deletions(-) create mode 100644 lib/spack/spack/cmd/common/__init__.py create mode 100644 lib/spack/spack/cmd/common/arguments.py diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 672999159c..02f6f5b98a 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -27,11 +27,12 @@ import sys import llnl.util.tty as tty -from llnl.util.lang import attr_setdefault - import spack -import spack.spec import spack.config +import spack.spec +from llnl.util.lang import * +from llnl.util.tty.colify import * +from llnl.util.tty.color import * # # Settings for commands that modify configuration @@ -145,3 +146,97 @@ def disambiguate_spec(spec): tty.die(*args) return matching_specs[0] + + +def ask_for_confirmation(message): + while True: + tty.msg(message + '[y/n]') + choice = raw_input().lower() + if choice == 'y': + break + elif choice == 'n': + raise SystemExit('Operation aborted') + tty.warn('Please reply either "y" or "n"') + + +def gray_hash(spec, length): + return colorize('@K{%s}' % spec.dag_hash(length)) + + +def display_specs(specs, **kwargs): + mode = kwargs.get('mode', 'short') + hashes = kwargs.get('long', False) + namespace = kwargs.get('namespace', False) + flags = kwargs.get('show_flags', False) + variants = kwargs.get('variants', False) + + hlen = 7 + if kwargs.get('very_long', False): + hashes = True + hlen = None + + nfmt = '.' if namespace else '_' + ffmt = '$%+' if flags else '' + vfmt = '$+' if variants else '' + format_string = '$%s$@%s%s' % (nfmt, ffmt, vfmt) + + # Make a dict with specs keyed by architecture and compiler. + index = index_by(specs, ('architecture', 'compiler')) + + # Traverse the index and print out each package + for i, (architecture, compiler) in enumerate(sorted(index)): + if i > 0: + print + + header = "%s{%s} / %s{%s}" % (spack.spec.architecture_color, + architecture, spack.spec.compiler_color, + compiler) + tty.hline(colorize(header), char='-') + + specs = index[(architecture, compiler)] + specs.sort() + + abbreviated = [s.format(format_string, color=True) for s in specs] + if mode == 'paths': + # Print one spec per line along with prefix path + width = max(len(s) for s in abbreviated) + width += 2 + format = " %%-%ds%%s" % width + + for abbrv, spec in zip(abbreviated, specs): + if hashes: + print(gray_hash(spec, hlen), ) + print(format % (abbrv, spec.prefix)) + + elif mode == 'deps': + for spec in specs: + print(spec.tree( + format=format_string, + color=True, + indent=4, + prefix=(lambda s: gray_hash(s, hlen)) if hashes else None)) + + elif mode == 'short': + # Print columns of output if not printing flags + if not flags: + + def fmt(s): + string = "" + if hashes: + string += gray_hash(s, hlen) + ' ' + string += s.format('$-%s$@%s' % (nfmt, vfmt), color=True) + + return string + + colify(fmt(s) for s in specs) + # Print one entry per line if including flags + else: + for spec in specs: + # Print the hash if necessary + hsh = gray_hash(spec, hlen) + ' ' if hashes else '' + print(hsh + spec.format(format_string, color=True) + '\n') + + else: + raise ValueError( + "Invalid mode for display_specs: %s. Must be one of (paths," + "deps, short)." % mode) # NOQA: ignore=E501 diff --git a/lib/spack/spack/cmd/common/__init__.py b/lib/spack/spack/cmd/common/__init__.py new file mode 100644 index 0000000000..ed1ec23bca --- /dev/null +++ b/lib/spack/spack/cmd/common/__init__.py @@ -0,0 +1,24 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py new file mode 100644 index 0000000000..a50bac5ac5 --- /dev/null +++ b/lib/spack/spack/cmd/common/arguments.py @@ -0,0 +1,88 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## + +import argparse + +import spack.modules +from spack.util.pattern import Bunch +__all__ = ['add_common_arguments'] + +_arguments = {} + + +def add_common_arguments(parser, list_of_arguments): + for argument in list_of_arguments: + if argument not in _arguments: + message = 'Trying to add the non existing argument "{0}" to a command' + raise KeyError(message.format(argument)) + x = _arguments[argument] + parser.add_argument(*x.flags, **x.kwargs) + + +class ConstraintAction(argparse.Action): + """Constructs a list of specs based on a constraint given on the command line + + An instance of this class is supposed to be used as an argument action in a parser. + + It will read a constraint and will attach a list of matching specs to the namespace + """ + qualifiers = {} + + def __call__(self, parser, namespace, values, option_string=None): + # Query specs from command line + d = self.qualifiers.get(namespace.subparser_name, {}) + specs = [s for s in spack.installed_db.query(**d)] + values = ' '.join(values) + if values: + specs = [x for x in specs if x.satisfies(values, strict=True)] + namespace.specs = specs + +_arguments['constraint'] = Bunch(flags=('constraint',), + kwargs={ + 'nargs': '*', + 'help': 'Optional constraint to select a subset of installed packages', + 'action': ConstraintAction + }) + +_arguments['module_type'] = Bunch(flags=('-m', '--module-type'), + kwargs={ + 'help': 'Type of module files', + 'default': 'tcl', + 'choices': spack.modules.module_types + }) + +_arguments['yes_to_all'] = Bunch(flags=('-y', '--yes-to-all'), + kwargs={ + 'action': 'store_true', + 'dest': 'yes_to_all', + 'help': 'Assume "yes" is the answer to every confirmation asked to the user.' + }) + +_arguments['recurse_dependencies'] = Bunch(flags=('-r', '--dependencies'), + kwargs={ + 'action': 'store_true', + 'dest': 'recurse_dependencies', + 'help': 'Recursively traverse spec dependencies' + }) diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index 3ec671f93f..d3ea38c573 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -31,7 +31,7 @@ from llnl.util.lang import * from llnl.util.tty.colify import * from llnl.util.tty.color import * -from llnl.util.lang import * +from spack.cmd import display_specs description = "Find installed spack packages" @@ -104,89 +104,6 @@ def setup_parser(subparser): help='optional specs to filter results') -def gray_hash(spec, length): - return colorize('@K{%s}' % spec.dag_hash(length)) - - -def display_specs(specs, **kwargs): - mode = kwargs.get('mode', 'short') - hashes = kwargs.get('long', False) - namespace = kwargs.get('namespace', False) - flags = kwargs.get('show_flags', False) - variants = kwargs.get('variants', False) - - hlen = 7 - if kwargs.get('very_long', False): - hashes = True - hlen = None - - nfmt = '.' if namespace else '_' - ffmt = '$%+' if flags else '' - vfmt = '$+' if variants else '' - format_string = '$%s$@%s%s' % (nfmt, ffmt, vfmt) - - # Make a dict with specs keyed by architecture and compiler. - index = index_by(specs, ('architecture', 'compiler')) - - # Traverse the index and print out each package - for i, (architecture, compiler) in enumerate(sorted(index)): - if i > 0: - print - - header = "%s{%s} / %s{%s}" % (spack.spec.architecture_color, - architecture, spack.spec.compiler_color, - compiler) - tty.hline(colorize(header), char='-') - - specs = index[(architecture, compiler)] - specs.sort() - - abbreviated = [s.format(format_string, color=True) for s in specs] - if mode == 'paths': - # Print one spec per line along with prefix path - width = max(len(s) for s in abbreviated) - width += 2 - format = " %%-%ds%%s" % width - - for abbrv, spec in zip(abbreviated, specs): - if hashes: - print(gray_hash(spec, hlen), ) - print(format % (abbrv, spec.prefix)) - - elif mode == 'deps': - for spec in specs: - print(spec.tree( - format=format_string, - color=True, - indent=4, - prefix=(lambda s: gray_hash(s, hlen)) if hashes else None)) - - elif mode == 'short': - # Print columns of output if not printing flags - if not flags: - - def fmt(s): - string = "" - if hashes: - string += gray_hash(s, hlen) + ' ' - string += s.format('$-%s$@%s' % (nfmt, vfmt), color=True) - - return string - - colify(fmt(s) for s in specs) - # Print one entry per line if including flags - else: - for spec in specs: - # Print the hash if necessary - hsh = gray_hash(spec, hlen) + ' ' if hashes else '' - print(hsh + spec.format(format_string, color=True) + '\n') - - else: - raise ValueError( - "Invalid mode for display_specs: %s. Must be one of (paths," - "deps, short)." % mode) # NOQA: ignore=E501 - - def query_arguments(args): # Check arguments if args.explicit and args.implicit: diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 6f9ede21ac..2c47e9fcb6 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -24,102 +24,59 @@ ############################################################################## from __future__ import print_function +import collections import os import shutil import sys -import collections -import argparse import llnl.util.tty as tty import spack.cmd +import spack.cmd.common.arguments as arguments from llnl.util.filesystem import mkdirp from spack.modules import module_types -from spack.util.string import * - -from spack.cmd.uninstall import ask_for_confirmation +#from spack.util.string import * description = "Manipulate module files" - -# Qualifiers to be used when querying the db for specs -constraint_qualifiers = { - 'refresh': { - 'installed': True, - 'known': True - }, - 'find': { - }, - 'load-list':{ - }, - 'rm': { - } -} +callbacks = {} -class ConstraintAction(argparse.Action): - qualifiers = {} - - def __call__(self, parser, namespace, values, option_string=None): - # Query specs from command line - d = self.qualifiers.get(namespace.subparser_name, {}) - specs = [s for s in spack.installed_db.query(**d)] - values = ' '.join(values) - if values: - specs = [x for x in specs if x.satisfies(values, strict=True)] - namespace.specs = specs - -# TODO : this needs better wrapping to be extracted -ConstraintAction.qualifiers.update(constraint_qualifiers) - - -def _add_common_arguments(subparser): - type_help = 'Type of module files' - subparser.add_argument('-m', '--module-type', help=type_help, default='tcl', choices=module_types) - constraint_help = 'Optional constraint to select a subset of installed packages' - subparser.add_argument('constraint', nargs='*', help=constraint_help, action=ConstraintAction) +def subcommand(subparser_name): + """Registers a function in the callbacks dictionary""" + def decorator(callback): + callbacks[subparser_name] = callback + return callback + return decorator def setup_parser(subparser): sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='subparser_name') # spack module refresh - refresh_parser = sp.add_parser('refresh', help='Regenerate all module files.') + refresh_parser = sp.add_parser('refresh', help='Regenerate module files') refresh_parser.add_argument('--delete-tree', help='Delete the module file tree before refresh', action='store_true') - _add_common_arguments(refresh_parser) - refresh_parser.add_argument( - '-y', '--yes-to-all', action='store_true', dest='yes_to_all', - help='Assume "yes" is the answer to every confirmation asked to the user.' - ) + arguments.add_common_arguments(refresh_parser, ['constraint', 'module_type', 'yes_to_all']) # spack module find - find_parser = sp.add_parser('find', help='Find module files for packages.') - _add_common_arguments(find_parser) + find_parser = sp.add_parser('find', help='Find module files for packages') + arguments.add_common_arguments(find_parser, ['constraint', 'module_type']) # spack module rm - rm_parser = sp.add_parser('rm', help='Find module files for packages.') - _add_common_arguments(rm_parser) - rm_parser.add_argument( - '-y', '--yes-to-all', action='store_true', dest='yes_to_all', - help='Assume "yes" is the answer to every confirmation asked to the user.' + rm_parser = sp.add_parser('rm', help='Remove module files') + arguments.add_common_arguments(rm_parser, ['constraint', 'module_type', 'yes_to_all']) + + # spack module loads + loads_parser = sp.add_parser( + 'loads', + help='Prompt the list of modules associated with packages that satisfy a constraint' ) + loads_parser.add_argument( + '--input-only', action='store_false', dest='shell', + help='Generate input for module command (instead of a shell script)') - # spack module load-list - loadlist_parser = sp.add_parser( - 'load-list', - help='Prompt the list of modules associated with packages that satisfy a contraint' - ) - loadlist_parser.add_argument( - '-d', '--dependencies', action='store_true', - dest='recurse_dependencies', - help='Recursively traverse spec dependencies') - - loadlist_parser.add_argument( - '-s', '--shell', action='store_true', dest='shell', - help='Generate shell script (instead of input for module command)') - - loadlist_parser.add_argument( + loads_parser.add_argument( '-p', '--prefix', dest='prefix', default='', help='Prepend to module names when issuing module load commands') - _add_common_arguments(loadlist_parser) + arguments.add_common_arguments(loads_parser, ['constraint', 'module_type', 'recurse_dependencies']) class MultipleMatches(Exception): @@ -129,8 +86,8 @@ class MultipleMatches(Exception): class NoMatch(Exception): pass - -def load_list(mtype, specs, args): +@subcommand('loads') +def loads(mtype, specs, args): # Get a comprehensive list of specs if args.recurse_dependencies: specs_from_user_constraint = specs[:] @@ -166,7 +123,7 @@ def load_list(mtype, specs, args): d['name'] = mod print(prompt_template.format(**d)) - +@subcommand('find') def find(mtype, specs, args): """ Look at all installed packages and see if the spec provided @@ -187,9 +144,11 @@ def find(mtype, specs, args): print(mod.use_name) +@subcommand('rm') def rm(mtype, specs, args): module_cls = module_types[mtype] - modules = [module_cls(spec) for spec in specs if os.path.exists(module_cls(spec).file_name)] + specs_with_modules = [spec for spec in specs if os.path.exists(module_cls(spec).file_name)] + modules = [module_cls(spec) for spec in specs_with_modules] if not modules: tty.msg('No module file matches your query') @@ -197,21 +156,20 @@ def rm(mtype, specs, args): # Ask for confirmation if not args.yes_to_all: - tty.msg('You are about to remove the following module files:\n') - for s in modules: - print(s.file_name) + tty.msg('You are about to remove {0} module files the following specs:\n'.format(mtype)) + spack.cmd.display_specs(specs_with_modules, long=True) print('') - ask_for_confirmation('Do you want to proceed ? ') + spack.cmd.ask_for_confirmation('Do you want to proceed ? ') # Remove the module files for s in modules: s.remove() +@subcommand('refresh') def refresh(mtype, specs, args): - """ - Regenerate all module files for installed packages known to - spack (some packages may no longer exist). + """Regenerate module files for installed packages + """ # Prompt a message to the user about what is going to change if not specs: @@ -219,11 +177,10 @@ def refresh(mtype, specs, args): return if not args.yes_to_all: - tty.msg('You are about to regenerate the {name} module files for the following specs:\n'.format(name=mtype)) - for s in specs: - print(s.format(color=True)) + tty.msg('You are about to regenerate {name} module files for the following specs:\n'.format(name=mtype)) + spack.cmd.display_specs(specs, long=True) print('') - ask_for_confirmation('Do you want to proceed ? ') + spack.cmd.ask_for_confirmation('Do you want to proceed ? ') cls = module_types[mtype] @@ -252,16 +209,17 @@ def refresh(mtype, specs, args): for x in writers: x.write(overwrite=True) -# Dictionary of callbacks based on the value of subparser_name -callbacks = { - 'refresh': refresh, - 'find': find, - 'load-list': load_list, - 'rm': rm -} - def module(parser, args): + # Qualifiers to be used when querying the db for specs + constraint_qualifiers = { + 'refresh': { + 'installed': True, + 'known': True + }, + } + arguments.ConstraintAction.qualifiers.update(constraint_qualifiers) + module_type = args.module_type constraint = args.constraint try: diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py index a6f08d09ed..92de33873b 100644 --- a/lib/spack/spack/cmd/uninstall.py +++ b/lib/spack/spack/cmd/uninstall.py @@ -30,7 +30,6 @@ import spack import spack.cmd import spack.repository -from spack.cmd.find import display_specs description = "Remove an installed package" @@ -47,17 +46,6 @@ } -def ask_for_confirmation(message): - while True: - tty.msg(message + '[y/n]') - choice = raw_input().lower() - if choice == 'y': - break - elif choice == 'n': - raise SystemExit('Operation aborted') - tty.warn('Please reply either "y" or "n"') - - def setup_parser(subparser): subparser.add_argument( '-f', '--force', action='store_true', dest='force', @@ -99,7 +87,7 @@ def concretize_specs(specs, allow_multiple_matches=False, force=False): if not allow_multiple_matches and len(matching) > 1: tty.error("%s matches multiple packages:" % spec) print() - display_specs(matching, **display_args) + spack.cmd.display_specs(matching, **display_args) print() has_errors = True @@ -179,7 +167,7 @@ def uninstall(parser, args): tty.error("Will not uninstall %s" % spec.format("$_$@$%@$#", color=True)) print('') print("The following packages depend on it:") - display_specs(lst, **display_args) + spack.cmd.display_specs(lst, **display_args) print('') has_error = True elif args.dependents: @@ -193,9 +181,9 @@ def uninstall(parser, args): if not args.yes_to_all: tty.msg("The following packages will be uninstalled : ") print('') - display_specs(uninstall_list, **display_args) + spack.cmd.display_specs(uninstall_list, **display_args) print('') - ask_for_confirmation('Do you want to proceed ? ') + spack.cmd.ask_for_confirmation('Do you want to proceed ? ') # Uninstall everything on the list do_uninstall(uninstall_list, args.force) diff --git a/lib/spack/spack/test/cmd/find.py b/lib/spack/spack/test/cmd/find.py index 371e9650e0..fa82db7733 100644 --- a/lib/spack/spack/test/cmd/find.py +++ b/lib/spack/spack/test/cmd/find.py @@ -27,11 +27,7 @@ import spack.cmd.find import unittest - -class Bunch(object): - - def __init__(self, **kwargs): - self.__dict__.update(kwargs) +from spack.util.pattern import Bunch class FindTest(unittest.TestCase): diff --git a/lib/spack/spack/util/pattern.py b/lib/spack/spack/util/pattern.py index 6d4bcb1039..6af39c87d8 100644 --- a/lib/spack/spack/util/pattern.py +++ b/lib/spack/spack/util/pattern.py @@ -114,3 +114,9 @@ def getter(*args, **kwargs): return wrapper_class return cls_decorator + + +class Bunch(object): + """Carries a bunch of named attributes (from Alex Martelli bunch)""" + def __init__(self, **kwargs): + self.__dict__.update(kwargs) From 3100c5948a7278bd1429c316a1c78264b5fafcb3 Mon Sep 17 00:00:00 2001 From: alalazo Date: Sat, 2 Jul 2016 12:14:30 +0200 Subject: [PATCH 15/68] module : added unit tests --- lib/spack/spack/cmd/module.py | 28 ++++++---- lib/spack/spack/test/__init__.py | 2 +- lib/spack/spack/test/cmd/module.py | 82 ++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 lib/spack/spack/test/cmd/module.py diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 2c47e9fcb6..374e71a4d8 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -32,12 +32,16 @@ import llnl.util.tty as tty import spack.cmd import spack.cmd.common.arguments as arguments -from llnl.util.filesystem import mkdirp +import llnl.util.filesystem as filesystem from spack.modules import module_types -#from spack.util.string import * description = "Manipulate module files" +# Dictionary that will be populated with the list of sub-commands +# Each sub-command must be callable and accept 3 arguments : +# - mtype : the type of the module file +# - specs : the list of specs to be processed +# - args : namespace containing the parsed command line arguments callbacks = {} @@ -51,6 +55,7 @@ def decorator(callback): def setup_parser(subparser): sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='subparser_name') + # spack module refresh refresh_parser = sp.add_parser('refresh', help='Regenerate module files') refresh_parser.add_argument('--delete-tree', help='Delete the module file tree before refresh', action='store_true') @@ -71,11 +76,12 @@ def setup_parser(subparser): ) loads_parser.add_argument( '--input-only', action='store_false', dest='shell', - help='Generate input for module command (instead of a shell script)') - + help='Generate input for module command (instead of a shell script)' + ) loads_parser.add_argument( '-p', '--prefix', dest='prefix', default='', - help='Prepend to module names when issuing module load commands') + help='Prepend to module names when issuing module load commands' + ) arguments.add_common_arguments(loads_parser, ['constraint', 'module_type', 'recurse_dependencies']) @@ -86,8 +92,10 @@ class MultipleMatches(Exception): class NoMatch(Exception): pass + @subcommand('loads') def loads(mtype, specs, args): + """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[:] @@ -123,6 +131,7 @@ def loads(mtype, specs, args): d['name'] = mod print(prompt_template.format(**d)) + @subcommand('find') def find(mtype, specs, args): """ @@ -146,13 +155,14 @@ def find(mtype, specs, args): @subcommand('rm') def rm(mtype, specs, args): + """Deletes module files associated with items in specs""" module_cls = module_types[mtype] specs_with_modules = [spec for spec in specs if os.path.exists(module_cls(spec).file_name)] modules = [module_cls(spec) for spec in specs_with_modules] if not modules: tty.msg('No module file matches your query') - return + raise SystemExit(1) # Ask for confirmation if not args.yes_to_all: @@ -168,9 +178,7 @@ def rm(mtype, specs, args): @subcommand('refresh') def refresh(mtype, specs, args): - """Regenerate module files for installed packages - - """ + """Regenerate module files for item in specs""" # Prompt a message to the user about what is going to change if not specs: tty.msg('No package matches your query') @@ -205,7 +213,7 @@ def refresh(mtype, specs, args): tty.msg('Regenerating {name} module files'.format(name=mtype)) if os.path.isdir(cls.path) and args.delete_tree: shutil.rmtree(cls.path, ignore_errors=False) - mkdirp(cls.path) + filesystem.mkdirp(cls.path) for x in writers: x.write(overwrite=True) diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index fb91f24721..dfbd73b91f 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -40,7 +40,7 @@ 'cc', 'link_tree', 'spec_yaml', 'optional_deps', 'make_executable', 'configure_guess', 'lock', 'database', 'namespace_trie', 'yaml', 'sbang', 'environment', 'cmd.find', - 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd'] + 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd', 'cmd.module'] def list_tests(): diff --git a/lib/spack/spack/test/cmd/module.py b/lib/spack/spack/test/cmd/module.py new file mode 100644 index 0000000000..52628f5b3b --- /dev/null +++ b/lib/spack/spack/test/cmd/module.py @@ -0,0 +1,82 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +import argparse +import os.path + +import spack.cmd.module as module +import spack.modules as modules +import spack.test.mock_database + + +class TestModule(spack.test.mock_database.MockDatabase): + def _get_module_files(self, args): + return [ + modules.module_types[args.module_type](spec).file_name for spec in args.specs + ] + + def test_module_common_operations(self): + parser = argparse.ArgumentParser() + module.setup_parser(parser) + # Try to remove a non existing module [tcl] + args = parser.parse_args(['rm', 'doesnotexist']) + self.assertRaises(SystemExit, module.module, parser, args) + # Remove existing modules [tcl] + args = parser.parse_args(['rm', '-y', 'mpileaks']) + module_files = self._get_module_files(args) + for item in module_files: + self.assertTrue(os.path.exists(item)) + module.module(parser, args) + for item in module_files: + self.assertFalse(os.path.exists(item)) + # Add them back [tcl] + args = parser.parse_args(['refresh', '-y', 'mpileaks']) + module.module(parser, args) + for item in module_files: + self.assertTrue(os.path.exists(item)) + # TODO : test the --delete-tree option + # TODO : this requires having a separate directory for test modules + # Try to find a module with multiple matches + args = parser.parse_args(['find', 'mpileaks']) + self.assertRaises(SystemExit, module.module, parser, args) + # Try to find a module with no matches + args = parser.parse_args(['find', 'doesnotexist']) + self.assertRaises(SystemExit, module.module, parser, args) + # Try to find a module + args = parser.parse_args(['find', 'libelf']) + module.module(parser, args) + # Remove existing modules [dotkit] + args = parser.parse_args(['rm', '-y', '-m', 'dotkit', 'mpileaks']) + module_files = self._get_module_files(args) + for item in module_files: + self.assertTrue(os.path.exists(item)) + module.module(parser, args) + for item in module_files: + self.assertFalse(os.path.exists(item)) + # Add them back [dotkit] + args = parser.parse_args(['refresh', '-y', '-m', 'dotkit', 'mpileaks']) + module.module(parser, args) + for item in module_files: + self.assertTrue(os.path.exists(item)) + # TODO : add tests for loads and find to check the prompt format From 6d988dde8dcc2d666631151e5dab429811ffed37 Mon Sep 17 00:00:00 2001 From: alalazo Date: Sat, 2 Jul 2016 12:54:36 +0200 Subject: [PATCH 16/68] qa : fixed flake8 issues --- lib/spack/spack/cmd/__init__.py | 19 +++---- lib/spack/spack/cmd/common/arguments.py | 64 ++++++++++++---------- lib/spack/spack/cmd/module.py | 46 ++++++++++------ lib/spack/spack/cmd/uninstall.py | 42 +++++++++------ lib/spack/spack/modules.py | 4 +- lib/spack/spack/test/__init__.py | 6 ++- lib/spack/spack/test/cmd/module.py | 3 +- lib/spack/spack/util/pattern.py | 72 +++++++++++++++---------- 8 files changed, 153 insertions(+), 103 deletions(-) diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 02f6f5b98a..230115df50 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -37,7 +37,8 @@ # # Settings for commands that modify configuration # -# Commands that modify confguration By default modify the *highest* priority scope. +# Commands that modify confguration By default modify the *highest* +# priority scope. default_modify_scope = spack.config.highest_precedence_scope().name # Commands that list confguration list *all* scopes by default. default_list_scope = None @@ -49,7 +50,7 @@ ignore_files = r'^\.|^__init__.py$|^#' SETUP_PARSER = "setup_parser" -DESCRIPTION = "description" +DESCRIPTION = "description" command_path = os.path.join(spack.lib_path, "spack", "cmd") @@ -72,7 +73,7 @@ def get_module(name): module_name, fromlist=[name, SETUP_PARSER, DESCRIPTION], level=0) - attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op + attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") fn_name = get_cmd_function_name(name) @@ -102,17 +103,17 @@ def parse_specs(args, **kwargs): specs = spack.spec.parse(args) for spec in specs: if concretize: - spec.concretize() # implies normalize + spec.concretize() # implies normalize elif normalize: spec.normalize() return specs - except spack.parse.ParseError, e: + except spack.parse.ParseError as e: tty.error(e.message, e.string, e.pos * " " + "^") sys.exit(1) - except spack.spec.SpecError, e: + except spack.spec.SpecError as e: tty.error(e.message) sys.exit(1) @@ -128,7 +129,7 @@ def elide_list(line_list, max_num=10): [1, 2, 3, '...', 6] """ if len(line_list) > max_num: - return line_list[:max_num-1] + ['...'] + line_list[-1:] + return line_list[:max_num - 1] + ['...'] + line_list[-1:] else: return line_list @@ -139,8 +140,8 @@ def disambiguate_spec(spec): tty.die("Spec '%s' matches no installed packages." % spec) elif len(matching_specs) > 1: - args = ["%s matches multiple packages." % spec, - "Matching packages:"] + args = ["%s matches multiple packages." % spec, + "Matching packages:"] args += [" " + str(s) for s in matching_specs] args += ["Use a more specific spec."] tty.die(*args) diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py index a50bac5ac5..af04170824 100644 --- a/lib/spack/spack/cmd/common/arguments.py +++ b/lib/spack/spack/cmd/common/arguments.py @@ -35,7 +35,7 @@ def add_common_arguments(parser, list_of_arguments): for argument in list_of_arguments: if argument not in _arguments: - message = 'Trying to add the non existing argument "{0}" to a command' + message = 'Trying to add the non existing argument "{0}" to a command' # NOQA: ignore=E501 raise KeyError(message.format(argument)) x = _arguments[argument] parser.add_argument(*x.flags, **x.kwargs) @@ -44,9 +44,9 @@ def add_common_arguments(parser, list_of_arguments): class ConstraintAction(argparse.Action): """Constructs a list of specs based on a constraint given on the command line - An instance of this class is supposed to be used as an argument action in a parser. - - It will read a constraint and will attach a list of matching specs to the namespace + An instance of this class is supposed to be used as an argument action + in a parser. It will read a constraint and will attach a list of matching + specs to the namespace """ qualifiers = {} @@ -59,30 +59,38 @@ def __call__(self, parser, namespace, values, option_string=None): specs = [x for x in specs if x.satisfies(values, strict=True)] namespace.specs = specs -_arguments['constraint'] = Bunch(flags=('constraint',), - kwargs={ - 'nargs': '*', - 'help': 'Optional constraint to select a subset of installed packages', - 'action': ConstraintAction - }) +parms = Bunch( + flags=('constraint',), + kwargs={ + 'nargs': '*', + 'help': 'Constraint to select a subset of installed packages', + 'action': ConstraintAction + }) +_arguments['constraint'] = parms -_arguments['module_type'] = Bunch(flags=('-m', '--module-type'), - kwargs={ - 'help': 'Type of module files', - 'default': 'tcl', - 'choices': spack.modules.module_types - }) +parms = Bunch( + flags=('-m', '--module-type'), + kwargs={ + 'help': 'Type of module files', + 'default': 'tcl', + 'choices': spack.modules.module_types + }) +_arguments['module_type'] = parms -_arguments['yes_to_all'] = Bunch(flags=('-y', '--yes-to-all'), - kwargs={ - 'action': 'store_true', - 'dest': 'yes_to_all', - 'help': 'Assume "yes" is the answer to every confirmation asked to the user.' - }) +parms = Bunch( + flags=('-y', '--yes-to-all'), + kwargs={ + 'action': 'store_true', + 'dest': 'yes_to_all', + 'help': 'Assume "yes" is the answer to every confirmation asked to the user.' # NOQA: ignore=E501 + }) +_arguments['yes_to_all'] = parms -_arguments['recurse_dependencies'] = Bunch(flags=('-r', '--dependencies'), - kwargs={ - 'action': 'store_true', - 'dest': 'recurse_dependencies', - 'help': 'Recursively traverse spec dependencies' - }) +parms = Bunch( + flags=('-r', '--dependencies'), + kwargs={ + 'action': 'store_true', + 'dest': 'recurse_dependencies', + 'help': 'Recursively traverse spec dependencies' + }) +_arguments['recurse_dependencies'] = parms diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index 374e71a4d8..a10e36e077 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -58,8 +58,14 @@ def setup_parser(subparser): # spack module refresh refresh_parser = sp.add_parser('refresh', help='Regenerate module files') - refresh_parser.add_argument('--delete-tree', help='Delete the module file tree before refresh', action='store_true') - arguments.add_common_arguments(refresh_parser, ['constraint', 'module_type', 'yes_to_all']) + refresh_parser.add_argument( + '--delete-tree', + help='Delete the module file tree before refresh', + action='store_true' + ) + arguments.add_common_arguments( + refresh_parser, ['constraint', 'module_type', 'yes_to_all'] + ) # spack module find find_parser = sp.add_parser('find', help='Find module files for packages') @@ -67,12 +73,14 @@ def setup_parser(subparser): # spack module rm rm_parser = sp.add_parser('rm', help='Remove module files') - arguments.add_common_arguments(rm_parser, ['constraint', 'module_type', 'yes_to_all']) + arguments.add_common_arguments( + rm_parser, ['constraint', 'module_type', 'yes_to_all'] + ) # spack module loads loads_parser = sp.add_parser( 'loads', - help='Prompt the list of modules associated with packages that satisfy a constraint' + help='Prompt the list of modules associated with a constraint' ) loads_parser.add_argument( '--input-only', action='store_false', dest='shell', @@ -82,7 +90,9 @@ def setup_parser(subparser): '-p', '--prefix', dest='prefix', default='', help='Prepend to module names when issuing module load commands' ) - arguments.add_common_arguments(loads_parser, ['constraint', 'module_type', 'recurse_dependencies']) + arguments.add_common_arguments( + loads_parser, ['constraint', 'module_type', 'recurse_dependencies'] + ) class MultipleMatches(Exception): @@ -100,20 +110,20 @@ def loads(mtype, specs, args): if args.recurse_dependencies: specs_from_user_constraint = specs[:] specs = [] - # FIXME : during module file creation nodes seem to be visited multiple - # FIXME : times even if cover='nodes' is given. This work around permits - # FIXME : to get a unique list of spec anyhow. Do we miss a merge - # FIXME : step among nodes that refer to the same package? + # 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))] + [item for item in spec.traverse(order='post', cover='nodes') if not (item in seen or seen_add(item))] # NOQA: ignore=E501 ) module_cls = module_types[mtype] - modules = [(spec, module_cls(spec).use_name) for spec in specs if os.path.exists(module_cls(spec).file_name)] + modules = [(spec, module_cls(spec).use_name) + for spec in specs if os.path.exists(module_cls(spec).file_name)] module_commands = { 'tcl': 'module load ', @@ -127,7 +137,8 @@ def loads(mtype, specs, args): prompt_template = '{comment}{command}{prefix}{name}' for spec, mod in modules: - d['comment'] = '' if not args.shell else '# {0}\n'.format(spec.format()) + d['comment'] = '' if not args.shell else '# {0}\n'.format( + spec.format()) d['name'] = mod print(prompt_template.format(**d)) @@ -157,7 +168,8 @@ def find(mtype, specs, args): def rm(mtype, specs, args): """Deletes module files associated with items in specs""" module_cls = module_types[mtype] - specs_with_modules = [spec for spec in specs if os.path.exists(module_cls(spec).file_name)] + specs_with_modules = [ + spec for spec in specs if os.path.exists(module_cls(spec).file_name)] modules = [module_cls(spec) for spec in specs_with_modules] if not modules: @@ -166,7 +178,7 @@ def rm(mtype, specs, args): # Ask for confirmation if not args.yes_to_all: - tty.msg('You are about to remove {0} module files the following specs:\n'.format(mtype)) + tty.msg('You are about to remove {0} module files the following specs:\n'.format(mtype)) # NOQA: ignore=E501 spack.cmd.display_specs(specs_with_modules, long=True) print('') spack.cmd.ask_for_confirmation('Do you want to proceed ? ') @@ -185,7 +197,7 @@ def refresh(mtype, specs, args): return if not args.yes_to_all: - tty.msg('You are about to regenerate {name} module files for the following specs:\n'.format(name=mtype)) + tty.msg('You are about to regenerate {name} module files for the following specs:\n'.format(name=mtype)) # NOQA: ignore=E501 spack.cmd.display_specs(specs, long=True) print('') spack.cmd.ask_for_confirmation('Do you want to proceed ? ') @@ -233,11 +245,11 @@ def module(parser, args): try: callbacks[args.subparser_name](module_type, args.specs, args) except MultipleMatches: - message = 'the constraint \'{query}\' matches multiple packages, and this is not allowed in this context' + message = 'the constraint \'{query}\' matches multiple packages, and this is not allowed in this context' # NOQA: ignore=E501 tty.error(message.format(query=constraint)) for s in args.specs: sys.stderr.write(s.format(color=True) + '\n') raise SystemExit(1) except NoMatch: - message = 'the constraint \'{query}\' match no package, and this is not allowed in this context' + message = 'the constraint \'{query}\' match no package, and this is not allowed in this context' # NOQA: ignore=E501 tty.die(message.format(query=constraint)) diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py index 92de33873b..a17b7c685c 100644 --- a/lib/spack/spack/cmd/uninstall.py +++ b/lib/spack/spack/cmd/uninstall.py @@ -42,7 +42,7 @@ display_args = { 'long': True, 'show_flags': True, - 'variants':True + 'variants': True } @@ -53,32 +53,37 @@ def setup_parser(subparser): subparser.add_argument( '-a', '--all', action='store_true', dest='all', help="USE CAREFULLY. Remove ALL installed packages that match each " + - "supplied spec. i.e., if you say uninstall libelf, ALL versions of " + - "libelf are uninstalled. This is both useful and dangerous, like rm -r.") + "supplied spec. i.e., if you say uninstall libelf, ALL versions of " + # NOQA: ignore=E501 + "libelf are uninstalled. This is both useful and dangerous, like rm -r.") # NOQA: ignore=E501 subparser.add_argument( '-d', '--dependents', action='store_true', dest='dependents', - help='Also uninstall any packages that depend on the ones given via command line.' + help='Also uninstall any packages that depend on the ones given via command line.' # NOQA: ignore=E501 ) subparser.add_argument( '-y', '--yes-to-all', action='store_true', dest='yes_to_all', - help='Assume "yes" is the answer to every confirmation asked to the user.' + help='Assume "yes" is the answer to every confirmation asked to the user.' # NOQA: ignore=E501 ) - subparser.add_argument('packages', nargs=argparse.REMAINDER, help="specs of packages to uninstall") + subparser.add_argument( + 'packages', + nargs=argparse.REMAINDER, + help="specs of packages to uninstall" + ) def concretize_specs(specs, allow_multiple_matches=False, force=False): - """ - Returns a list of specs matching the non necessarily concretized specs given from cli + """Returns a list of specs matching the non necessarily + concretized specs given from cli Args: specs: list of specs to be matched against installed packages - allow_multiple_matches : boolean (if True multiple matches for each item in specs are admitted) + allow_multiple_matches : if True multiple matches are admitted Return: list of specs """ - specs_from_cli = [] # List of specs that match expressions given via command line + # List of specs that match expressions given via command line + specs_from_cli = [] has_errors = False for spec in specs: matching = spack.installed_db.query(spec) @@ -104,8 +109,8 @@ def concretize_specs(specs, allow_multiple_matches=False, force=False): def installed_dependents(specs): - """ - Returns a dictionary that maps a spec with a list of its installed dependents + """Returns a dictionary that maps a spec with a list of its + installed dependents Args: specs: list of specs to be checked for dependents @@ -135,7 +140,7 @@ def do_uninstall(specs, force): try: # should work if package is known to spack packages.append(item.package) - except spack.repository.UnknownPackageError as e: + except spack.repository.UnknownPackageError: # The package.py file has gone away -- but still # want to uninstall. spack.Package(item).do_uninstall(force=True) @@ -157,14 +162,17 @@ def uninstall(parser, args): with spack.installed_db.write_transaction(): specs = spack.cmd.parse_specs(args.packages) # Gets the list of installed specs that match the ones give via cli - uninstall_list = concretize_specs(specs, args.all, args.force) # takes care of '-a' is given in the cli - dependent_list = installed_dependents(uninstall_list) # takes care of '-d' + # takes care of '-a' is given in the cli + uninstall_list = concretize_specs(specs, args.all, args.force) + dependent_list = installed_dependents( + uninstall_list) # takes care of '-d' # Process dependent_list and update uninstall_list has_error = False if dependent_list and not args.dependents and not args.force: for spec, lst in dependent_list.items(): - tty.error("Will not uninstall %s" % spec.format("$_$@$%@$#", color=True)) + tty.error("Will not uninstall %s" % + spec.format("$_$@$%@$#", color=True)) print('') print("The following packages depend on it:") spack.cmd.display_specs(lst, **display_args) @@ -176,7 +184,7 @@ def uninstall(parser, args): uninstall_list = list(set(uninstall_list)) if has_error: - tty.die('You can use spack uninstall --dependents to uninstall these dependencies as well') + tty.die('You can use spack uninstall --dependents to uninstall these dependencies as well') # NOQA: ignore=E501 if not args.yes_to_all: tty.msg("The following packages will be uninstalled : ") diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index 82016feb84..e648c6140f 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -188,7 +188,8 @@ def parse_config_options(module_generator): ##### # Automatic loading loads - module_file_actions['hash_length'] = module_configuration.get('hash_length', 7) + module_file_actions['hash_length'] = module_configuration.get( + 'hash_length', 7) module_file_actions['autoload'] = dependencies( module_generator.spec, module_file_actions.get('autoload', 'none')) # Prerequisites @@ -238,6 +239,7 @@ class EnvModule(object): formats = {} class __metaclass__(type): + def __init__(cls, name, bases, dict): type.__init__(cls, name, bases, dict) if cls.name != 'env_module' and cls.name in CONFIGURATION[ diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index dfbd73b91f..bf46e011b1 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -32,7 +32,8 @@ from spack.test.tally_plugin import Tally """Names of tests to be included in Spack's test suite""" -test_names = ['architecture', 'versions', 'url_parse', 'url_substitution', 'packages', 'stage', +test_names = ['architecture', 'versions', 'url_parse', 'url_substitution', + 'packages', 'stage', 'spec_syntax', 'spec_semantics', 'spec_dag', 'concretize', 'multimethod', 'install', 'package_sanity', 'config', 'directory_layout', 'pattern', 'python_version', 'git_fetch', @@ -40,7 +41,8 @@ 'cc', 'link_tree', 'spec_yaml', 'optional_deps', 'make_executable', 'configure_guess', 'lock', 'database', 'namespace_trie', 'yaml', 'sbang', 'environment', 'cmd.find', - 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd', 'cmd.module'] + 'cmd.uninstall', 'cmd.test_install', + 'cmd.test_compiler_cmd', 'cmd.module'] def list_tests(): diff --git a/lib/spack/spack/test/cmd/module.py b/lib/spack/spack/test/cmd/module.py index 52628f5b3b..36a4a73fe6 100644 --- a/lib/spack/spack/test/cmd/module.py +++ b/lib/spack/spack/test/cmd/module.py @@ -31,9 +31,10 @@ class TestModule(spack.test.mock_database.MockDatabase): + def _get_module_files(self, args): return [ - modules.module_types[args.module_type](spec).file_name for spec in args.specs + modules.module_types[args.module_type](spec).file_name for spec in args.specs # NOQA: ignore=E501 ] def test_module_common_operations(self): diff --git a/lib/spack/spack/util/pattern.py b/lib/spack/spack/util/pattern.py index 6af39c87d8..bc5e9d2ffe 100644 --- a/lib/spack/spack/util/pattern.py +++ b/lib/spack/spack/util/pattern.py @@ -28,42 +28,50 @@ def composite(interface=None, method_list=None, container=list): - """ - Returns a class decorator that patches a class adding all the methods it needs to be a composite for a given - interface. + """Returns a class decorator that patches a class adding all the methods + it needs to be a composite for a given interface. - :param interface: class exposing the interface to which the composite object must conform. Only non-private and - non-special methods will be taken into account + :param interface: class exposing the interface to which the composite + object must conform. Only non-private and non-special methods will be + taken into account :param method_list: names of methods that should be part of the composite - :param container: container for the composite object (default = list). Must fulfill the MutableSequence contract. - The composite class will expose the container API to manage object composition + :param container: container for the composite object (default = list). + Must fulfill the MutableSequence contract. The composite class will expose + the container API to manage object composition :return: class decorator """ - # Check if container fulfills the MutableSequence contract and raise an exception if it doesn't - # The patched class returned by the decorator will inherit from the container class to expose the - # interface needed to manage objects composition + # Check if container fulfills the MutableSequence contract and raise an + # exception if it doesn't. The patched class returned by the decorator will + # inherit from the container class to expose the interface needed to manage + # objects composition if not issubclass(container, collections.MutableSequence): raise TypeError("Container must fulfill the MutableSequence contract") - # Check if at least one of the 'interface' or the 'method_list' arguments are defined + # Check if at least one of the 'interface' or the 'method_list' arguments + # are defined if interface is None and method_list is None: - raise TypeError("Either 'interface' or 'method_list' must be defined on a call to composite") + raise TypeError("Either 'interface' or 'method_list' must be defined on a call to composite") # NOQA : ignore=E501 def cls_decorator(cls): - # Retrieve the base class of the composite. Inspect its methods and decide which ones will be overridden + # Retrieve the base class of the composite. Inspect its methods and + # decide which ones will be overridden def no_special_no_private(x): return inspect.ismethod(x) and not x.__name__.startswith('_') - # Patch the behavior of each of the methods in the previous list. This is done associating an instance of the - # descriptor below to any method that needs to be patched. + # Patch the behavior of each of the methods in the previous list. + # This is done associating an instance of the descriptor below to + # any method that needs to be patched. class IterateOver(object): + """Decorator used to patch methods in a composite. + + It iterates over all the items in the instance containing the + associated attribute and calls for each of them an attribute + with the same name """ - Decorator used to patch methods in a composite. It iterates over all the items in the instance containing the - associated attribute and calls for each of them an attribute with the same name - """ + def __init__(self, name, func=None): self.name = name self.func = func @@ -72,8 +80,9 @@ def __get__(self, instance, owner): def getter(*args, **kwargs): for item in instance: getattr(item, self.name)(*args, **kwargs) - # If we are using this descriptor to wrap a method from an interface, then we must conditionally - # use the `functools.wraps` decorator to set the appropriate fields. + # If we are using this descriptor to wrap a method from an + # interface, then we must conditionally use the + # `functools.wraps` decorator to set the appropriate fields if self.func is not None: getter = functools.wraps(self.func)(getter) return getter @@ -81,7 +90,8 @@ def getter(*args, **kwargs): dictionary_for_type_call = {} # Construct a dictionary with the methods explicitly passed as name if method_list is not None: - # python@2.7: method_list_dict = {name: IterateOver(name) for name in method_list} + # python@2.7: method_list_dict = {name: IterateOver(name) for name + # in method_list} method_list_dict = {} for name in method_list: method_list_dict[name] = IterateOver(name) @@ -89,28 +99,33 @@ def getter(*args, **kwargs): # Construct a dictionary with the methods inspected from the interface if interface is not None: ########## - # python@2.7: interface_methods = {name: method for name, method in inspect.getmembers(interface, predicate=no_special_no_private)} + # python@2.7: interface_methods = {name: method for name, method in + # inspect.getmembers(interface, predicate=no_special_no_private)} interface_methods = {} - for name, method in inspect.getmembers(interface, predicate=no_special_no_private): + for name, method in inspect.getmembers(interface, predicate=no_special_no_private): # NOQA: ignore=E501 interface_methods[name] = method ########## - # python@2.7: interface_methods_dict = {name: IterateOver(name, method) for name, method in interface_methods.iteritems()} + # python@2.7: interface_methods_dict = {name: IterateOver(name, + # method) for name, method in interface_methods.iteritems()} interface_methods_dict = {} for name, method in interface_methods.iteritems(): interface_methods_dict[name] = IterateOver(name, method) ########## dictionary_for_type_call.update(interface_methods_dict) - # Get the methods that are defined in the scope of the composite class and override any previous definition + # Get the methods that are defined in the scope of the composite + # class and override any previous definition ########## - # python@2.7: cls_method = {name: method for name, method in inspect.getmembers(cls, predicate=inspect.ismethod)} + # python@2.7: cls_method = {name: method for name, method in + # inspect.getmembers(cls, predicate=inspect.ismethod)} cls_method = {} - for name, method in inspect.getmembers(cls, predicate=inspect.ismethod): + for name, method in inspect.getmembers(cls, predicate=inspect.ismethod): # NOQA: ignore=E501 cls_method[name] = method ########## dictionary_for_type_call.update(cls_method) # Generate the new class on the fly and return it # FIXME : inherit from interface if we start to use ABC classes? - wrapper_class = type(cls.__name__, (cls, container), dictionary_for_type_call) + wrapper_class = type(cls.__name__, (cls, container), + dictionary_for_type_call) return wrapper_class return cls_decorator @@ -118,5 +133,6 @@ def getter(*args, **kwargs): class Bunch(object): """Carries a bunch of named attributes (from Alex Martelli bunch)""" + def __init__(self, **kwargs): self.__dict__.update(kwargs) From 7551e4c14f2f88c00f147684b01a72a69e3ecce5 Mon Sep 17 00:00:00 2001 From: Geoffrey Oxberry Date: Sun, 10 Jul 2016 18:02:51 -0700 Subject: [PATCH 17/68] cmake@3.6.0 Add CMake version 3.6.0. --- var/spack/repos/builtin/packages/cmake/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/var/spack/repos/builtin/packages/cmake/package.py b/var/spack/repos/builtin/packages/cmake/package.py index 7b2a125fe5..d7c8f646a0 100644 --- a/var/spack/repos/builtin/packages/cmake/package.py +++ b/var/spack/repos/builtin/packages/cmake/package.py @@ -30,6 +30,7 @@ class Cmake(Package): homepage = 'https://www.cmake.org' url = 'https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz' + version('3.6.0', 'aa40fbecf49d99c083415c2411d12db9') version('3.5.2', '701386a1b5ec95f8d1075ecf96383e02') version('3.5.1', 'ca051f4a66375c89d1a524e726da0296') version('3.5.0', '33c5d09d4c33d4ffcc63578a6ba8777e') From b7d9b58cc5de8a36d43cc082cac0e1ccb6e05f74 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Tue, 12 Jul 2016 19:54:44 +0200 Subject: [PATCH 18/68] Fix preferred providers. --- lib/spack/spack/preferred_packages.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/preferred_packages.py b/lib/spack/spack/preferred_packages.py index 4820584150..e873fa3c7e 100644 --- a/lib/spack/spack/preferred_packages.py +++ b/lib/spack/spack/preferred_packages.py @@ -41,7 +41,7 @@ def _order_for_package(self, pkgname, component, second_key, test_all=True): pkglist.append('all') for pkg in pkglist: order = self.preferred.get(pkg, {}).get(component, {}) - if type(order) is dict: + if isinstance(order, dict) and second_key: order = order.get(second_key, {}) if not order: continue @@ -89,9 +89,9 @@ def _component_compare(self, pkgname, component, a, b, reverse_natural_compare, # a and b are considered to match entries in the sorting list if they # satisfy the list component. def _spec_compare(self, pkgname, component, a, b, reverse_natural_compare, second_key): - if not a or not a.concrete: + if not a or (not a.concrete and not second_key): return -1 - if not b or not b.concrete: + if not b or (not b.concrete and not second_key): return 1 specs = self._spec_for_pkgname(pkgname, component, second_key) a_index = None From 52ca215e2947f7fe5c5248ccbd5e4fa19c8536fd Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Wed, 13 Jul 2016 10:50:57 +0200 Subject: [PATCH 19/68] mkl: add provide blas/lapack --- .../repos/builtin/packages/mkl/package.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/var/spack/repos/builtin/packages/mkl/package.py b/var/spack/repos/builtin/packages/mkl/package.py index 454e78d29c..889851c953 100644 --- a/var/spack/repos/builtin/packages/mkl/package.py +++ b/var/spack/repos/builtin/packages/mkl/package.py @@ -18,6 +18,11 @@ class Mkl(IntelInstaller): version('11.3.3.210', 'f72546df27f5ebb0941b5d21fd804e34', url="file://%s/l_mkl_11.3.3.210.tgz" % os.getcwd()) + # virtual dependency + provides('blas') + provides('lapack') + # TODO: MKL also provides implementation of Scalapack. + def install(self, spec, prefix): self.intel_prefix = os.path.join(prefix, "pkg") @@ -26,3 +31,21 @@ def install(self, spec, prefix): mkl_dir = os.path.join(self.intel_prefix, "mkl") for f in os.listdir(mkl_dir): os.symlink(os.path.join(mkl_dir, f), os.path.join(self.prefix, f)) + + def setup_dependent_package(self, module, dspec): + # For now use Single Dynamic Library: + # To set the threading layer at run time, use the + # mkl_set_threading_layer function or set MKL_THREADING_LAYER + # variable to one of the following values: INTEL, SEQUENTIAL, PGI. + # To set interface layer at run time, use the mkl_set_interface_layer + # function or set the MKL_INTERFACE_LAYER variable to LP64 or ILP64. + + # Otherwise one would need to specify several libraries + # (e.g. mkl_intel_lp64;mkl_sequential;mkl_core), which reflect + # different interface and threading layers. + + name = 'libmkl_rt.%s' % dso_suffix + libdir = find_library_path(name, self.prefix.lib64, self.prefix.lib) + + self.spec.blas_shared_lib = join_path(libdir, name) + self.spec.lapack_shared_lib = self.spec.blas_shared_lib From 5ffc50732bdcfca325115e23d359612426f38854 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 13 Jul 2016 23:05:08 +0200 Subject: [PATCH 20/68] flake8 fixes --- lib/spack/spack/preferred_packages.py | 99 +++++++++++++++------------ 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/lib/spack/spack/preferred_packages.py b/lib/spack/spack/preferred_packages.py index e873fa3c7e..1b94f03de7 100644 --- a/lib/spack/spack/preferred_packages.py +++ b/lib/spack/spack/preferred_packages.py @@ -26,8 +26,10 @@ import spack from spack.version import * + class PreferredPackages(object): - _default_order = {'compiler' : [ 'gcc', 'intel', 'clang', 'pgi', 'xlc' ] } # Arbitrary, but consistent + # Arbitrary, but consistent + _default_order = {'compiler': ['gcc', 'intel', 'clang', 'pgi', 'xlc']} def __init__(self): self.preferred = spack.config.get_config('packages') @@ -35,7 +37,8 @@ def __init__(self): # Given a package name, sort component (e.g, version, compiler, ...), and # a second_key (used by providers), return the list - def _order_for_package(self, pkgname, component, second_key, test_all=True): + def _order_for_package(self, pkgname, component, second_key, + test_all=True): pkglist = [pkgname] if test_all: pkglist.append('all') @@ -48,11 +51,11 @@ def _order_for_package(self, pkgname, component, second_key, test_all=True): return [str(s).strip() for s in order] return [] - # A generic sorting function. Given a package name and sort # component, return less-than-0, 0, or greater-than-0 if # a is respectively less-than, equal to, or greater than b. - def _component_compare(self, pkgname, component, a, b, reverse_natural_compare, second_key): + def _component_compare(self, pkgname, component, a, b, + reverse_natural_compare, second_key): if a is None: return -1 if b is None: @@ -84,11 +87,11 @@ def _component_compare(self, pkgname, component, a, b, reverse_natural_compare, else: return 0 - # A sorting function for specs. Similar to component_compare, but # a and b are considered to match entries in the sorting list if they # satisfy the list component. - def _spec_compare(self, pkgname, component, a, b, reverse_natural_compare, second_key): + def _spec_compare(self, pkgname, component, a, b, + reverse_natural_compare, second_key): if not a or (not a.concrete and not second_key): return -1 if not b or (not b.concrete and not second_key): @@ -98,78 +101,88 @@ def _spec_compare(self, pkgname, component, a, b, reverse_natural_compare, secon b_index = None reverse = -1 if reverse_natural_compare else 1 for i, cspec in enumerate(specs): - if a_index == None and (cspec.satisfies(a) or a.satisfies(cspec)): + if a_index is None and (cspec.satisfies(a) or a.satisfies(cspec)): a_index = i if b_index: break - if b_index == None and (cspec.satisfies(b) or b.satisfies(cspec)): + if b_index is None and (cspec.satisfies(b) or b.satisfies(cspec)): b_index = i if a_index: break - if a_index != None and b_index == None: return -1 - elif a_index == None and b_index != None: return 1 - elif a_index != None and b_index == a_index: return -1 * cmp(a, b) - elif a_index != None and b_index != None and a_index != b_index: return cmp(a_index, b_index) - else: return cmp(a, b) * reverse - - + if a_index is not None and b_index is None: + return -1 + elif a_index is None and b_index is not None: + return 1 + elif a_index is not None and b_index == a_index: + return -1 * cmp(a, b) + elif (a_index is not None and b_index is not None and + a_index != b_index): + return cmp(a_index, b_index) + else: + return cmp(a, b) * reverse # Given a sort order specified by the pkgname/component/second_key, return # a list of CompilerSpecs, VersionLists, or Specs for that sorting list. def _spec_for_pkgname(self, pkgname, component, second_key): key = (pkgname, component, second_key) - if not key in self._spec_for_pkgname_cache: + if key not in self._spec_for_pkgname_cache: pkglist = self._order_for_package(pkgname, component, second_key) if not pkglist: if component in self._default_order: pkglist = self._default_order[component] if component == 'compiler': - self._spec_for_pkgname_cache[key] = [spack.spec.CompilerSpec(s) for s in pkglist] + self._spec_for_pkgname_cache[key] = \ + [spack.spec.CompilerSpec(s) for s in pkglist] elif component == 'version': - self._spec_for_pkgname_cache[key] = [VersionList(s) for s in pkglist] + self._spec_for_pkgname_cache[key] = \ + [VersionList(s) for s in pkglist] else: - self._spec_for_pkgname_cache[key] = [spack.spec.Spec(s) for s in pkglist] + self._spec_for_pkgname_cache[key] = \ + [spack.spec.Spec(s) for s in pkglist] return self._spec_for_pkgname_cache[key] - def provider_compare(self, pkgname, provider_str, a, b): - """Return less-than-0, 0, or greater than 0 if a is respecively less-than, equal-to, or - greater-than b. A and b are possible implementations of provider_str. - One provider is less-than another if it is preferred over the other. - For example, provider_compare('scorep', 'mpi', 'mvapich', 'openmpi') would return -1 if - mvapich should be preferred over openmpi for scorep.""" - return self._spec_compare(pkgname, 'providers', a, b, False, provider_str) - + """Return less-than-0, 0, or greater than 0 if a is respecively + less-than, equal-to, or greater-than b. A and b are possible + implementations of provider_str. One provider is less-than another + if it is preferred over the other. For example, + provider_compare('scorep', 'mpi', 'mvapich', 'openmpi') would + return -1 if mvapich should be preferred over openmpi for scorep.""" + return self._spec_compare(pkgname, 'providers', a, b, False, + provider_str) def spec_has_preferred_provider(self, pkgname, provider_str): - """Return True iff the named package has a list of preferred provider""" - return bool(self._order_for_package(pkgname, 'providers', provider_str, False)) - + """Return True iff the named package has a list of preferred + providers""" + return bool(self._order_for_package(pkgname, 'providers', + provider_str, False)) def version_compare(self, pkgname, a, b): """Return less-than-0, 0, or greater than 0 if version a of pkgname is - respecively less-than, equal-to, or greater-than version b of pkgname. - One version is less-than another if it is preferred over the other.""" + respectively less-than, equal-to, or greater-than version b of + pkgname. One version is less-than another if it is preferred over + the other.""" return self._spec_compare(pkgname, 'version', a, b, True, None) - def variant_compare(self, pkgname, a, b): """Return less-than-0, 0, or greater than 0 if variant a of pkgname is - respecively less-than, equal-to, or greater-than variant b of pkgname. - One variant is less-than another if it is preferred over the other.""" + respectively less-than, equal-to, or greater-than variant b of + pkgname. One variant is less-than another if it is preferred over + the other.""" return self._component_compare(pkgname, 'variant', a, b, False, None) - def architecture_compare(self, pkgname, a, b): - """Return less-than-0, 0, or greater than 0 if architecture a of pkgname is - respecively less-than, equal-to, or greater-than architecture b of pkgname. - One architecture is less-than another if it is preferred over the other.""" - return self._component_compare(pkgname, 'architecture', a, b, False, None) - + """Return less-than-0, 0, or greater than 0 if architecture a of pkgname + is respectively less-than, equal-to, or greater-than architecture b + of pkgname. One architecture is less-than another if it is preferred + over the other.""" + return self._component_compare(pkgname, 'architecture', a, b, + False, None) def compiler_compare(self, pkgname, a, b): """Return less-than-0, 0, or greater than 0 if compiler a of pkgname is - respecively less-than, equal-to, or greater-than compiler b of pkgname. - One compiler is less-than another if it is preferred over the other.""" + respecively less-than, equal-to, or greater-than compiler b of + pkgname. One compiler is less-than another if it is preferred over + the other.""" return self._spec_compare(pkgname, 'compiler', a, b, False, None) From 668b4f1b2ce8e61457309d67b798e58ef481a08e Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Wed, 13 Jul 2016 23:36:23 +0200 Subject: [PATCH 21/68] mkl: set MKLROOT --- var/spack/repos/builtin/packages/mkl/package.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/var/spack/repos/builtin/packages/mkl/package.py b/var/spack/repos/builtin/packages/mkl/package.py index 889851c953..f1f07c90f5 100644 --- a/var/spack/repos/builtin/packages/mkl/package.py +++ b/var/spack/repos/builtin/packages/mkl/package.py @@ -49,3 +49,10 @@ def setup_dependent_package(self, module, dspec): self.spec.blas_shared_lib = join_path(libdir, name) self.spec.lapack_shared_lib = self.spec.blas_shared_lib + + def setup_dependent_environment(self, spack_env, run_env, dependent_spec): + # set up MKLROOT for everyone using MKL package + spack_env.set('MKLROOT', self.prefix) + + def setup_environment(self, spack_env, env): + env.set('MKLROOT', self.prefix) From b29b7595dda88831b7c0330b34df4c7b1e1c1734 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Fri, 15 Jul 2016 17:35:10 +0200 Subject: [PATCH 22/68] mkl: add info on interface and threading layers to the docstring --- var/spack/repos/builtin/packages/mkl/package.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/var/spack/repos/builtin/packages/mkl/package.py b/var/spack/repos/builtin/packages/mkl/package.py index f1f07c90f5..6ea64f5313 100644 --- a/var/spack/repos/builtin/packages/mkl/package.py +++ b/var/spack/repos/builtin/packages/mkl/package.py @@ -9,7 +9,13 @@ class Mkl(IntelInstaller): Note: You will have to add the download file to a mirror so that Spack can find it. For instructions on how to set up a - mirror, see http://software.llnl.gov/spack/mirrors.html""" + mirror, see http://software.llnl.gov/spack/mirrors.html. + + To set the threading layer at run time set MKL_THREADING_LAYER + variable to one of the following values: INTEL, SEQUENTIAL, PGI. + To set interface layer at run time, use set the MKL_INTERFACE_LAYER + variable to LP64 or ILP64. + """ homepage = "https://software.intel.com/en-us/intel-mkl" From 96e9dbca0828e0664c4c20d6223b94d8040fc1a6 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Fri, 15 Jul 2016 22:41:01 +0200 Subject: [PATCH 23/68] suite-sparse: enable TBB and fix Blas/Lapack libs --- .../builtin/packages/suite-sparse/package.py | 29 ++++++++++--------- .../packages/suite-sparse/tbb_453.patch | 13 +++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 var/spack/repos/builtin/packages/suite-sparse/tbb_453.patch diff --git a/var/spack/repos/builtin/packages/suite-sparse/package.py b/var/spack/repos/builtin/packages/suite-sparse/package.py index 2cc89b843f..a71bfd8bd4 100644 --- a/var/spack/repos/builtin/packages/suite-sparse/package.py +++ b/var/spack/repos/builtin/packages/suite-sparse/package.py @@ -32,21 +32,20 @@ class SuiteSparse(Package): homepage = 'http://faculty.cse.tamu.edu/davis/suitesparse.html' url = 'http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.5.1.tar.gz' - version('4.5.1', 'f0ea9aad8d2d1ffec66a5b6bfeff5319') version('4.5.3', '8ec57324585df3c6483ad7f556afccbd') + version('4.5.1', 'f0ea9aad8d2d1ffec66a5b6bfeff5319') - # FIXME: (see below) - # variant('tbb', default=True, description='Build with Intel TBB') + variant('tbb', default=True, description='Build with Intel TBB') depends_on('blas') depends_on('lapack') depends_on('metis@5.1.0', when='@4.5.1:') - # FIXME: # in @4.5.1. TBB support in SPQR seems to be broken as TBB-related linkng # flags does not seem to be used, which leads to linking errors on Linux. - # Try re-enabling in future versions. - # depends_on('tbb', when='+tbb') + depends_on('tbb', when='@4.5.3:+tbb') + + patch('tbb_453.patch', when='@4.5.3') def install(self, spec, prefix): # The build system of SuiteSparse is quite old-fashioned. @@ -73,20 +72,24 @@ def install(self, spec, prefix): ]) # Intel TBB in SuiteSparseQR - if '+tbb' in spec: + if 'tbb' in spec: make_args.extend([ 'SPQR_CONFIG=-DHAVE_TBB', 'TBB=-L%s -ltbb' % spec['tbb'].prefix.lib, ]) - # BLAS arguments require path to libraries - # FIXME: (blas/lapack always provide libblas and liblapack as aliases) + # Make sure Spack's Blas/Lapack is used. Otherwise System's + # Blas/Lapack might be picked up. + blas = to_link_flags(spec['blas'].blas_shared_lib) + lapack = to_link_flags(spec['lapack'].lapack_shared_lib) if '@4.5.1' in spec: # adding -lstdc++ is clearly an ugly way to do this, but it follows # with the TCOV path of SparseSuite 4.5.1's Suitesparse_config.mk - make_args.extend([ - 'BLAS=-lblas -lstdc++', - 'LAPACK=-llapack' - ]) + blas += ' -lstdc++' + + make_args.extend([ + 'BLAS=%s' % blas, + 'LAPACK=%s' % lapack + ]) make('install', *make_args) diff --git a/var/spack/repos/builtin/packages/suite-sparse/tbb_453.patch b/var/spack/repos/builtin/packages/suite-sparse/tbb_453.patch new file mode 100644 index 0000000000..70241ed017 --- /dev/null +++ b/var/spack/repos/builtin/packages/suite-sparse/tbb_453.patch @@ -0,0 +1,13 @@ +diff --git a/SPQR/Lib/Makefile b/SPQR/Lib/Makefile +index eaade58..d0de852 100644 +--- a/SPQR/Lib/Makefile ++++ b/SPQR/Lib/Makefile +@@ -13,7 +13,7 @@ ccode: all + include ../../SuiteSparse_config/SuiteSparse_config.mk + + # SPQR depends on CHOLMOD, AMD, COLAMD, LAPACK, the BLAS and SuiteSparse_config +-LDLIBS += -lamd -lcolamd -lcholmod -lsuitesparseconfig $(LAPACK) $(BLAS) ++LDLIBS += -lamd -lcolamd -lcholmod -lsuitesparseconfig $(TBB) $(LAPACK) $(BLAS) + + # compile and install in SuiteSparse/lib + library: From d61190c3fffc3597c49dc995590dc419b10aab73 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Sat, 16 Jul 2016 00:48:04 +0200 Subject: [PATCH 24/68] Explicitly request zmpi in module blacklist test. --- lib/spack/spack/test/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/test/modules.py b/lib/spack/spack/test/modules.py index 6d2e3705bd..b6d35154e3 100644 --- a/lib/spack/spack/test/modules.py +++ b/lib/spack/spack/test/modules.py @@ -266,7 +266,7 @@ def test_alter_environment(self): def test_blacklist(self): spack.modules.CONFIGURATION = configuration_blacklist - spec = spack.spec.Spec('mpileaks') + spec = spack.spec.Spec('mpileaks ^zmpi') content = self.get_modulefile_content(spec) self.assertEqual(len([x for x in content if 'is-loaded' in x]), 1) self.assertEqual(len([x for x in content if 'module load ' in x]), 1) From 992250ddeab77a605c1e0c47363bd750949d59a5 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 07:24:05 +0200 Subject: [PATCH 25/68] add to_lib_name() to get library name from a path --- lib/spack/llnl/util/filesystem.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index e800c6717a..adb6b8034e 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -42,7 +42,7 @@ 'FileFilter', 'change_sed_delimiter', 'is_exe', 'force_symlink', 'set_executable', 'copy_mode', 'unset_executable_mode', 'remove_dead_links', 'remove_linked_tree', 'find_library_path', - 'fix_darwin_install_name', 'to_link_flags'] + 'fix_darwin_install_name', 'to_link_flags', 'to_lib_name'] def filter_file(regex, repl, *filenames, **kwargs): @@ -430,6 +430,11 @@ def fix_darwin_install_name(path): subprocess.Popen(["install_name_tool", "-change", dep, loc, lib], stdout=subprocess.PIPE).communicate()[0] # NOQA: ignore=E501 break +def to_lib_name(library): + """Transforms a path to the library /path/to/lib.xyz into + """ + # Assume libXYZ.suffix + return os.path.basename(library)[3:].split(".")[0] def to_link_flags(library): """Transforms a path to a into linking flags -L -l. @@ -438,8 +443,7 @@ def to_link_flags(library): A string of linking flags. """ dir = os.path.dirname(library) - # Assume libXYZ.suffix - name = os.path.basename(library)[3:].split(".")[0] + name = to_lib_name(library) res = '-L%s -l%s' % (dir, name) return res From 514c61b8fe923de7eb0c41205fdfaae48afb5cdf Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 07:28:31 +0200 Subject: [PATCH 26/68] hypre: don't hardcode blas/lapack/mpi; optionally run tests --- .../repos/builtin/packages/hypre/package.py | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/var/spack/repos/builtin/packages/hypre/package.py b/var/spack/repos/builtin/packages/hypre/package.py index f87dae9f4e..0941d07ebe 100644 --- a/var/spack/repos/builtin/packages/hypre/package.py +++ b/var/spack/repos/builtin/packages/hypre/package.py @@ -46,21 +46,26 @@ class Hypre(Package): depends_on("lapack") def install(self, spec, prefix): - blas_dir = spec['blas'].prefix - lapack_dir = spec['lapack'].prefix - mpi_dir = spec['mpi'].prefix - - os.environ['CC'] = os.path.join(mpi_dir, 'bin', 'mpicc') - os.environ['CXX'] = os.path.join(mpi_dir, 'bin', 'mpicxx') - os.environ['F77'] = os.path.join(mpi_dir, 'bin', 'mpif77') - + os.environ['CC'] = spec['mpi'].mpicc + os.environ['CXX'] = spec['mpi'].mpicxx + os.environ['F77'] = spec['mpi'].mpif77 + # Since +shared does not build on macOS and also Atlas does not have + # a single static lib to build against, link against shared libs with + # a hope that --whole-archive linker option (or alike) was used + # to command the linker to include whole static libs' content into the + # shared lib + # Note: --with-(lapack|blas)_libs= needs space separated list of names configure_args = [ - "--prefix=%s" % prefix, - "--with-lapack-libs=lapack", - "--with-lapack-lib-dirs=%s/lib" % lapack_dir, - "--with-blas-libs=blas", - "--with-blas-lib-dirs=%s/lib" % blas_dir] + '--prefix=%s' % prefix, + '--with-lapack-libs=%s' % to_lib_name( + spec['lapack'].lapack_shared_lib), + '--with-lapack-lib-dirs=%s/lib' % spec['lapack'].prefix, + '--with-blas-libs=%s' % to_lib_name( + spec['blas'].blas_shared_lib), + '--with-blas-lib-dirs=%s/lib' % spec['blas'].prefix + ] + if '+shared' in self.spec: configure_args.append("--enable-shared") @@ -76,4 +81,12 @@ def install(self, spec, prefix): configure(*configure_args) make() + if self.run_tests: + make("check") + make("test") + Executable(join_path('test', 'ij'))() + sstruct = Executable(join_path('test', 'struct')) + sstruct() + sstruct('-in', 'test/sstruct.in.default', '-solver', '40', + '-rhsone') make("install") From 987fb137f97b8673efdcd126bef56bc6c8d06dc0 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 07:31:38 +0200 Subject: [PATCH 27/68] trilinos: don't hardcode blas/lapack names --- var/spack/repos/builtin/packages/trilinos/package.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/var/spack/repos/builtin/packages/trilinos/package.py b/var/spack/repos/builtin/packages/trilinos/package.py index 3a53ac5c01..100e30169d 100644 --- a/var/spack/repos/builtin/packages/trilinos/package.py +++ b/var/spack/repos/builtin/packages/trilinos/package.py @@ -116,6 +116,7 @@ def install(self, spec, prefix): options.extend(std_cmake_args) mpi_bin = spec['mpi'].prefix.bin + # Note: -DXYZ_LIBRARY_NAMES= needs semicolon separated list of names options.extend([ '-DTrilinos_ENABLE_ALL_PACKAGES:BOOL=ON', '-DTrilinos_ENABLE_ALL_OPTIONAL_PACKAGES:BOOL=ON', @@ -129,10 +130,12 @@ def install(self, spec, prefix): '-DTPL_ENABLE_MPI:BOOL=ON', '-DMPI_BASE_DIR:PATH=%s' % spec['mpi'].prefix, '-DTPL_ENABLE_BLAS=ON', - '-DBLAS_LIBRARY_NAMES=blas', # FIXME: don't hardcode names + '-DBLAS_LIBRARY_NAMES=%s' % to_lib_name( + spec['blas'].blas_shared_lib), '-DBLAS_LIBRARY_DIRS=%s' % spec['blas'].prefix.lib, '-DTPL_ENABLE_LAPACK=ON', - '-DLAPACK_LIBRARY_NAMES=lapack', + '-DLAPACK_LIBRARY_NAMES=%s' % to_lib_name( + spec['lapack'].lapack_shared_lib), '-DLAPACK_LIBRARY_DIRS=%s' % spec['lapack'].prefix, '-DTrilinos_ENABLE_EXPLICIT_INSTANTIATION:BOOL=ON', '-DTrilinos_ENABLE_CXX11:BOOL=ON', From 6175ce75596bf1abdedda3aaccb7bbed86453f0a Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 07:37:38 +0200 Subject: [PATCH 28/68] netlib-scalapack: make sure Spack's Lapack is used --- .../repos/builtin/packages/netlib-scalapack/package.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/var/spack/repos/builtin/packages/netlib-scalapack/package.py b/var/spack/repos/builtin/packages/netlib-scalapack/package.py index f7fe26a42d..cb2d8b44fc 100644 --- a/var/spack/repos/builtin/packages/netlib-scalapack/package.py +++ b/var/spack/repos/builtin/packages/netlib-scalapack/package.py @@ -53,6 +53,15 @@ def install(self, spec, prefix): "-DUSE_OPTIMIZED_LAPACK_BLAS:BOOL=ON", # forces scalapack to use find_package(LAPACK) ] + # Make sure we use Spack's Lapack: + options.extend([ + '-DLAPACK_FOUND=true', + '-DLAPACK_INCLUDE_DIRS=%s' % spec['lapack'].prefix.include, + '-DLAPACK_LIBRARIES=%s' % ( + spec['lapack'].lapack_shared_lib if '+shared' in spec else + spec['lapack'].lapack_static_lib), + ]) + if '+fpic' in spec: options.extend([ "-DCMAKE_C_FLAGS=-fPIC", From 0752eccfa5f865419f0ab4f3de06f5feea1aa422 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 07:38:42 +0200 Subject: [PATCH 29/68] mumps: don't hardcode blas name; remove unused depends_on(lapack) --- var/spack/repos/builtin/packages/mumps/package.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/mumps/package.py b/var/spack/repos/builtin/packages/mumps/package.py index 92c45c9b95..630c33562b 100644 --- a/var/spack/repos/builtin/packages/mumps/package.py +++ b/var/spack/repos/builtin/packages/mumps/package.py @@ -50,7 +50,6 @@ class Mumps(Package): depends_on('metis@5:', when='+metis') depends_on('parmetis', when="+parmetis") depends_on('blas') - depends_on('lapack') depends_on('scalapack', when='+mpi') depends_on('mpi', when='+mpi') @@ -63,7 +62,9 @@ def write_makefile_inc(self): if ('+parmetis' in self.spec or '+ptscotch' in self.spec) and '+mpi' not in self.spec: raise RuntimeError('You cannot use the variants parmetis or ptscotch without mpi') - makefile_conf = ["LIBBLAS = -L%s -lblas" % self.spec['blas'].prefix.lib] + makefile_conf = ["LIBBLAS = %s" % to_link_flags( + self.spec['blas'].blas_shared_lib) + ] orderings = ['-Dpord'] @@ -189,7 +190,7 @@ def install(self, spec, prefix): install_tree('lib', prefix.lib) install_tree('include', prefix.include) - if '~mpi' in spec: + if '~mpi' in spec: lib_dsuffix = '.dylib' if sys.platform == 'darwin' else '.so' lib_suffix = lib_dsuffix if '+shared' in spec else '.a' install('libseq/libmpiseq%s' % lib_suffix, prefix.lib) From 9ea4f80f154f264986dcadf9de4dd192b8dce037 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 07:58:51 +0200 Subject: [PATCH 30/68] flake8 fixes --- lib/spack/llnl/util/filesystem.py | 2 ++ var/spack/repos/builtin/packages/hypre/package.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index adb6b8034e..6e4cd338fe 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -430,12 +430,14 @@ def fix_darwin_install_name(path): subprocess.Popen(["install_name_tool", "-change", dep, loc, lib], stdout=subprocess.PIPE).communicate()[0] # NOQA: ignore=E501 break + def to_lib_name(library): """Transforms a path to the library /path/to/lib.xyz into """ # Assume libXYZ.suffix return os.path.basename(library)[3:].split(".")[0] + def to_link_flags(library): """Transforms a path to a into linking flags -L -l. diff --git a/var/spack/repos/builtin/packages/hypre/package.py b/var/spack/repos/builtin/packages/hypre/package.py index 0941d07ebe..65fef57559 100644 --- a/var/spack/repos/builtin/packages/hypre/package.py +++ b/var/spack/repos/builtin/packages/hypre/package.py @@ -23,7 +23,9 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## from spack import * -import os, sys +import os +import sys + class Hypre(Package): """Hypre is a library of high performance preconditioners that @@ -37,7 +39,7 @@ class Hypre(Package): version('2.10.0b', '768be38793a35bb5d055905b271f5b8e') # hypre does not know how to build shared libraries on Darwin - variant('shared', default=sys.platform!='darwin', description="Build shared library version (disables static library)") + variant('shared', default=(sys.platform != 'darwin'), description="Build shared library version (disables static library)") # SuperluDist have conflicting headers with those in Hypre variant('internal-superlu', default=True, description="Use internal Superlu routines") From 561748a063f8dab8bb5542b8bfab0878ab0fff06 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 08:03:54 +0200 Subject: [PATCH 31/68] netlib-scalapack: flake8 fixes --- .../packages/netlib-scalapack/package.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/var/spack/repos/builtin/packages/netlib-scalapack/package.py b/var/spack/repos/builtin/packages/netlib-scalapack/package.py index cb2d8b44fc..e91c044965 100644 --- a/var/spack/repos/builtin/packages/netlib-scalapack/package.py +++ b/var/spack/repos/builtin/packages/netlib-scalapack/package.py @@ -25,8 +25,10 @@ from spack import * import sys + class NetlibScalapack(Package): - """ScaLAPACK is a library of high-performance linear algebra routines for parallel distributed memory machines""" + """ScaLAPACK is a library of high-performance linear algebra routines for + parallel distributed memory machines""" homepage = "http://www.netlib.org/scalapack/" url = "http://www.netlib.org/scalapack/scalapack-2.0.2.tgz" @@ -48,10 +50,13 @@ class NetlibScalapack(Package): def install(self, spec, prefix): options = [ - "-DBUILD_SHARED_LIBS:BOOL=%s" % ('ON' if '+shared' in spec else 'OFF'), - "-DBUILD_STATIC_LIBS:BOOL=%s" % ('OFF' if '+shared' in spec else 'ON'), - "-DUSE_OPTIMIZED_LAPACK_BLAS:BOOL=ON", # forces scalapack to use find_package(LAPACK) - ] + "-DBUILD_SHARED_LIBS:BOOL=%s" % ('ON' if '+shared' in spec else + 'OFF'), + "-DBUILD_STATIC_LIBS:BOOL=%s" % ('OFF' if '+shared' in spec else + 'ON'), + # forces scalapack to use find_package(LAPACK): + "-DUSE_OPTIMIZED_LAPACK_BLAS:BOOL=ON", + ] # Make sure we use Spack's Lapack: options.extend([ @@ -75,11 +80,10 @@ def install(self, spec, prefix): make() make("install") - # The shared libraries are not installed correctly on Darwin; correct this + # The shared libraries are not installed correctly on Darwin: if (sys.platform == 'darwin') and ('+shared' in spec): fix_darwin_install_name(prefix.lib) - def setup_dependent_package(self, module, dependent_spec): spec = self.spec lib_dsuffix = '.dylib' if sys.platform == 'darwin' else '.so' @@ -87,4 +91,5 @@ def setup_dependent_package(self, module, dependent_spec): spec.fc_link = '-L%s -lscalapack' % spec.prefix.lib spec.cc_link = spec.fc_link - spec.libraries = [join_path(spec.prefix.lib, 'libscalapack%s' % lib_suffix)] + spec.libraries = [join_path(spec.prefix.lib, + 'libscalapack%s' % lib_suffix)] From 1bd3a702c99ec41bbed510102769bba6984bbd30 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 16 Jul 2016 08:12:57 +0200 Subject: [PATCH 32/68] mumps: flake8 fixes --- .../repos/builtin/packages/mumps/package.py | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/var/spack/repos/builtin/packages/mumps/package.py b/var/spack/repos/builtin/packages/mumps/package.py index 630c33562b..b85a6d2b94 100644 --- a/var/spack/repos/builtin/packages/mumps/package.py +++ b/var/spack/repos/builtin/packages/mumps/package.py @@ -23,7 +23,10 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## from spack import * -import os, sys, glob +import os +import sys +import glob + class Mumps(Package): """MUMPS: a MUltifrontal Massively Parallel sparse direct Solver""" @@ -44,7 +47,6 @@ class Mumps(Package): variant('idx64', default=False, description='Use int64_t/integer*8 as default index type') variant('shared', default=True, description='Build shared libraries') - depends_on('scotch + esmumps', when='~ptscotch+scotch') depends_on('scotch + esmumps + mpi', when='+ptscotch') depends_on('metis@5:', when='+metis') @@ -59,8 +61,8 @@ class Mumps(Package): # end before install # def patch(self): def write_makefile_inc(self): - if ('+parmetis' in self.spec or '+ptscotch' in self.spec) and '+mpi' not in self.spec: - raise RuntimeError('You cannot use the variants parmetis or ptscotch without mpi') + if ('+parmetis' in self.spec or '+ptscotch' in self.spec) and '+mpi' not in self.spec: # NOQA: ignore=E501 + raise RuntimeError('You cannot use the variants parmetis or ptscotch without mpi') # NOQA: ignore=E501 makefile_conf = ["LIBBLAS = %s" % to_link_flags( self.spec['blas'].blas_shared_lib) @@ -70,33 +72,41 @@ def write_makefile_inc(self): if '+ptscotch' in self.spec or '+scotch' in self.spec: join_lib = ' -l%s' % ('pt' if '+ptscotch' in self.spec else '') - makefile_conf.extend( - ["ISCOTCH = -I%s" % self.spec['scotch'].prefix.include, - "LSCOTCH = -L%s %s%s" % (self.spec['scotch'].prefix.lib, - join_lib, - join_lib.join(['esmumps', 'scotch', 'scotcherr']))]) + makefile_conf.extend([ + "ISCOTCH = -I%s" % self.spec['scotch'].prefix.include, + "LSCOTCH = -L%s %s%s" % (self.spec['scotch'].prefix.lib, + join_lib, + join_lib.join(['esmumps', + 'scotch', + 'scotcherr'])) + ]) + orderings.append('-Dscotch') if '+ptscotch' in self.spec: orderings.append('-Dptscotch') if '+parmetis' in self.spec and '+metis' in self.spec: - libname = 'parmetis' if '+parmetis' in self.spec else 'metis' - makefile_conf.extend( - ["IMETIS = -I%s" % self.spec['parmetis'].prefix.include, - "LMETIS = -L%s -l%s -L%s -l%s" % (self.spec['parmetis'].prefix.lib, 'parmetis',self.spec['metis'].prefix.lib, 'metis')]) + makefile_conf.extend([ + "IMETIS = -I%s" % self.spec['parmetis'].prefix.include, + "LMETIS = -L%s -l%s -L%s -l%s" % ( + self.spec['parmetis'].prefix.lib, 'parmetis', + self.spec['metis'].prefix.lib, 'metis') + ]) orderings.append('-Dparmetis') elif '+metis' in self.spec: - makefile_conf.extend( - ["IMETIS = -I%s" % self.spec['metis'].prefix.include, - "LMETIS = -L%s -l%s" % (self.spec['metis'].prefix.lib, 'metis')]) + makefile_conf.extend([ + "IMETIS = -I%s" % self.spec['metis'].prefix.include, + "LMETIS = -L%s -l%s" % (self.spec['metis'].prefix.lib, 'metis') + ]) orderings.append('-Dmetis') makefile_conf.append("ORDERINGSF = %s" % (' '.join(orderings))) # when building shared libs need -fPIC, otherwise - # /usr/bin/ld: graph.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC + # /usr/bin/ld: graph.o: relocation R_X86_64_32 against `.rodata.str1.1' + # can not be used when making a shared object; recompile with -fPIC fpic = '-fPIC' if '+shared' in self.spec else '' # TODO: test this part, it needs a full blas, scalapack and # partitionning environment with 64bit integers @@ -105,7 +115,7 @@ def write_makefile_inc(self): # the fortran compilation flags most probably are # working only for intel and gnu compilers this is # perhaps something the compiler should provide - ['OPTF = %s -O -DALLOW_NON_INIT %s' % (fpic,'-fdefault-integer-8' if self.compiler.name == "gcc" else '-i8'), + ['OPTF = %s -O -DALLOW_NON_INIT %s' % (fpic, '-fdefault-integer-8' if self.compiler.name == "gcc" else '-i8'), # NOQA: ignore=E501 'OPTL = %s -O ' % fpic, 'OPTC = %s -O -DINTSIZE64' % fpic]) else: @@ -114,7 +124,6 @@ def write_makefile_inc(self): 'OPTL = %s -O ' % fpic, 'OPTC = %s -O ' % fpic]) - if '+mpi' in self.spec: makefile_conf.extend( ["CC = %s" % join_path(self.spec['mpi'].prefix.bin, 'mpicc'), @@ -135,16 +144,17 @@ def write_makefile_inc(self): if '+shared' in self.spec: if sys.platform == 'darwin': - # Building dylibs with mpif90 causes segfaults on 10.8 and 10.10. Use gfortran. (Homebrew) + # Building dylibs with mpif90 causes segfaults on 10.8 and + # 10.10. Use gfortran. (Homebrew) makefile_conf.extend([ 'LIBEXT=.dylib', - 'AR=%s -dynamiclib -Wl,-install_name -Wl,%s/$(notdir $@) -undefined dynamic_lookup -o ' % (os.environ['FC'],prefix.lib), + 'AR=%s -dynamiclib -Wl,-install_name -Wl,%s/$(notdir $@) -undefined dynamic_lookup -o ' % (os.environ['FC'], prefix.lib), # NOQA: ignore=E501 'RANLIB=echo' ]) else: makefile_conf.extend([ 'LIBEXT=.so', - 'AR=$(FL) -shared -Wl,-soname -Wl,%s/$(notdir $@) -o' % prefix.lib, + 'AR=$(FL) -shared -Wl,-soname -Wl,%s/$(notdir $@) -o' % prefix.lib, # NOQA: ignore=E501 'RANLIB=echo' ]) else: @@ -154,9 +164,8 @@ def write_makefile_inc(self): 'RANLIB = ranlib' ]) - - makefile_inc_template = join_path(os.path.dirname(self.module.__file__), - 'Makefile.inc') + makefile_inc_template = join_path( + os.path.dirname(self.module.__file__), 'Makefile.inc') with open(makefile_inc_template, "r") as fh: makefile_conf.extend(fh.read().split('\n')) @@ -165,8 +174,6 @@ def write_makefile_inc(self): makefile_inc = '\n'.join(makefile_conf) fh.write(makefile_inc) - - def install(self, spec, prefix): make_libs = [] @@ -194,11 +201,11 @@ def install(self, spec, prefix): lib_dsuffix = '.dylib' if sys.platform == 'darwin' else '.so' lib_suffix = lib_dsuffix if '+shared' in spec else '.a' install('libseq/libmpiseq%s' % lib_suffix, prefix.lib) - for f in glob.glob(join_path('libseq','*.h')): + for f in glob.glob(join_path('libseq', '*.h')): install(f, prefix.include) - # FIXME: extend the tests to mpirun -np 2 (or alike) when build with MPI - # FIXME: use something like numdiff to compare blessed output with the current + # FIXME: extend the tests to mpirun -np 2 when build with MPI + # FIXME: use something like numdiff to compare output files with working_dir('examples'): if '+float' in spec: os.system('./ssimpletest < input_simpletest_real') From 2e4966c8544efbd41d737e4ba2e7d005af32bcbb Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Mon, 18 Jul 2016 10:11:18 +0200 Subject: [PATCH 33/68] netlib-scalapack: use dso_suffix --- var/spack/repos/builtin/packages/netlib-scalapack/package.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/netlib-scalapack/package.py b/var/spack/repos/builtin/packages/netlib-scalapack/package.py index e91c044965..a96b367be4 100644 --- a/var/spack/repos/builtin/packages/netlib-scalapack/package.py +++ b/var/spack/repos/builtin/packages/netlib-scalapack/package.py @@ -86,10 +86,9 @@ def install(self, spec, prefix): def setup_dependent_package(self, module, dependent_spec): spec = self.spec - lib_dsuffix = '.dylib' if sys.platform == 'darwin' else '.so' - lib_suffix = lib_dsuffix if '+shared' in spec else '.a' + lib_suffix = dso_suffix if '+shared' in spec else 'a' spec.fc_link = '-L%s -lscalapack' % spec.prefix.lib spec.cc_link = spec.fc_link spec.libraries = [join_path(spec.prefix.lib, - 'libscalapack%s' % lib_suffix)] + 'libscalapack.%s' % lib_suffix)] From cdc2ebee9018cc4cf067d73f269628901a8d4487 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 18 Jul 2016 01:11:24 -0700 Subject: [PATCH 34/68] Better error messages for `spack reindex`. --- lib/spack/spack/database.py | 7 ++++--- lib/spack/spack/directory_layout.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index c95abd7423..eabf740dbc 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -646,6 +646,7 @@ def __init__(self, path, msg=''): class InvalidDatabaseVersionError(SpackError): def __init__(self, expected, found): super(InvalidDatabaseVersionError, self).__init__( - "Expected database version %s but found version %s." + \ - "Try running `spack reindex` to fix." % - (expected, found)) + "Expected database version %s but found version %s." + % (expected, found), + "`spack reindex` may fix this, or you may need a newer " + "Spack version.") diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index a5e76043ad..8150a6da2b 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -34,6 +34,7 @@ import llnl.util.tty as tty from llnl.util.filesystem import join_path, mkdirp +import spack from spack.spec import Spec from spack.error import SpackError @@ -223,8 +224,14 @@ def write_spec(self, spec, path): def read_spec(self, path): """Read the contents of a file and parse them as a spec""" - with open(path) as f: - spec = Spec.from_yaml(f) + try: + with open(path) as f: + spec = Spec.from_yaml(f) + except Exception as e: + if spack.debug: + raise + raise SpecReadError( + 'Unable to read file: %s' % path, 'Cause: ' + str(e)) # Specs read from actual installations are always concrete spec._mark_concrete() @@ -456,10 +463,12 @@ def __init__(self, path): "Install path %s already exists!") +class SpecReadError(DirectoryLayoutError): + """Raised when directory layout can't read a spec.""" + + class InvalidExtensionSpecError(DirectoryLayoutError): """Raised when an extension file has a bad spec in it.""" - def __init__(self, message): - super(InvalidExtensionSpecError, self).__init__(message) class ExtensionAlreadyInstalledError(DirectoryLayoutError): From 73f10c9363e584708a39cf02758fc837dc02b8d3 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 15 Jul 2016 16:01:01 -0700 Subject: [PATCH 35/68] Fix broken `spack info` command after build dep merge. - Added a method to get dependencies of particular types from Package - Fixed info command. --- lib/spack/spack/cmd/info.py | 2 +- lib/spack/spack/package.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index 5774034062..f8b6ceab59 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -84,7 +84,7 @@ def print_text_info(pkg): for deptype in ('build', 'link', 'run'): print print "%s Dependencies:" % deptype.capitalize() - deps = pkg.dependencies(deptype) + deps = pkg.dependencies_of_type(deptype) if deps: colify(deps, indent=4) else: diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 7f53b461b2..3a7b61f7e6 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -565,6 +565,13 @@ def fetcher(self): def fetcher(self, f): self._fetcher = f + + def dependencies_of_type(self, *deptypes): + """Get subset of the dependencies with certain types.""" + return dict((name, conds) for name, conds in self.dependencies.items() + if any(d in self._deptypes[name] for d in deptypes)) + + @property def extendee_spec(self): """ From 192369dd2b495678e9c701f253eefd15d57fc7d1 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sun, 17 Jul 2016 15:47:57 -0700 Subject: [PATCH 36/68] Fix #1265: Errors in spack reindex - Consolidated code to read spec.yaml and database index.yaml into one method (`read_yaml_dep_specs()`) in spec.py. - Code understands old hash format, tuple format, and dicts for dep specs, for backward compatibility. - Spec YAML now uses a dict with keys to represent dep specs (this is more future-proof). - Dep specs no longer contain !!py-tuple entries in YAML (only lists properly YAML-ize) - bump database version. --- lib/spack/spack/database.py | 14 ++--- lib/spack/spack/spec.py | 103 ++++++++++++++++++++++++------------ 2 files changed, 74 insertions(+), 43 deletions(-) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index eabf740dbc..a30994b57c 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -60,7 +60,7 @@ _db_dirname = '.spack-db' # DB version. This is stuck in the DB file to track changes in format. -_db_version = Version('0.9.1') +_db_version = Version('0.9.2') # Default timeout for spack database locks is 5 min. _db_lock_timeout = 60 @@ -215,14 +215,10 @@ def _read_spec_from_yaml(self, hash_key, installs, parent_key=None): # Add dependencies from other records in the install DB to # form a full spec. if 'dependencies' in spec_dict[spec.name]: - for dep in spec_dict[spec.name]['dependencies'].values(): - if type(dep) == tuple: - dep_hash, deptypes = dep - else: - dep_hash = dep - deptypes = spack.alldeps - child = self._read_spec_from_yaml(dep_hash, installs, hash_key) - spec._add_dependency(child, deptypes) + yaml_deps = spec_dict[spec.name]['dependencies'] + for dname, dhash, dtypes in Spec.read_yaml_dep_specs(yaml_deps): + child = self._read_spec_from_yaml(dhash, installs, hash_key) + spec._add_dependency(child, dtypes) # Specs from the database need to be marked concrete because # they represent actual installations. diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index d3a5f66e57..7f765f8090 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -155,6 +155,7 @@ every time we call str()""" _any_version = VersionList([':']) +# Special types of dependencies. alldeps = ('build', 'link', 'run') nolink = ('build', 'run') @@ -296,10 +297,15 @@ def __repr__(self): @key_ordering class DependencySpec(object): - """ - Dependencies have conditions in which they apply. + """Dependencies can be one (or more) of several types: - This stores both what is depended on and why it is a dependency. + - build: needs to be in the PATH at build time. + - link: is linked to and added to compiler flags. + - run: needs to be in the PATH for the package to run. + + Fields: + - spec: the spack.spec.Spec description of a dependency. + - deptypes: strings representing the type of dependency this is. """ def __init__(self, spec, deptypes): self.spec = spec @@ -558,15 +564,15 @@ def dependents(self, deptype=None): def _find_deps_dict(self, where, deptype): deptype = self._deptype_norm(deptype) - return [(dep.spec.name, dep) - for dep in where.values() - if deptype and any(d in deptype for d in dep.deptypes)] + return dict((dep.spec.name, dep) + for dep in where.values() + if deptype and any(d in deptype for d in dep.deptypes)) def dependencies_dict(self, deptype=None): - return dict(self._find_deps_dict(self._dependencies, deptype)) + return self._find_deps_dict(self._dependencies, deptype) def dependents_dict(self, deptype=None): - return dict(self._find_deps_dict(self._dependents, deptype)) + return self._find_deps_dict(self._dependents, deptype) # # Private routines here are called by the parser when building a spec. @@ -914,9 +920,11 @@ def to_node_dict(self): d = { 'parameters': params, 'arch': self.architecture, - 'dependencies': dict((d, (deps[d].spec.dag_hash(), - deps[d].deptypes)) - for d in sorted(deps.keys())) + 'dependencies': dict( + (name, { + 'hash': dspec.spec.dag_hash(), + 'type': [str(s) for s in dspec.deptypes]}) + for name, dspec in deps.items()) } # Older concrete specs do not have a namespace. Omit for @@ -982,13 +990,35 @@ def from_node_dict(node): raise SpackRecordError( "Did not find a valid format for variants in YAML file") - # XXX(deptypes): why are dependencies not meant to be read here? - #for name, dep_info in node['dependencies'].items(): - # (dag_hash, deptypes) = dep_info - # spec._dependencies[name] = DependencySpec(dag_hash, deptypes) + # Don't read dependencies here; from_node_dict() is used by + # from_yaml() to read the root *and* each dependency spec. return spec + + @staticmethod + def read_yaml_dep_specs(dependency_dict): + """Read the DependencySpec portion of a YAML-formatted Spec. + + This needs to be backward-compatible with older spack spec + formats so that reindex will work on old specs/databases. + """ + for dep_name, elt in dependency_dict.items(): + if isinstance(elt, basestring): + # original format, elt is just the dependency hash. + dag_hash, deptypes = elt, ['build', 'link'] + elif isinstance(elt, tuple): + # original deptypes format: (used tuples, not future-proof) + dag_hash, deptypes = elt + elif isinstance(elt, dict): + # new format: elements of dependency spec are keyed. + dag_hash, deptypes = elt['hash'], elt['type'] + else: + raise SpecError("Couldn't parse dependency types in spec.") + + yield dep_name, dag_hash, list(deptypes) + + @staticmethod def from_yaml(stream): """Construct a spec from YAML. @@ -1000,27 +1030,30 @@ def from_yaml(stream): represent more than the DAG does. """ - deps = {} - spec = None - try: yfile = yaml.load(stream) except MarkedYAMLError, e: raise SpackYAMLError("error parsing YAML spec:", str(e)) - for node in yfile['spec']: - name = next(iter(node)) - dep = Spec.from_node_dict(node) - if not spec: - spec = dep - deps[dep.name] = dep + nodes = yfile['spec'] - for node in yfile['spec']: + # Read nodes out of list. Root spec is the first element; + # dependencies are the following elements. + dep_list = [Spec.from_node_dict(node) for node in nodes] + if not dep_list: + raise SpecError("YAML spec contains no nodes.") + deps = dict((spec.name, spec) for spec in dep_list) + spec = dep_list[0] + + for node in nodes: + # get dependency dict from the node. name = next(iter(node)) - for dep_name, (dep, deptypes) in \ - node[name]['dependencies'].items(): - deps[name]._dependencies[dep_name] = \ - DependencySpec(deps[dep_name], deptypes) + yaml_deps = node[name]['dependencies'] + for dname, dhash, dtypes in Spec.read_yaml_dep_specs(yaml_deps): + # Fill in dependencies by looking them up by name in deps dict + deps[name]._dependencies[dname] = DependencySpec( + deps[dname], set(dtypes)) + return spec def _concretize_helper(self, presets=None, visited=None): @@ -1505,13 +1538,13 @@ def normalize(self, force=False): # Ensure first that all packages & compilers in the DAG exist. self.validate_names() # Get all the dependencies into one DependencyMap - spec_deps = self.flat_dependencies_with_deptype(copy=False, - deptype_query=alldeps) + spec_deps = self.flat_dependencies_with_deptype( + copy=False, deptype_query=alldeps) # Initialize index of virtual dependency providers if # concretize didn't pass us one already - provider_index = ProviderIndex([s.spec for s in spec_deps.values()], - restrict=True) + provider_index = ProviderIndex( + [s.spec for s in spec_deps.values()], restrict=True) # traverse the package DAG and fill out dependencies according # to package files & their 'when' specs @@ -2244,12 +2277,14 @@ def tree(self, **kwargs): indent = kwargs.pop('indent', 0) fmt = kwargs.pop('format', '$_$@$%@+$+$=') prefix = kwargs.pop('prefix', None) + deptypes = kwargs.pop('deptypes', ('build', 'link')) check_kwargs(kwargs, self.tree) out = "" cur_id = 0 ids = {} - for d, node in self.traverse(order='pre', cover=cover, depth=True): + for d, node in self.traverse( + order='pre', cover=cover, depth=True, deptypes=deptypes): if prefix is not None: out += prefix(node) out += " " * indent From cddaba8add41bc93659070f1ffd18ffc9a0dabb0 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 18 Jul 2016 02:20:41 -0700 Subject: [PATCH 37/68] flake8 fixes. - package.py - spec.py - test/architecture.py --- lib/spack/spack/cmd/info.py | 5 +- lib/spack/spack/database.py | 4 +- lib/spack/spack/package.py | 118 ++++++++-------- lib/spack/spack/spec.py | 193 ++++++++++++++------------- lib/spack/spack/test/architecture.py | 64 ++++++--- 5 files changed, 214 insertions(+), 170 deletions(-) diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index f8b6ceab59..498518057b 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -29,9 +29,11 @@ description = "Get detailed information on a particular package" + def padder(str_list, extra=0): """Return a function to pad elements of a list.""" length = max(len(str(s)) for s in str_list) + extra + def pad(string): string = str(string) padding = max(0, length - len(string)) @@ -40,7 +42,8 @@ def pad(string): def setup_parser(subparser): - subparser.add_argument('name', metavar="PACKAGE", help="Name of package to get info for.") + subparser.add_argument( + 'name', metavar="PACKAGE", help="Name of package to get info for.") def print_text_info(pkg): diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index a30994b57c..317b0d5784 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -635,8 +635,8 @@ def _exit(self): class CorruptDatabaseError(SpackError): def __init__(self, path, msg=''): super(CorruptDatabaseError, self).__init__( - "Spack database is corrupt: %s. %s." + \ - "Try running `spack reindex` to fix." % (path, msg)) + "Spack database is corrupt: %s. %s." % (path, msg), + "Try running `spack reindex` to fix.") class InvalidDatabaseVersionError(SpackError): diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 3a7b61f7e6..6a92c548fb 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -37,7 +37,6 @@ import re import textwrap import time -import glob import string import llnl.util.tty as tty @@ -62,10 +61,10 @@ from spack.stage import Stage, ResourceStage, StageComposite from spack.util.compression import allowed_archive from spack.util.environment import dump_environment -from spack.util.executable import ProcessError, Executable, which +from spack.util.executable import ProcessError, which from spack.version import * from spack import directory_layout -from urlparse import urlparse + """Allowed URL schemes for spack packages.""" _ALLOWED_URL_SCHEMES = ["http", "https", "ftp", "file", "git"] @@ -410,7 +409,6 @@ def package_dir(self): """Return the directory where the package.py file lives.""" return os.path.dirname(self.module.__file__) - @property def global_license_dir(self): """Returns the directory where global license files for all @@ -565,13 +563,11 @@ def fetcher(self): def fetcher(self, f): self._fetcher = f - def dependencies_of_type(self, *deptypes): """Get subset of the dependencies with certain types.""" return dict((name, conds) for name, conds in self.dependencies.items() if any(d in self._deptypes[name] for d in deptypes)) - @property def extendee_spec(self): """ @@ -694,7 +690,7 @@ def installed_dependents(self): if self.name == spec.name: continue # XXX(deptype): Should build dependencies not count here? - #for dep in spec.traverse(deptype=('run')): + # for dep in spec.traverse(deptype=('run')): for dep in spec.traverse(deptype=spack.alldeps): if self.spec == dep: dependents.append(spec) @@ -706,13 +702,13 @@ def prefix(self): return self.spec.prefix @property - #TODO: Change this to architecture + # TODO: Change this to architecture def compiler(self): """Get the spack.compiler.Compiler object used to build this package""" if not self.spec.concrete: raise ValueError("Can only get a compiler for a concrete package.") return spack.compilers.compiler_for_spec(self.spec.compiler, - self.spec.architecture) + self.spec.architecture) def url_version(self, version): """ @@ -768,7 +764,6 @@ def do_fetch(self, mirror_only=False): self.stage.cache_local() - def do_stage(self, mirror_only=False): """Unpacks the fetched tarball, then changes into the expanded tarball directory.""" @@ -886,6 +881,7 @@ def _resource_stage(self, resource): return resource_stage_folder install_phases = set(['configure', 'build', 'install', 'provenance']) + def do_install(self, keep_prefix=False, keep_stage=False, @@ -897,7 +893,7 @@ def do_install(self, fake=False, explicit=False, dirty=False, - install_phases = install_phases): + install_phases=install_phases): """Called by commands to install a package and its dependencies. Package implementations should override install() to describe @@ -918,7 +914,8 @@ def do_install(self, run_tests -- Runn tests within the package's install() """ if not self.spec.concrete: - raise ValueError("Can only install concrete packages: %s." % self.spec.name) + raise ValueError("Can only install concrete packages: %s." + % self.spec.name) # No installation needed if package is external if self.spec.external: @@ -927,7 +924,8 @@ def do_install(self, return # Ensure package is not already installed - if 'install' in install_phases and spack.install_layout.check_installed(self.spec): + layout = spack.install_layout + if 'install' in install_phases and layout.check_installed(self.spec): tty.msg("%s is already installed in %s" % (self.name, self.prefix)) rec = spack.installed_db.get_record(self.spec) if (not rec.explicit) and explicit: @@ -1008,20 +1006,17 @@ def build_process(): if 'install' in self.install_phases: self.sanity_check_prefix() - # Copy provenance into the install directory on success if 'provenance' in self.install_phases: - log_install_path = spack.install_layout.build_log_path( - self.spec) - env_install_path = spack.install_layout.build_env_path( - self.spec) - packages_dir = spack.install_layout.build_packages_path( - self.spec) + log_install_path = layout.build_log_path(self.spec) + env_install_path = layout.build_env_path(self.spec) + packages_dir = layout.build_packages_path(self.spec) # Remove first if we're overwriting another build # (can happen with spack setup) try: - shutil.rmtree(packages_dir) # log_install_path and env_install_path are inside this + # log_install_path and env_install_path are here + shutil.rmtree(packages_dir) except: pass @@ -1048,7 +1043,7 @@ def build_process(): except directory_layout.InstallDirectoryAlreadyExistsError: if 'install' in install_phases: # Abort install if install directory exists. - # But do NOT remove it (you'd be overwriting someon else's stuff) + # But do NOT remove it (you'd be overwriting someone's data) tty.warn("Keeping existing install prefix in place.") raise else: @@ -1540,24 +1535,29 @@ def _hms(seconds): parts.append("%.2fs" % s) return ' '.join(parts) + class StagedPackage(Package): """A Package subclass where the install() is split up into stages.""" def install_setup(self): - """Creates an spack_setup.py script to configure the package later if we like.""" - raise InstallError("Package %s provides no install_setup() method!" % self.name) + """Creates a spack_setup.py script to configure the package later.""" + raise InstallError( + "Package %s provides no install_setup() method!" % self.name) def install_configure(self): """Runs the configure process.""" - raise InstallError("Package %s provides no install_configure() method!" % self.name) + raise InstallError( + "Package %s provides no install_configure() method!" % self.name) def install_build(self): """Runs the build process.""" - raise InstallError("Package %s provides no install_build() method!" % self.name) + raise InstallError( + "Package %s provides no install_build() method!" % self.name) def install_install(self): """Runs the install process.""" - raise InstallError("Package %s provides no install_install() method!" % self.name) + raise InstallError( + "Package %s provides no install_install() method!" % self.name) def install(self, spec, prefix): if 'setup' in self.install_phases: @@ -1574,9 +1574,10 @@ def install(self, spec, prefix): else: # Create a dummy file so the build doesn't fail. # That way, the module file will also be created. - with open(os.path.join(prefix, 'dummy'), 'w') as fout: + with open(os.path.join(prefix, 'dummy'), 'w'): pass + # stackoverflow.com/questions/12791997/how-do-you-do-a-simple-chmod-x-from-within-python def make_executable(path): mode = os.stat(path).st_mode @@ -1584,9 +1585,7 @@ def make_executable(path): os.chmod(path, mode) - class CMakePackage(StagedPackage): - def make_make(self): import multiprocessing # number of jobs spack will to build with. @@ -1600,37 +1599,41 @@ def make_make(self): return make def configure_args(self): - """Returns package-specific arguments to be provided to the configure command.""" + """Returns package-specific arguments to be provided to + the configure command. + """ return list() def configure_env(self): - """Returns package-specific environment under which the configure command should be run.""" + """Returns package-specific environment under which the + configure command should be run. + """ return dict() - def spack_transitive_include_path(self): + def transitive_inc_path(self): return ';'.join( os.path.join(dep, 'include') for dep in os.environ['SPACK_DEPENDENCIES'].split(os.pathsep) ) def install_setup(self): - cmd = [str(which('cmake'))] + \ - spack.build_environment.get_std_cmake_args(self) + \ - ['-DCMAKE_INSTALL_PREFIX=%s' % os.environ['SPACK_PREFIX'], - '-DCMAKE_C_COMPILER=%s' % os.environ['SPACK_CC'], - '-DCMAKE_CXX_COMPILER=%s' % os.environ['SPACK_CXX'], - '-DCMAKE_Fortran_COMPILER=%s' % os.environ['SPACK_FC']] + \ - self.configure_args() + cmd = [str(which('cmake'))] + cmd += spack.build_environment.get_std_cmake_args(self) + cmd += ['-DCMAKE_INSTALL_PREFIX=%s' % os.environ['SPACK_PREFIX'], + '-DCMAKE_C_COMPILER=%s' % os.environ['SPACK_CC'], + '-DCMAKE_CXX_COMPILER=%s' % os.environ['SPACK_CXX'], + '-DCMAKE_Fortran_COMPILER=%s' % os.environ['SPACK_FC']] + cmd += self.configure_args() - env = dict() - env['PATH'] = os.environ['PATH'] - env['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.spack_transitive_include_path() - env['CMAKE_PREFIX_PATH'] = os.environ['CMAKE_PREFIX_PATH'] + env = { + 'PATH': os.environ['PATH'], + 'SPACK_TRANSITIVE_INCLUDE_PATH': self.transitive_inc_path(), + 'CMAKE_PREFIX_PATH': os.environ['CMAKE_PREFIX_PATH'] + } setup_fname = 'spconfig.py' with open(setup_fname, 'w') as fout: - fout.write(\ -r"""#!%s + fout.write(r"""#!%s # import sys @@ -1638,7 +1641,7 @@ def install_setup(self): import subprocess def cmdlist(str): - return list(x.strip().replace("'",'') for x in str.split('\n') if x) + return list(x.strip().replace("'",'') for x in str.split('\n') if x) env = dict(os.environ) """ % sys.executable) @@ -1646,34 +1649,39 @@ def cmdlist(str): for name in env_vars: val = env[name] if string.find(name, 'PATH') < 0: - fout.write('env[%s] = %s\n' % (repr(name),repr(val))) + fout.write('env[%s] = %s\n' % (repr(name), repr(val))) else: if name == 'SPACK_TRANSITIVE_INCLUDE_PATH': sep = ';' else: sep = ':' - fout.write('env[%s] = "%s".join(cmdlist("""\n' % (repr(name),sep)) + fout.write('env[%s] = "%s".join(cmdlist("""\n' + % (repr(name), sep)) for part in string.split(val, sep): fout.write(' %s\n' % part) fout.write('"""))\n') - fout.write("env['CMAKE_TRANSITIVE_INCLUDE_PATH'] = env['SPACK_TRANSITIVE_INCLUDE_PATH'] # Deprecated\n") + fout.write("env['CMAKE_TRANSITIVE_INCLUDE_PATH'] = " + "env['SPACK_TRANSITIVE_INCLUDE_PATH'] # Deprecated\n") fout.write('\ncmd = cmdlist("""\n') fout.write('%s\n' % cmd[0]) for arg in cmd[1:]: fout.write(' %s\n' % arg) fout.write('""") + sys.argv[1:]\n') - fout.write('\nproc = subprocess.Popen(cmd, env=env)\nproc.wait()\n') + fout.write('\nproc = subprocess.Popen(cmd, env=env)\n') + fout.write('proc.wait()\n') make_executable(setup_fname) - def install_configure(self): cmake = which('cmake') with working_dir(self.build_directory, create=True): - os.environ.update(self.configure_env()) - os.environ['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.spack_transitive_include_path() - options = self.configure_args() + spack.build_environment.get_std_cmake_args(self) + env = os.environ + env.update(self.configure_env()) + env['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.transitive_inc_path() + + options = self.configure_args() + options += spack.build_environment.get_std_cmake_args(self) cmake(self.source_directory, *options) def install_build(self): diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 7f765f8090..e694f2b2da 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -96,7 +96,6 @@ expansion when it is the first character in an id typed on the command line. """ import sys -import itertools import hashlib import base64 import imp @@ -116,8 +115,6 @@ import spack.error import spack.compilers as compilers -# TODO: move display_specs to some other location. -from spack.cmd.find import display_specs from spack.version import * from spack.util.string import * from spack.util.prefix import Prefix @@ -650,7 +647,8 @@ def _set_platform(self, value): mod = imp.load_source(mod_name, path) class_name = mod_to_class(value) if not hasattr(mod, class_name): - tty.die('No class %s defined in %s' % (class_name, mod_name)) + tty.die( + 'No class %s defined in %s' % (class_name, mod_name)) cls = getattr(mod, class_name) if not inspect.isclass(cls): tty.die('%s.%s is not a class' % (mod_name, class_name)) @@ -673,13 +671,15 @@ def _set_platform(self, value): def _set_os(self, value): """Called by the parser to set the architecture operating system""" - if self.architecture.platform: - self.architecture.platform_os = self.architecture.platform.operating_system(value) + arch = self.architecture + if arch.platform: + arch.platform_os = arch.platform.operating_system(value) def _set_target(self, value): """Called by the parser to set the architecture target""" - if self.architecture.platform: - self.architecture.target = self.architecture.platform.target(value) + arch = self.architecture + if arch.platform: + arch.target = arch.platform.target(value) def _add_dependency(self, spec, deptypes): """Called by the parser to add another spec as a dependency.""" @@ -694,8 +694,9 @@ def _add_dependency(self, spec, deptypes): # @property def fullname(self): - return (('%s.%s' % (self.namespace, self.name)) if self.namespace else - (self.name if self.name else '')) + return ( + ('%s.%s' % (self.namespace, self.name)) if self.namespace else + (self.name if self.name else '')) @property def root(self): @@ -751,15 +752,15 @@ def concrete(self): if self._concrete: return True - self._concrete = bool(not self.virtual - and self.namespace is not None - and self.versions.concrete - and self.variants.concrete - and self.architecture - and self.architecture.concrete - and self.compiler and self.compiler.concrete - and self.compiler_flags.concrete - and self._dependencies.concrete) + self._concrete = bool(not self.virtual and + self.namespace is not None and + self.versions.concrete and + self.variants.concrete and + self.architecture and + self.architecture.concrete and + self.compiler and self.compiler.concrete and + self.compiler_flags.concrete and + self._dependencies.concrete) return self._concrete def traverse(self, visited=None, deptype=None, **kwargs): @@ -870,9 +871,9 @@ def return_val(res): for name in sorted(successors): child = successors[name] children = child.spec.traverse_with_deptype( - visited, d=d + 1, deptype=deptype_query, - deptype_query=deptype_query, - _self_deptype=child.deptypes, **kwargs) + visited, d=d + 1, deptype=deptype_query, + deptype_query=deptype_query, + _self_deptype=child.deptypes, **kwargs) for elt in children: yield elt @@ -995,7 +996,6 @@ def from_node_dict(node): return spec - @staticmethod def read_yaml_dep_specs(dependency_dict): """Read the DependencySpec portion of a YAML-formatted Spec. @@ -1018,7 +1018,6 @@ def read_yaml_dep_specs(dependency_dict): yield dep_name, dag_hash, list(deptypes) - @staticmethod def from_yaml(stream): """Construct a spec from YAML. @@ -1204,14 +1203,16 @@ def _expand_virtual_packages(self): def feq(cfield, sfield): return (not cfield) or (cfield == sfield) - if replacement is spec or (feq(replacement.name, spec.name) and - feq(replacement.versions, spec.versions) and - feq(replacement.compiler, spec.compiler) and - feq(replacement.architecture, spec.architecture) and - feq(replacement._dependencies, spec._dependencies) and - feq(replacement.variants, spec.variants) and - feq(replacement.external, spec.external) and - feq(replacement.external_module, spec.external_module)): + if replacement is spec or ( + feq(replacement.name, spec.name) and + feq(replacement.versions, spec.versions) and + feq(replacement.compiler, spec.compiler) and + feq(replacement.architecture, spec.architecture) and + feq(replacement._dependencies, spec._dependencies) and + feq(replacement.variants, spec.variants) and + feq(replacement.external, spec.external) and + feq(replacement.external_module, + spec.external_module)): continue # Refine this spec to the candidate. This uses # replace_with AND dup so that it can work in @@ -1268,10 +1269,10 @@ def concretize(self): if s.namespace is None: s.namespace = spack.repo.repo_for_pkg(s.name).namespace - for s in self.traverse(root=False): if s.external_module: - compiler = spack.compilers.compiler_for_spec(s.compiler, s.architecture) + compiler = spack.compilers.compiler_for_spec( + s.compiler, s.architecture) for mod in compiler.modules: load_module(mod) @@ -1617,20 +1618,17 @@ def constrain(self, other, deps=True): other.variants[v]) # TODO: Check out the logic here - if self.architecture is not None and other.architecture is not None: - if self.architecture.platform is not None and other.architecture.platform is not None: - if self.architecture.platform != other.architecture.platform: - raise UnsatisfiableArchitectureSpecError(self.architecture, - other.architecture) - if self.architecture.platform_os is not None and other.architecture.platform_os is not None: - if self.architecture.platform_os != other.architecture.platform_os: - raise UnsatisfiableArchitectureSpecError(self.architecture, - other.architecture) - if self.architecture.target is not None and other.architecture.target is not None: - if self.architecture.target != other.architecture.target: - raise UnsatisfiableArchitectureSpecError(self.architecture, - other.architecture) - + sarch, oarch = self.architecture, other.architecture + if sarch is not None and oarch is not None: + if sarch.platform is not None and oarch.platform is not None: + if sarch.platform != oarch.platform: + raise UnsatisfiableArchitectureSpecError(sarch, oarch) + if sarch.platform_os is not None and oarch.platform_os is not None: + if sarch.platform_os != oarch.platform_os: + raise UnsatisfiableArchitectureSpecError(sarch, oarch) + if sarch.target is not None and oarch.target is not None: + if sarch.target != oarch.target: + raise UnsatisfiableArchitectureSpecError(sarch, oarch) changed = False if self.compiler is not None and other.compiler is not None: @@ -1645,15 +1643,16 @@ def constrain(self, other, deps=True): changed |= self.compiler_flags.constrain(other.compiler_flags) old = str(self.architecture) - if self.architecture is None or other.architecture is None: - self.architecture = self.architecture or other.architecture + sarch, oarch = self.architecture, other.architecture + if sarch is None or other.architecture is None: + self.architecture = sarch or oarch else: - if self.architecture.platform is None or other.architecture.platform is None: - self.architecture.platform = self.architecture.platform or other.architecture.platform - if self.architecture.platform_os is None or other.architecture.platform_os is None: - self.architecture.platform_os = self.architecture.platform_os or other.architecture.platform_os - if self.architecture.target is None or other.architecture.target is None: - self.architecture.target = self.architecture.target or other.architecture.target + if sarch.platform is None or oarch.platform is None: + self.architecture.platform = sarch.platform or oarch.platform + if sarch.platform_os is None or oarch.platform_os is None: + sarch.platform_os = sarch.platform_os or oarch.platform_os + if sarch.target is None or oarch.target is None: + sarch.target = sarch.target or oarch.target changed |= (str(self.architecture) != old) if deps: @@ -1784,15 +1783,25 @@ def satisfies(self, other, deps=True, strict=False): # Architecture satisfaction is currently just string equality. # If not strict, None means unconstrained. - if self.architecture and other.architecture: - if ((self.architecture.platform and other.architecture.platform and self.architecture.platform != other.architecture.platform) or - (self.architecture.platform_os and other.architecture.platform_os and self.architecture.platform_os != other.architecture.platform_os) or - (self.architecture.target and other.architecture.target and self.architecture.target != other.architecture.target)): + sarch, oarch = self.architecture, other.architecture + if sarch and oarch: + if ((sarch.platform and + oarch.platform and + sarch.platform != oarch.platform) or + + (sarch.platform_os and + oarch.platform_os and + sarch.platform_os != oarch.platform_os) or + + (sarch.target and + oarch.target and + sarch.target != oarch.target)): return False - elif strict and ((other.architecture and not self.architecture) or - (other.architecture.platform and not self.architecture.platform) or - (other.architecture.platform_os and not self.architecture.platform_os) or - (other.architecture.target and not self.architecture.target)): + + elif strict and ((oarch and not sarch) or + (oarch.platform and not sarch.platform) or + (oarch.platform_os and not sarch.platform_os) or + (oarch.target and not sarch.target)): return False if not self.compiler_flags.satisfies( @@ -1874,11 +1883,16 @@ def _dup(self, other, **kwargs): # We don't count dependencies as changes here changed = True if hasattr(self, 'name'): - changed = (self.name != other.name and self.versions != other.versions and \ - self.architecture != other.architecture and self.compiler != other.compiler and \ - self.variants != other.variants and self._normal != other._normal and \ - self.concrete != other.concrete and self.external != other.external and \ - self.external_module != other.external_module and self.compiler_flags != other.compiler_flags) + changed = (self.name != other.name and + self.versions != other.versions and + self.architecture != other.architecture and + self.compiler != other.compiler and + self.variants != other.variants and + self._normal != other._normal and + self.concrete != other.concrete and + self.external != other.external and + self.external_module != other.external_module and + self.compiler_flags != other.compiler_flags) # Local node attributes get copied first. self.name = other.name @@ -1922,7 +1936,7 @@ def _dup(self, other, **kwargs): # here. if depspec.spec.name not in new_spec._dependencies: new_spec._add_dependency( - new_nodes[depspec.spec.name], depspec.deptypes) + new_nodes[depspec.spec.name], depspec.deptypes) # Since we preserved structure, we can copy _normal safely. self._normal = other._normal @@ -2033,7 +2047,6 @@ def _cmp_node(self): self.compiler, self.compiler_flags) - def eq_node(self, other): """Equality with another spec, not including dependencies.""" return self._cmp_node() == other._cmp_node() @@ -2229,41 +2242,39 @@ def write(s, c): def dep_string(self): return ''.join("^" + dep.format() for dep in self.sorted_deps()) - def __cmp__(self, other): - #Package name sort order is not configurable, always goes alphabetical + # Package name sort order is not configurable, always goes alphabetical if self.name != other.name: return cmp(self.name, other.name) - #Package version is second in compare order + # Package version is second in compare order pkgname = self.name if self.versions != other.versions: - return spack.pkgsort.version_compare(pkgname, - self.versions, other.versions) + return spack.pkgsort.version_compare( + pkgname, self.versions, other.versions) - #Compiler is third + # Compiler is third if self.compiler != other.compiler: - return spack.pkgsort.compiler_compare(pkgname, - self.compiler, other.compiler) + return spack.pkgsort.compiler_compare( + pkgname, self.compiler, other.compiler) - #Variants + # Variants if self.variants != other.variants: - return spack.pkgsort.variant_compare(pkgname, - self.variants, other.variants) + return spack.pkgsort.variant_compare( + pkgname, self.variants, other.variants) - #Target + # Target if self.architecture != other.architecture: - return spack.pkgsort.architecture_compare(pkgname, - self.architecture, other.architecture) + return spack.pkgsort.architecture_compare( + pkgname, self.architecture, other.architecture) - #Dependency is not configurable + # Dependency is not configurable if self._dependencies != other._dependencies: return -1 if self._dependencies < other._dependencies else 1 - #Equal specs + # Equal specs return 0 - def __str__(self): return self.format() + self.dep_string() @@ -2338,8 +2349,8 @@ def __init__(self): # Lexer is always the same for every parser. _lexer = SpecLexer() -class SpecParser(spack.parse.Parser): +class SpecParser(spack.parse.Parser): def __init__(self): super(SpecParser, self).__init__(_lexer) self.previous = None @@ -2392,8 +2403,8 @@ def do_parse(self): except spack.parse.ParseError, e: raise SpecParseError(e) - - # If the spec has an os or a target and no platform, give it the default platform + # If the spec has an os or a target and no platform, give it + # the default platform for spec in specs: for s in spec.traverse(): if s.architecture.os_string or s.architecture.target_string: diff --git a/lib/spack/spack/test/architecture.py b/lib/spack/spack/test/architecture.py index ae3f08deed..09bdb021af 100644 --- a/lib/spack/spack/test/architecture.py +++ b/lib/spack/spack/test/architecture.py @@ -1,7 +1,31 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## """ Test checks if the architecture class is created correctly and also that the functions are looking for the correct architecture name """ -import unittest +import itertools import os import platform as py_platform import spack @@ -14,9 +38,8 @@ from spack.test.mock_packages_test import * -#class ArchitectureTest(unittest.TestCase): -class ArchitectureTest(MockPackagesTest): +class ArchitectureTest(MockPackagesTest): def setUp(self): super(ArchitectureTest, self).setUp() self.platform = spack.architecture.platform() @@ -36,24 +59,22 @@ def test_dict_functions_for_architecture(self): self.assertEqual(arch, new_arch) - self.assertTrue( isinstance(arch, spack.architecture.Arch) ) - self.assertTrue( isinstance(arch.platform, spack.architecture.Platform) ) - self.assertTrue( isinstance(arch.platform_os, - spack.architecture.OperatingSystem) ) - self.assertTrue( isinstance(arch.target, - spack.architecture.Target) ) - self.assertTrue( isinstance(new_arch, spack.architecture.Arch) ) - self.assertTrue( isinstance(new_arch.platform, - spack.architecture.Platform) ) - self.assertTrue( isinstance(new_arch.platform_os, - spack.architecture.OperatingSystem) ) - self.assertTrue( isinstance(new_arch.target, - spack.architecture.Target) ) - + self.assertTrue(isinstance(arch, spack.architecture.Arch)) + self.assertTrue(isinstance(arch.platform, spack.architecture.Platform)) + self.assertTrue(isinstance(arch.platform_os, + spack.architecture.OperatingSystem)) + self.assertTrue(isinstance(arch.target, + spack.architecture.Target)) + self.assertTrue(isinstance(new_arch, spack.architecture.Arch)) + self.assertTrue(isinstance(new_arch.platform, + spack.architecture.Platform)) + self.assertTrue(isinstance(new_arch.platform_os, + spack.architecture.OperatingSystem)) + self.assertTrue(isinstance(new_arch.target, + spack.architecture.Target)) def test_platform(self): output_platform_class = spack.architecture.platform() - my_arch_class = None if os.path.exists('/opt/cray/craype'): my_platform_class = CrayXc() elif os.path.exists('/bgsys'): @@ -91,7 +112,7 @@ def test_user_defaults(self): default_os = self.platform.operating_system("default_os") default_target = self.platform.target("default_target") - default_spec = Spec("libelf") # default is no args + default_spec = Spec("libelf") # default is no args default_spec.concretize() self.assertEqual(default_os, default_spec.architecture.platform_os) self.assertEqual(default_target, default_spec.architecture.target) @@ -107,10 +128,11 @@ def test_user_input_combination(self): combinations = itertools.product(os_list, target_list) results = [] for arch in combinations: - o,t = arch + o, t = arch spec = Spec("libelf os=%s target=%s" % (o, t)) spec.concretize() - results.append(spec.architecture.platform_os == self.platform.operating_system(o)) + results.append(spec.architecture.platform_os == + self.platform.operating_system(o)) results.append(spec.architecture.target == self.platform.target(t)) res = all(results) From 2b3ba850b31af879312bc1e7c8400c2725a5c038 Mon Sep 17 00:00:00 2001 From: Paul Hopkins Date: Mon, 18 Jul 2016 12:51:58 +0100 Subject: [PATCH 38/68] Fix spack package-list to correctly handle deptypes --- lib/spack/spack/cmd/package-list.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/cmd/package-list.py b/lib/spack/spack/cmd/package-list.py index bc64c77eab..ffb656c468 100644 --- a/lib/spack/spack/cmd/package-list.py +++ b/lib/spack/spack/cmd/package-list.py @@ -48,7 +48,8 @@ def rst_table(elts): def print_rst_package_list(): """Print out information on all packages in restructured text.""" - pkgs = sorted(spack.repo.all_packages(), key=lambda s:s.name.lower()) + pkgs = sorted(spack.repo.all_packages(), key=lambda s: s.name.lower()) + pkg_names = [p.name for p in pkgs] print ".. _package-list:" print @@ -62,7 +63,7 @@ def print_rst_package_list(): print "Spack currently has %d mainline packages:" % len(pkgs) print - print rst_table("`%s`_" % p.name for p in pkgs) + print rst_table("`%s`_" % p for p in pkg_names) print print "-----" @@ -79,14 +80,15 @@ def print_rst_package_list(): print if pkg.versions: print "Versions:" - print " " + ", ".join(str(v) for v in reversed(sorted(pkg.versions))) + print " " + ", ".join(str(v) for v in + reversed(sorted(pkg.versions))) - for deptype in ('build', 'link', 'run'): - deps = pkg.dependencies(deptype) + for deptype in spack.alldeps: + deps = pkg.dependencies_of_type(deptype) if deps: print "%s Dependencies" % deptype.capitalize() - print " " + ", ".join("`%s`_" % d if d != "mpi" else d - for d in build_deps) + print " " + ", ".join("%s_" % d if d in pkg_names + else d for d in deps) print print "Description:" From cc027148ebdafbc58f3ad86b384c38534357062a Mon Sep 17 00:00:00 2001 From: Paul Hopkins Date: Mon, 18 Jul 2016 12:52:23 +0100 Subject: [PATCH 39/68] Flake8 fixes in cmd/package-list.py file --- lib/spack/spack/cmd/package-list.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/package-list.py b/lib/spack/spack/cmd/package-list.py index ffb656c468..2d25ebc63e 100644 --- a/lib/spack/spack/cmd/package-list.py +++ b/lib/spack/spack/cmd/package-list.py @@ -34,15 +34,15 @@ def github_url(pkg): """Link to a package file on github.""" - return ("https://github.com/llnl/spack/blob/master/var/spack/packages/%s/package.py" % - pkg.name) + url = "https://github.com/llnl/spack/blob/master/var/spack/packages/%s/package.py" # NOQA: ignore=E501 + return (url % pkg.name) def rst_table(elts): """Print out a RST-style table.""" cols = StringIO() ncol, widths = colify(elts, output=cols, tty=True) - header = " ".join("=" * (w-1) for w in widths) + header = " ".join("=" * (w - 1) for w in widths) return "%s\n%s%s" % (header, cols.getvalue(), header) From e9f42c1a94f58e5fa916705f67716c26818a7eae Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 5 Jul 2016 10:21:15 -0500 Subject: [PATCH 40/68] Allow spack create to automatically detect octave build system --- lib/spack/spack/cmd/checksum.py | 2 +- lib/spack/spack/cmd/create.py | 145 +++++++++++++++++--------------- 2 files changed, 78 insertions(+), 69 deletions(-) diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py index 95bd4771ed..9cdb0bd012 100644 --- a/lib/spack/spack/cmd/checksum.py +++ b/lib/spack/spack/cmd/checksum.py @@ -59,7 +59,7 @@ def get_checksums(versions, urls, **kwargs): with Stage(url, keep=keep_stage) as stage: stage.fetch() if i == 0 and first_stage_function: - first_stage_function(stage) + first_stage_function(stage, url) hashes.append((version, spack.util.crypto.checksum(hashlib.md5, stage.archive_file))) diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index c9fa687b74..009b2f308b 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -103,6 +103,64 @@ def install(self, spec, prefix): ${install} """) +# Build dependencies and extensions +dependencies_dict = { + 'autotools': "# depends_on('foo')", + 'cmake': "depends_on('cmake')", + 'scons': "depends_on('scons')", + 'python': "extends('python')", + 'R': "extends('R')", + 'octave': "extends('octave')", + 'unknown': "# depends_on('foo')" +} + +# Default installation instructions +install_dict = { + 'autotools': """\ + # FIXME: Modify the configure line to suit your build system here. + configure('--prefix={0}'.format(prefix)) + + # FIXME: Add logic to build and install here. + make() + make('install')""", + + 'cmake': """\ + with working_dir('spack-build', create=True): + # FIXME: Modify the cmake line to suit your build system here. + cmake('..', *std_cmake_args) + + # FIXME: Add logic to build and install here. + make() + make('install')""", + + 'scons': """\ + # FIXME: Add logic to build and install here. + scons('prefix={0}'.format(prefix)) + scons('install')""", + + 'python': """\ + # FIXME: Add logic to build and install here. + python('setup.py', 'install', '--prefix={0}'.format(prefix))""", + + 'R': """\ + # FIXME: Add logic to build and install here. + R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir), + self.stage.source_path)""", + + 'octave': """\ + # FIXME: Add logic to build and install here. + octave('--quiet', '--norc', + '--built-in-docstrings-file=/dev/null', + '--texi-macros-file=/dev/null', + '--eval', 'pkg prefix {0}; pkg install {1}'.format( + prefix, self.stage.archive_file))""", + + 'unknown': """\ + # FIXME: Unknown build system + make() + make('install')""" +} + def make_version_calls(ver_hash_tuples): """Adds a version() call to the package for each version found.""" @@ -133,60 +191,17 @@ def setup_parser(subparser): setup_parser.subparser = subparser -class ConfigureGuesser(object): - def __call__(self, stage): - """Try to guess the type of build system used by the project. - Set any necessary build dependencies or extensions. - Set the appropriate default installation instructions.""" +class BuildSystemGuesser(object): + def __call__(self, stage, url): + """Try to guess the type of build system used by a project based on + the contents of its archive or the URL it was downloaded from.""" - # Build dependencies and extensions - dependenciesDict = { - 'autotools': "# depends_on('foo')", - 'cmake': "depends_on('cmake', type='build')", - 'scons': "depends_on('scons', type='build')", - 'python': "extends('python', type=nolink)", - 'R': "extends('R')", - 'unknown': "# depends_on('foo')" - } - - # Default installation instructions - installDict = { - 'autotools': """\ - # FIXME: Modify the configure line to suit your build system here. - configure('--prefix={0}'.format(prefix)) - - # FIXME: Add logic to build and install here. - make() - make('install')""", - - 'cmake': """\ - with working_dir('spack-build', create=True): - # FIXME: Modify the cmake line to suit your build system here. - cmake('..', *std_cmake_args) - - # FIXME: Add logic to build and install here. - make() - make('install')""", - - 'scons': """\ - # FIXME: Add logic to build and install here. - scons('prefix={0}'.format(prefix)) - scons('install')""", - - 'python': """\ - # FIXME: Add logic to build and install here. - python('setup.py', 'install', '--prefix={0}'.format(prefix))""", - - 'R': """\ - # FIXME: Add logic to build and install here. - R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir), - self.stage.source_path)""", - - 'unknown': """\ - # FIXME: Unknown build system - make() - make('install')""" - } + # Most octave extensions are hosted on Octave-Forge: + # http://octave.sourceforge.net/index.html + # They all have the same base URL. + if 'downloads.sourceforge.net/octave/' in url: + self.build_system = 'octave' + return # A list of clues that give us an idea of the build system a package # uses. If the regular expression matches a file contained in the @@ -224,12 +239,6 @@ def __call__(self, stage): self.build_system = build_system - # Set any necessary build dependencies or extensions. - self.dependencies = dependenciesDict[build_system] - - # Set the appropriate default installation instructions - self.install = installDict[build_system] - def guess_name_and_version(url, args): # Try to deduce name and version of the new package from the URL @@ -334,8 +343,8 @@ def create(parser, args): # Fetch tarballs (prompting user if necessary) versions, urls = fetch_tarballs(url, name, version) - # Try to guess what configure system is used. - guesser = ConfigureGuesser() + # Try to guess what build system is used. + guesser = BuildSystemGuesser() ver_hash_tuples = spack.cmd.checksum.get_checksums( versions, urls, first_stage_function=guesser, @@ -344,13 +353,13 @@ def create(parser, args): if not ver_hash_tuples: tty.die("Could not fetch any tarballs for %s" % name) - # Prepend 'py-' to python package names, by convention. + # Add prefix to package name if it is an extension. if guesser.build_system == 'python': - name = 'py-%s' % name - - # Prepend 'r-' to R package names, by convention. + name = 'py-{0}'.format(name) if guesser.build_system == 'R': - name = 'r-%s' % name + name = 'r-{0}'.format(name) + if guesser.build_system == 'octave': + name = 'octave-{0}'.format(name) # Create a directory for the new package. pkg_path = repo.filename_for_package_name(name) @@ -367,8 +376,8 @@ def create(parser, args): class_name=mod_to_class(name), url=url, versions=make_version_calls(ver_hash_tuples), - dependencies=guesser.dependencies, - install=guesser.install)) + dependencies=dependencies_dict[guesser.build_system], + install=install_dict[guesser.build_system])) # If everything checks out, go ahead and edit. spack.editor(pkg_path) From 199a8af7cc4e75e66cf53c3a2bb4c9b28aec64f1 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 5 Jul 2016 10:39:40 -0500 Subject: [PATCH 41/68] Flake8 --- lib/spack/spack/cmd/checksum.py | 19 +++++++++++-------- lib/spack/spack/cmd/create.py | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py index 9cdb0bd012..aedb0fd99c 100644 --- a/lib/spack/spack/cmd/checksum.py +++ b/lib/spack/spack/cmd/checksum.py @@ -42,7 +42,8 @@ def setup_parser(subparser): '--keep-stage', action='store_true', dest='keep_stage', help="Don't clean up staging area when command completes.") subparser.add_argument( - 'versions', nargs=argparse.REMAINDER, help='Versions to generate checksums for') + 'versions', nargs=argparse.REMAINDER, + help='Versions to generate checksums for') def get_checksums(versions, urls, **kwargs): @@ -61,8 +62,8 @@ def get_checksums(versions, urls, **kwargs): if i == 0 and first_stage_function: first_stage_function(stage, url) - hashes.append((version, - spack.util.crypto.checksum(hashlib.md5, stage.archive_file))) + hashes.append((version, spack.util.crypto.checksum( + hashlib.md5, stage.archive_file))) i += 1 except FailedDownloadError as e: tty.msg("Failed to fetch %s" % url) @@ -79,12 +80,12 @@ def checksum(parser, args): # If the user asked for specific versions, use those. if args.versions: versions = {} - for v in args.versions: - v = ver(v) - if not isinstance(v, Version): + for version in args.versions: + version = ver(version) + if not isinstance(version, Version): tty.die("Cannot generate checksums for version lists or " + "version ranges. Use unambiguous versions.") - versions[v] = pkg.url_for_version(v) + versions[version] = pkg.url_for_version(version) else: versions = pkg.fetch_remote_versions() if not versions: @@ -111,5 +112,7 @@ def checksum(parser, args): if not version_hashes: tty.die("Could not fetch any versions for %s" % pkg.name) - version_lines = [" version('%s', '%s')" % (v, h) for v, h in version_hashes] + version_lines = [ + " version('%s', '%s')" % (v, h) for v, h in version_hashes + ] tty.msg("Checksummed new versions of %s:" % pkg.name, *version_lines) diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index 009b2f308b..2c440096d1 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -124,7 +124,7 @@ def install(self, spec, prefix): make() make('install')""", - 'cmake': """\ + 'cmake': """\ with working_dir('spack-build', create=True): # FIXME: Modify the cmake line to suit your build system here. cmake('..', *std_cmake_args) From 262ab401884a8b46992872b8c010fa844cb14271 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 5 Jul 2016 11:33:29 -0500 Subject: [PATCH 42/68] Update build_system_guess test with new class name --- lib/spack/spack/test/__init__.py | 2 +- ...nfigure_guess.py => build_system_guess.py} | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) rename lib/spack/spack/test/{configure_guess.py => build_system_guess.py} (88%) diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index fb91f24721..19bc1d89d3 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -38,7 +38,7 @@ 'directory_layout', 'pattern', 'python_version', 'git_fetch', 'svn_fetch', 'hg_fetch', 'mirror', 'modules', 'url_extrapolate', 'cc', 'link_tree', 'spec_yaml', 'optional_deps', - 'make_executable', 'configure_guess', 'lock', 'database', + 'make_executable', 'build_system_guess', 'lock', 'database', 'namespace_trie', 'yaml', 'sbang', 'environment', 'cmd.find', 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd'] diff --git a/lib/spack/spack/test/configure_guess.py b/lib/spack/spack/test/build_system_guess.py similarity index 88% rename from lib/spack/spack/test/configure_guess.py rename to lib/spack/spack/test/build_system_guess.py index bad3673e7a..80b867a528 100644 --- a/lib/spack/spack/test/configure_guess.py +++ b/lib/spack/spack/test/build_system_guess.py @@ -28,14 +28,14 @@ import unittest from llnl.util.filesystem import * -from spack.cmd.create import ConfigureGuesser +from spack.cmd.create import BuildSystemGuesser from spack.stage import Stage from spack.test.mock_packages_test import * from spack.util.executable import which class InstallTest(unittest.TestCase): - """Tests the configure guesser in spack create""" + """Tests the build system guesser in spack create""" def setUp(self): self.tar = which('tar') @@ -60,15 +60,11 @@ def check_archive(self, filename, system): with Stage(url) as stage: stage.fetch() - guesser = ConfigureGuesser() - guesser(stage) + guesser = BuildSystemGuesser() + guesser(stage, url) self.assertEqual(system, guesser.build_system) - def test_python(self): - self.check_archive('setup.py', 'python') - - def test_autotools(self): self.check_archive('configure', 'autotools') @@ -77,7 +73,17 @@ def test_cmake(self): self.check_archive('CMakeLists.txt', 'cmake') + def test_scons(self): + self.check_archive('SConstruct', 'scons') + + + def test_python(self): + self.check_archive('setup.py', 'python') + + + def test_R(self): + self.check_archive('NAMESPACE', 'R') + + def test_unknown(self): self.check_archive('foobar', 'unknown') - - From 89c9bec81ec3afa96ba25dd6aea9727abc8a8f0f Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 5 Jul 2016 11:36:07 -0500 Subject: [PATCH 43/68] Flake8 --- lib/spack/spack/test/__init__.py | 19 ++++++++++--------- lib/spack/spack/test/build_system_guess.py | 8 -------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index 19bc1d89d3..9f7da46a1a 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -32,15 +32,16 @@ from spack.test.tally_plugin import Tally """Names of tests to be included in Spack's test suite""" -test_names = ['architecture', 'versions', 'url_parse', 'url_substitution', 'packages', 'stage', - 'spec_syntax', 'spec_semantics', 'spec_dag', 'concretize', - 'multimethod', 'install', 'package_sanity', 'config', - 'directory_layout', 'pattern', 'python_version', 'git_fetch', - 'svn_fetch', 'hg_fetch', 'mirror', 'modules', 'url_extrapolate', - 'cc', 'link_tree', 'spec_yaml', 'optional_deps', - 'make_executable', 'build_system_guess', 'lock', 'database', - 'namespace_trie', 'yaml', 'sbang', 'environment', 'cmd.find', - 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd'] +test_names = [ + 'architecture', 'versions', 'url_parse', 'url_substitution', 'packages', + 'stage', 'spec_syntax', 'spec_semantics', 'spec_dag', 'concretize', + 'multimethod', 'install', 'package_sanity', 'config', 'directory_layout', + 'pattern', 'python_version', 'git_fetch', 'svn_fetch', 'hg_fetch', + 'mirror', 'modules', 'url_extrapolate', 'cc', 'link_tree', 'spec_yaml', + 'optional_deps', 'make_executable', 'build_system_guess', 'lock', + 'database', 'namespace_trie', 'yaml', 'sbang', 'environment', 'cmd.find', + 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd' +] def list_tests(): diff --git a/lib/spack/spack/test/build_system_guess.py b/lib/spack/spack/test/build_system_guess.py index 80b867a528..e728a47cf4 100644 --- a/lib/spack/spack/test/build_system_guess.py +++ b/lib/spack/spack/test/build_system_guess.py @@ -44,12 +44,10 @@ def setUp(self): os.chdir(self.tmpdir) self.stage = None - def tearDown(self): shutil.rmtree(self.tmpdir, ignore_errors=True) os.chdir(self.orig_dir) - def check_archive(self, filename, system): mkdirp('archive') touch(join_path('archive', filename)) @@ -64,26 +62,20 @@ def check_archive(self, filename, system): guesser(stage, url) self.assertEqual(system, guesser.build_system) - def test_autotools(self): self.check_archive('configure', 'autotools') - def test_cmake(self): self.check_archive('CMakeLists.txt', 'cmake') - def test_scons(self): self.check_archive('SConstruct', 'scons') - def test_python(self): self.check_archive('setup.py', 'python') - def test_R(self): self.check_archive('NAMESPACE', 'R') - def test_unknown(self): self.check_archive('foobar', 'unknown') From 583232ea521c24158a9e537520a5eb434b08a74c Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 12 Jul 2016 11:38:13 -0500 Subject: [PATCH 44/68] Build Python with Tkinter support --- .../repos/builtin/packages/python/package.py | 42 ++++++++++++++++--- .../repos/builtin/packages/tcl/package.py | 6 +++ .../repos/builtin/packages/tk/package.py | 6 +++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py index 516b5c6cfe..bbb1e9c13a 100644 --- a/var/spack/repos/builtin/packages/python/package.py +++ b/var/spack/repos/builtin/packages/python/package.py @@ -53,6 +53,7 @@ class Python(Package): extendable = True + variant('tk', default=False, description='Provide support for Tkinter') variant('ucs4', default=False, description='Enable UCS4 (wide) unicode strings') # From https://docs.python.org/2/c-api/unicode.html: Python's default # builds use a 16-bit type for Py_UNICODE and store Unicode values @@ -68,6 +69,8 @@ class Python(Package): depends_on("ncurses") depends_on("sqlite") depends_on("zlib") + depends_on("tk", when="+tk") + depends_on("tcl", when="+tk") def install(self, spec, prefix): # Need this to allow python build to find the Python installation. @@ -77,24 +80,32 @@ def install(self, spec, prefix): # Rest of install is pretty standard except setup.py needs to # be able to read the CPPFLAGS and LDFLAGS as it scans for the # library and headers to build - cppflags = ' -I'.join([ + include_dirs = [ spec['openssl'].prefix.include, spec['bzip2'].prefix.include, spec['readline'].prefix.include, spec['ncurses'].prefix.include, spec['sqlite'].prefix.include, spec['zlib'].prefix.include - ]) + ] - ldflags = ' -L'.join([ + library_dirs = [ spec['openssl'].prefix.lib, spec['bzip2'].prefix.lib, spec['readline'].prefix.lib, spec['ncurses'].prefix.lib, spec['sqlite'].prefix.lib, spec['zlib'].prefix.lib - ]) + ] + + if '+tk' in spec: + include_dirs.extend([ + spec['tk'].prefix.include, spec['tcl'].prefix.include + ]) + library_dirs.extend([ + spec['tk'].prefix.lib, spec['tcl'].prefix.lib + ]) config_args = [ "--prefix={0}".format(prefix), "--with-threads", "--enable-shared", - "CPPFLAGS=-I{0}".format(cppflags), - "LDFLAGS=-L{0}".format(ldflags) + "CPPFLAGS=-I{0}".format(" -I".join(include_dirs)), + "LDFLAGS=-L{0}".format(" -L".join(library_dirs)) ] if '+ucs4' in spec: @@ -116,6 +127,25 @@ def install(self, spec, prefix): self.filter_compilers(spec, prefix) + # TODO: Once better testing support is integrated, add the following tests + # https://wiki.python.org/moin/TkInter + # + # if '+tk' in spec: + # env['TK_LIBRARY'] = join_path(spec['tk'].prefix.lib, + # 'tk{0}'.format(spec['tk'].version.up_to(2))) + # env['TCL_LIBRARY'] = join_path(spec['tcl'].prefix.lib, + # 'tcl{0}'.format(spec['tcl'].version.up_to(2))) + # + # $ python + # >>> import _tkinter + # + # if spec.satisfies('@3:') + # >>> import tkinter + # >>> tkinter._test() + # else: + # >>> import Tkinter + # >>> Tkinter._test() + def filter_compilers(self, spec, prefix): """Run after install to tell the configuration files and Makefiles to use the compilers that Spack built the package with. diff --git a/var/spack/repos/builtin/packages/tcl/package.py b/var/spack/repos/builtin/packages/tcl/package.py index a4d8b515bb..4a957fd9de 100644 --- a/var/spack/repos/builtin/packages/tcl/package.py +++ b/var/spack/repos/builtin/packages/tcl/package.py @@ -44,6 +44,12 @@ def url_for_version(self, version): depends_on('zlib') + def setup_environment(self, spack_env, env): + # When using Tkinter from within spack provided python+tk, python + # will not be able to find Tcl/Tk unless TCL_LIBRARY is set. + env.set('TCL_LIBRARY', join_path(self.prefix.lib, 'tcl{0}'.format( + self.spec.version.up_to(2)))) + def install(self, spec, prefix): with working_dir('unix'): configure("--prefix=%s" % prefix) diff --git a/var/spack/repos/builtin/packages/tk/package.py b/var/spack/repos/builtin/packages/tk/package.py index 330e1c77f5..097cd411f1 100644 --- a/var/spack/repos/builtin/packages/tk/package.py +++ b/var/spack/repos/builtin/packages/tk/package.py @@ -40,6 +40,12 @@ def url_for_version(self, version): depends_on("tcl") + def setup_environment(self, spack_env, env): + # When using Tkinter from within spack provided python+tk, python + # will not be able to find Tcl/Tk unless TK_LIBRARY is set. + env.set('TK_LIBRARY', join_path(self.prefix.lib, 'tk{0}'.format( + self.spec.version.up_to(2)))) + def install(self, spec, prefix): with working_dir('unix'): configure("--prefix=%s" % prefix, From ea425a101a698705609698771c0542d2be70987e Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 12 Jul 2016 11:44:24 -0500 Subject: [PATCH 45/68] Flake8 and new tk version --- var/spack/repos/builtin/packages/tcl/package.py | 10 ++++++---- var/spack/repos/builtin/packages/tk/package.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/var/spack/repos/builtin/packages/tcl/package.py b/var/spack/repos/builtin/packages/tcl/package.py index 4a957fd9de..ef922314d8 100644 --- a/var/spack/repos/builtin/packages/tcl/package.py +++ b/var/spack/repos/builtin/packages/tcl/package.py @@ -24,6 +24,7 @@ ############################################################################## from spack import * + class Tcl(Package): """Tcl (Tool Command Language) is a very powerful but easy to learn dynamic programming language, suitable for a very wide @@ -34,9 +35,6 @@ class Tcl(Package): extensible.""" homepage = "http://www.tcl.tk" - def url_for_version(self, version): - return 'http://prdownloads.sourceforge.net/tcl/tcl%s-src.tar.gz' % version - version('8.6.5', '0e6426a4ca9401825fbc6ecf3d89a326') version('8.6.4', 'd7cbb91f1ded1919370a30edd1534304') version('8.6.3', 'db382feca91754b7f93da16dc4cdad1f') @@ -44,6 +42,10 @@ def url_for_version(self, version): depends_on('zlib') + def url_for_version(self, version): + base_url = 'http://prdownloads.sourceforge.net/tcl' + return '{0}/tcl{1}-src.tar.gz'.format(base_url, version) + def setup_environment(self, spack_env, env): # When using Tkinter from within spack provided python+tk, python # will not be able to find Tcl/Tk unless TCL_LIBRARY is set. @@ -52,6 +54,6 @@ def setup_environment(self, spack_env, env): def install(self, spec, prefix): with working_dir('unix'): - configure("--prefix=%s" % prefix) + configure("--prefix={0}".format(prefix)) make() make("install") diff --git a/var/spack/repos/builtin/packages/tk/package.py b/var/spack/repos/builtin/packages/tk/package.py index 097cd411f1..894d3af6cc 100644 --- a/var/spack/repos/builtin/packages/tk/package.py +++ b/var/spack/repos/builtin/packages/tk/package.py @@ -24,6 +24,7 @@ ############################################################################## from spack import * + class Tk(Package): """Tk is a graphical user interface toolkit that takes developing desktop applications to a higher level than conventional @@ -33,13 +34,15 @@ class Tk(Package): and more.""" homepage = "http://www.tcl.tk" - def url_for_version(self, version): - return "http://prdownloads.sourceforge.net/tcl/tk%s-src.tar.gz" % version - + version('8.6.5', '11dbbd425c3e0201f20d6a51482ce6c4') version('8.6.3', '85ca4dbf4dcc19777fd456f6ee5d0221') depends_on("tcl") + def url_for_version(self, version): + base_url = "http://prdownloads.sourceforge.net/tcl" + return "{0}/tk{1}-src.tar.gz".format(base_url, version) + def setup_environment(self, spack_env, env): # When using Tkinter from within spack provided python+tk, python # will not be able to find Tcl/Tk unless TK_LIBRARY is set. @@ -48,7 +51,7 @@ def setup_environment(self, spack_env, env): def install(self, spec, prefix): with working_dir('unix'): - configure("--prefix=%s" % prefix, - "--with-tcl=%s" % spec['tcl'].prefix.lib) + configure("--prefix={0}".format(prefix), + "--with-tcl={0}".format(spec['tcl'].prefix.lib)) make() make("install") From a46138dea94cdcddd91f83aaedb7388a0e53f7e4 Mon Sep 17 00:00:00 2001 From: Paul Hopkins Date: Mon, 18 Jul 2016 13:59:58 +0100 Subject: [PATCH 46/68] More flake8 fixes for package-list --- lib/spack/spack/cmd/package-list.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/spack/spack/cmd/package-list.py b/lib/spack/spack/cmd/package-list.py index 2d25ebc63e..a27502d30e 100644 --- a/lib/spack/spack/cmd/package-list.py +++ b/lib/spack/spack/cmd/package-list.py @@ -22,10 +22,8 @@ # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -import re import cgi from StringIO import StringIO -import llnl.util.tty as tty from llnl.util.tty.colify import * import spack From 2b4d2b8748669ad5a2c45d2024d265f12071c441 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Jul 2016 11:39:26 -0400 Subject: [PATCH 47/68] gitignore: don't require opt to be a directory I use a symlink to make it easy to swap out. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 040df3eafd..bfc6172a4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /var/spack/stage /var/spack/cache *.pyc -/opt/ +/opt *~ .DS_Store .idea From 19df1ea79d5539986652de84782856bcc7a84037 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Mon, 18 Jul 2016 17:53:26 +0200 Subject: [PATCH 48/68] flake8 fix --- lib/spack/spack/test/modules.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/spack/spack/test/modules.py b/lib/spack/spack/test/modules.py index b6d35154e3..135cd028e3 100644 --- a/lib/spack/spack/test/modules.py +++ b/lib/spack/spack/test/modules.py @@ -27,7 +27,6 @@ import StringIO import spack.modules -import unittest from spack.test.mock_packages_test import MockPackagesTest FILE_REGISTRY = collections.defaultdict(StringIO.StringIO) From 49cd6f6269267b5388b3dcc31ec2cafc58567e80 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 18 Jul 2016 16:01:48 -0400 Subject: [PATCH 49/68] py-numpy: Add py-setuptools dependencies Closes #1281. --- var/spack/repos/builtin/packages/py-numpy/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/var/spack/repos/builtin/packages/py-numpy/package.py b/var/spack/repos/builtin/packages/py-numpy/package.py index 6bc11a5e48..15adcbc2ac 100644 --- a/var/spack/repos/builtin/packages/py-numpy/package.py +++ b/var/spack/repos/builtin/packages/py-numpy/package.py @@ -44,6 +44,7 @@ class PyNumpy(Package): extends('python') depends_on('py-nose', type='build') + depends_on('py-setuptools') depends_on('blas', when='+blas') depends_on('lapack', when='+lapack') From 67fade5b1e128e7bb08ef4709da5e15a22d10ee6 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 18 Jul 2016 17:08:56 -0400 Subject: [PATCH 50/68] Declare dependency of "py-h5py +mpi" on "py-mpi4py" --- var/spack/repos/builtin/packages/py-h5py/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/var/spack/repos/builtin/packages/py-h5py/package.py b/var/spack/repos/builtin/packages/py-h5py/package.py index c1950a91ac..f96cb9b4cd 100644 --- a/var/spack/repos/builtin/packages/py-h5py/package.py +++ b/var/spack/repos/builtin/packages/py-h5py/package.py @@ -46,6 +46,7 @@ class PyH5py(Package): depends_on('hdf5@1.8.4:') depends_on('hdf5+mpi', when='+mpi') depends_on('mpi', when='+mpi') + depends_on('py-mpi4py', when='+mpi') # Build and runtime dependencies depends_on('py-numpy@1.6.1:', type=nolink) From 607813d5ce6dbd5063f9a0ac6d90aea8b307da3f Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 18 Jul 2016 14:13:14 -0700 Subject: [PATCH 51/68] setuptools is a build dependency in numpy. --- var/spack/repos/builtin/packages/py-numpy/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/spack/repos/builtin/packages/py-numpy/package.py b/var/spack/repos/builtin/packages/py-numpy/package.py index 15adcbc2ac..2febdac658 100644 --- a/var/spack/repos/builtin/packages/py-numpy/package.py +++ b/var/spack/repos/builtin/packages/py-numpy/package.py @@ -44,7 +44,7 @@ class PyNumpy(Package): extends('python') depends_on('py-nose', type='build') - depends_on('py-setuptools') + depends_on('py-setuptools', type='build') depends_on('blas', when='+blas') depends_on('lapack', when='+lapack') From 46ee4a3a5360010e77f77f201ffd5e4289516cc4 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Mon, 18 Jul 2016 14:25:17 -0700 Subject: [PATCH 52/68] Using cc -craype-verbose to get cray platform type --- lib/spack/spack/platforms/cray_xc.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/platforms/cray_xc.py b/lib/spack/spack/platforms/cray_xc.py index e710303e23..8dc575bb71 100644 --- a/lib/spack/spack/platforms/cray_xc.py +++ b/lib/spack/spack/platforms/cray_xc.py @@ -2,6 +2,7 @@ from spack.architecture import Platform, Target from spack.operating_systems.linux_distro import LinuxDistro from spack.operating_systems.cnl import Cnl +from spack.util.executable import which class CrayXc(Platform): priority = 20 @@ -42,5 +43,11 @@ def __init__(self): @classmethod def detect(self): - return os.path.exists('/opt/cray/craype') + if os.path.exists('/cray_home'): + cc_verbose = which('cc') + cc_verbose.add_default_arg('-craype-verbose') + text = cc_verbose(output=str, error=str, ignore_errors=True).split() + if '-D__CRAYXC' in text: + return True + return False From 02340062b4d435ee97cec857f25122b8f2e3c990 Mon Sep 17 00:00:00 2001 From: mwilliammyers Date: Mon, 18 Jul 2016 16:17:07 -0600 Subject: [PATCH 53/68] package - jasper - Add new jasper package --- .../fix_alpha_channel_assert_fail.patch | 25 ++++++++ .../repos/builtin/packages/jasper/package.py | 63 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 var/spack/repos/builtin/packages/jasper/fix_alpha_channel_assert_fail.patch create mode 100644 var/spack/repos/builtin/packages/jasper/package.py diff --git a/var/spack/repos/builtin/packages/jasper/fix_alpha_channel_assert_fail.patch b/var/spack/repos/builtin/packages/jasper/fix_alpha_channel_assert_fail.patch new file mode 100644 index 0000000000..cbf79ff971 --- /dev/null +++ b/var/spack/repos/builtin/packages/jasper/fix_alpha_channel_assert_fail.patch @@ -0,0 +1,25 @@ +diff --git a/src/libjasper/jpc/jpc_dec.c b/src/libjasper/jpc/jpc_dec.c +index fa72a0e..1f4845f 100644 +--- a/src/libjasper/jpc/jpc_dec.c ++++ b/src/libjasper/jpc/jpc_dec.c +@@ -1069,12 +1069,18 @@ static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile) + /* Apply an inverse intercomponent transform if necessary. */ + switch (tile->cp->mctid) { + case JPC_MCT_RCT: +- assert(dec->numcomps == 3); ++ if (dec->numcomps != 3 && dec->numcomps != 4) { ++ jas_eprintf("bad number of components (%d)\n", dec->numcomps); ++ return -1; ++ } + jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data, + tile->tcomps[2].data); + break; + case JPC_MCT_ICT: +- assert(dec->numcomps == 3); ++ if (dec->numcomps != 3 && dec->numcomps != 4) { ++ jas_eprintf("bad number of components (%d)\n", dec->numcomps); ++ return -1; ++ } + jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data, + tile->tcomps[2].data); + break; diff --git a/var/spack/repos/builtin/packages/jasper/package.py b/var/spack/repos/builtin/packages/jasper/package.py new file mode 100644 index 0000000000..f450c7d155 --- /dev/null +++ b/var/spack/repos/builtin/packages/jasper/package.py @@ -0,0 +1,63 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +from spack import * + + +class Jasper(Package): + """Library for manipulating JPEG-2000 images""" + + homepage = "https://www.ece.uvic.ca/~frodo/jasper/" + url = "https://www.ece.uvic.ca/~frodo/jasper/software/jasper-1.900.1.zip" + + version('1.900.1', 'a342b2b4495b3e1394e161eb5d85d754') + + variant('shared', default=True, + description='Builds shared versions of the libraries') + variant('debug', default=False, + description='Builds debug versions of the libraries') + + depends_on('libjpeg-turbo') + + # Fixes a bug (still in upstream as of v.1.900.1) where an assertion fails + # when certain JPEG-2000 files with an alpha channel are processed + # see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=469786 + patch('fix_alpha_channel_assert_fail.patch') + + def install(self, spec, prefix): + configure_options = [ + '--prefix={0}'.format(prefix), + '--mandir={0}'.format(spec.prefix.man), + ] + + if '+shared' in spec: + configure_options.append('--enable-shared') + + if '+debug' not in spec: + configure_options.append('--disable-debug') + + configure(*configure_options) + + make() + make('install') From 218fc602fad2caf88b5e71c640b1569e5ab408da Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Mon, 18 Jul 2016 15:43:21 -0700 Subject: [PATCH 54/68] Let packages call use_cray_compilers() in install to get , etc set to cray names --- lib/spack/env/cc | 4 ++-- lib/spack/env/craype/CC | 1 + lib/spack/env/craype/cc | 1 + lib/spack/env/craype/ftn | 1 + lib/spack/spack/package.py | 7 +++++++ 5 files changed, 12 insertions(+), 2 deletions(-) create mode 120000 lib/spack/env/craype/CC create mode 120000 lib/spack/env/craype/cc create mode 120000 lib/spack/env/craype/ftn diff --git a/lib/spack/env/cc b/lib/spack/env/cc index bf98b4c354..c6bb50d261 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -110,13 +110,13 @@ case "$command" in comp="CXX" lang_flags=CXX ;; - f90|fc|f95|gfortran|ifort|pgfortran|xlf90|nagfor) + ftn|f90|fc|f95|gfortran|ifort|pgfortran|xlf90|nagfor) command="$SPACK_FC" language="Fortran 90" comp="FC" lang_flags=F ;; - f77|gfortran|ifort|pgfortran|xlf|nagfor) + f77|gfortran|ifort|pgfortran|xlf|nagfor|ftn) command="$SPACK_F77" language="Fortran 77" comp="F77" diff --git a/lib/spack/env/craype/CC b/lib/spack/env/craype/CC new file mode 120000 index 0000000000..82c2b8e90a --- /dev/null +++ b/lib/spack/env/craype/CC @@ -0,0 +1 @@ +../cc \ No newline at end of file diff --git a/lib/spack/env/craype/cc b/lib/spack/env/craype/cc new file mode 120000 index 0000000000..82c2b8e90a --- /dev/null +++ b/lib/spack/env/craype/cc @@ -0,0 +1 @@ +../cc \ No newline at end of file diff --git a/lib/spack/env/craype/ftn b/lib/spack/env/craype/ftn new file mode 120000 index 0000000000..82c2b8e90a --- /dev/null +++ b/lib/spack/env/craype/ftn @@ -0,0 +1 @@ +../cc \ No newline at end of file diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 6a92c548fb..c916bfaaa2 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1439,6 +1439,13 @@ def install_dependency_symlinks(pkg, spec, prefix): flatten_dependencies(spec, prefix) +def use_cray_compiler_names(): + """Compiler names for builds that rely on cray compiler names.""" + os.environ['CC'] = 'cc' + os.environ['CXX'] = 'CC' + os.environ['FC'] = 'ftn' + os.environ['F77'] = 'ftn' + def flatten_dependencies(spec, flat_dir): """Make each dependency of spec present in dir via symlink.""" for dep in spec.traverse(root=False): From 94df1b801a70b72f86e4a4a30c5bfeb018a8c5d2 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 18 Jul 2016 20:11:32 -0400 Subject: [PATCH 55/68] Update NetCDF to version 4.4.1 This version supports HDF5 1.10 in a backward-compatible manner. --- var/spack/repos/builtin/packages/netcdf/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/var/spack/repos/builtin/packages/netcdf/package.py b/var/spack/repos/builtin/packages/netcdf/package.py index 063d38e4f9..13d6bc6944 100644 --- a/var/spack/repos/builtin/packages/netcdf/package.py +++ b/var/spack/repos/builtin/packages/netcdf/package.py @@ -33,6 +33,7 @@ class Netcdf(Package): homepage = "http://www.unidata.ucar.edu/software/netcdf" url = "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.3.3.tar.gz" + version('4.4.1', '7843e35b661c99e1d49e60791d5072d8') version('4.4.0', 'cffda0cbd97fdb3a06e9274f7aef438e') version('4.3.3', '5fbd0e108a54bd82cb5702a73f56d2ae') From 71684cb07128bebdbabaaa695ef05f98ed9cd49f Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 18 Jul 2016 23:04:20 -0400 Subject: [PATCH 56/68] Flex requires m4 --- var/spack/repos/builtin/packages/flex/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/var/spack/repos/builtin/packages/flex/package.py b/var/spack/repos/builtin/packages/flex/package.py index 800e4b9d96..9b173bb0dd 100644 --- a/var/spack/repos/builtin/packages/flex/package.py +++ b/var/spack/repos/builtin/packages/flex/package.py @@ -35,6 +35,7 @@ class Flex(Package): version('2.5.39', 'e133e9ead8ec0a58d81166b461244fde') depends_on("bison", type='build') + depends_on("m4", type='build') def install(self, spec, prefix): configure("--prefix=%s" % prefix) From 25e765baae6f98141cb7896bbcbb840607a4842f Mon Sep 17 00:00:00 2001 From: "Robert D. French" Date: Tue, 19 Jul 2016 10:15:00 -0700 Subject: [PATCH 57/68] Download Adios from Github Get adios from github, not NCCS Use correct hash, thanks Ben --- var/spack/repos/builtin/packages/adios/package.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/var/spack/repos/builtin/packages/adios/package.py b/var/spack/repos/builtin/packages/adios/package.py index 9e0452ba6f..59e0a451a9 100644 --- a/var/spack/repos/builtin/packages/adios/package.py +++ b/var/spack/repos/builtin/packages/adios/package.py @@ -12,9 +12,9 @@ class Adios(Package): """ homepage = "http://www.olcf.ornl.gov/center-projects/adios/" - url = "http://users.nccs.gov/~pnorbert/adios-1.9.0.tar.gz" + url = "https://github.com/ornladios/ADIOS/archive/v1.9.0.tar.gz" - version('1.9.0', 'dbf5cb10e32add2f04c9b4052b7ffa76') + version('1.9.0', '310ff02388bbaa2b1c1710ee970b5678') # Lots of setting up here for this package # module swap PrgEnv-intel PrgEnv-$COMP From 1c9cf668a1c56a7259d988f263cdab89e7234890 Mon Sep 17 00:00:00 2001 From: "Robert D. French" Date: Tue, 19 Jul 2016 10:06:36 -0700 Subject: [PATCH 58/68] Silver Search 0.32 is out PEP8 Love + Re-adding v0.30.0 --- .../repos/builtin/packages/the_silver_searcher/package.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/var/spack/repos/builtin/packages/the_silver_searcher/package.py b/var/spack/repos/builtin/packages/the_silver_searcher/package.py index 988619df30..c98e964efa 100644 --- a/var/spack/repos/builtin/packages/the_silver_searcher/package.py +++ b/var/spack/repos/builtin/packages/the_silver_searcher/package.py @@ -24,11 +24,13 @@ ############################################################################## from spack import * + class TheSilverSearcher(Package): """Fast recursive grep alternative""" homepage = "http://geoff.greer.fm/ag/" - url = "http://geoff.greer.fm/ag/releases/the_silver_searcher-0.30.0.tar.gz" + url = "http://geoff.greer.fm/ag/releases/the_silver_searcher-0.32.0.tar.gz" + version('0.32.0', '3fdfd5836924246073d5344257a06823') version('0.30.0', '95e2e7859fab1156c835aff7413481db') depends_on('pcre') From dd7bd4f320651411a1125268310b2b1f590ad213 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 19 Jul 2016 14:59:04 -0700 Subject: [PATCH 59/68] Make frontend OS on Cray machines a proper linux distro. --- lib/spack/spack/platforms/cray_xc.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/platforms/cray_xc.py b/lib/spack/spack/platforms/cray_xc.py index 8dc575bb71..0f6599ab30 100644 --- a/lib/spack/spack/platforms/cray_xc.py +++ b/lib/spack/spack/platforms/cray_xc.py @@ -10,9 +10,8 @@ class CrayXc(Platform): back_end = 'ivybridge' default = 'ivybridge' - front_os = "SuSE11" back_os = "CNL10" - default_os = "CNL10" + default_os = "CNL10" def __init__(self): ''' Since cori doesn't have ivybridge as a front end it's better @@ -33,12 +32,15 @@ def __init__(self): # Could switch to use modules and fe targets for front end # Currently using compilers by path for front end. self.add_target('sandybridge', Target('sandybridge')) - self.add_target('ivybridge', + self.add_target('ivybridge', Target('ivybridge', 'craype-ivybridge')) - self.add_target('haswell', - Target('haswell','craype-haswell')) + self.add_target('haswell', + Target('haswell','craype-haswell')) - self.add_operating_system('SuSE11', LinuxDistro()) + # Front end of the cray platform is a linux distro. + linux_dist = LinuxDistro() + self.front_os = str(linux_dist) + self.add_operating_system(str(linux_dist), linux_dist) self.add_operating_system('CNL10', Cnl()) @classmethod @@ -50,4 +52,3 @@ def detect(self): if '-D__CRAYXC' in text: return True return False - From 6b0fb476ab917e68370b61cf77eff8fdedb79e09 Mon Sep 17 00:00:00 2001 From: "Robert D. French" Date: Tue, 19 Jul 2016 15:57:55 -0700 Subject: [PATCH 60/68] Draft CDO --- .../repos/builtin/packages/cdo/package.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 var/spack/repos/builtin/packages/cdo/package.py diff --git a/var/spack/repos/builtin/packages/cdo/package.py b/var/spack/repos/builtin/packages/cdo/package.py new file mode 100644 index 0000000000..09c4fde455 --- /dev/null +++ b/var/spack/repos/builtin/packages/cdo/package.py @@ -0,0 +1,44 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +from spack import * + + +class Cdo(Package): + """CDO is a collection of command line Operators to manipulate and analyse + Climate and NWP model Data. """ + + # FIXME: Add a proper url for your package's homepage here. + homepage = "https://code.zmaw.de/projects/cdo" + url = "https://code.zmaw.de/attachments/download/10198/cdo-1.6.9.tar.gz" + + version('1.6.9', 'bf0997bf20e812f35e10188a930e24e2') + + # FIXME: Add additional dependencies if required. + depends_on('netcdf') + + def install(self, spec, prefix): + configure('--prefix={0}'.format(prefix)) + make() + make('install') From 26480f14f901da087efbac263835c8767eaea23a Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 19 Jul 2016 17:10:17 -0700 Subject: [PATCH 61/68] Add "default" configuration scope. - Default scope is versioned with spack and can be overridden by site or user config. - Default scope provides sensible default concretization preferences for all of Spack. - per-platform concretization scope can be added later (to force a particular MPI on, e.g., Cray systems) --- .gitignore | 2 +- etc/spack/{ => defaults}/modules.yaml | 15 ++++++++++++--- etc/spack/defaults/packages.yaml | 21 +++++++++++++++++++++ etc/spack/defaults/repos.yaml | 14 ++++++++++++++ etc/spack/repos.yaml | 8 -------- lib/spack/spack/config.py | 9 ++++++++- 6 files changed, 56 insertions(+), 13 deletions(-) rename etc/spack/{ => defaults}/modules.yaml (53%) create mode 100644 etc/spack/defaults/packages.yaml create mode 100644 etc/spack/defaults/repos.yaml delete mode 100644 etc/spack/repos.yaml diff --git a/.gitignore b/.gitignore index bfc6172a4e..1d4d24aa52 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ *~ .DS_Store .idea -/etc/spack/* +/etc/spack/*.yaml /etc/spackconfig /share/spack/dotkit /share/spack/modules diff --git a/etc/spack/modules.yaml b/etc/spack/defaults/modules.yaml similarity index 53% rename from etc/spack/modules.yaml rename to etc/spack/defaults/modules.yaml index 9ae54a2d09..8864a76547 100644 --- a/etc/spack/modules.yaml +++ b/etc/spack/defaults/modules.yaml @@ -1,8 +1,17 @@ # ------------------------------------------------------------------------- -# This is the default spack module files generation configuration. +# This is the default configuration for Spack's module file generation. # -# Changes to this file will affect all users of this spack install, -# although users can override these settings in their ~/.spack/modules.yaml. +# Settings here are versioned with Spack and are intended to provide +# sensible defaults out of the box. Spack maintainers should edit this +# file to keep it current. +# +# Users can override these settings by editing the following files. +# +# Per-spack-instance settings (overrides defaults): +# $SPACK_ROOT/etc/spack/modules.yaml +# +# Per-user settings (overrides default and site settings): +# ~/.spack/modules.yaml # ------------------------------------------------------------------------- modules: enable: diff --git a/etc/spack/defaults/packages.yaml b/etc/spack/defaults/packages.yaml new file mode 100644 index 0000000000..83f9eb7ece --- /dev/null +++ b/etc/spack/defaults/packages.yaml @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------- +# This file controls default concretization preferences for Spack. +# +# Settings here are versioned with Spack and are intended to provide +# sensible defaults out of the box. Spack maintainers should edit this +# file to keep it current. +# +# Users can override these settings by editing the following files. +# +# Per-spack-instance settings (overrides defaults): +# $SPACK_ROOT/etc/spack/packages.yaml +# +# Per-user settings (overrides default and site settings): +# ~/.spack/packages.yaml +# ------------------------------------------------------------------------- +packages: + all: + providers: + mpi: [openmpi, mpich] + blas: [openblas] + lapack: [openblas] diff --git a/etc/spack/defaults/repos.yaml b/etc/spack/defaults/repos.yaml new file mode 100644 index 0000000000..f3e00653eb --- /dev/null +++ b/etc/spack/defaults/repos.yaml @@ -0,0 +1,14 @@ +# ------------------------------------------------------------------------- +# This is the default spack repository configuration. It includes the +# builtin spack package repository. +# +# Users can override these settings by editing the following files. +# +# Per-spack-instance settings (overrides defaults): +# $SPACK_ROOT/etc/spack/repos.yaml +# +# Per-user settings (overrides default and site settings): +# ~/.spack/repos.yaml +# ------------------------------------------------------------------------- +repos: + - $spack/var/spack/repos/builtin diff --git a/etc/spack/repos.yaml b/etc/spack/repos.yaml deleted file mode 100644 index 2d4ff54ce6..0000000000 --- a/etc/spack/repos.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# ------------------------------------------------------------------------- -# This is the default spack repository configuration. -# -# Changes to this file will affect all users of this spack install, -# although users can override these settings in their ~/.spack/repos.yaml. -# ------------------------------------------------------------------------- -repos: - - $spack/var/spack/repos/builtin diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 3a66e9f2a6..8b5e96f97d 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -497,8 +497,15 @@ def clear(self): """Empty cached config information.""" self.sections = {} +"""Default configuration scope is the lowest-level scope. These are + versioned with Spack and can be overridden by sites or users.""" +ConfigScope('defaults', os.path.join(spack.etc_path, 'spack', 'defaults')) -ConfigScope('site', os.path.join(spack.etc_path, 'spack')), +"""Site configuration is per spack instance, for sites or projects. + No site-level configs should be checked into spack by default.""" +ConfigScope('site', os.path.join(spack.etc_path, 'spack')) + +"""User configuration can override both spack defaults and site config.""" ConfigScope('user', os.path.expanduser('~/.spack')) From 83330d2b59d925b2e57b63081461a759a5e92b11 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Wed, 20 Jul 2016 08:50:32 -0500 Subject: [PATCH 62/68] Re-ignore licenses directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1d4d24aa52..960b5b0035 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *~ .DS_Store .idea +/etc/spack/licenses /etc/spack/*.yaml /etc/spackconfig /share/spack/dotkit From 69e36c98219cdf3eda9de44c4205c4de0f212fd9 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 20 Jul 2016 11:25:46 -0400 Subject: [PATCH 63/68] Ensure that per-4.4.1 NetCDF doesn't use HDF5 1.10 --- var/spack/repos/builtin/packages/netcdf/package.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/var/spack/repos/builtin/packages/netcdf/package.py b/var/spack/repos/builtin/packages/netcdf/package.py index 13d6bc6944..ad4ee59640 100644 --- a/var/spack/repos/builtin/packages/netcdf/package.py +++ b/var/spack/repos/builtin/packages/netcdf/package.py @@ -48,8 +48,10 @@ class Netcdf(Package): # Required for NetCDF-4 support depends_on("zlib") - depends_on("hdf5+mpi", when='+mpi') - depends_on("hdf5~mpi", when='~mpi') + depends_on('hdf5@:1.8+mpi', when='@:4.4.0+mpi') + depends_on('hdf5+mpi', when='@4.4.1:+mpi') + depends_on('hdf5@:1.8~mpi', when='@:4.4.0~mpi') + depends_on('hdf5~mpi', when='@4.4.1:~mpi') def install(self, spec, prefix): # Environment variables From 4434f482c08c90011ba489b65ce7f75be35fb5bb Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 20 Jul 2016 09:48:54 -0700 Subject: [PATCH 64/68] remove FIXMEs --- var/spack/repos/builtin/packages/cdo/package.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/var/spack/repos/builtin/packages/cdo/package.py b/var/spack/repos/builtin/packages/cdo/package.py index 09c4fde455..7400c3a56c 100644 --- a/var/spack/repos/builtin/packages/cdo/package.py +++ b/var/spack/repos/builtin/packages/cdo/package.py @@ -29,13 +29,11 @@ class Cdo(Package): """CDO is a collection of command line Operators to manipulate and analyse Climate and NWP model Data. """ - # FIXME: Add a proper url for your package's homepage here. homepage = "https://code.zmaw.de/projects/cdo" url = "https://code.zmaw.de/attachments/download/10198/cdo-1.6.9.tar.gz" version('1.6.9', 'bf0997bf20e812f35e10188a930e24e2') - # FIXME: Add additional dependencies if required. depends_on('netcdf') def install(self, spec, prefix): From 4c506b36c5e6762ce08b616fa32a6064f7766ad3 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 20 Jul 2016 10:25:07 -0700 Subject: [PATCH 65/68] Improved cray_xc detection --- lib/spack/spack/platforms/cray_xc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/spack/spack/platforms/cray_xc.py b/lib/spack/spack/platforms/cray_xc.py index 0f6599ab30..24aa614e86 100644 --- a/lib/spack/spack/platforms/cray_xc.py +++ b/lib/spack/spack/platforms/cray_xc.py @@ -45,10 +45,10 @@ def __init__(self): @classmethod def detect(self): - if os.path.exists('/cray_home'): - cc_verbose = which('cc') - cc_verbose.add_default_arg('-craype-verbose') - text = cc_verbose(output=str, error=str, ignore_errors=True).split() + try: + cc_verbose = which('ftn') + text = cc_verbose('-craype-verbose', output=str, error=str, ignore_errors=True).split() if '-D__CRAYXC' in text: return True - return False + finally: + return False From 26d1ddc176ac52ff76893432755de54cab3cecfc Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 20 Jul 2016 10:28:38 -0700 Subject: [PATCH 66/68] Improved cray_xc detection bug fix --- lib/spack/spack/platforms/cray_xc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/platforms/cray_xc.py b/lib/spack/spack/platforms/cray_xc.py index 24aa614e86..8bc03874de 100644 --- a/lib/spack/spack/platforms/cray_xc.py +++ b/lib/spack/spack/platforms/cray_xc.py @@ -50,5 +50,7 @@ def detect(self): text = cc_verbose('-craype-verbose', output=str, error=str, ignore_errors=True).split() if '-D__CRAYXC' in text: return True - finally: + else: + return False + except: return False From 0d18f7249c38fdf8c452acd39533b09d13031583 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 20 Jul 2016 10:50:18 -0700 Subject: [PATCH 67/68] fixed flake errors --- lib/spack/spack/platforms/cray_xc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/platforms/cray_xc.py b/lib/spack/spack/platforms/cray_xc.py index 8bc03874de..fd16f7d9ba 100644 --- a/lib/spack/spack/platforms/cray_xc.py +++ b/lib/spack/spack/platforms/cray_xc.py @@ -4,6 +4,7 @@ from spack.operating_systems.cnl import Cnl from spack.util.executable import which + class CrayXc(Platform): priority = 20 front_end = 'sandybridge' @@ -35,7 +36,7 @@ def __init__(self): self.add_target('ivybridge', Target('ivybridge', 'craype-ivybridge')) self.add_target('haswell', - Target('haswell','craype-haswell')) + Target('haswell', 'craype-haswell')) # Front end of the cray platform is a linux distro. linux_dist = LinuxDistro() @@ -47,7 +48,9 @@ def __init__(self): def detect(self): try: cc_verbose = which('ftn') - text = cc_verbose('-craype-verbose', output=str, error=str, ignore_errors=True).split() + text = cc_verbose('-craype-verbose', + output=str, error=str, + ignore_errors=True).split() if '-D__CRAYXC' in text: return True else: From 106147716ac73180ce80e693ea276612d36b2215 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 20 Jul 2016 11:00:56 -0700 Subject: [PATCH 68/68] fixed flake errors --- lib/spack/spack/platforms/cray_xc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/platforms/cray_xc.py b/lib/spack/spack/platforms/cray_xc.py index fd16f7d9ba..e3c7761a94 100644 --- a/lib/spack/spack/platforms/cray_xc.py +++ b/lib/spack/spack/platforms/cray_xc.py @@ -48,8 +48,8 @@ def __init__(self): def detect(self): try: cc_verbose = which('ftn') - text = cc_verbose('-craype-verbose', - output=str, error=str, + text = cc_verbose('-craype-verbose', + output=str, error=str, ignore_errors=True).split() if '-D__CRAYXC' in text: return True