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

Revision history [back]

click to hide/show revision 1
initial version

You can tell the setup.py to install individual modules rather than packages:

http://docs.python.org/2/distutils/setupscript.html#listing-individual-modules

A setup.py for your example might look like this:

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

d = generate_distutils_setup(
    py_modules=['camera_info_manager'],
    package_dir={'': 'src'}
)

setup(**d)

When I was testing this I noticed that catkin warns:

*** Arguments ['py_modules'] to setup() not supported in catkin devel space in setup.py of camera_info_manager_py

This indicates to me that we never implemented support for this argument in devel spaces. We should support this, so I opened a ticket:

https://github.com/ros/catkin/issues/399

For now that means that if you want your package to work in the devel space then you should wrap it in a python package, and you can transparently do this using the package __all__ magic variable.

http://docs.python.org/2/tutorial/modules.html#importing-from-a-package

You can tell the setup.py to install individual modules rather than packages:

http://docs.python.org/2/distutils/setupscript.html#listing-individual-modules

A setup.py for your example might look like this:

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

d = generate_distutils_setup(
    py_modules=['camera_info_manager'],
    package_dir={'': 'src'}
)

setup(**d)

When I was testing this I noticed that catkin warns:

*** Arguments ['py_modules'] to setup() not supported in catkin devel space in setup.py of camera_info_manager_py

This indicates to me that we never implemented support for this argument in devel spaces. We should support this, so I opened a ticket:

https://github.com/ros/catkin/issues/399

For now that means that if you want your package to work in the devel space then you should wrap it in a python package, and you can transparently do this using the package __all__ magic variable.

http://docs.python.org/2/tutorial/modules.html#importing-from-a-package

UPDATE:

Your current layout is:

src/
  camera_info_manager.py

And your setup.py might be:

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

d = generate_distutils_setup(
    py_modules=['camera_info_manager'],
    package_dir={'': 'src'}
)

setup(**d)

I would propose that you change your layout to this:

src/
  camera_info_manager/
    __init__.py
    camera_info_manager.py

And in the __init__.py:

from .camera_info_manager import CameraInfoManager, etc...
__all__ = ['CameraInfoManager', 'free_func1', 'another_class']

Users will still be able to do this:

import camera_info_manager
cinfo = camera_info_manager.CameraInfoManager()

Or

from camera_info_manager import *
cinfo = CameraInfoManager()

But they will also be able to do this:

from camera_info_manager.camera_info_manager import CameraInfoManager
cinfo = CameraInfoManager()

And your setup.py:

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

d = generate_distutils_setup(
    packages=['camera_info_manager'],
    package_dir={'': 'src'}
)

setup(**d)