Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(diracx-cli): adapt jobs cli to resolve issue with typer >= 0.12.4 #290

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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