首页 > 解决方案 > 带有三个单引号的 Python setup.py entry_points 语法

问题描述

我正在查看 CKAN 的扩展,它们的 entry_points 条目如下所示:

setup(
    #...,
    entry_points='''
        [ckan.plugins]
        template=ckanext.template.plugin:TemplatePlugin

        [babel.extractors]
        ckan = ckan.lib.extract:extract_ckan

        [paste.paster_command]
        template=ckanext.template.commands.custom_commands:CustomCommand

    ''',
    #...,
)

我正在尝试升级使用 CKAN 的 CLI 的现有扩展。上面的第 3 个条目用于 CLI 命令。我正在尝试将其更新为不再使用 Paster 而是使用 Click 的 CKAN 最新版本。

我试图告诉如何更新[paste.paster_command],但我找不到使用此 entry_points 语法来确定如何更新它的任何其他内容的引用。对于我能找到的对 setup.py 语法的任何引用,它如下所示(在本例中来自 Click 的文档):

setup(
    #...,
    entry_points={
        'console_scripts': [
            'yourscript = yourpackage.scripts.yourscript:cli',
        ],
    },
)

setuptools 文档仅引用与 setup.cfg 相关的 entry_points。因此,他们文档中的 entry_points 示例没有帮助。因此,鉴于我能找到的,我必须假设上面的三引号语法只是常规的 Python 字符串格式,而方括号是“额外的依赖项”。真的?如果不是,它们是什么?对此“替代”字符串语法的任何引用将不胜感激。

标签: pythonsetuptoolsckan

解决方案


根据 Zharktas 在 CKAN 的 GitHub 讨论板上的回复:

语法采用 .ini 样式: https ://setuptools.readthedocs.io/en/latest/pkg_resources.html#creating-and-parsing “如果数据是字符串或行序列,则首先将其拆分为 .ini -style 节(使用 split_sections() 实用程序函数)和节名用作组名。"

使用 IClick 接口实现的 Click 命令不再需要在 entry_points 中输入,因为它们是通过新的 ckan 命令执行的,而不是通过 entry_points 告诉 paster 的 paster。

如果您只想支持 CKAN 2.9,您可以删除整个条目。


推荐阅读