codemetapy
codemetapy copied to clipboard
Error on windows usage
When I use codemetapy on Windows, the below error has occured.
file://C:\Users\MUSTAF~1\AppData\Local\Temp\codemeta.jsonld does not look like a valid URI, trying to serialize this will break.
file://C:\Users\MUSTAF~1\AppData\Local\Temp\schemaorgcontext.jsonld does not look like a valid URI, trying to serialize this will break.
file://C:\Users\MUSTAF~1\AppData\Local\Temp\stype.jsonld does not look like a valid URI, trying to serialize this will break.
file://C:\Users\MUSTAF~1\AppData\Local\Temp\iodata.jsonld does not look like a valid URI, trying to serialize this will break.
file://C:\Users\MUSTAF~1\AppData\Local\Temp\repostatus.jsonld does not look like a valid URI, trying to serialize this will break.
I checked where the error occurs and it looks like when creating file path, you add 'file://' to the string, such as below.
SCHEMA_LOCAL_SOURCE = "file://" + os.path.join(TMPDIR, "schemaorgcontext.jsonld")
CODEMETA_LOCAL_SOURCE = "file://" + os.path.join(TMPDIR, "codemeta.jsonld")
STYPE_LOCAL_SOURCE = "file://" + os.path.join(TMPDIR, "stype.jsonld")
IODATA_LOCAL_SOURCE = "file://" + os.path.join(TMPDIR, "iodata.jsonld")
REPOSTATUS_LOCAL_SOURCE = "file://" + os.path.join(TMPDIR, "repostatus.jsonld")
If you check this issue, I opened in rdflib, you can see rdflib make a string replacement like below.
if absolute_location.startswith("file:///"):
filename = url2pathname(absolute_location.replace("file:///", "/"))
file = open(filename, "rb")
else:
input_source = URLInputSource(absolute_location, format)
Since Windows paths does not start with '/', when you only add 'file://' to the beginning, rdflib cannot read the files and the errors I mentioned occurs.
I would like to add that this is not an rdflib-specific problem, but in fact rdflib is correct in expecting a path starting with file:/// also on Windows, e.g. see here
As on Unix (i.e. linux and mac) absolute paths start with /, prepending file:// yields the desired result. On Windows, one needs to prepend file:/// and replace \ with /, so that the correct path looks like file:///c:/.../....
But this means that codemetapy must be fixed in multiple places (probably it needs a proper cross-platform "to file uri"/"from file uri" utility function), I tried to find a minimal non-invasive fix, but failed (because of many inline uses of replace with file:// in certain methods).