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?
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.
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.
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.
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.
It is supported. You need a config section:
[options.extras_require]
test = faker; pytest
Syntax is documented here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With