-
Notifications
You must be signed in to change notification settings - Fork 2
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
Enhance and refactor URIs resolving logic #11
Conversation
3ea5b5a
to
8e9ef4e
Compare
Thanks a lot! I am not a big fan of erroring on non-existing |
Mhh, CI was probably disabled, let me enable it. |
There is a CI warning on Linux and macOS
is this expected? Instead, on Windows the test fail. |
if (len(model_filenames) > 1): | ||
warnings.warn(f"resolve-robotics-uri-py: Multiple files ({pathlist_list_to_string(model_filenames)}) found for uri \"{uri}\", returning the first one.") | ||
# Ensure the URI path is absolute | ||
uri_path = uri_path if uri_path.startswith("/") else f"/{uri_path}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is wrong on Windows, and probably the reason why the tests are failing on Windows. Can't we just pass uri_path
to pathlib.Path
? If it is not an absolute path, an error will be raised, as it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, the problem is that you removed the special handling in model_filenames.append(uri.replace("file:/", ""))
for the file:/
. Any specific reason to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider an URI in the form file://absolute/path/to/file.txt
, and the URI without scheme /absolute/path/to/file.txt
. With this PR, URIs without schemes fall back to file://
.
When the scheme is stripped, the path becomes either absolute/path/to/file.tx
or remains /absolute/path/to/file.txt
. At least in Ubuntu, I need to add a trailing /
.
Before this PR, the logic was always removing file:/
(note the missing trailing /
). Leaving an extra /
in case the path was already absolute. I'll make some test in CI on windows to figure out what's wrong there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the scheme is stripped, the path becomes either absolute/path/to/file.tx or remains /absolute/path/to/file.txt. At least in Ubuntu, I need to add a trailing /.
I am a bit confused. If the scheme is file:/
, so if you remove it you remain with /absolute/path/to/file.txt
, in which context you will have absolute/path/to/file.txt
after stripping file:/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never strip file:/
. The new logic always strips file://
and adds a leading /
to the resulting path if it doesn't start already with /
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think that the logic (and the test) were at least incomplete also before. It seems that before it was kind of assuming that file uri in Windows were file:/C:/etc/etc
, but according to https://datatracker.ietf.org/doc/rfc8089/ also file:C:/etc/etc
and file:///C:/etc/etc
are supported, and actually the latter is the one used in https://en.wikipedia.org/wiki/File_URI_scheme . However, for sure it seems that here instead now file://C:/etc/etc
is used/assumed, and that from what I understand is not a failure file:
uri.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, I think we're not yet close to support the full file://
specification. Maybe we can try to be 100% compatible in a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I am not even sure we want to be, whatever subset works fine for the average robotics users for us is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, if I am not wrong in https://github.com/ami-iit/resolve-robotics-uri-py/pull/11/files#diff-1e7414883e02e7f25fddd798742a4cd9cc87486af18923f0efb6940c30f49ebeR95 we are building uris like file://C:/path/to
, that from what I understand are not compatible with the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in https://github.com/ami-iit/resolve-robotics-uri-py/pull/11/files#diff-bde2b03789a37955655850a5b32d09d6775334952d2f4fbfe5510b5e005223ffR135 it seems that we are building file://C:/path/to
URIs.
Is there any reason not to raise any exception in this case? If I ask a library to resolve an URI, and this URI points to a non-existent resource, I'd expect the library to fail rather than returning silently something that is not usable. |
I guess it depends from then context or the users. For example, also in C++ filesystem library there is both |
I resolved the paths before using them. Now CI on windows fails with the following error:
It seems that |
20a8ca9
to
d822042
Compare
Partially fixed by using Regardless to this, now the mismatch is the following:
The resolved path is More details in https://stackoverflow.com/a/59840535. |
I may recall wrong, but that may be the reason why for the file
|
e465122
to
898aeee
Compare
7a16be3
to
96e41c9
Compare
Now it the behavior should be fixed on all platforms. The path to the found resource is not only guaranteed to be existing, it is also guaranteed to be the resolved path. Good to go from my side. |
I added some tests that I guess should fail with the current version of the logic, while worked fine before. |
Ok, I have no idea why the CI is not failing as one command is failing, anyhow you can see from the output that the absolute file is not found:
while it should return |
fd3ca7d
to
1d52fbf
Compare
Now the PR should be ready for review. Relevant changes: |
Also the command check is working fine, it was not working as |
21da473
to
7887966
Compare
7887966
to
e6ef710
Compare
Main changes:
file://
path (that is assumed to be absolute) does not exist.file://
is used by default.After these changes, the resolved URI is ensured to be an existing file. Before, there were cases in which the resolved path was a non-existent file. Now downstream projects that consume the resulting
pathlib.Path
object can prevent to check the existence of the resolved file.Furthermore:
Superseeds #10.