feat: add filter based spec to list

This commit is contained in:
Daylin Morgan 2023-08-08 13:02:20 -05:00
parent 95531c310c
commit 7a0f3d6ad6
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -55,7 +55,7 @@ from typing import (
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import urlopen from urllib.request import urlopen
__version__ = "23.8a2-7-ge8f6228-dev" __version__ = "23.8a2-8-g95531c3-dev"
class Spinner: class Spinner:
@ -1226,6 +1226,13 @@ class Cache:
if str(p) in vivenv.meta.files if str(p) in vivenv.meta.files
} }
def _filter_spec(self, spec: str) -> Set[ViVenv]:
return {
vivenv
for _, vivenv in self.vivenvs.items()
if spec in ", ".join(vivenv.meta.spec)
}
def filter(self, filters: Dict[str, str]) -> Dict[str, ViVenv]: def filter(self, filters: Dict[str, str]) -> Dict[str, ViVenv]:
vivenv_sets = [] vivenv_sets = []
@ -1233,9 +1240,11 @@ class Cache:
if "-" in k: # date-based filters all have hyphen if "-" in k: # date-based filters all have hyphen
(date_name, when) = k.split("-") (date_name, when) = k.split("-")
vivenv_sets.append(self._filter_date(date_name, when, _parse_date(v))) vivenv_sets.append(self._filter_date(date_name, when, _parse_date(v)))
else: elif k == "files":
vivenv_sets.append(self._filter_file(v)) vivenv_sets.append(self._filter_file(v))
elif k == "spec":
vivenv_sets.append(self._filter_spec(v))
if vivenv_sets: if vivenv_sets:
return {vivenv.name: vivenv for vivenv in set.union(*vivenv_sets)} return {vivenv.name: vivenv for vivenv in set.union(*vivenv_sets)}
else: else:
@ -1750,6 +1759,7 @@ class Cli:
"accessed-before", "accessed-before",
"accessed-after", "accessed-after",
"files", "files",
"spec",
], ],
), ),
], ],
@ -2022,7 +2032,7 @@ class Cli:
args.rest = sys.argv[i + 1 :] args.rest = sys.argv[i + 1 :]
else: else:
args = self.parser.parse_args() args = self.parser.parse_args()
if args.func.__name__ in ("run", "exe"): if args.func.__name__ in ("cmd_run", "cmd_exe"):
args.rest = [] args.rest = []
self._validate_args(args) self._validate_args(args)