You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python setup.py entry_points三重单引号语法及CKAN CLI升级问题

问题解答

1. entry_points字符串写法规则说明

  • 你的猜测不正确:三重单引号包裹的是INI风格的entry_points声明字符串,是setuptools早期版本就支持的合法写法,和字典格式完全等价,不存在特殊语法规则。
  • 方括号包裹的内容不是dependency extra,是entry point分组名,和字典写法里的一级键作用完全一致:
    • 比如字符串写法里的[ckan.plugins],对应字典写法里key为ckan.plugins的条目
    • 每个分组下的xxx=xxx:xxx行,对应字典写法里该key对应列表中的单个条目

该写法属于setuptools遗留兼容写法,功能上和字典、setup.cfg中声明的entry_points完全一致,仅格式不同。

2. 适配新版CKAN Click CLI的修改方案

新版CKAN弃用paster后,自定义CLI命令对应的entry point分组名改为ckan.click_command,你可以根据使用习惯选择保留字符串写法或切换为字典写法:

方案1:保留现有字符串写法

直接替换原来的[paste.paster_command]分组即可,修改后配置如下:

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

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

        [ckan.click_command]
        template=ckanext.template.commands.custom_commands:cli
    ''',
    #...,
)

注意:需要把原来CustomCommand类实现的paster命令,改成用Click装饰器定义的cli可调用对象。

方案2:切换为官方推荐的字典写法

如果希望和当前主流写法对齐,可以直接改成字典格式:

setup(
    #...,
    entry_points={
        'ckan.plugins': [
            'template=ckanext.template.plugin:TemplatePlugin',
        ],
        'babel.extractors': [
            'ckan = ckan.lib.extract:extract_ckan',
        ],
        'ckan.click_command': [
            'template=ckanext.template.commands.custom_commands:cli',
        ]
    },
    #...,
)

内容的提问来源于stack exchange,提问作者GG2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 01:45:04