服务的动态发现
Setuptools的一项功能是可以将脚本安装到系统中作为可执行命令,这就需要通过entry_points属性来进行配置。entry_points属性接受一个字典类型的值,其中使用键console_scripts和gui_scripts来定义命令及其对应的入口函数。例如:
setup(
...
entry_points = {
'console_scripts': [
'foo = demo:test_foo',
'bar = demo:test_bar'
],
'gui_scripts': [
'gui = demo:test_gui'
]
}
)
当这个包在使用EasyInstall或者pip进行安装的时候,就会在系统中生成foo、bar和gui三条可执行命令,分别对应相应包下的指定函数。这些命令一般会存在于系统的PATH环境变量中,可以直接在命令行环境中使用。其中console_scripts用来定义命令行应用的入口命令,gui_scripts用来定义执行图形界面应用的入口命令。