Skip to content

Commit

Permalink
Merge pull request #6270 from ColemanTom/sort_cylc_show_task_proxies
Browse files Browse the repository at this point in the history
Sort cylc show task proxies
  • Loading branch information
oliver-sanders authored Aug 6, 2024
2 parents e2da477 + 6039eba commit 9220919
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes.d/6266.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'cylc show' task output is now sorted by the task id
8 changes: 5 additions & 3 deletions cylc/flow/scripts/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ async def prereqs_and_outputs_query(
}
}
results = await pclient.async_request('graphql', tp_kwargs)
multi = len(results['taskProxies']) > 1
for t_proxy in results['taskProxies']:
task_proxies = sorted(results['taskProxies'],
key=lambda proxy: proxy['id'])
multi = len(task_proxies) > 1
for t_proxy in task_proxies:
task_id = Tokens(t_proxy['id']).relative_id
state = t_proxy['state']
if options.json:
Expand Down Expand Up @@ -379,7 +381,7 @@ async def prereqs_and_outputs_query(

print_completion_state(t_proxy)

if not results['taskProxies']:
if not task_proxies:
ansiprint(
f"<red>No matching active tasks found: {', '.join(ids_list)}",
file=sys.stderr)
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/scripts/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,46 @@ async def test_task_meta_query(mod_my_schd, capsys):
'URL': 'http://hasthelargehadroncolliderdestroyedtheworldyet.com/',
}
}


async def test_task_instance_query(
flow, scheduler, start, capsys
):
"""It should fetch task instance data, sorted by task name."""

colour_init(strip=True, autoreset=True)
opts = SimpleNamespace(
comms_timeout=5,
json=False,
task_defs=None,
list_prereqs=False,
)
schd = scheduler(
flow(
{
'scheduling': {
'graph': {'R1': 'zed & dog & cat & ant'},
},
}
),
paused_start=False
)
async with start(schd):
await schd.update_data_structure()
ret = await show(
schd.workflow,
[Tokens('//1/*')],
opts,
)
assert ret == 0

out, _ = capsys.readouterr()
assert [
line for line in out.splitlines()
if line.startswith("Task ID")
] == [ # results should be sorted
'Task ID: 1/ant',
'Task ID: 1/cat',
'Task ID: 1/dog',
'Task ID: 1/zed',
]

0 comments on commit 9220919

Please sign in to comment.