Skip to content

Commit

Permalink
Merge pull request #15439 from bernt-matthias/fix-looks-like-yaml-w-c…
Browse files Browse the repository at this point in the history
…lass

[22.05] fix looks_like_yaml_or_cwl_with_class
  • Loading branch information
mvdbeek authored Jan 30, 2023
2 parents bff1a04 + 8ec08f6 commit 7c8d732
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/loader_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def looks_like_a_data_manager_xml(path):

def as_dict_if_looks_like_yaml_or_cwl_with_class(path, classes):
"""
get a dict from yaml file if it contains `class: CLASS`, where CLASS is
get a dict from yaml file if it contains a line `class: CLASS`, where CLASS is
any string given in CLASSES. must appear in the first 5k and also load
properly in total.
"""
Expand All @@ -199,7 +199,7 @@ def as_dict_if_looks_like_yaml_or_cwl_with_class(path, classes):
start_contents = f.read(5 * 1024)
except UnicodeDecodeError:
return False, None
if re.search(rf"\nclass:\s+({'|'.join(classes)})\s*\n", start_contents) is None:
if re.search(rf"^class:\s+{'|'.join(classes)}\s*$", start_contents, re.MULTILINE) is None:
return False, None

with open(path) as f:
Expand Down
24 changes: 24 additions & 0 deletions test/unit/tool_util/test_loader_directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import tempfile

from galaxy.tool_util.loader_directory import is_a_yaml_with_class


def test_is_a_yaml_with_class():
with tempfile.NamedTemporaryFile("w", suffix=".yaml") as tf:
fname = tf.name
tf.write(
"""class: GalaxyWorkflow
name: "Test Workflow"
inputs:
- id: input1
outputs:
- id: wf_output_1
outputSource: first_cat/out_file1
steps:
- tool_id: cat
label: first_cat
in:
input1: input1"""
)
tf.flush()
assert is_a_yaml_with_class(fname, ["GalaxyWorkflow"])

0 comments on commit 7c8d732

Please sign in to comment.