## page was renamed from UsingPython3/identify_dependencies ## page was renamed from TransitionToPython3/identify_dependencies ## page was renamed from transition_to_python_3/identify_dependencies ## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = Identify dependencies using Python ## multi-line description to be displayed in search ## description = The first step to determining if your packages support Python 3 is to determine which of your dependencies depend on Python. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link=[[UsingPython3/SourceCodeChanges|Source code changes to support Python 3]] ## next.1.link= ## what level user is this tutorial for ## level=IntermediateCategory ## keywords = #################################### <> This tutorial is part of [[UsingPython3|a series about transitioning a ROS 1 package to Python 3]]. <> == Identify dependencies using Python == While you can make changes to your package to support Python 3 at any time, your package's dependencies must already support Python 3 before you can test that your changes work. The first step to determining if your packages support Python 3 is to determine which of your dependencies depend on Python. === Identify rosdep keys and ROS packages === Dependencies will fall into two categories: rosdep keys and ROS packages. You'll need to know which category a dependency belongs to in order to check if it depends on Python. Open your package's '''package.xml''' and look at all the dependencies it lists. For each dependency, you can determine if it is a rosdep key or a ROS package by trying to resolve it using '''rosdep'''. If it is a ROS package, then on your operating system it will resolve to an apt package beginning with '''ros--'''. If it is a rosdep key, it will resolve to something else. Reference: * [[Distributions]] for the available ros distro. * "ROS package" or "rosdep package"? * "ROS package": packages that are enlisted in `%ROS_DISTRO%/distribution.yml` on [[https://github.com/ros/rosdistro|github.com/ros/rosdistro]]. See [[ROS/ReleasingAPackage#Adding_a_package_to_rosdistro]] for how to release into ROS distro. * "rosdep package": packages that are enlisted in `rosdep` folder on the same [[https://github.com/ros/rosdistro|github.com/ros/rosdistro]] repository. Example '''kdl_parser_py''' is a ROS package {{{#!bash $ rosdep resolve --rosdistro=melodic kdl_parser_py #apt ros-melodic-kdl-parser-py }}} '''python-numpy''' is a rosdep key {{{#!bash $ rosdep resolve --rosdistro=melodic python-numpy #apt python-numpy }}} Write down two lists: 1. dependencies that are rosdep keys 1. dependencies that are ROS packages === Identify rosdep keys depending on Python 2 === Now that you have a list of rosdep keys, it is time to determine if they depend on Python 2. There is a tool to do this called [[https://github.com/osrf/py3-ready|py3-ready]]. Install it using the instructions in its README. For each of your rosdep keys, use '''py3-ready check-rosdep ''' to check if it depends on Python 2. {{{#!bash $ py3-ready check-rosdep python-sip rosdep key python-sip depends on python }}} It might be ok that some rosdep keys depend on Python 2. For example, the rosdep key '''boost''' depends on Python 2, but that is only an issue if you are using [[https://www.boost.org/doc/libs/1_70_0/libs/python/doc/html/index.html|Boost Python]] to create a Python 2 module. Make a list of all rosdep keys that depend on Python 2 and install Python modules that your package uses. All other rosdep keys can be ignored. === Identifying ROS packages depending on Python 2 === [[https://github.com/osrf/py3-ready|py3-ready]] can also tell which ROS packages depend on Python 2. However, the important information is whether your package uses any Python modules from it. Check your package's Python code for imports of Python modules with the same name as the ROS package. Your package might be using Python modules from dependencies of your dependencies. You can investigate this by using '''py3-ready check-package --quiet --dot '''. This will output a graph of dependencies leading to Python 2 in dot format. Use a tool like [[http://www.webgraphviz.com/|WebGraphviz]] to visualize it. Make a list of all ROS packages through which your package gets Python 2 modules directly or transitively. == Finding Python 3 versions of dependencies == Your package's dependencies will need to support Python 3 before your package can support it. This means finding replacements for your rosdep keys that support Python 3, and making sure ROS packages you depend on also support it. === Finding Python 3 equivalent rosdep keys === If you depend on rosdep keys which depend on Python 2, your package will need to use a different rosdep key in Noetic. For most cases this means finding an equivalent rosdep key that supports Python 3. For example, an equivalent to [[https://github.com/ros/rosdistro/blob/0ec3b63421edc490199613cb7fae314c0175c707/rosdep/python.yaml#L2466-L2498|python-numpy]] is [[https://github.com/ros/rosdistro/blob/0ec3b63421edc490199613cb7fae314c0175c707/rosdep/python.yaml#L5079-L5085|python3-numpy]]. Rosdep keys tend to match Debian package names. Most of the time this means your current rosdep key begins with '''python-''', and the replacement will begin with '''python3-''', but this is not always the case. If your key starts with '''python-''', then first try finding a key in [[https://github.com/sloretz/rosdistro/blob/master/rosdep/python.yaml|python.yaml]] beginning with '''python3-'''. Otherwise, try finding keys with similar names. If you cannot find an equivalent key, then it likely hasn't been created yet. Create a new key following the instructions at [[https://github.com/ros/rosdistro/blob/master/CONTRIBUTING.md#rosdep-rules-contributions|ros/rosdistro/CONTRIBUTING.md]]. [[https://github.com/ros/rosdistro/pull/21800|Here]] is an example of a pull request adding a Python 3 rosdep key. === Determining if upstream ROS packages support Python 3 === All ROS packages your package depends on will need to support Python 3 before you can test your package. Currently the Noetic build farm is not available, and is not expected to be until Ubuntu releases the first packages for their '''F''' release. In the meantime, a source entry in the [[https://github.com/ros/rosdistro/blob/master/noetic/distribution.yaml|noetic/distribution.yaml]] is the recommended way to signal that a repository has started transitioning to Noetic. It does not mean the packages are 100% working; instead, it means it might be far enough along for your package to begin testing your package with it. All packages planning to release to Noetic should be added to this file, not just the ones using Python. If there is no source entry for that package, then check upstream repository for any open issues about Python 3. If they have started making changes, then consider asking the maintainer to add a source entry for Noetic, or add one yourself. If they have not begun the transition to Python 3, then consider helping by opening issues and pull requests. <> ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE