python-packaging 命令行脚本

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'],
    }
    ...
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值