setuptools-py2cfg icon indicating copy to clipboard operation
setuptools-py2cfg copied to clipboard

Exception raised when a command is imported in setup.py

Open pganssle opened this issue 5 years ago • 1 comments

Apparently the mocking logic causes an exception if you try to import commands from setuptools.

If I have a setup.py like this:

from setuptools import setup
from setuptools.command.upload import upload

class Uploader(upload):
    def run(*args, **kwargs):
        raise Exception("Don't use setup.py upload")

setup(
    name="mypkg",
    cmdclass={
        "upload": Uploader,
    },
)

I get the following exception:

  File "path/to/setuptools-py2cfg/setuptools_py2cfg.py", line 60, in main
    setup, setuppy_dir = execsetup(Path(args.setup_py.name).resolve())
  File "path/to/setuptools-py2cfg/setuptools_py2cfg.py", line 51, in execsetup
    exec(setup_py.read_text())
  File "<string>", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1123, in _get_spec
TypeError: 'Mock' object is not iterable

I believe that the problem here is that the problem is because commands try to load some importlib hooks or something, and when you give it a Mock it doesn't work seamlessly.

I think probably restoring the original setuptools.command module is probably the best way to fix this. Of course, getting something meaningful out of this also relies on solving #7, because you cannot translate cmdclass to a declarative equivalent.

I'd say the different levels of support, from easiest to hardest:

  1. Try to detect this exception and throw a more descriptive exception
  2. Support it, ignore the cmdclass parameter to setup, possibly throwing a warning.
  3. Full support with #7.

pganssle avatar Nov 13 '18 17:11 pganssle