如何使python-ros2软件包含糊以隐藏源代码?

发布于 2025-01-27 05:35:07 字数 100 浏览 4 评论 0原文

我有一个ROS2-Python(RCLPY)包,其中有多个子弹可以一起使用。我想使软件包含糊不清,以隐藏源代码,然后将可执行文件留下来完成工作。有什么想法如何使用软件包和启动文件的设置。

I have a ROS2-python (rclpy) package with multiple subpackages that work together. I would like to cythonize the package in order to hide the source code and just leave the executables to do the job. Any idea how could I do that with the setup.py of the package and the launch files ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一紙繁鸢 2025-02-03 05:35:07

因此,如果有人面对同样的问题,我会回答自己的问题。为了使您的ROS2软件包用Python搅拌,最好的方法是将所需的Cython组件分别添加到每个软件包的 setup.py 中。我已经标记了Cython Parts(带有< - ),以进行更好的施工。

请注意,使用COLCON构建包装后,Python源代码的副本将存储在Colcon生成的安装目录下。您可以轻松地手动删除它们,并且该软件包应使用生成的C和共享对象文件运行。

from glob import glob
from setuptools import setup
from Cython.Build import cythonize <--
import os

package_name = 'your_package_name_here'

files = package_name + "/*.py"

setup(
    ext_modules=cythonize(files,compiler_directives={'language_level' : "3"},force=True,quiet=True), <--
    name=package_name,
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name), glob('launch/*.launch.py'))
    ],
    install_requires=['setuptools', "wheel",  "Cython"], <--
    zip_safe=True,
    maintainer='NAME',
    maintainer_email='EMAIL',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'SOME CODE HERE',
        ],
    },
)

So I would answer my own question in case someone faced the same issue. For cythonizing your ros2 package in python the best way is adding the required cython components to the setup.py of each package separately. I have marked the cython parts (with <--) for a better understranding.

Please note that after building the package using colcon, a copy of the python source codes would be stored under the install directory produced by colcon. You can easily delete them manually and the package should run with the generated c and shared object files.

from glob import glob
from setuptools import setup
from Cython.Build import cythonize <--
import os

package_name = 'your_package_name_here'

files = package_name + "/*.py"

setup(
    ext_modules=cythonize(files,compiler_directives={'language_level' : "3"},force=True,quiet=True), <--
    name=package_name,
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name), glob('launch/*.launch.py'))
    ],
    install_requires=['setuptools', "wheel",  "Cython"], <--
    zip_safe=True,
    maintainer='NAME',
    maintainer_email='EMAIL',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'SOME CODE HERE',
        ],
    },
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文