Skip to content

Commit 9846d30

Browse files
committed
fix: use URIRef only when available
1 parent bdf294d commit 9846d30

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

nipype/interfaces/base.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ def safe_encode(x):
675675
return pm.Literal("Unknown", pm.XSD['string'])
676676
if isinstance(x, (str, unicode)):
677677
if os.path.exists(x):
678-
return pm.URIRef('file://%s%s' % (getfqdn(), x))
678+
try:
679+
return pm.URIRef('file://%s%s' % (getfqdn(), x))
680+
except AttributeError:
681+
return pm.Literal('file://%s%s' % (getfqdn(), x),
682+
pm.XSD['anyURI'])
679683
else:
680684
return pm.Literal(x, pm.XSD['string'])
681685
if isinstance(x, (int,)):
@@ -1085,8 +1089,7 @@ def write_provenance(self, results, filename='provenance', format='turtle'):
10851089
g.add_namespace(dcterms)
10861090
g.add_namespace(nipype)
10871091

1088-
a0_attrs = {foaf["host"]: pm.URIRef(runtime.hostname),
1089-
nipype['module']: self.__module__,
1092+
a0_attrs = {nipype['module']: self.__module__,
10901093
nipype["interface"]: classname,
10911094
pm.PROV["label"]: classname,
10921095
nipype['duration']: safe_encode(runtime.duration),
@@ -1095,6 +1098,12 @@ def write_provenance(self, results, filename='provenance', format='turtle'):
10951098
nipype['platform']: safe_encode(runtime.platform),
10961099
nipype['version']: safe_encode(runtime.version),
10971100
}
1101+
try:
1102+
a0_attrs[foaf["host"]] = pm.URIRef(runtime.hostname)
1103+
except AttributeError:
1104+
a0_attrs[foaf["host"]] = pm.Literal(runtime.hostname,
1105+
pm.XSD['anyURI'])
1106+
10981107
try:
10991108
a0_attrs.update({nipype['command']: safe_encode(runtime.cmdline)})
11001109
a0_attrs.update({nipype['command_path']: safe_encode(runtime.command_path)})

0 commit comments

Comments
 (0)