Skip to content

Commit eafb929

Browse files
author
Alan Christie
committed
feat: Initial support for molecules type
1 parent 1728d35 commit eafb929

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

src/jote/jote.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
# The user CANNOT have any pf their own nextflow config.
5151
_USR_HOME: str = os.environ.get("HOME", "")
5252

53+
# A string that has some sort of input prefix
54+
# e.g. "file://". This is what we expect to find in a test-input string that
55+
# has such a prefix.
56+
_TEST_INPUT_URL_MARKER: str = "://"
57+
5358

5459
class TestResult(Enum):
5560
"""Return value from '_run_a_test()'"""
@@ -92,6 +97,17 @@ def _lint(definition_filename: str) -> bool:
9297
return True
9398

9499

100+
def _get_test_input_url_prefix(test_input_string: str) -> Optional[str]:
101+
"""Gets the string's file prefix (e.g. "file://") from what's expected to be
102+
a test input string or None if there isn't one. If the prefix is "file://"
103+
this function returns "file://".
104+
"""
105+
prefix_index = test_input_string.find(_TEST_INPUT_URL_MARKER)
106+
if prefix_index >= 0:
107+
return test_input_string[:prefix_index] + _TEST_INPUT_URL_MARKER
108+
return None
109+
110+
95111
def _validate_schema(definition_filename: str) -> bool:
96112
"""Checks the Job Definition against the decoder's schema."""
97113

@@ -617,6 +633,7 @@ def _run_a_test(
617633

618634
# A list of input files (relative to this directory)
619635
# We populate this with everything we find declared as an input
636+
# (unless it's of type 'molecules' and the input looks like a molecule)
620637
input_files: List[str] = []
621638

622639
# Process every 'input'
@@ -639,17 +656,33 @@ def _run_a_test(
639656
return None, TestResult.FAILED
640657

641658
if variable_is_input:
642-
# Is it an input (not an option).
643-
# The input is a list if it's declared as 'multiple'
644-
if job_definition.variables.inputs.properties[variable].multiple:
645-
job_variables[variable] = []
646-
for value in job_definition.tests[job_test_name].inputs[variable]:
647-
job_variables[variable].append(os.path.basename(value))
648-
input_files.append(value)
649-
else:
659+
# Variable has no corresponding input file if it's type is'molecules'
660+
# and the value looks like a molecule.
661+
if (
662+
job_definition.variables.inputs.properties[variable].type
663+
== "molecules"
664+
):
650665
value = job_definition.tests[job_test_name].inputs[variable]
651-
job_variables[variable] = os.path.basename(value)
652-
input_files.append(value)
666+
job_variables[variable] = value
667+
prefix = _get_test_input_url_prefix(value)
668+
if prefix:
669+
# There's a prefix so it's a file (not a molecule string)
670+
# The input file for "file://one.sdf" is the basename "one.sdf"
671+
input_files.append(value[len(prefix) :])
672+
else:
673+
# It is an input (not an option).
674+
# The input is a list if it's declared as 'multiple'.
675+
if job_definition.variables.inputs.properties[variable].multiple:
676+
job_variables[variable] = []
677+
for value in job_definition.tests[job_test_name].inputs[
678+
variable
679+
]:
680+
job_variables[variable].append(os.path.basename(value))
681+
input_files.append(value)
682+
else:
683+
value = job_definition.tests[job_test_name].inputs[variable]
684+
job_variables[variable] = os.path.basename(value)
685+
input_files.append(value)
653686

654687
decoded_command: str = ""
655688
test_environment: Dict[str, str] = {}

0 commit comments

Comments
 (0)