summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Fischer <rpf2116@columbia.edu>2018-05-18 17:03:42 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2018-11-09 00:31:24 -0800
commitd1cce990cd682ce76eebec9d311e2c10d0082d82 (patch)
tree948d2294b749f6a59d0a3684f23cb06ec0da9803
parent037457adc902fcd371efac310a8d5451aef3610f (diff)
downloadspack-d1cce990cd682ce76eebec9d311e2c10d0082d82.tar.gz
spack-d1cce990cd682ce76eebec9d311e2c10d0082d82.tar.bz2
spack-d1cce990cd682ce76eebec9d311e2c10d0082d82.tar.xz
spack-d1cce990cd682ce76eebec9d311e2c10d0082d82.zip
env: refactor common arguments
-rw-r--r--lib/spack/spack/cmd/common/arguments.py15
-rw-r--r--lib/spack/spack/cmd/install.py71
-rw-r--r--lib/spack/spack/cmd/modules/__init__.py18
-rw-r--r--lib/spack/spack/cmd/spec.py15
-rw-r--r--lib/spack/spack/cmd/uninstall.py41
-rw-r--r--lib/spack/spack/spec.py6
6 files changed, 108 insertions, 58 deletions
diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py
index 3b03d146f0..99a4abe876 100644
--- a/lib/spack/spack/cmd/common/arguments.py
+++ b/lib/spack/spack/cmd/common/arguments.py
@@ -76,6 +76,11 @@ _arguments['recurse_dependencies'] = Args(
'-r', '--dependencies', action='store_true', dest='recurse_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(
'--clean',
action='store_false',
@@ -106,6 +111,16 @@ _arguments['tags'] = Args(
'-t', '--tags', action='append',
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(
'-n', '--no-checksum', action='store_true', default=False,
help="do not use checksums to verify downloadeded files (unsafe)")
diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py
index 733f29361b..c1f1d09072 100644
--- a/lib/spack/spack/cmd/install.py
+++ b/lib/spack/spack/cmd/install.py
@@ -25,18 +25,8 @@ section = "build"
level = "short"
-def setup_parser(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"""
- )
- arguments.add_common_arguments(subparser, ['jobs'])
+def add_common_arguments(subparser):
+ arguments.add_common_arguments(subparser, ['jobs', 'install_status'])
subparser.add_argument(
'--overwrite', action='store_true',
help="reinstall an existing spec, even if it has dependents")
@@ -65,14 +55,52 @@ the dependencies"""
subparser.add_argument(
'--fake', action='store_true',
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(
'-f', '--file', action='append', default=[],
dest='specfiles', metavar='SPEC_YAML_FILE',
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(
'package',
nargs=argparse.REMAINDER,
@@ -159,17 +187,10 @@ def install(parser, args, **kwargs):
# Parse cli arguments and construct a dictionary
# that will be passed to Package.do_install API
+ update_kwargs_from_args(args, kwargs)
kwargs.update({
- 'keep_prefix': args.keep_prefix,
- 'keep_stage': args.keep_stage,
- '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
+ 'install_dependencies': ('dependencies' in args.things_to_install),
+ 'install_package': ('package' in args.things_to_install)
})
if args.run_tests:
diff --git a/lib/spack/spack/cmd/modules/__init__.py b/lib/spack/spack/cmd/modules/__init__.py
index 4972acfe0e..598130c4da 100644
--- a/lib/spack/spack/cmd/modules/__init__.py
+++ b/lib/spack/spack/cmd/modules/__init__.py
@@ -54,22 +54,30 @@ def setup_parser(subparser):
'loads',
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',
help='generate input for module command (instead of a shell script)'
)
- loads_parser.add_argument(
+ subparser.add_argument(
'-p', '--prefix', dest='prefix', default='',
help='prepend to module names when issuing module load commands'
)
- loads_parser.add_argument(
+ subparser.add_argument(
'-x', '--exclude', dest='exclude', action='append', default=[],
help="exclude package from output; may be specified multiple times"
)
arguments.add_common_arguments(
- loads_parser, ['constraint', 'recurse_dependencies']
+ subparser, ['recurse_dependencies']
)
- return sp
class MultipleSpecsMatch(Exception):
diff --git a/lib/spack/spack/cmd/spec.py b/lib/spack/spack/cmd/spec.py
index 3280d0b356..c0ce5b9bad 100644
--- a/lib/spack/spack/cmd/spec.py
+++ b/lib/spack/spack/cmd/spec.py
@@ -19,8 +19,9 @@ section = "build"
level = "short"
-def setup_parser(subparser):
- arguments.add_common_arguments(subparser, ['long', 'very_long'])
+def add_common_arguments(subparser):
+ arguments.add_common_arguments(
+ subparser, ['long', 'very_long', 'install_status'])
subparser.add_argument(
'-y', '--yaml', action='store_true', default=False,
help='print concrete spec as YAML')
@@ -31,11 +32,7 @@ def setup_parser(subparser):
subparser.add_argument(
'-N', '--namespaces', action='store_true', default=False,
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(
'-t', '--types', action='store_true', default=False,
help='show dependency types')
@@ -43,6 +40,10 @@ def setup_parser(subparser):
'specs', nargs=argparse.REMAINDER, help="specs of packages")
+def setup_parser(subparser):
+ add_common_arguments(subparser)
+
+
def spec(parser, args):
name_fmt = '$.' if args.namespaces else '$_'
kwargs = {'cover': args.cover,
diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py
index 2e2810b984..574bd64b44 100644
--- a/lib/spack/spack/cmd/uninstall.py
+++ b/lib/spack/spack/cmd/uninstall.py
@@ -9,6 +9,7 @@ import argparse
import spack.cmd
import spack.package
+import spack.cmd.common.arguments as arguments
import spack.repo
import spack.store
@@ -31,11 +32,16 @@ display_args = {
}
-def setup_parser(subparser):
+def add_common_arguments(subparser):
subparser.add_argument(
'-f', '--force', action='store_true', dest='force',
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(
'-a', '--all', action='store_true', dest='all',
help="USE CAREFULLY. remove ALL installed packages that match each "
@@ -45,15 +51,6 @@ def setup_parser(subparser):
"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(
'packages',
nargs=argparse.REMAINDER,
help="specs of packages to uninstall")
@@ -148,16 +145,12 @@ def do_uninstall(specs, force):
item.do_uninstall(force=force)
-def get_uninstall_list(args):
- specs = [any]
- if args.packages:
- specs = spack.cmd.parse_specs(args.packages)
-
+def get_uninstall_list(args, specs):
# Gets the list of installed specs that match the ones give via cli
# takes care of '-a' is given in the cli
uninstall_list = find_matching_specs(specs, args.all, args.force)
- # Takes care of '-d'
+ # Takes care of '-R'
dependent_list = installed_dependents(uninstall_list)
# Process dependent_list and update uninstall_list
@@ -181,12 +174,9 @@ def get_uninstall_list(args):
return uninstall_list
-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.')
+def uninstall_specs(args, specs):
- uninstall_list = get_uninstall_list(args)
+ uninstall_list = get_uninstall_list(args, specs)
if not uninstall_list:
tty.warn('There are no package to uninstall.')
@@ -201,3 +191,12 @@ def uninstall(parser, args):
# Uninstall everything on the list
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])
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 40d5fae28c..d5bc56fb6c 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -3227,6 +3227,7 @@ class Spec(object):
prefix = kwargs.pop('prefix', None)
show_types = kwargs.pop('show_types', False)
deptypes = kwargs.pop('deptypes', 'all')
+ recurse_dependencies = kwargs.pop('recurse_dependencies', True)
check_kwargs(kwargs, self.tree)
out = ""
@@ -3275,6 +3276,11 @@ class Spec(object):
if d > 0:
out += "^"
out += node.format(fmt, color=color) + "\n"
+
+ # Check if we wanted just the first line
+ if not recurse_dependencies:
+ break
+
return out
def __repr__(self):