Installing a build-time generated Python module
Related to my previous question about dynamically generated .msg files, this time I have a dynamically generated Python module. It is the output of lcm-gen
or you could think of it as a module generated by protobuf or whatever else.
I invoke lcm-gen
to create the Python module:
execute_process(
COMMAND lcm-gen --python
--ppath "${GENERATED_LCM_PY_DIR}"
"${LCM_TYPES}"
)
This creates a directory structure inside my build directory somewhere, like:
lcm_py_dir/
generated_moduleA/
...
generated_moduleB/
...
Now I want to set this generated module to be installed into the PYTHONPATH
by Catkin.
I've tried using catkin_python_setup
and providing a setup.py
file that does something like this:
setup_args = generate_distutils_setup(
packages=os.listdir(lcm_py_dir),
package_dir={'':lcm_py_dir}
)
This creates a dummy module generated_moduleA
inside dist-packages/
, but I cannot import the objects I expect to find in it.
I believe there may be a bug because my package_dir
in the Python code is an absolute path, not relative to the source directory. If I patch the dummy generated_moduleA/__init__.py
file's __extended_path
to use the correct path, it does seem to work better.