Skip to content
Snippets Groups Projects
Commit 85508d10 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

data-envs: add a --filter flag to den-list-data-envs

parent f04c2e5c
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,20 @@
return cmds
def filter_option(target):
return click.option(
"--filter",
"filters",
multiple=True,
help=f"""Criteria to filter {target} with. Filters are additive.
They are of the form `key=value`, where `key` is the dot-delimited key
inside the result file, and `value` is the expected value.
If `value` starts with `re:`, then it is checked against
the regular expression that follows.""",
)
@click.group()
def poulpe_cli():
"""The main entry point for Poulpe command"""
......@@ -102,7 +116,8 @@
@poulpe_cli.command()
@click.option("--den-path", type=click.Path(exists=True), default=".")
def den_list_data_envs(den_path="."):
@filter_option(target="data-environments")
def den_list_data_envs(den_path=".", filters=None):
"""Find and list Data Enviroment available in a Poulpe Den"""
den_root = Path(den_path)
den = den_mod.PoulpeDen(den_root)
......@@ -106,7 +121,10 @@
"""Find and list Data Enviroment available in a Poulpe Den"""
den_root = Path(den_path)
den = den_mod.PoulpeDen(den_root)
den_mod.list_data_env(den)
if filters is None:
filters = []
filters = filter.parse_filters(filters)
den_mod.list_data_env(den, filters=filters)
@poulpe_cli.command()
......@@ -245,17 +263,7 @@
default=False,
help="Display the contents as JSON instead of the filenames",
)
@click.option(
"--filter",
"filters",
multiple=True,
help="""Criteria to filter results with. Filters are additive.
They are of the form `key=value`, where `key` is the dot-delimited key
inside the result file, and `value` is the expected value.
If `value` starts with `re:`, then it is checked against
the regular expression that follows.""",
)
@filter_option(target="results")
@click.argument("result_paths", metavar="RESULTS", nargs=-1)
def result_search(
result_paths,
......
......@@ -10,5 +10,6 @@
from pathlib import Path
from poulpe import basics
from poulpe import benchmarks
from poulpe import binenvs as bin_env_mod
from poulpe import dataenvs
......@@ -13,6 +14,6 @@
from poulpe import binenvs as bin_env_mod
from poulpe import dataenvs
from poulpe import benchmarks
from poulpe import filter
class PoulpeDen:
......@@ -51,5 +52,5 @@
def tooling_dir(self):
return self.root_dir / "tooling"
def find_data_envs(self):
def find_data_envs(self, filters=()):
"""walk the data-envs directory in search of data-env"""
......@@ -55,4 +56,12 @@
"""walk the data-envs directory in search of data-env"""
data_envs = self._find_all_data_envs()
result = []
for d in data_envs:
if filter.apply_filters(filters, d.data_env_vars):
result.append(d)
return result
def _find_all_data_envs(self):
den_data_envs = []
# search for data_envs in the data_env directory
......@@ -199,6 +208,6 @@
print(f" ~ {c} {d}")
def list_data_env(den):
for data_env in den.find_data_envs():
def list_data_env(den, filters=()):
for data_env in den.find_data_envs(filters=filters):
print(f"{data_env.path}")
......@@ -50,3 +50,9 @@
$ poulpe den-list-data-envs
data-envs/bar
data-envs/foo
filter list
-----------
$ poulpe den-list-data-envs --filter mercurial.repo.graph.visible-revision-count="re:^1....$"
data-envs/foo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment