ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Best practice installing custom dependencies for ROS2?

asked 2021-06-21 07:07:58 -0500

bvaningen gravatar image

Hi! I want to install a python package located on gitlab that I have created myself as a dependency for one of my ros packages. Although I know that pip install can be used, I was wondering what the advised method is for ROS2 packages and its dependencies.

I have found the following link on using custom dependencies using rosdep:
https://answers.ros.org/question/2954...

It appends to the list used by rosdep. I have not been able to find any other example that uses a similar approach.

Is this a valid approach for adding a custom dependency or should I use normal pip install instead? For me using rosdep for installing all dependencies would be useful as only one command is needed.

edit retag flag offensive close merge delete

Comments

If using rosdep, the approach described in the second answer to #q295471 is basically the current best practice afaik.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-22 02:46:24 -0500 )edit

I have got it to work more or less with some addition to #q295471(as can be seen in my answer) only now I am getting a strange error

Installing collected packages: repo
Successfully installed repo-0.1
ERROR: the following rosdeps failed to install
pip: Failed to detect successful installation of [git+https://github.com/user/repo.git@master]

Would this have anything to do with this approach to adding custom dependencies? Normal pip installation does not indicate this error ...

bvaningen gravatar image bvaningen  ( 2021-06-22 11:33:34 -0500 )edit

You might need to tell pip the name of the module that will be installed using the git+https link. You normally do that using something like this:

git+https://github.com/user/repo.git@master#egg=myCustomPkg

rosdep will try to use pip to figure out whether the dependency was installed. If the name of the Python package is different from the key passed to rosdep, it's likely you'll get complaints.

In this case, the key maps to git+https://github.com/user/repo.git@master. I'm not entirely sure how pip would check that was installed. Hopefully the #egg= bit helps.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-22 11:43:52 -0500 )edit

Unfortunately I have been unable to get the #egg= to generate a successful install through rosdep. pip show myCustomPkg does show what I expect

bvaningen gravatar image bvaningen  ( 2021-06-22 12:20:24 -0500 )edit

It looks like this is the code involved in the detection.

Does pip freeze show the name of the package (or: the name of the rosdep key)?

It could be the full URL is considered the name of the package, which will of course never match, as that's not what pip shows.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-22 12:41:58 -0500 )edit

running pip freeze does show the name of the package! Is it worthwhile to make an issue on the rosdep repo?

bvaningen gravatar image bvaningen  ( 2021-06-23 02:43:42 -0500 )edit

You could try to add some print(..)s in the .pys of rosdep on your system. I'd be interested to know whether rosdep is trying to detect whether git+https://github.com/user/repo.git@master#egg=myCustomPkg is installed (as in: that exact same). If that's the case, that would seem to be a likely cause.

On a Debian/Ubuntu install, that should be in /usr/lib/python3/dist-packages/rosdep2/platforms/pip.py. It's not too nice, but for a quick test you could just sudo nano /usr/lib/python3/dist-packages/rosdep2/platforms/pip.py and add print(..)s in pip_detect(..) to see what it's doing.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-23 02:51:05 -0500 )edit

I did as you said and can confirm your hypothesis:

It could be the full URL is considered the name of the package, which will of course never match, as that's not what pip shows.

what i found is that

pkgs =['git+https://github.com/user/repo.git@master#egg=myCustomPkg']

while the pip output shows

'myCustomPkg==0.1'
bvaningen gravatar image bvaningen  ( 2021-06-23 03:42:49 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-22 11:21:57 -0500

bvaningen gravatar image

updated 2021-06-23 03:55:18 -0500

so I think that I have found the way by looking closely at q295471 and deducing some key commands that were missing. I am adding them below for completeness.

1. Created a custom_deps.yaml with the following content:

myCustomPkg:
ubuntu:
    pip:
        packages: ["git+https://github.com/user/repo.git@master"]

2. Create file /etc/ros/rosdep/sources.list.d/19-default.list and append custom_deps.yaml to it
As stated in https://docs.ros.org/en/independent/api/rosdep/html/contributing_rules.html

Create a new file in /etc/ros/rosdep/sources.list.d/ that points at your forked repository instead. The filename should use a lower number so it is processed first.

we can do the same but then for our custom repo, hence:

sudo touch /etc/ros/rosdep/sources.list.d/19-default.list

and then

sudo sh -c 'echo yaml file://$(readlink -f custom_deps.yaml) >> /etc/ros/rosdep/sources.list.d/19-default.list'

3. Update rosdep

rosdep update

If done correctly the following will be seen in the terminal, where you see that the custom_deps.yaml is being used!

Hit file:///home/user/ros2_ws/src/myPackage/custom_deps.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml

Also, running rosdep resolve myCustomPkg gave

#pip
git+https://github.com/user/repo.git@master

4. Add your new custom dependency to the package.xml of the package that depends on it using

```<exec_depend>myCustomPkg</exec_depend>```

5. Install the dependency
Using the command rosdep install --from-paths src/myRosPackage then installs the dependency

edit flag offensive delete link more

Comments

1

Append this file to /etc/ros/rosdep/sources.list.d/20-default.list

adding a new file referencing your custom .yaml would be better I believe, as if 20-default.list ever gets updated, your changes will be overwritten.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-22 11:25:09 -0500 )edit

good point, I will change the answer accordingly!

bvaningen gravatar image bvaningen  ( 2021-06-22 11:43:32 -0500 )edit
1

Note btw: it's unusual for a Python pip dependency to be a depend type dependency (which would be both a build and exec depend). Typical Python packages are exec_depend only.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-23 03:48:53 -0500 )edit

alright, changed my answer to reflect this

bvaningen gravatar image bvaningen  ( 2021-06-23 03:55:56 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-06-21 07:07:58 -0500

Seen: 1,712 times

Last updated: Jun 23 '21