env: refactor common arguments
This commit is contained in:
parent
037457adc9
commit
d1cce990cd
6 changed files with 108 additions and 58 deletions
|
@ -76,6 +76,11 @@ def _specs(self, **kwargs):
|
||||||
'-r', '--dependencies', action='store_true', dest='recurse_dependencies',
|
'-r', '--dependencies', action='store_true', dest='recurse_dependencies',
|
||||||
help='recursively traverse spec dependencies')
|
help='recursively traverse spec dependencies')
|
||||||
|
|
||||||
|
_arguments['recurse_dependents'] = Args(
|
||||||
|
'-R', '--dependents', action='store_true', dest='dependents',
|
||||||
|
help='also uninstall any packages that depend on the ones given '
|
||||||
|
'via command line')
|
||||||
|
|
||||||
_arguments['clean'] = Args(
|
_arguments['clean'] = Args(
|
||||||
'--clean',
|
'--clean',
|
||||||
action='store_false',
|
action='store_false',
|
||||||
|
@ -106,6 +111,16 @@ def _specs(self, **kwargs):
|
||||||
'-t', '--tags', action='append',
|
'-t', '--tags', action='append',
|
||||||
help='filter a package query by tags')
|
help='filter a package query by tags')
|
||||||
|
|
||||||
|
_arguments['jobs'] = Args(
|
||||||
|
'-j', '--jobs', action='store', type=int, dest="jobs",
|
||||||
|
help="explicitly set number of make jobs, default is #cpus.")
|
||||||
|
|
||||||
|
_arguments['install_status'] = Args(
|
||||||
|
'-I', '--install-status', action='store_true', default=False,
|
||||||
|
help='show install status of packages. packages can be: '
|
||||||
|
'installed [+], missing and needed by an installed package [-], '
|
||||||
|
'or not installed (no annotation)')
|
||||||
|
|
||||||
_arguments['no_checksum'] = Args(
|
_arguments['no_checksum'] = Args(
|
||||||
'-n', '--no-checksum', action='store_true', default=False,
|
'-n', '--no-checksum', action='store_true', default=False,
|
||||||
help="do not use checksums to verify downloadeded files (unsafe)")
|
help="do not use checksums to verify downloadeded files (unsafe)")
|
||||||
|
|
|
@ -25,18 +25,8 @@
|
||||||
level = "short"
|
level = "short"
|
||||||
|
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def add_common_arguments(subparser):
|
||||||
subparser.add_argument(
|
arguments.add_common_arguments(subparser, ['jobs', 'install_status'])
|
||||||
'--only',
|
|
||||||
default='package,dependencies',
|
|
||||||
dest='things_to_install',
|
|
||||||
choices=['package', 'dependencies'],
|
|
||||||
help="""select the mode of installation.
|
|
||||||
the default is to install the package along with all its dependencies.
|
|
||||||
alternatively one can decide to install only the package or only
|
|
||||||
the dependencies"""
|
|
||||||
)
|
|
||||||
arguments.add_common_arguments(subparser, ['jobs'])
|
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'--overwrite', action='store_true',
|
'--overwrite', action='store_true',
|
||||||
help="reinstall an existing spec, even if it has dependents")
|
help="reinstall an existing spec, even if it has dependents")
|
||||||
|
@ -65,14 +55,52 @@ def setup_parser(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'--fake', action='store_true',
|
'--fake', action='store_true',
|
||||||
help="fake install for debug purposes.")
|
help="fake install for debug purposes.")
|
||||||
|
|
||||||
|
cd_group = subparser.add_mutually_exclusive_group()
|
||||||
|
arguments.add_common_arguments(cd_group, ['clean', 'dirty'])
|
||||||
|
|
||||||
|
|
||||||
|
def update_kwargs_from_args(args, kwargs):
|
||||||
|
"""Parse cli arguments and construct a dictionary
|
||||||
|
that will be passed to Package.do_install API"""
|
||||||
|
|
||||||
|
kwargs.update({
|
||||||
|
'keep_prefix': args.keep_prefix,
|
||||||
|
'keep_stage': args.keep_stage,
|
||||||
|
'restage': not args.dont_restage,
|
||||||
|
'install_source': args.install_source,
|
||||||
|
'make_jobs': args.jobs,
|
||||||
|
'verbose': args.verbose,
|
||||||
|
'fake': args.fake,
|
||||||
|
'dirty': args.dirty,
|
||||||
|
'use_cache': args.use_cache
|
||||||
|
})
|
||||||
|
if hasattr(args, 'setup'):
|
||||||
|
setups = set()
|
||||||
|
for arglist_s in args.setup:
|
||||||
|
for arg in [x.strip() for x in arglist_s.split(',')]:
|
||||||
|
setups.add(arg)
|
||||||
|
kwargs['setup'] = setups
|
||||||
|
tty.msg('Setup={0}'.format(kwargs['setup']))
|
||||||
|
|
||||||
|
|
||||||
|
def setup_parser(subparser):
|
||||||
|
add_common_arguments(subparser)
|
||||||
|
subparser.add_argument(
|
||||||
|
'--only',
|
||||||
|
default='package,dependencies',
|
||||||
|
dest='things_to_install',
|
||||||
|
choices=['package', 'dependencies'],
|
||||||
|
help="""select the mode of installation.
|
||||||
|
the default is to install the package along with all its dependencies.
|
||||||
|
alternatively one can decide to install only the package or only
|
||||||
|
the dependencies"""
|
||||||
|
)
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-f', '--file', action='append', default=[],
|
'-f', '--file', action='append', default=[],
|
||||||
dest='specfiles', metavar='SPEC_YAML_FILE',
|
dest='specfiles', metavar='SPEC_YAML_FILE',
|
||||||
help="install from file. Read specs to install from .yaml files")
|
help="install from file. Read specs to install from .yaml files")
|
||||||
|
|
||||||
cd_group = subparser.add_mutually_exclusive_group()
|
|
||||||
arguments.add_common_arguments(cd_group, ['clean', 'dirty'])
|
|
||||||
|
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'package',
|
'package',
|
||||||
nargs=argparse.REMAINDER,
|
nargs=argparse.REMAINDER,
|
||||||
|
@ -159,17 +187,10 @@ def install(parser, args, **kwargs):
|
||||||
|
|
||||||
# Parse cli arguments and construct a dictionary
|
# Parse cli arguments and construct a dictionary
|
||||||
# that will be passed to Package.do_install API
|
# that will be passed to Package.do_install API
|
||||||
|
update_kwargs_from_args(args, kwargs)
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
'keep_prefix': args.keep_prefix,
|
'install_dependencies': ('dependencies' in args.things_to_install),
|
||||||
'keep_stage': args.keep_stage,
|
'install_package': ('package' in args.things_to_install)
|
||||||
'restage': not args.dont_restage,
|
|
||||||
'install_source': args.install_source,
|
|
||||||
'install_deps': 'dependencies' in args.things_to_install,
|
|
||||||
'make_jobs': args.jobs,
|
|
||||||
'verbose': args.verbose,
|
|
||||||
'fake': args.fake,
|
|
||||||
'dirty': args.dirty,
|
|
||||||
'use_cache': args.use_cache
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if args.run_tests:
|
if args.run_tests:
|
||||||
|
|
|
@ -54,22 +54,30 @@ def setup_parser(subparser):
|
||||||
'loads',
|
'loads',
|
||||||
help='prompt the list of modules associated with a constraint'
|
help='prompt the list of modules associated with a constraint'
|
||||||
)
|
)
|
||||||
loads_parser.add_argument(
|
add_loads_arguments(loads_parser)
|
||||||
|
arguments.add_common_arguments(
|
||||||
|
loads_parser, ['constraint']
|
||||||
|
)
|
||||||
|
|
||||||
|
return sp
|
||||||
|
|
||||||
|
|
||||||
|
def add_loads_arguments(subparser):
|
||||||
|
subparser.add_argument(
|
||||||
'--input-only', action='store_false', dest='shell',
|
'--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(
|
subparser.add_argument(
|
||||||
'-p', '--prefix', dest='prefix', default='',
|
'-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'
|
||||||
)
|
)
|
||||||
loads_parser.add_argument(
|
subparser.add_argument(
|
||||||
'-x', '--exclude', dest='exclude', action='append', default=[],
|
'-x', '--exclude', dest='exclude', action='append', default=[],
|
||||||
help="exclude package from output; may be specified multiple times"
|
help="exclude package from output; may be specified multiple times"
|
||||||
)
|
)
|
||||||
arguments.add_common_arguments(
|
arguments.add_common_arguments(
|
||||||
loads_parser, ['constraint', 'recurse_dependencies']
|
subparser, ['recurse_dependencies']
|
||||||
)
|
)
|
||||||
return sp
|
|
||||||
|
|
||||||
|
|
||||||
class MultipleSpecsMatch(Exception):
|
class MultipleSpecsMatch(Exception):
|
||||||
|
|
|
@ -19,8 +19,9 @@
|
||||||
level = "short"
|
level = "short"
|
||||||
|
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def add_common_arguments(subparser):
|
||||||
arguments.add_common_arguments(subparser, ['long', 'very_long'])
|
arguments.add_common_arguments(
|
||||||
|
subparser, ['long', 'very_long', 'install_status'])
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-y', '--yaml', action='store_true', default=False,
|
'-y', '--yaml', action='store_true', default=False,
|
||||||
help='print concrete spec as YAML')
|
help='print concrete spec as YAML')
|
||||||
|
@ -31,11 +32,7 @@ def setup_parser(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-N', '--namespaces', action='store_true', default=False,
|
'-N', '--namespaces', action='store_true', default=False,
|
||||||
help='show fully qualified package names')
|
help='show fully qualified package names')
|
||||||
subparser.add_argument(
|
|
||||||
'-I', '--install-status', action='store_true', default=False,
|
|
||||||
help='show install status of packages. packages can be: '
|
|
||||||
'installed [+], missing and needed by an installed package [-], '
|
|
||||||
'or not installed (no annotation)')
|
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-t', '--types', action='store_true', default=False,
|
'-t', '--types', action='store_true', default=False,
|
||||||
help='show dependency types')
|
help='show dependency types')
|
||||||
|
@ -43,6 +40,10 @@ def setup_parser(subparser):
|
||||||
'specs', nargs=argparse.REMAINDER, help="specs of packages")
|
'specs', nargs=argparse.REMAINDER, help="specs of packages")
|
||||||
|
|
||||||
|
|
||||||
|
def setup_parser(subparser):
|
||||||
|
add_common_arguments(subparser)
|
||||||
|
|
||||||
|
|
||||||
def spec(parser, args):
|
def spec(parser, args):
|
||||||
name_fmt = '$.' if args.namespaces else '$_'
|
name_fmt = '$.' if args.namespaces else '$_'
|
||||||
kwargs = {'cover': args.cover,
|
kwargs = {'cover': args.cover,
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
import spack.cmd
|
import spack.cmd
|
||||||
import spack.package
|
import spack.package
|
||||||
|
import spack.cmd.common.arguments as arguments
|
||||||
import spack.repo
|
import spack.repo
|
||||||
import spack.store
|
import spack.store
|
||||||
|
|
||||||
|
@ -31,11 +32,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def add_common_arguments(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-f', '--force', action='store_true', dest='force',
|
'-f', '--force', action='store_true', dest='force',
|
||||||
help="remove regardless of whether other packages depend on this one")
|
help="remove regardless of whether other packages depend on this one")
|
||||||
|
arguments.add_common_arguments(
|
||||||
|
subparser, ['recurse_dependents', 'yes_to_all'])
|
||||||
|
|
||||||
|
|
||||||
|
def setup_parser(subparser):
|
||||||
|
add_common_arguments(subparser)
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-a', '--all', action='store_true', dest='all',
|
'-a', '--all', action='store_true', dest='all',
|
||||||
help="USE CAREFULLY. remove ALL installed packages that match each "
|
help="USE CAREFULLY. remove ALL installed packages that match each "
|
||||||
|
@ -44,15 +50,6 @@ def setup_parser(subparser):
|
||||||
"supplied all installed software will be uninstalled. this "
|
"supplied all installed software will be uninstalled. this "
|
||||||
"is both useful and dangerous, like rm -r")
|
"is both useful and dangerous, like rm -r")
|
||||||
|
|
||||||
subparser.add_argument(
|
|
||||||
'-R', '--dependents', action='store_true', dest='dependents',
|
|
||||||
help='also uninstall any packages that depend on the ones given '
|
|
||||||
'via command line')
|
|
||||||
|
|
||||||
subparser.add_argument(
|
|
||||||
'-y', '--yes-to-all', action='store_true', dest='yes_to_all',
|
|
||||||
help='assume "yes" is the answer to every confirmation requested')
|
|
||||||
|
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'packages',
|
'packages',
|
||||||
nargs=argparse.REMAINDER,
|
nargs=argparse.REMAINDER,
|
||||||
|
@ -148,16 +145,12 @@ def num_installed_deps(pkg):
|
||||||
item.do_uninstall(force=force)
|
item.do_uninstall(force=force)
|
||||||
|
|
||||||
|
|
||||||
def get_uninstall_list(args):
|
def get_uninstall_list(args, specs):
|
||||||
specs = [any]
|
|
||||||
if args.packages:
|
|
||||||
specs = spack.cmd.parse_specs(args.packages)
|
|
||||||
|
|
||||||
# Gets the list of installed specs that match the ones give via cli
|
# Gets the list of installed specs that match the ones give via cli
|
||||||
# takes care of '-a' is given in the cli
|
# takes care of '-a' is given in the cli
|
||||||
uninstall_list = find_matching_specs(specs, args.all, args.force)
|
uninstall_list = find_matching_specs(specs, args.all, args.force)
|
||||||
|
|
||||||
# Takes care of '-d'
|
# Takes care of '-R'
|
||||||
dependent_list = installed_dependents(uninstall_list)
|
dependent_list = installed_dependents(uninstall_list)
|
||||||
|
|
||||||
# Process dependent_list and update uninstall_list
|
# Process dependent_list and update uninstall_list
|
||||||
|
@ -181,12 +174,9 @@ def get_uninstall_list(args):
|
||||||
return uninstall_list
|
return uninstall_list
|
||||||
|
|
||||||
|
|
||||||
def uninstall(parser, args):
|
def uninstall_specs(args, specs):
|
||||||
if not args.packages and not args.all:
|
|
||||||
tty.die('uninstall requires at least one package argument.',
|
|
||||||
' Use `spack uninstall --all` to uninstall ALL packages.')
|
|
||||||
|
|
||||||
uninstall_list = get_uninstall_list(args)
|
uninstall_list = get_uninstall_list(args, specs)
|
||||||
|
|
||||||
if not uninstall_list:
|
if not uninstall_list:
|
||||||
tty.warn('There are no package to uninstall.')
|
tty.warn('There are no package to uninstall.')
|
||||||
|
@ -201,3 +191,12 @@ def uninstall(parser, args):
|
||||||
|
|
||||||
# Uninstall everything on the list
|
# Uninstall everything on the list
|
||||||
do_uninstall(uninstall_list, args.force)
|
do_uninstall(uninstall_list, args.force)
|
||||||
|
|
||||||
|
|
||||||
|
def uninstall(parser, args):
|
||||||
|
if not args.packages and not args.all:
|
||||||
|
tty.die('uninstall requires at least one package argument.',
|
||||||
|
' Use `spack uninstall --all` to uninstall ALL packages.')
|
||||||
|
|
||||||
|
uninstall_specs(
|
||||||
|
args, spack.cmd.parse_specs(args.packages) if args.packages else [any])
|
||||||
|
|
|
@ -3227,6 +3227,7 @@ def tree(self, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', None)
|
prefix = kwargs.pop('prefix', None)
|
||||||
show_types = kwargs.pop('show_types', False)
|
show_types = kwargs.pop('show_types', False)
|
||||||
deptypes = kwargs.pop('deptypes', 'all')
|
deptypes = kwargs.pop('deptypes', 'all')
|
||||||
|
recurse_dependencies = kwargs.pop('recurse_dependencies', True)
|
||||||
check_kwargs(kwargs, self.tree)
|
check_kwargs(kwargs, self.tree)
|
||||||
|
|
||||||
out = ""
|
out = ""
|
||||||
|
@ -3275,6 +3276,11 @@ def tree(self, **kwargs):
|
||||||
if d > 0:
|
if d > 0:
|
||||||
out += "^"
|
out += "^"
|
||||||
out += node.format(fmt, color=color) + "\n"
|
out += node.format(fmt, color=color) + "\n"
|
||||||
|
|
||||||
|
# Check if we wanted just the first line
|
||||||
|
if not recurse_dependencies:
|
||||||
|
break
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
Loading…
Reference in a new issue