From a4ac99877a512249fa7d126f48716d590cfa80a9 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Fri, 17 Jun 2016 12:00:35 -0700 Subject: [PATCH 1/8] cmd/list: adding description search and glob by default --- lib/spack/spack/cmd/list.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 1e3699cee0..5406283b05 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -28,7 +28,7 @@ from llnl.util.tty.colify import colify import spack -import fnmatch +import fnmatch, re description ="List available spack packages" @@ -39,20 +39,41 @@ def setup_parser(subparser): subparser.add_argument( '-i', '--insensitive', action='store_true', default=False, help='Filtering will be case insensitive.') + subparser.add_argument( + '-s', '--search_description', action='store_true', default=False, + help='Filtering will also search the description for a match.') def list(parser, args): # 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 if args.filter: - def match(p, f): - if args.insensitive: - p = p.lower() - f = f.lower() - return fnmatch.fnmatchcase(p, f) - pkgs = [p for p in pkgs if any(match(p, f) for f in args.filter)] + filters = [] + for f in args.filter: + if '*' not in f and '?' not in f: + filters.append('*' + f + '*') + else: + filters.append(f) + + res = [re.compile(fnmatch.translate(f), + flags=re.I if args.insensitive else 0) + for f in filters] + + if args.search_description: + def match(p, f): + if f.match(p): + return True + + pkg = spack.repo.get(p) + 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. sorted_packages = sorted(pkgs, key=lambda s:s.lower()) From 0743ef4d0ba6632992fee3657f0d89200d4e481b Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Fri, 17 Jun 2016 13:32:28 -0700 Subject: [PATCH 2/8] fixing flake8 issues --- lib/spack/spack/cmd/list.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 5406283b05..d1c19b45c6 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -28,9 +28,11 @@ from llnl.util.tty.colify import colify import spack -import fnmatch, re +import fnmatch +import re + +description = "List available spack packages" -description ="List available spack packages" def setup_parser(subparser): subparser.add_argument( @@ -76,10 +78,10 @@ def match(p, f): pkgs = [p for p in pkgs if any(match(p, f) for f in res)] # sort before displaying. - sorted_packages = sorted(pkgs, key=lambda s:s.lower()) + sorted_packages = sorted(pkgs, key=lambda s: s.lower()) # Print all the package names in columns - indent=0 + indent = 0 if sys.stdout.isatty(): tty.msg("%d packages." % len(sorted_packages)) colify(sorted_packages, indent=indent) From 8770f2a0ea14c7145e87bfd08ca7149ae3838127 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Fri, 17 Jun 2016 13:42:27 -0700 Subject: [PATCH 3/8] fixing last flake8 issue --- lib/spack/spack/cmd/list.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index d1c19b45c6..228ab76780 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -52,16 +52,14 @@ def list(parser, args): # filter if a filter arg was provided if args.filter: - filters = [] + res = [] for f in args.filter: if '*' not in f and '?' not in f: - filters.append('*' + f + '*') + r = fnmatch.translate('*' + f + '*') else: - filters.append(f) - - res = [re.compile(fnmatch.translate(f), - flags=re.I if args.insensitive else 0) - for f in filters] + r = fnmatch.translate(f) + rc = re.compile(r, flags=re.I if args.insensitive else 0) + res.append(rc) if args.search_description: def match(p, f): From 0377f3580b0985bd65fb64e82a6fbb9b397b56ab Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Mon, 20 Jun 2016 10:53:19 -0700 Subject: [PATCH 4/8] switching argument naming --- lib/spack/spack/cmd/list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 228ab76780..9ce63fa1a4 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -42,7 +42,7 @@ def setup_parser(subparser): '-i', '--insensitive', action='store_true', default=False, help='Filtering will be case insensitive.') subparser.add_argument( - '-s', '--search_description', action='store_true', default=False, + '-d', '--search-description', action='store_true', default=False, help='Filtering will also search the description for a match.') From 6180e6c047ba09a8c7359ba9327ca6a332b4e073 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Mon, 20 Jun 2016 11:33:56 -0700 Subject: [PATCH 5/8] automatic case-insensitive like smartsearch, docs New documentation for the new options, also case insensitive by default unless the user includes an upper-case character in their pattern. --- lib/spack/docs/basic_usage.rst | 25 +++++++++++++++++++++---- lib/spack/spack/cmd/list.py | 3 ++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index 50c48b802b..f4d42c23ad 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -24,12 +24,29 @@ Spack can install: .. command-output:: spack list -The packages are listed by name in alphabetical order. You can also -do wildcats searches using ``*``: +The packages are listed by name in alphabetical order. If you specify a +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 iwth +``*``, so ``util`` is equivalent to ``*util*``. A pattern with no capitol +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 capitol 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: diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 9ce63fa1a4..974c4778ab 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -58,7 +58,8 @@ def list(parser, args): r = fnmatch.translate('*' + f + '*') else: r = fnmatch.translate(f) - rc = re.compile(r, flags=re.I if args.insensitive else 0) + 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: From ac728d3e60ef9ef8c52333449592c5933b9c59ce Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Mon, 20 Jun 2016 11:38:39 -0700 Subject: [PATCH 6/8] fixing capitol->capital typos --- lib/spack/docs/basic_usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index f4d42c23ad..ceec8c7723 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -27,7 +27,7 @@ Spack can install: The packages are listed by name in alphabetical order. If you specify a 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 iwth -``*``, so ``util`` is equivalent to ``*util*``. A pattern with no capitol +``*``, 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: @@ -36,7 +36,7 @@ All packages whose names contain "sql" case insensitive: .. command-output:: spack list sql -All packages whose names start with a capitol M: +All packages whose names start with a capital M: .. command-output:: spack list M* From f6aa864bc42f2ed517a836f398fb5ee00a2494b3 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Mon, 20 Jun 2016 11:41:36 -0700 Subject: [PATCH 7/8] adding quotes to make sure the glob is interpreted correctly --- lib/spack/docs/basic_usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index ceec8c7723..f103f7f5a5 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -38,7 +38,7 @@ All packages whose names contain "sql" case insensitive: All packages whose names start with a capital M: -.. command-output:: spack list M* +.. command-output:: spack list 'M*' All packages whose names or descriptions contain Documentation: From 45482187b473d3b613700bb29af82748a54c4d1a Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Mon, 20 Jun 2016 11:42:35 -0700 Subject: [PATCH 8/8] one more typo issue --- lib/spack/docs/basic_usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index f103f7f5a5..ec193e767d 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -26,7 +26,7 @@ Spack can install: The packages are listed by name in alphabetical order. If you specify a 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 iwth +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