Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put extras_require in setup.cfg

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?

like image 875
kojiro Avatar asked Apr 13 '18 15:04

kojiro


People also ask

What is setup CFG?

The setup. cfg is an ini file, containing option defaults for setup.py commands. You can pretty much specify every keyword we used in the setup.py file in the new setup. cfg file and simply use the setup.py file as the command line interface.

What is Setup_requires in setup py?

The items listed in setup_requires get implicitly installed whenever you execute the setup.py but one of the common ways that the setup.py is executed is via another tool, such as pip , who is already managing dependencies.

What is a setup CFG file python?

setup. cfg is a cheekily named Python package which supports providing all of a Python distribution's metadata and build configuration via the setup. cfg file at the base of the distribution's source tree, rather than in the setup.py script. The standard setup.py script is reduced to a stub which uses the setup.

How install pip using setup py?

Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


1 Answers

It is supported. You need a config section:

[options.extras_require]
test = faker; pytest

Syntax is documented here.

like image 90
wim Avatar answered Sep 27 '22 23:09

wim