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
12 changes: 12 additions & 0 deletions mkconcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def cleanup_script_files():
edges_text = soup.find_all('edge')
nodes_text = soup.find_all('node')

if not nodes_text:
logging.error(f"No nodes found in {GRAPHML_FILE}. Is it a valid GraphML workflow?")
sys.exit(1)

# Store the edges and nodes in a dictionary
edge_label_regex = re.compile(r"0x([a-fA-F0-9]+)_(\S+)")
edges_dict = dict()
Expand Down Expand Up @@ -438,6 +442,7 @@ def cleanup_script_files():
node_edge_params = {}
edge_label_regex = re.compile(r"0x([^_]+)_(\S+)")

missing_sources = []
logging.info("Aggregating ZMQ edge parameters for nodes...")
if copy_script_py_path:
for edge_element in soup.find_all('edge'):
Expand Down Expand Up @@ -533,6 +538,7 @@ def cleanup_script_files():
template_script_full_path = os.path.join(sourcedir, original_script)
if not os.path.exists(template_script_full_path):
logging.error(f"Cannot specialize: Original script '{template_script_full_path}' not found in '{sourcedir}'.")
missing_sources.append(original_script)
continue

new_script_relpath = copy_with_port_portname.run_specialization_script(
Expand Down Expand Up @@ -602,6 +608,8 @@ def cleanup_script_files():
shutil.copy2(script_source_path, script_target_path)
else:
logging.error(f"Script '{sourcecode}' not found in sourcedir '{sourcedir}'")
if "." in sourcecode: # pulled containers have no source file
missing_sources.append(sourcecode)

# The rest of the file handling (Dockerfiles, .dir) uses 'dockername',
# which is now derived from the specialized script name, maintaining consistency.
Expand All @@ -615,6 +623,10 @@ def cleanup_script_files():
shutil.copytree(os.path.join(sourcedir, dir_for_node), os.path.join(outdir, "src", dir_for_node), dirs_exist_ok=True)


if missing_sources:
logging.error(f"Node source file(s) not found in {sourcedir}: {', '.join(sorted(set(missing_sources)))}")
sys.exit(1)

#determine languages used in the graphml
required_langs = set()
for node in nodes_dict:
Expand Down
48 changes: 48 additions & 0 deletions tests/test_mkconcore_missing_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import subprocess
import sys
from pathlib import Path

MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py"

GRAPH = """<?xml version="1.0"?>
<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>a:a.py</y:NodeLabel></data></node>
<node id="n1"><data key="d0"><y:NodeLabel>b:b.py</y:NodeLabel></data></node>
<edge source="n0" target="n1"><data key="d1"><y:EdgeLabel>0x1_x</y:EdgeLabel></data></edge>
</graph>
</graphml>
"""


def _run(tmp_path, scripts):
src = tmp_path / "src"
src.mkdir()
for name in scripts:
(src / name).write_text("print('x')\n")
wf = tmp_path / "w.graphml"
wf.write_text(GRAPH)
return subprocess.run(
[
sys.executable,
str(MKCONCORE),
str(wf),
str(src),
str(tmp_path / "out"),
"posix",
],
cwd=tmp_path,
capture_output=True,
text=True,
)


def test_mkconcore_fails_when_source_file_missing(tmp_path):
result = _run(tmp_path, ["a.py"])
assert result.returncode != 0
assert "b.py" in result.stdout + result.stderr


def test_mkconcore_succeeds_when_all_sources_exist(tmp_path):
assert _run(tmp_path, ["a.py", "b.py"]).returncode == 0
32 changes: 32 additions & 0 deletions tests/test_mkconcore_no_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import subprocess
import sys
from pathlib import Path

import pytest

MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py"

EMPTY_GRAPH = (
'<?xml version="1.0"?>\n'
'<graphml xmlns="http://graphml.graphdrawing.org/xmlns">'
'<graph id="G" edgedefault="directed"></graph></graphml>\n'
)


@pytest.mark.parametrize("content", [EMPTY_GRAPH, "this is not xml"])
def test_mkconcore_fails_when_graph_has_no_nodes(tmp_path, content):
wf = tmp_path / "w.graphml"
wf.write_text(content)
src = tmp_path / "src"
src.mkdir()
out = tmp_path / "out"

result = subprocess.run(
[sys.executable, str(MKCONCORE), str(wf), str(src), str(out), "posix"],
cwd=tmp_path,
capture_output=True,
text=True,
)

assert result.returncode != 0
assert "No nodes found" in result.stdout + result.stderr
Loading