Skip to content

Conversation

@c-rizz
Copy link

@c-rizz c-rizz commented Feb 7, 2025

Following the work on using xacro without ROS I implemented a little change to allow using the find directive without ROS dependencies.
This allows to call xacro.process_doc() with a dict that associates package names to package paths. This is then used by the $(find ...) directive. If this argument is not specified all remains as before.
I find this to be quite useful when using multi-file xacro definitions when not using ROS.
I feel it would be a nice addition.

@traversaro
Copy link

A possible alternative would be permit users to specify somehow a function that resolves package references in place of the default implementation, in this way one could either provide an hardcoded mapping (as in this PR) or use some logic to find package paths based on environment variables (as done for example in https://github.com/ami-iit/resolve-robotics-uri-py .

@c-rizz
Copy link
Author

c-rizz commented Feb 8, 2025

I went with this solution as it is the most simple, and when using xacro from python a more complex resolution logic can always be implemented when forming the mapping dict. But yes, also a function could be passed in place of the dict.

@mjcarroll
Copy link
Member

mjcarroll commented Feb 13, 2025

Just a note that with the bazel implementation, I added a --root-dir flag that allows all includes to be resolved relative to that directory.

The way that this works for bazel is that the buildsystem copies (or symlinks) all of the dependencies of the build to a common temp directory, and then sets the --root-dir to that directory.

That was a quick way to get a similar behavior without getting the bazel semantics tied up in the xacro implementation. Could something similar be done here?

@c-rizz
Copy link
Author

c-rizz commented Feb 25, 2025

I believe this here is a bit different, and more flexible. In my case the goal was to be able to use xacro models contained in pure python packages (which were created bit repackaging ROS1 packages). With this I am able to install these packages from pip, find their location with importlib and inform xacro on where to find each package's root folder. Having all of this I can simply xacro-compile models installed from pip without having to rearrange my workspace.
With a flag like --root-dir I would have to copy/symlink all the packages in a common folder, right?

@rhaschke
Copy link
Contributor

Sorry for not responding yet. I agree to @traversaro that defining a resolver function is the most elegant way to handle find directives independently from ROS. @c-rizz, your logic to use importlib to resolve a package location could be ideally realized in such a function.
I'm happy to integrate a corresponding PR. This one, passing an additional dict argument will be rejected.

@c-rizz
Copy link
Author

c-rizz commented Sep 4, 2025

Hello, so you mean it could be done passing an argument to process_doc like in this PR, but passing a resolver function instead of a dict? Do you think it should completely override the current resolve behavior or use the current behavior as a fallback? Because I could just change slightly this PR, replacing the dict with a callable and falling back to the normal behavior if the resolver functions returns None (equivalent to the case of the dict not having the a key for package).
Would this work for you?

@rhaschke
Copy link
Contributor

rhaschke commented Sep 4, 2025

Instead of explicitly passing a function, one should just overwrite a default resolve function.

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