Skip to content

expose base path of resource#17

Merged
dirk-thomas merged 1 commit intomasterfrom
expose_base_path
Nov 8, 2016
Merged

expose base path of resource#17
dirk-thomas merged 1 commit intomasterfrom
expose_base_path

Conversation

@dirk-thomas
Copy link
Copy Markdown
Contributor

The C++ part can be reviewed and merged.

I would be curious how others would sugggest to update the Python API to provide the same feature.

@dirk-thomas dirk-thomas added the in review Waiting for review (Kanban column) label Nov 7, 2016
@dirk-thomas dirk-thomas self-assigned this Nov 7, 2016
@tfoote
Copy link
Copy Markdown
Member

tfoote commented Nov 7, 2016

+1 the logic looks fine. My first interpretation of base_path from the name was incorrect, but I can't come up with a better suggestion. It's more closely related to something like the install prefix.

@dhood
Copy link
Copy Markdown
Contributor

dhood commented Nov 7, 2016

please don't merge yet

@dhood
Copy link
Copy Markdown
Contributor

dhood commented Nov 8, 2016

thanks for waiting. The logic looks good to me too.

While I was investigating something I added a couple of tests in #18 which check that the expected path is being returned.

On the name, "prefix path" might be clearer than "base path". That's the term used in the environment variable AMENT_PREFIX_PATH and in other documentation.

As for the Python API, maybe add a return_prefix_path=False argument to get_resource that would make it return a tuple when requested?

@dirk-thomas
Copy link
Copy Markdown
Contributor Author

Renamed to prefix_path.

@dirk-thomas
Copy link
Copy Markdown
Contributor Author

Regarding the Python API I am not sure that a different return value structure based on the arguments is a good thing. I would expect that this would break user expectation quite often. But we can make the decision independently of this PR - maybe talk about it in an upcoming meeting.

@tfoote
Copy link
Copy Markdown
Member

tfoote commented Nov 8, 2016

I agree that changing the return type based on the argument would lead to unexpected breakages when refactoring. Thinking about this I think that there's 3 potential queries that one might want. The content, the full path, or the prefix_path. This approach covers 2 of the 3, but actually requires reading in the full content, which might be large, just to return the prefix_path. I think that 3 separate calls might make sense for both languages. Unless we're worried about race conditions there's no need to bundle the queries.

@dhood
Copy link
Copy Markdown
Contributor

dhood commented Nov 8, 2016

Regarding the full path, I get the impression that it's not something the user should be getting access to since it's kind of an implementation detail of the index. Returning the prefix path of a found resource is useful for knowing which prefix the resource came from in the case that there are many prefixes, but I don't think the user is expected to manipulate the resources themselves. I didn't see it explicitly written in the documentation but I think I have gotten this impression from conversations in the past

About having separate vs bundled functions, the python API has has_resource which separately returns the prefix path but not the content (the cmake version is just boolean return). I would still see value in returning the prefix path in addition to the content in get_resource, just for not wasting time finding the same resource twice if you want both the content and the prefix, but there might be other ways around that.

I suppose that depending on how strongly we feel about keeping the functions separate, it may end up affecting this PR. but I agree that once that decision is made about how to approach exposing the functionality (maybe it doesn't have to be the same across the languages), the python implementation details can be discussed independently

@dirk-thomas
Copy link
Copy Markdown
Contributor Author

@tfoote I don't think that splitting these queries into three separate functions is a good idea. The information returned is based on the environment and filesystem. There is no way to ensure atomic operation across those functions therefore the individual results of them might be inconsistent. Therefore I don't think it is a good API design to separate them.

@dirk-thomas
Copy link
Copy Markdown
Contributor Author

dirk-thomas commented Nov 8, 2016

I added C++ has_resource despite the fact that we don't have any use case to check for a resource without getting the content yet.

I also updated Python get_resource to always return a tuple instead of just the content.

Build Status


#include "ament_index_cpp/has_resource.hpp"

#include <cassert>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can this be removed for both files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I removed it from two files as well as sstream from this.

@dirk-thomas
Copy link
Copy Markdown
Contributor Author

I reverted the change to the copyright year since the code was written in 2015 (coming from the other file). So it shouldn't be 2016.

Copy link
Copy Markdown
Contributor

@dhood dhood left a comment

Choose a reason for hiding this comment

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

I'm fixing a typo

@dirk-thomas
Copy link
Copy Markdown
Contributor Author

Should I wait for explicit approvals for the referenced PRs or are they implicitly ok to be merged too?

@dirk-thomas dirk-thomas merged commit b245c3f into master Nov 8, 2016
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Nov 8, 2016
@mikaelarguedas
Copy link
Copy Markdown
Contributor

can this branch be deleted?

@dirk-thomas dirk-thomas deleted the expose_base_path branch February 28, 2017 06:32
@dirk-thomas
Copy link
Copy Markdown
Contributor Author

Absolutely, done.

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.

4 participants