Skip to content
Open
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
1 change: 1 addition & 0 deletions concore_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Validates a GraphML workflow file before running.

**Options:**
- `-s, --source <dir>` - Source directory to verify file references exist
- `-t, --type <type>` - Also check the workflow can be built for this execution type (`windows`, `posix` or `docker`). Pulled containers (a node label with no file extension, such as `CZ:cpymat`) are only valid with `docker`

Checks:
- Valid XML structure
Expand Down
11 changes: 10 additions & 1 deletion concore_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,23 @@ def build(workflow_file, source, output, type, auto_build, compose, zmq):
type=click.Choice(["text", "json"]),
help="Validation output format",
)
def validate(workflow_file, source, output_format):
@click.option(
"--type",
"-t",
"exec_type",
default=None,
type=click.Choice(["windows", "posix", "docker"]),
help="Also check the workflow can be built for this execution type",
)
def validate(workflow_file, source, output_format, exec_type):
"""Validate a workflow file"""
try:
ok = validate_workflow(
workflow_file,
source,
console,
output_format=output_format,
exec_type=exec_type,
)
if not ok:
sys.exit(1)
Expand Down
13 changes: 12 additions & 1 deletion concore_cli/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def _build_payload(workflow_path, source_root, errors, warnings, info, source_no
}


def validate_workflow(workflow_file, source_dir, console, output_format="text"):
def validate_workflow(
workflow_file, source_dir, console, output_format="text", exec_type=None
):
workflow_path = Path(workflow_file)
source_root = resolve_source_dir(workflow_path, source_dir)

Expand Down Expand Up @@ -256,6 +258,15 @@ def finalize():
source_nodes[filename] = node_id
if not filename:
errors.append(f"Node '{label}' has no filename")
elif (
exec_type in ("posix", "windows")
and "." not in filename
):
errors.append(
f"Node '{label}' is a pulled container (no file "
f"extension); pulled containers need --type docker, "
f"not {exec_type}"
)
elif not any(
filename.endswith(ext)
for ext in [".py", ".cpp", ".m", ".v", ".java"]
Expand Down
48 changes: 48 additions & 0 deletions tests/test_validate_exec_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
from click.testing import CliRunner

from concore_cli.cli import cli

GRAPH = """<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:y="http://www.yworks.com/xml/graphml">
<graph id="G" edgedefault="directed">
<node id="n0"><data key="d0"><y:NodeLabel>CZ:{first}</y:NodeLabel></data></node>
<node id="n1"><data key="d0"><y:NodeLabel>PZ:pm.py</y:NodeLabel></data></node>
</graph>
</graphml>
"""


def _validate(tmp_path, first, *extra):
src = tmp_path / "src"
src.mkdir(exist_ok=True)
(src / "pm.py").write_text("x\n")
if "." in first:
(src / first).write_text("x\n")
wf = tmp_path / "wf.graphml"
wf.write_text(GRAPH.format(first=first), encoding="utf-8")
return CliRunner().invoke(cli, ["validate", str(wf), "--source", str(src), *extra])


@pytest.mark.parametrize("exec_type", ["posix", "windows"])
def test_pulled_container_is_an_error_for_posix_and_windows(tmp_path, exec_type):
result = _validate(tmp_path, "cpymat", "--type", exec_type)
assert result.exit_code == 1
assert "pulled container" in result.output
assert f"not {exec_type}" in result.output


def test_pulled_container_is_fine_for_docker(tmp_path):
result = _validate(tmp_path, "cpymat", "--type", "docker")
assert "pulled container" not in result.output


def test_without_type_nothing_changes(tmp_path):
result = _validate(tmp_path, "cpymat")
assert "pulled container" not in result.output


def test_regular_source_files_pass_with_a_type(tmp_path):
result = _validate(tmp_path, "controller.py", "--type", "posix")
assert result.exit_code == 0, result.output
assert "pulled container" not in result.output
Loading