Skip to content

Commit 66590ca

Browse files
author
Alan Christie
committed
feat: Add get splitter and combiner variables
1 parent 51816a2 commit 66590ca

File tree

3 files changed

+130
-24
lines changed

3 files changed

+130
-24
lines changed

decoder/decoder.py

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_job_doc_url(
222222
# https://raw.githubusercontent.com/InformaticsMatters/
223223
# virtual-screening/main/data-manager/docs
224224

225-
doc_url: Optional[str] = job_definition.get("doc-url", None)
225+
doc_url: Optional[str] = job_definition.get("doc-url")
226226

227227
# If doc-url starts 'https://' just return it
228228
if doc_url and doc_url.startswith("https://"):
@@ -246,9 +246,7 @@ def get_pull_secret_names(job_definition: Dict[str, Any]) -> Set[str]:
246246
"""
247247
names: Set[str] = set()
248248

249-
# Check the environment block...
250-
pull_secret: Optional[str] = job_definition.get("image", {}).get("pull-secret")
251-
if pull_secret:
249+
if pull_secret := job_definition.get("image", {}).get("pull-secret"):
252250
names.add(pull_secret)
253251

254252
return names
@@ -289,15 +287,14 @@ def get_file_assets(job_definition: Dict[str, Any]) -> List[Dict[str, str]]:
289287

290288
# Iterate through the file block...
291289
file_block: List[Dict[str, Any]] = job_definition.get("image", {}).get("file", [])
292-
for item in file_block:
293-
if "account-server-asset" in item["content-from"]:
294-
file_assets.append(
295-
{
296-
"asset-name": item["content-from"]["account-server-asset"]["name"],
297-
"image-file": item["name"],
298-
}
299-
)
300-
290+
file_assets.extend(
291+
{
292+
"asset-name": item["content-from"]["account-server-asset"]["name"],
293+
"image-file": item["name"],
294+
}
295+
for item in file_block
296+
if "account-server-asset" in item["content-from"]
297+
)
301298
return file_assets
302299

303300

@@ -315,15 +312,14 @@ def get_environment_assets(job_definition: Dict[str, Any]) -> List[Dict[str, str
315312
environment: List[Dict[str, Any]] = job_definition.get("image", {}).get(
316313
"environment", []
317314
)
318-
for item in environment:
319-
if "account-server-asset" in item["value-from"]:
320-
env_assets.append(
321-
{
322-
"asset-name": item["value-from"]["account-server-asset"]["name"],
323-
"variable": item["name"],
324-
}
325-
)
326-
315+
env_assets.extend(
316+
{
317+
"asset-name": item["value-from"]["account-server-asset"]["name"],
318+
"variable": item["name"],
319+
}
320+
for item in environment
321+
if "account-server-asset" in item["value-from"]
322+
)
327323
return env_assets
328324

329325

@@ -343,12 +339,12 @@ def get_jobs_replaced(job_definition: Dict[str, Any]) -> Optional[List[str]]:
343339
return list(replaced)
344340

345341

346-
def get_outputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
342+
def get_outputs(job_definition: Dict[str, Any]) -> Dict[str, Any]:
347343
"""Given a Job Definition this function returns the outputs declared."""
348344
return job_definition.get("variables", {}).get("outputs", {}).get("properties", {})
349345

350346

351-
def get_inputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
347+
def get_inputs(job_definition: Dict[str, Any]) -> Dict[str, Any]:
352348
"""Given a Job Definition this function returns the inputs declared."""
353349
return job_definition.get("variables", {}).get("inputs", {}).get("properties", {})
354350

@@ -360,6 +356,30 @@ def get_image(job_definition: Dict[str, Any]) -> Tuple[str, str]:
360356
return image_name, image_tag
361357

362358

359+
def get_combine_variables(job_definition: Dict[str, Any]) -> Set[str]:
360+
"""Returns the names of all (input) variables that are expected to representing
361+
multiple input files - indications that this is a 'combiner' job.
362+
These variables are of type 'files'."""
363+
results: Set[str] = {
364+
variable
365+
for variable, definition in get_inputs(job_definition).items()
366+
if definition["type"] == "files"
367+
}
368+
return results
369+
370+
371+
def get_split_variables(job_definition: Dict[str, Any]) -> Set[str]:
372+
"""Returns the names of all (out) variables that are expected to representing
373+
multiple out files - indications that this is a 'splitter' job.
374+
These variables are of type 'files'."""
375+
results: Set[str] = {
376+
variable
377+
for variable, definition in get_outputs(job_definition).items()
378+
if definition["type"] == "files"
379+
}
380+
return results
381+
382+
363383
def decode(
364384
template_text: str,
365385
variable_map: Optional[Dict[str, str]],
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Tests for the decoder's get_outputs() function.
2+
from typing import Dict
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.unit
7+
8+
from decoder import decoder
9+
10+
11+
def test_get_combine_variables_when_none():
12+
# Arrange
13+
job_definition: Dict = {}
14+
15+
# Act
16+
combines = decoder.get_combine_variables(job_definition)
17+
18+
# Assert
19+
assert combines == set()
20+
21+
22+
def test_get_combine_variables():
23+
# Arrange
24+
job_definition: Dict = {
25+
"variables": {
26+
"inputs": {
27+
"properties": {
28+
"pdbFile": {
29+
"title": "PDB File",
30+
"mime-types": ["chemical/x-pdb"],
31+
"type": "files",
32+
}
33+
}
34+
}
35+
}
36+
}
37+
38+
# Act
39+
combines = decoder.get_combine_variables(job_definition)
40+
41+
# Assert
42+
assert combines
43+
assert "pdbFile" in combines

tests/test_get_split_variables.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Tests for the decoder's get_outputs() function.
2+
from typing import Dict
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.unit
7+
8+
from decoder import decoder
9+
10+
11+
def test_get_split_variables_when_none():
12+
# Arrange
13+
job_definition: Dict = {}
14+
15+
# Act
16+
splits = decoder.get_split_variables(job_definition)
17+
18+
# Assert
19+
assert splits == set()
20+
21+
22+
def test_get_split_variables():
23+
# Arrange
24+
job_definition: Dict = {
25+
"variables": {
26+
"outputs": {
27+
"properties": {
28+
"pdbFile": {
29+
"title": "PDB File",
30+
"mime-types": ["chemical/x-pdb"],
31+
"type": "files",
32+
}
33+
}
34+
}
35+
}
36+
}
37+
38+
# Act
39+
splits = decoder.get_split_variables(job_definition)
40+
41+
# Assert
42+
assert splits
43+
assert "pdbFile" in splits

0 commit comments

Comments
 (0)