Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cmdclass in setup.cfg #2570

Closed
makeroo opened this issue Feb 17, 2021 · 0 comments · Fixed by #2571
Closed

Support cmdclass in setup.cfg #2570

makeroo opened this issue Feb 17, 2021 · 0 comments · Fixed by #2571

Comments

@makeroo
Copy link

makeroo commented Feb 17, 2021

Having cmdclass defined in setup.cfg causes sdist, or any other, command to fail because its value is not properly parsed into a dict.

How to replicate

setup.cfg example:

[metadata]
name = cmdclass example

[options]
packages = find:
cmdclass =
    sdist = build.CustomSdistCommand

setup.py:

import setuptools
setuptools.setup()

build.py

from setuptools.command.sdist import sdist

class CustomSdistCommand (sdist):
    def run(self):
        print('custom steps...')
        super(sdist, self).run()

error:

❯ python setup.py sdist
Traceback (most recent call last):
  File ".../setup.py", line 5, in <module>
    setuptools.setup()
  File ".../.venv/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File ".../lib/python3.9/distutils/core.py", line 134, in setup
    ok = dist.parse_command_line()
  File ".../lib/python3.9/distutils/dist.py", line 483, in parse_command_line
    args = self._parse_command_opts(parser, args)
  File ".../.venv/lib/python3.9/site-packages/setuptools/dist.py", line 916, in _parse_command_opts
    nargs = _Distribution._parse_command_opts(self, parser, args)
  File ".../lib/python3.9/distutils/dist.py", line 539, in _parse_command_opts
    cmd_class = self.get_command_class(command)
  File ".../.venv/lib/python3.9/site-packages/setuptools/dist.py", line 750, in get_command_class
    return self.cmdclass[command]
TypeError: string indices must be integers

It happens because self.cmdclass evaluates to the string "sdist = build.CustomSdistCommand" but it should be { "sdist": <class 'build.CustomSdistCommand'> }

Environment details:

❯ python
Python 3.9.0 (v3.9.0:9cf6752276, Oct  5 2020, 11:29:23) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

PIP: 21.0.1
setuptools: 53.0.0

Possible solutions:
either change setup.cfg structure introducing options.cmdclass section or fix setuptools/dist.py Distribution._parse_config_files method so that it parses cmdclass value.

Full minimal example:
example.zip

makeroo pushed a commit to makeroo/setuptools that referenced this issue Feb 18, 2021
jaraco added a commit that referenced this issue Feb 26, 2021
Correctly parse cmdclass in setup.cfg. Fixes #2570
This was referenced Mar 8, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant