如何将 extras_require 放入 setup.cfg

How to put extras_require in setup.cfg

setuptools 30.3.0 引入了声明式包配置,允许我们将大部分用于直接传递给 setuptools.setup 的选项放在 setup.cfg 文件中。例如,给定以下 setup.cfg:

[metadata]
name = hello-world
description = Example of hello world

[options]
zip_safe = False
packages =
  hello_world
install_requires =
  examples
  example1

一个setup.py只包含

import setuptools
setuptools.setup()

会做所有正确的事。

但是,我一直无法找出 extras_require 的正确语法。在setup args中,它是一个字典,比如

setup(extras_require={'test': ['faker', 'pytest']})

但我想不出在 setup.cfg 中使用的正确语法。我尝试阅读文档,但找不到 setuptools 期望的正确语法。我也尝试了一些猜测

[options]
extras_require =
  test=faker,pytest

它失败了。

Traceback (most recent call last):
  File "./setup.py", line 15, in <module>
    'pylint',
  File "/lib/site-packages/setuptools/__init__.py", line 128, in setup
    _install_setup_requires(attrs)
  File "/lib/site-packages/setuptools/__init__.py", line 121, in _install_setup_requires
    dist.parse_config_files(ignore_option_errors=True)
  File "/lib/python3.6/site-packages/setuptools/dist.py", line 495, in parse_config_files
    self._finalize_requires()
  File "/lib/python3.6/site-packages/setuptools/dist.py", line 419, in _finalize_requires
    for extra in self.extras_require.keys():
AttributeError: 'str' object has no attribute 'keys'

阅读代码,我不是 100% 确定这是否受支持,但基于 PEP 508 看来这应该是受支持的用例。我错过了什么?

支持。您需要配置 部分:

[options.extras_require]
test = faker; pytest

语法已记录 here