ros2 命令加载过程

ros2 命令

#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'ros2cli==0.13.1','console_scripts','ros2'
import re
import sys

# for compatibility with easy_install; see #2198
__requires__ = 'ros2cli==0.13.1'

try:
    from importlib.metadata import distribution
except ImportError:
    try:
        from importlib_metadata import distribution
    except ImportError:
        from pkg_resources import load_entry_point


def importlib_load_entry_point(spec, group, name):
    dist_name, _, _ = spec.partition('==')
    matches = (
        entry_point
        for entry_point in distribution(dist_name).entry_points
        if entry_point.group == group and entry_point.name == name
    )
    return next(matches).load()


globals().setdefault('load_entry_point', importlib_load_entry_point)

if __name__ == '__main__':
    # sys.argv[0]= ros2当前目录
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    # 其中load_entry_point的用法前提是,ros2cli工具在安装的时候会在*..egg-info文件夹下面的entry_points.txt文件中有相应程序的入口点。
    sys.exit(('ros2cli==0.13.1', 'console_scripts', 'ros2')())

这个是在包的setup.py 里定义的,下面是ros2pkg 的entry_points示例
eg:install/lib/python3.6/site-packages/ros2pkg-0.13.1-py3.6.egg-info/entry_points.txt

[ros2cli.command]
pkg = ros2pkg.command.pkg:PkgCommand

[ros2cli.extension_point]
ros2pkg.verb = ros2pkg.verb:VerbExtension

[ros2pkg.verb]
create = ros2pkg.verb.create:CreateVerb
executables = ros2pkg.verb.executables:ExecutablesVerb
list = ros2pkg.verb.list:ListVerb
prefix = ros2pkg.verb.prefix:PrefixVerb
xml = ros2pkg.verb.xml:XmlVerb

你可能感兴趣的:(ros2,前端,vue.js,linux)