Ask Your Question
0

How to execute python scripts in their source folder when using colcon?

asked 2020-02-19 06:59:51 -0500

martinakos gravatar image

updated 2020-02-25 04:22:45 -0500

I've just started using colcon to build a bunch of ROS packages, mixed python/C++.

colcon moves the built packages to the install folder, including the python files. After sourcing install/setup.bash I can roslaunch my python nodes. However, the python files being executed are the ones copied to the install folder, so if I want to attach a debbuger to the running python code I have to do it with the files copied to the install folder. This is a big problem for me, because I'm constantly changing the python code while debugging and I want to do that in the source folder, not in the install folder.

I have tried to use colcon build with --symlink-install but it still copies the python files.

Is there any way to execute the python files in the source folder?

UPDATE:

I haven't got to work --symlink-install as I would expect yet. So I'll give a bit more of detail on what I've tried so far:

first: I use Ubuntu 18.04 with ROS Melodic. the colcon version is:

colcon version-check
colcon-argcomplete 0.3.3: up-to-date
colcon-bash 0.4.2: up-to-date
colcon-cd 0.1.1: up-to-date
colcon-cmake 0.2.18: up-to-date
colcon-core 0.5.3: up-to-date
colcon-defaults 0.2.3: up-to-date
colcon-devtools 0.2.2: up-to-date
colcon-library-path 0.2.1: up-to-date
colcon-metadata 0.2.3: up-to-date
colcon-notification 0.2.12: up-to-date
colcon-output 0.2.7: up-to-date
colcon-package-information 0.3.1: up-to-date
colcon-package-selection 0.2.5: up-to-date
colcon-parallel-executor 0.2.4: up-to-date
colcon-pkg-config 0.1.0: up-to-date
colcon-powershell 0.3.6: up-to-date
colcon-python-setup-py 0.2.3: up-to-date
colcon-recursive-crawl 0.2.1: up-to-date
colcon-ros 0.3.15: up-to-date
colcon-test-result 0.3.8: up-to-date
colcon-zsh 0.4.0: up-to-date

As my python node is very short I initially tried to install it as a script: My directory structure is:

workspace
    src
        gazebo_utils
            launch
                node.launch
           meshes
           urdf
           src
                python_node.py
           CMakeList.txt
           package.xml

My CMakeLists.txt is:

cmake_minimum_required(VERSION 3.5)
project(gazebo_utils)

find_package(catkin REQUIRED)
catkin_package()
catkin_install_python(PROGRAMS
    src/python_node.py
    DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install( 
    DIRECTORY launch urdf meshes 
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

The package.xml is minimal with only catkin as buildtool_depend

I build with: colcon build --symlink-install --packages-select gazebo_utils

I source . install/setup.bash and I can roslaunch gazebo_utils node.launch successfully and the node works. However, what has been installed and is executed is:

workspace
   install
       gazebo_utils
          lib
             gazebo_utils
                python_node.py  (this is a copy not a symlink)

and my python code is a copy no a symlink.

Then I tried to put the code into a python package: I use this directory structure:

workspace
    src
        gazebo_utils
            launch
                node.launch
           meshes
           urdf
           src
                gazebo_utils
                    __init__.py
                    python_node.py
           CMakeList.txt
           package.xml   
           setup.py

__init__.py is empty

The CMakeLists.txt now is:

cmake_minimum_required(VERSION 3.5)
project(gazebo_utils)

find_package(catkin REQUIRED)
catkin_package()
catkin_python_setup()

install( 
    DIRECTORY launch urdf meshes 
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

and setup.py is:

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values ...
(more)
edit retag flag offensive close merge delete

Comments

I have tried to use colcon build with --symlink-install but it still copies the python files.

I don't think that is the case. In the build directory the Python sources are symlinked and in the install directory only an .egg-link file is created which references the symlinks in the build directory. You might want to make sure that you are using the latest state of the tools, retry with a clean workspace, and if the problem persists share exact steps to reproduce your problem.

Dirk Thomas gravatar image Dirk Thomas  ( 2020-02-19 11:23:36 -0500 )edit

I see there are some symlinks in the build folder but not for my python file. In the CMakeLists for the ros package I use catkin_install_python() with my python file (just one file for the moment) and that file has been copied (not symlinked) both to install and build folders. If the file had been symlinked to the build folder how would I launch that ros node? what setup.bash should I source?

martinakos gravatar image martinakos  ( 2020-02-20 06:53:31 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-02-25 10:31:02 -0500

Dirk Thomas gravatar image

ROS 1 / catkin doesn't offer a symlink install option. So passing --symlink-install to colcon won't do anything special for catkin packages.

This option only has an effect on ROS 2 packages.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-02-19 06:59:51 -0500

Seen: 27 times

Last updated: Feb 25