问题
I am working on a python script to organize a project consisting of several repos. Some of the targets are build using catkin. Since catkin is a python tool, I suspect there has to be a way to call an equivalent to catkin build
from within a python script.
However, I am struggeling to do so. The closest I have come so far is:
from catkin_tools.commands import catkin
catkin.main(["build"])
However, this does not look correct to me, apart from the fact that upon finishing the build process, I end up with:
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/home/user/.local/lib/python3.6/site-packages/trollius/base_events.py", line 395, in __del__
File "/home/user/.local/lib/python3.6/site-packages/trollius/unix_events.py", line 65, in close
File "/home/user/.local/lib/python3.6/site-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object
Is there some pythonic way to build catkin packages from withing a running python programm?
回答1:
Turns out the Exception I saw was due to trollius not properly being supported in python3.6. In the most current version of catkin_tools, trollius is replaced by asyncio. Since this change is not available via pip or apt install, I had to install catkin from source.
Additionally, the way I solved my problem is certainly improveable but works for now.
from catkin_tools.commands import catkin
try:
catkin.main(["build","testtarget","--cmake-args","-DFLAG"])
except SystemExit as ret:
if ret.code == 0:
return True
else:
return False
来源:https://stackoverflow.com/questions/59612739/trigger-catkin-build-process-from-within-python