How to put extras_require in setup.cfg
Asked Answered
D

1

26

setuptools 30.3.0 introduced declarative package config, allowing us to put most of the options we used to pass directly to setuptools.setup in setup.cfg files. For example, given following setup.cfg:

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

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

A setup.py containing only

import setuptools
setuptools.setup()

will do all the right things.

However, I haven't been able to figure out the correct syntax for extras_require. In setup args, it is a dictionary, like

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

But I can't figure out the right syntax to use in setup.cfg. I tried reading the docs, but I can't find the correct syntax that setuptools expects for a dictionary there. I tried a few guesses, too

[options]
extras_require =
  test=faker,pytest

it fails.

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'

Reading the code, I'm not 100% sure this is supported, but based on PEP 508 it seems this should be a supported use case. What am I missing?

Djerba answered 13/4, 2018 at 15:18 Comment(0)
C
43

It is supported. You need a config section:

[options.extras_require]
test = faker; pytest

Syntax is documented here.

Cacique answered 13/4, 2018 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.