Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on windows usage #49

Open
mustafasoylu opened this issue Nov 28, 2023 · 1 comment
Open

Error on windows usage #49

mustafasoylu opened this issue Nov 28, 2023 · 1 comment

Comments

@mustafasoylu
Copy link

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.

@apirogov
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants