Skip to content

Commit 321c00e

Browse files
Ryan CaliRyan Cali
authored andcommitted
Implemented --version call in PROV as well as tests
1 parent 00c9573 commit 321c00e

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

pydra/engine/audit.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def audit_check(self, flag):
171171

172172
def audit_task(self, task):
173173
import subprocess as sp
174-
175174
label = task.name
176175
if hasattr(task.inputs, "executable"):
177176
command = task.cmdline
@@ -187,13 +186,15 @@ def audit_task(self, task):
187186
software = command.split()[0]
188187
software = software + " " + "--version"
189188
# take the first word of command as the name of the executable (this may not always be the case)
190-
version_cmd = (
191-
sp.run(software, shell=True, check=True, stdout=sp.PIPE)
192-
.stdout.decode("utf-8")
193-
.splitlines()[0]
194-
)
189+
version_cmd = (sp.run(software, shell=True, stdout=sp.PIPE).stdout.decode("utf-8"))
190+
try:
191+
version_cmd = version_cmd.splitlines()[0]
192+
193+
except IndexError:
194+
version_cmd = None
195+
195196
else:
196-
software = None
197+
version_cmd = None
197198

198199
start_message = {
199200
"@id": self.aid,
@@ -202,7 +203,7 @@ def audit_task(self, task):
202203
"Command": command,
203204
"StartedAtTime": now(),
204205
# "Used": input_file,
205-
"AssociatedWith": version_cmd,
206+
"AssociatedWith": version_cmd
206207
}
207208

208209
# new code to be added here for i/o tracking - WIP

pydra/engine/tests/test_task.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,10 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
10031003
for file in glob(str(message_path) + "/*.jsonld"):
10041004
with open(file, "r") as f:
10051005
data = json.load(f)
1006-
if "label" in data:
1006+
print(data)
1007+
if "Label" in data:
10071008
json_content.append(True)
1008-
assert "testfunc" == data["label"]
1009+
assert "testfunc" == data["Label"]
10091010
assert any(json_content)
10101011

10111012

@@ -1031,16 +1032,46 @@ def test_audit_shellcommandtask(tmpdir):
10311032
for file in glob(str(message_path) + "/*.jsonld"):
10321033
with open(file, "r") as f:
10331034
data = json.load(f)
1034-
if "label" in data:
1035+
print(data)
1036+
if "Label" in data:
10351037
label_content.append(True)
1036-
if "command" in data:
1038+
if "Command" in data:
10371039
command_content.append(True)
1038-
assert "ls -l" == data["command"]
1040+
assert "ls -l" == data["Command"]
10391041

10401042
print(command_content)
10411043
assert any(label_content)
10421044

10431045

1046+
1047+
1048+
def test_audit_shellcommandtask_version(tmpdir):
1049+
cmd = "mrcat"
1050+
shelly = ShellCommandTask(
1051+
name="shelly",
1052+
executable=cmd,
1053+
audit_flags=AuditFlag.PROV,
1054+
messengers=FileMessenger(),
1055+
)
1056+
1057+
import subprocess as sp
1058+
import glob
1059+
shelly.cache_dir = tmpdir
1060+
shelly()
1061+
message_path = tmpdir / shelly.checksum / "messages"
1062+
# go through each jsonld file in message_path and check if the label field exists
1063+
version_content = []
1064+
for file in glob.glob(str(message_path) + "/*.jsonld"):
1065+
with open(file, "r") as f:
1066+
data = json.load(f)
1067+
if "AssociatedWith" in data:
1068+
if "== mrcat 3.0.3 ==" in data["AssociatedWith"]:
1069+
version_content.append(True)
1070+
1071+
1072+
assert any(version_content)
1073+
1074+
10441075
def test_audit_prov_messdir_1(tmpdir, use_validator):
10451076
"""customized messenger dir"""
10461077

0 commit comments

Comments
 (0)