From d862507bcf41a80ecb98493aef5d5bcd7d2a0518 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 12 Nov 2021 08:34:18 +0100 Subject: Fix overloaded argparse keys (#27379) Commands should not reuse option names defined in main. --- lib/spack/spack/cmd/env.py | 16 +++++++--------- lib/spack/spack/cmd/install.py | 6 ++++-- lib/spack/spack/cmd/python.py | 4 ++-- lib/spack/spack/reporters/cdash.py | 1 - lib/spack/spack/test/cmd/env.py | 2 +- share/spack/spack-completion.bash | 7 +------ 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py index b88e1281bc..2f94bbc445 100644 --- a/lib/spack/spack/cmd/env.py +++ b/lib/spack/spack/cmd/env.py @@ -411,8 +411,6 @@ def env_status(args): # def env_loads_setup_parser(subparser): """list modules for an installed environment '(see spack module loads)'""" - subparser.add_argument( - 'env', nargs='?', help='name of env to generate loads file for') subparser.add_argument( '-n', '--module-set-name', default='default', help='module set for which to generate load operations') @@ -448,19 +446,19 @@ def env_loads(args): def env_update_setup_parser(subparser): """update environments to the latest format""" subparser.add_argument( - metavar='env', dest='env', + metavar='env', dest='update_env', help='name or directory of the environment to activate' ) spack.cmd.common.arguments.add_common_arguments(subparser, ['yes_to_all']) def env_update(args): - manifest_file = ev.manifest_file(args.env) + manifest_file = ev.manifest_file(args.update_env) backup_file = manifest_file + ".bkp" needs_update = not ev.is_latest_format(manifest_file) if not needs_update: - tty.msg('No update needed for the environment "{0}"'.format(args.env)) + tty.msg('No update needed for the environment "{0}"'.format(args.update_env)) return proceed = True @@ -470,7 +468,7 @@ def env_update(args): 'Spack that are older than this version may not be able to ' 'read it. Spack stores backups of the updated environment ' 'which can be retrieved with "spack env revert"') - tty.msg(msg.format(args.env)) + tty.msg(msg.format(args.update_env)) proceed = tty.get_yes_or_no('Do you want to proceed?', default=False) if not proceed: @@ -478,20 +476,20 @@ def env_update(args): ev.update_yaml(manifest_file, backup_file=backup_file) msg = 'Environment "{0}" has been updated [backup={1}]' - tty.msg(msg.format(args.env, backup_file)) + tty.msg(msg.format(args.update_env, backup_file)) def env_revert_setup_parser(subparser): """restore environments to their state before update""" subparser.add_argument( - metavar='env', dest='env', + metavar='env', dest='revert_env', help='name or directory of the environment to activate' ) spack.cmd.common.arguments.add_common_arguments(subparser, ['yes_to_all']) def env_revert(args): - manifest_file = ev.manifest_file(args.env) + manifest_file = ev.manifest_file(args.revert_env) backup_file = manifest_file + ".bkp" # Check that both the spack.yaml and the backup exist, the inform user diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index c04fb23ea3..95b195bc53 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -38,7 +38,7 @@ def update_kwargs_from_args(args, kwargs): 'keep_stage': args.keep_stage, 'restage': not args.dont_restage, 'install_source': args.install_source, - 'verbose': args.verbose, + 'verbose': args.verbose or args.install_verbose, 'fake': args.fake, 'dirty': args.dirty, 'use_cache': args.use_cache, @@ -130,7 +130,7 @@ remote spec matches that of the local spec""") help="install source files in prefix") arguments.add_common_arguments(subparser, ['no_checksum', 'deprecated']) subparser.add_argument( - '-v', '--verbose', action='store_true', + '-v', '--verbose', action='store_true', dest='install_verbose', help="display verbose build output while installing") subparser.add_argument( '--fake', action='store_true', @@ -285,6 +285,8 @@ def install_specs(cli_args, kwargs, specs): def install(parser, args, **kwargs): + # TODO: unify args.verbose? + tty.set_verbose(args.verbose or args.install_verbose) if args.help_cdash: parser = argparse.ArgumentParser( diff --git a/lib/spack/spack/cmd/python.py b/lib/spack/spack/cmd/python.py index 156e01b4ba..a7b998a8da 100644 --- a/lib/spack/spack/cmd/python.py +++ b/lib/spack/spack/cmd/python.py @@ -23,7 +23,7 @@ level = "long" def setup_parser(subparser): subparser.add_argument( - '-V', '--version', action='store_true', + '-V', '--version', action='store_true', dest='python_version', help='print the Python version number and exit') subparser.add_argument( '-c', dest='python_command', help='command to execute') @@ -42,7 +42,7 @@ def setup_parser(subparser): def python(parser, args, unknown_args): - if args.version: + if args.python_version: print('Python', platform.python_version()) return diff --git a/lib/spack/spack/reporters/cdash.py b/lib/spack/spack/reporters/cdash.py index cb9539b2d7..19721fc676 100644 --- a/lib/spack/spack/reporters/cdash.py +++ b/lib/spack/spack/reporters/cdash.py @@ -62,7 +62,6 @@ class CDash(Reporter): def __init__(self, args): Reporter.__init__(self, args) - tty.set_verbose(args.verbose) self.success = True self.template_dir = os.path.join('reports', 'cdash') self.cdash_upload_url = args.cdash_upload_url diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 553d80c562..d7e712d3d0 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -868,7 +868,7 @@ def test_env_loads(install_mockery, mock_fetch): install('--fake') with ev.read('test'): - env('loads', 'test') + env('loads') e = ev.read('test') diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index e9022d47bb..fa3ebd3c3e 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -969,12 +969,7 @@ _spack_env_st() { } _spack_env_loads() { - if $list_options - then - SPACK_COMPREPLY="-h --help -n --module-set-name -m --module-type --input-only -p --prefix -x --exclude -r --dependencies" - else - _environments - fi + SPACK_COMPREPLY="-h --help -n --module-set-name -m --module-type --input-only -p --prefix -x --exclude -r --dependencies" } _spack_env_view() { -- cgit v1.2.3-70-g09d2