Skip to content

Commit

Permalink
fix: adapt jobs cli to resolve issue with typer >= 0.12.4
Browse files Browse the repository at this point in the history
  • Loading branch information
aldbr committed Sep 13, 2024
1 parent 6f72a35 commit 8073c66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion diracx-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"gitpython",
"pydantic",
"rich",
"typer <0.12.4",
"typer",
"pyyaml",
]
dynamic = ["version"]
Expand Down
13 changes: 11 additions & 2 deletions diracx-cli/src/diracx/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
app = AsyncTyper()


available_operators = (
f"Scalar operators: {', '.join([op.value for op in ScalarSearchOperator])}. "
f"Vector operators: {', '.join([op.value for op in VectorSearchOperator])}."
)


def parse_condition(value: str) -> SearchSpec:
parameter, operator, rest = value.split(" ", 2)
if operator in set(ScalarSearchOperator):
Expand Down Expand Up @@ -51,15 +57,18 @@ async def search(
"Owner",
"LastUpdateTime",
],
condition: Annotated[list[SearchSpec], Option(parser=parse_condition)] = [],
condition: Annotated[
list[str], Option(help=f'Example: "JobID eq 1000". {available_operators}')
] = [],
all: bool = False,
page: int = 1,
per_page: int = 10,
):
search_specs = [parse_condition(cond) for cond in condition]
async with DiracClient() as api:
jobs, content_range = await api.jobs.search(
parameters=None if all else parameter,
search=condition if condition else None,
search=search_specs if search_specs else None,
page=page,
per_page=per_page,
cls=lambda _, jobs, headers: (
Expand Down
6 changes: 2 additions & 4 deletions diracx-cli/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pytest import raises

from diracx import cli
from diracx.core.models import ScalarSearchSpec
from diracx.core.preferences import get_diracx_preferences

TEST_JDL = """
Expand Down Expand Up @@ -80,8 +79,7 @@ async def test_search(with_cli_login, jdl_file, capfd):
assert "JobGroup" in cap.out

# Search for a job that doesn't exist
condition = ScalarSearchSpec(parameter="Status", operator="eq", value="nonexistent")
await cli.jobs.search(condition=[condition])
await cli.jobs.search(condition=["Status eq nonexistent"])
cap = capfd.readouterr()
assert cap.err == ""
assert "[]" == cap.out.strip()
Expand Down Expand Up @@ -114,7 +112,7 @@ async def test_search(with_cli_login, jdl_file, capfd):
assert "Showing all jobs" in cap.out

# Search for a job that doesn't exist
await cli.jobs.search(condition=[condition])
await cli.jobs.search(condition=["Status eq nonexistent"])
cap = capfd.readouterr()
assert cap.err == ""
assert "No jobs found" in cap.out

0 comments on commit 8073c66

Please sign in to comment.