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

Non URI file scheme equal type name support #688

Merged
merged 22 commits into from
Mar 29, 2022

Conversation

msteinsto
Copy link
Contributor

Closes #685 by allowing the OspModelDescription file to be located in a different directory than the OspSystemStructure file togheter with the model fmu. A new function for parsing a query file parameter is added for non file URI schemes with a fallback of the existing function. Both relative and absolute path is supported. This has previously only been possible for local simulations.

Copy link
Member

@ljamt ljamt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Have used cosim cli with this PR to verify the intended behavior.

Copy link
Member

@restenb restenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK, tests OK. One suggestion added as comment.

{
const auto query = queryUri.query();
if (query && query->find("file=") < query->size()) {
if (query->find("file=file:///") < query->size()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this effectively tie us down to the "classical" three slashes file URI scheme only? Sounds to me like it is now considered optional, quote from RFC 8089:

"According to the definition in [[RFC1738](https://www.rfc-editor.org/rfc/rfc1738)], a file URL always started
   with the token "file://", followed by an (optionally blank) host name
   and a "/".  The syntax given in [Section 2](https://www.rfc-editor.org/rfc/rfc8089#section-2) makes the entire authority
   component, including the double slashes "//", optional."

https://www.rfc-editor.org/rfc/rfc8089#appendix-A

Should we take into account that the file URI may be of the form file:/ also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think there also have to be made changes to proxy_uri_sub_resolver::lookup_model for consistency. file:/// in the query is used there to distinguish between relative and absolute path. Report as separate issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that then. There are a couple other things I'm skeptical about in the resolvers, like the reliance on substr(specific_number). Should be worth a closer look.

Copy link
Contributor

@davidhjp01 davidhjp01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! just one comment regarding the function computing the parent path

if (query->find("file=file:///") < query->size()) {
return file_uri_to_path(std::string(query->substr(5)));
}
const auto uriToAppend = cosim::path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better for readability if this function just gets the parent of baseUri as the first argument, rather than computing it here. I think the function signature might mislead users that it will use the full baseUri for computing the final path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the reasoning and if this was an isolated case it would make sense to rename it to baseUriParentPath or similar. The reason I am still leaning towards keeping the current code is that baseUri is consistently used in multiple similar functions and I find it strange to have a one-off parameter that is very similar but not quite equal. Further inputs are much appreciated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this would be an improvement to readability and/or usability of the code, then I'd say just do it. No need to rely on adherence to a similar implementation elsewhere (in fact, perhaps that too should be updated).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New commit with baseParentUri instead of baseUri with required updates is added. Parent path uri is found before calling the file_query_uri_to_path function

@kyllingstad
Copy link
Member

kyllingstad commented Mar 21, 2022

Looks good to me too. The only thing I'm wondering is whether file_query_uri_to_path() belongs in uri.hpp. The rest of that header AFAICT is all generic, standard URI-related functionality. The new function seems to be more of an OSP-specific thing which is only used in the OSP config parser. Perhaps it should be moved to osp_config_parser.cpp as an internal implementation detail?

@msteinsto
Copy link
Contributor Author

Looks good to me too. The only thing I'm wondering is whether file_query_uri_to_path() belongs in uri.hpp. The rest of that header AFAICT is all generic, standard URI-related functionality. The new function seems to be more of an OSP-specific thing which is only used in the OSP config parser. Perhaps it should be moved to osp_config_parser.cpp as an internal implementation detail?

Depends if the function is expected to be reused later outside osp_config_parser.cpp. I can currently find one other potential use case in a refactored proxy_uri_sub_resolver::lookup_model. As of now I agree it is more a OSP-specific thing and belongs in osp_config_parser.cpp. Inputs?

@kyllingstad
Copy link
Member

kyllingstad commented Mar 22, 2022

I'd look at it the other way around. If we later find that the function is useful elsewhere, it can easily be moved to the public API then. But once a function is in the public API, it's difficult to change or get rid of, so we shouldn't add it prematurely.

endif()

include("AddTestExecutable")
foreach(test IN LISTS tests)
if (LIBCOSIM_WITH_PROXYFMU)
list(APPEND dependencies "proxyfmu::proxyfmu-client")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line does nothing as dependencies is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in latest commit

@msteinsto msteinsto merged commit 194a5da into master Mar 29, 2022
@msteinsto msteinsto deleted the bug/proxy-fmu-equal-type-name branch March 29, 2022 12:10
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

Successfully merging this pull request may close these issues.

Models with OspModelDescription files and equal model description names cannot be used with fmu-proxy
6 participants