Skip to content

Commit

Permalink
Better scan workflow detection. (#4830)
Browse files Browse the repository at this point in the history
scan: Better scan workflow detection.
  • Loading branch information
hjoliver authored Apr 21, 2022
1 parent 5361c42 commit af39199
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ workflow source argument), and rename the `--flow-name` option to

### Fixes

[#4830](https://github.com/cylc/cylc-flow/pull/4830) -
Workflow scan now detects Cylc 7 suites installed, but not yet run, by Cylc 8.

[#4554](https://github.com/cylc/cylc-flow/pull/4554) - Fix incorrect
implementation of the ISO 8601 recurrence format no. 1
(`R<number>/<start-point>/<second-point>`)
Expand Down
54 changes: 33 additions & 21 deletions cylc/flow/network/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@
SERVICE = Path(WorkflowFiles.Service.DIRNAME)
CONTACT = Path(WorkflowFiles.Service.CONTACT)

FLOW_FILES = {
# marker files/dirs which we use to determine if something is a flow
WorkflowFiles.Service.DIRNAME,
WorkflowFiles.FLOW_FILE, # cylc8 flow definition file name
WorkflowFiles.LOG_DIR
}

EXCLUDE_FILES = {
WorkflowFiles.RUN_N,
WorkflowFiles.Install.SOURCE
Expand Down Expand Up @@ -115,26 +108,45 @@ def dir_is_flow(listing: Iterable[Path]) -> Optional[bool]:
"""
names = {path.name for path in listing}

if WorkflowFiles.SUITE_RC in names:
# a Cylc 7 workflow ...
# Cylc 8:
# - "cylc install" creates a source dir link and a "log' directory as
# well as installing the flow.cylc or suite.rc, but only the workflow
# definition is needed for it to be runnable by Cylc 8.

# Cylc 7:
# - suites manually registered in-place do not have a suite.rc in the run
# directory and cannot be run by Cylc 8
# - suites installed (manually or by "rose suite-run") can be run by Cylc 8
# if not already run by Cylc 7
# - "rose suite-run --install-only" creates a "log/suite" directory
# - running with Cylc 7 creates "log/suite/log"

if WorkflowFiles.FLOW_FILE in names:
# A Cylc 8 workflow.
return True

elif WorkflowFiles.SUITE_RC in names:
# An installed Cylc 7 workflow ...
for path in listing:
if path.name == WorkflowFiles.LOG_DIR:
if (path / 'workflow').exists():
# Cylc 8: log/workflow/log
return True
else:
# Cylc 7: log/suite/log
if (
(path / 'suite' / 'log').exists()
and not (path / 'workflow').exists()
):
# ... already run by Cylc 7 (and not re-run by Cylc 8 after
# removing the DB)
return None
# workflow doesn't have a log dir so has not been run
# so could be either a Cylc 7 or a Cylc 8 workflow
return True
else:
# ... can be run by Cylc 8
return True

if FLOW_FILES & names:
# a pure Cylc 8 workflow
# Has not been run (and not installed by "rose suite-run" or
# "cylc install"). Can be run by Cylc 8.
return True

# random directory
return False
else:
# A random directory
return False


@pipe
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def init_flows(tmp_path, running=None, registered=None, un_registered=None):
def make_registered(name, running=False):
run_d = Path(tmp_path, name)
run_d.mkdir(parents=True, exist_ok=True)
(run_d / "flow.cylc").touch()
if "run" in name:
root = Path(tmp_path, name).parent
with suppress(FileExistsError):
Expand Down Expand Up @@ -433,6 +434,13 @@ def cylc7_run_dir(tmp_path):
Path(cylc8, WorkflowFiles.LOG_DIR, 'workflow').mkdir(parents=True)
Path(cylc8, WorkflowFiles.LOG_DIR, 'workflow', 'log').touch()

# a Cylc 7 workflow installed by Cylc 8 but not run yet.
# (should appear in scan results)
cylc8a = tmp_path / 'cylc8a'
cylc8a.mkdir()
(cylc8a / WorkflowFiles.SUITE_RC).touch()
Path(cylc8a, WorkflowFiles.LOG_DIR, 'install').mkdir(parents=True)

# crazy niche case of a Cylc 7 workflow that has had its DB removed
# and re-run under Cylc 8
# (should appear in scan results)
Expand All @@ -455,5 +463,5 @@ async def test_scan_cylc7(cylc7_run_dir):
assert await listify(
scan(cylc7_run_dir)
) == [
'cylc78', 'cylc8', 'either'
'cylc78', 'cylc8', 'cylc8a', 'either'
]

0 comments on commit af39199

Please sign in to comment.