Skip to content

Commit

Permalink
Fix workflow-state alt run-dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Mar 21, 2024
1 parent 82bd7cc commit e6e5ee8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
9 changes: 6 additions & 3 deletions cylc/flow/id_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async def parse_ids_async(
constraint: str = 'tasks',
max_workflows: Optional[int] = None,
max_tasks: Optional[int] = None,
alt_run_dir: Optional[str] = None,
) -> Tuple[Dict[str, List[Tokens]], Any]:
"""Parse IDs from the command line.
Expand Down Expand Up @@ -294,7 +295,8 @@ async def parse_ids_async(

# infer the run number if not specified the ID (and if possible)
if infer_latest_runs:
_infer_latest_runs(tokens_list, src_path=src_path)
_infer_latest_runs(
tokens_list, src_path=src_path, alt_run_dir=alt_run_dir)

_validate_number(
*tokens_list,
Expand Down Expand Up @@ -409,13 +411,14 @@ def _validate_workflow_ids(*tokens_list, src_path):
detect_both_flow_and_suite(src_path)


def _infer_latest_runs(tokens_list, src_path):
def _infer_latest_runs(tokens_list, src_path, alt_run_dir=None):
for ind, tokens in enumerate(tokens_list):
if ind == 0 and src_path:
# source workflow passed in as a path
continue
tokens_list[ind] = tokens.duplicate(
workflow=infer_latest_run_from_id(tokens['workflow'])
workflow=infer_latest_run_from_id(
tokens['workflow'], alt_run_dir)
)
pass

Expand Down
17 changes: 10 additions & 7 deletions cylc/flow/scripts/workflow_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_option_parser() -> COP:
help="The top level cylc run directory if non-standard. The "
"database should be DIR/WORKFLOW_ID/log/db. Use to interrogate "
"workflows owned by others, etc.; see note above.",
metavar="DIR", action="store", dest="run_dir", default=None)
metavar="DIR", action="store", dest="alt_run_dir", default=None)

parser.add_option(
"-s", "--offset",
Expand Down Expand Up @@ -196,10 +196,6 @@ def get_option_parser() -> COP:

@cli_function(get_option_parser, remove_opts=["--db"])
def main(parser: COP, options: 'Values', workflow_id: str) -> None:
workflow_id, *_ = parse_id(
workflow_id,
constraint='workflows',
)

if options.use_task_point and options.cycle:
raise InputError(
Expand Down Expand Up @@ -232,10 +228,17 @@ def main(parser: COP, options: 'Values', workflow_id: str) -> None:
raise InputError(f"invalid status '{options.status}'")

# this only runs locally
if options.run_dir:
run_dir = expand_path(options.run_dir)
if options.alt_run_dir:
run_dir = alt_run_dir = expand_path(options.alt_run_dir)

Check warning on line 232 in cylc/flow/scripts/workflow_state.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/workflow_state.py#L232

Added line #L232 was not covered by tests
else:
run_dir = get_cylc_run_dir()
alt_run_dir = None

workflow_id, *_ = parse_id(
workflow_id,
constraint='workflows',
alt_run_dir=alt_run_dir
)

pollargs = {
'workflow_id': workflow_id,
Expand Down
16 changes: 12 additions & 4 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,16 +862,22 @@ def check_reserved_dir_names(name: Union[Path, str]) -> None:
raise WorkflowFilesError(err_msg.format('run<number>'))


def infer_latest_run_from_id(workflow_id: str) -> str:
run_dir = Path(get_workflow_run_dir(workflow_id))
_, id_ = infer_latest_run(run_dir)
def infer_latest_run_from_id(
workflow_id: str, alt_run_dir: Optional[str] = None
) -> str:
if alt_run_dir is not None:
run_dir = Path(alt_run_dir) / Path(workflow_id)

Check warning on line 869 in cylc/flow/workflow_files.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/workflow_files.py#L869

Added line #L869 was not covered by tests
else:
run_dir = Path(get_workflow_run_dir(workflow_id))
_, id_ = infer_latest_run(run_dir, alt_run_dir=alt_run_dir)
return id_


def infer_latest_run(
path: Path,
implicit_runN: bool = True,
warn_runN: bool = True,
alt_run_dir: Optional[str] = None,
) -> Tuple[Path, str]:
"""Infer the numbered run dir if the workflow has a runN symlink.
Expand All @@ -890,15 +896,17 @@ def infer_latest_run(
- WorkflowFilesError if the runN symlink is not valid.
- InputError if the path does not exist.
"""
cylc_run_dir = get_cylc_run_dir()
cylc_run_dir = alt_run_dir or get_cylc_run_dir()
try:
id_ = str(path.relative_to(cylc_run_dir))
except ValueError:
raise ValueError(f"{path} is not in the cylc-run directory")

if not path.exists():
raise InputError(
f'Workflow ID not found: {id_}\n(Directory not found: {path})'
)

if path.name == WorkflowFiles.RUN_N:
runN_path = path
if warn_runN:
Expand Down

0 comments on commit e6e5ee8

Please sign in to comment.