Issue 23426: run_setup is broken in distutils (original) (raw)
With the following simple setup.py
$ cat setup.py from distutils.core import setup from distutils.command.install import install
class install1(install): sub_commands = install.sub_commamnds
setup(name='bug', cmdclass={'install': install1})
I get
from distutils.core import run_setup run_setup('setup.py') Traceback (most recent call last): File "", line 1, in File "Lib/distutils/core.py", line 216, in run_setup exec(f.read(), g, l) File "", line 4, in File "", line 5, in install1 NameError: name 'install' is not defined
Furthermore, on an even simpler setup.py:
$ cat setup1.py from distutils.core import setup
setup(name='bug')
run_setup runs, but clobbers sys.argv:
from distutils.core import run_setup run_setup('setup1.py', script_args=['--name']) bug <distutils.dist.Distribution object at 0x101dddef0> import sys;sys.argv ['setup1.py', '--name']
The change in exec doesn't make sense to me (but see lower :))
file should be in globals, not locals, right?
Also if it is right, then exec(foo, g) should be equivalent :)
The reset of the patch looks ok. But I can see your patch shows this breaking - I'm guessing its one of the things I keep forgetting about module scope evaluation and the import system - anyhoo.
Applying to 3.6.
Also looking at it the saving of argv is still broken even with your patch - the original argv is mutated, and the /name/ not the /value/ is restored. We should rebind argv to the copy, then restore the binding. But that can be done later.