默认 · 10月 12, 2021 0

使用pypi将脚本打包成命令行

内容纲要

核心发布包时候,添加如下

setup.py

setup(
    name=name, #修改包名字-
    version=version,
    description=description,
    author=author,
    author_email=author_email,
    url=url,
    # install_requires=read_requirements('requirements.txt'),  # 指定需要安装的依赖
    long_description=long_description,
    long_description_content_type="text/markdown",
    install_requires=[
        'pytorch-lightning>=1.4.0',
        'tkitAutoTokenizerPosition>=0.0.0.3',
        'pytorch-crf>=0.7.2',
        'transformers>=4.9.2',
        'tkitJson>=0.0.0.3',

    ],
    packages=['tkitTagger'],
    # 这里封装命令行操作
    entry_points = { 
        'console_scripts': ['taggerTrainer=tkitTagger.TaggerTrainer:main'], 
    }
    # scripts=['tkitTagger/TaggerTrainer.py'],
    )

 ```

# 脚本文件
./tkitTagger/TaggerTrainer.py

```python
from pytorch_lightning.utilities.cli import LightningCLI
from tkitTagger.model import autoModel

def main():
    cli = LightningCLI(autoModel,save_config_overwrite=True)

if __name__ == "__main__": 
  main()
%d 博主赞过: