https://python-packaging-zh.readthedocs.io/zh_CN/latest/command-line-scripts.html#scripts
setuptools
可以将命令行工具添加到包中.有两种方法:
1.scripts
参数
把命令工具卸载单独的文件中,一般放在bin目录下
test/
test/
__init__.py
...
setup.py
bin/
test-test
...
在setup.py
中添加
setup(
...
scripts=['bin/test-test'],
...
)
2.console_scripts
console_scripts
是一个’entry points
,允许python
的一个def
注册成命令行工具.
test/
test/
__init__.py
command_line.py
...
setup.py
...
修改command_line.py
模块只提供命令行工具:
import test
def main():
print test.aa()
在setup.py
中注册main()
setup(
...
entry_points = {
'console_scripts': ['test-aa=test.command_line:main'],
}
...
)