jinscoe123
jinscoe123

Reputation: 1739

Python setuptools AttributeError when reading in setup.cfg configuration

I have the following setup.py file:

import setuptools
import setuptools.config

_CONFIG = setuptools.config.read_configuration('setup.cfg')

setuptools.setup(
    **_CONFIG
    )

...and setup.cfg file:

[metadata]
name = Example
version = 1.0.0
author = First Last
author_email = [email protected]
home_page = https://www.github.com/firstlast/example
description = Example is an example project.
long_description = file: README.md
license_file = LICENSE
platform = any
keywords = example
classifiers =
  Programming Language :: Python
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: 3.4
  Programming Language :: Python :: 3.5
  Programming Language :: Python :: 3.6
  Programming Language :: Python :: 3.7
  License :: Other/Proprietary License
  Operating System :: OS Independent

[options]
zip_safe = False
include_package_data = True
python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*
packages =
  example
setup_requires =
  setuptools
install_requires =
  requests

[options.extras_require]
dev =
  ipython


In order to install the module, I'm doing the following:

  1. Create a virtual environment with pipenv.

    $ pipenv --three
    
  2. Activate the virtual environment.

    $ pipenv shell
    
  3. Try to install the example module in the virtual environment.

    $ pip install .
    


When I perform step #3, I get the following error:

Processing /Users/firstlast/Stuff/learn/python/setuptools/example
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/jw/f2zw3cls6xj20dld1h8st4jc0000gp/T/pip-req-build-rcbbm11x/setup.py", line 37, in <module>
        **_CONFIG
      File "/Users/firstlast/.local/share/virtualenvs/example-tYFXe0D0/lib/python3.7/site-packages/setuptools/__init__.py", line 140, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/Users/firstlast/.local/share/virtualenvs/example-tYFXe0D0/lib/python3.7/site-packages/setuptools/dist.py", line 370, in __init__
        k: v for k, v in attrs.items()
      File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 251, in __init__
        for (opt, val) in cmd_options.items():
    AttributeError: 'bool' object has no attribute 'items'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jw/f2zw3cls6xj20dld1h8st4jc0000gp/T/pip-req-build-rcbbm11x/


It seems that setuptools is using the value specified by zip_file as a dictionary, when in reality it is a boolean.


Could someone please explain what I'm doing wrong?



NOTE

The version of Python installed in the virtual environment by pipenv --three is Python 3.7.

I've confirmed that within the virtual environment, setuptools is up-to-date (i.e. pip install --upgrade setuptools => "Requirement already up-to-date: ... (40.4.3)"), as well as pip itself (i.e. pip --version == 18.0).

Upvotes: 3

Views: 2881

Answers (1)

jwodder
jwodder

Reputation: 57470

That's not how setup.cfg is used. read_configuration() is only for use by non-setuptools code that wants to read setup.cfg; there's no need to call it in your own setup.py, because setup() does the reading & processing of setup.cfg itself. Just change your setup.py to:

import setuptools

setuptools.setup()

Upvotes: 6

Related Questions