Merge branch 'list-ext' of https://github.com/trws/spack into trws-list-ext
This commit is contained in:
commit
cbd5a0a6e3
2 changed files with 53 additions and 14 deletions
|
@ -24,12 +24,29 @@ Spack can install:
|
||||||
|
|
||||||
.. command-output:: spack list
|
.. command-output:: spack list
|
||||||
|
|
||||||
The packages are listed by name in alphabetical order. You can also
|
The packages are listed by name in alphabetical order. If you specify a
|
||||||
do wildcats searches using ``*``:
|
pattern to match, it will follow this set of rules. A pattern with no
|
||||||
|
wildcards, ``*`` or ``?``, will be treated as though it started and ended with
|
||||||
|
``*``, so ``util`` is equivalent to ``*util*``. A pattern with no capital
|
||||||
|
letters will be treated as case-insensitive. You can also add the ``-i`` flag
|
||||||
|
to specify a case insensitive search, or ``-d`` to search the description of
|
||||||
|
the package in addition to the name. Some examples:
|
||||||
|
|
||||||
.. command-output:: spack list m*
|
All packages whose names contain "sql" case insensitive:
|
||||||
|
|
||||||
.. command-output:: spack list *util*
|
.. command-output:: spack list sql
|
||||||
|
|
||||||
|
All packages whose names start with a capital M:
|
||||||
|
|
||||||
|
.. command-output:: spack list 'M*'
|
||||||
|
|
||||||
|
All packages whose names or descriptions contain Documentation:
|
||||||
|
|
||||||
|
.. command-output:: spack list -d Documentation
|
||||||
|
|
||||||
|
All packages whose names contain documentation case insensitive:
|
||||||
|
|
||||||
|
.. command-output:: spack list -d documentation
|
||||||
|
|
||||||
.. _spack-info:
|
.. _spack-info:
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,11 @@
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import re
|
||||||
|
|
||||||
description = "List available spack packages"
|
description = "List available spack packages"
|
||||||
|
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'filter', nargs=argparse.REMAINDER,
|
'filter', nargs=argparse.REMAINDER,
|
||||||
|
@ -39,20 +41,40 @@ def setup_parser(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-i', '--insensitive', action='store_true', default=False,
|
'-i', '--insensitive', action='store_true', default=False,
|
||||||
help='Filtering will be case insensitive.')
|
help='Filtering will be case insensitive.')
|
||||||
|
subparser.add_argument(
|
||||||
|
'-d', '--search-description', action='store_true', default=False,
|
||||||
|
help='Filtering will also search the description for a match.')
|
||||||
|
|
||||||
|
|
||||||
def list(parser, args):
|
def list(parser, args):
|
||||||
# Start with all package names.
|
# Start with all package names.
|
||||||
pkgs = spack.repo.all_package_names()
|
pkgs = set(spack.repo.all_package_names())
|
||||||
|
|
||||||
# filter if a filter arg was provided
|
# filter if a filter arg was provided
|
||||||
if args.filter:
|
if args.filter:
|
||||||
|
res = []
|
||||||
|
for f in args.filter:
|
||||||
|
if '*' not in f and '?' not in f:
|
||||||
|
r = fnmatch.translate('*' + f + '*')
|
||||||
|
else:
|
||||||
|
r = fnmatch.translate(f)
|
||||||
|
rc = re.compile(r, flags=re.I if args.insensitive or not any(
|
||||||
|
l.isupper() for l in f) else 0)
|
||||||
|
res.append(rc)
|
||||||
|
|
||||||
|
if args.search_description:
|
||||||
def match(p, f):
|
def match(p, f):
|
||||||
if args.insensitive:
|
if f.match(p):
|
||||||
p = p.lower()
|
return True
|
||||||
f = f.lower()
|
|
||||||
return fnmatch.fnmatchcase(p, f)
|
pkg = spack.repo.get(p)
|
||||||
pkgs = [p for p in pkgs if any(match(p, f) for f in args.filter)]
|
if pkg.__doc__:
|
||||||
|
return f.match(pkg.__doc__)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
def match(p, f):
|
||||||
|
return f.match(p)
|
||||||
|
pkgs = [p for p in pkgs if any(match(p, f) for f in res)]
|
||||||
|
|
||||||
# sort before displaying.
|
# sort before displaying.
|
||||||
sorted_packages = sorted(pkgs, key=lambda s: s.lower())
|
sorted_packages = sorted(pkgs, key=lambda s: s.lower())
|
||||||
|
|
Loading…
Reference in a new issue