This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: run_setup is broken in distutils
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, dstufft, eric.araujo, python-dev, rbcollins
Priority: normal Keywords: patch

Created on 2015-02-09 21:06 by belopolsky, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit belopolsky, 2015-02-09 21:08 belopolsky, 2015-02-09 21:12
issue23426.patch belopolsky, 2015-02-09 21:14 review
issue23426-with-tests.patch belopolsky, 2015-02-10 00:16 review
Messages (5)
msg235632 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2015-02-09 21:06
With the following simple

$ cat
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('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Lib/distutils/", line 216, in run_setup
    exec(, g, l)
  File "<string>", line 4, in <module>
  File "<string>", line 5, in install1
NameError: name 'install' is not defined

Furthermore, on an even simpler

$ cat
from distutils.core import setup


run_setup runs, but clobbers sys.argv:

>>> from distutils.core import run_setup
>>> run_setup('', script_args=['--name'])
<distutils.dist.Distribution object at 0x101dddef0>
>>> import sys;sys.argv
['', '--name']
msg235634 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2015-02-09 21:14
Attached patch fixes both issues.
msg235650 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2015-02-10 00:16
Added tests.
msg247499 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-28 03:45
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.
msg247500 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-28 03:55
New changeset d8950778e3c2 by Robert Collins in branch 'default':
Issue #23426: run_setup was broken in distutils.
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67614
2015-07-28 04:00:48rbcollinssetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2015-07-28 03:55:19python-devsetnosy: + python-dev
messages: + msg247500
2015-07-28 03:45:19rbcollinssetnosy: + rbcollins
messages: + msg247499
2015-02-10 00:17:30belopolskysetstage: test needed -> commit review
2015-02-10 00:16:33belopolskysetfiles: + issue23426-with-tests.patch

messages: + msg235650
stage: test needed
2015-02-09 21:14:23belopolskysetmessages: + msg235634
2015-02-09 21:14:04belopolskysetfiles: + issue23426.patch
keywords: + patch
2015-02-09 21:12:26belopolskysetfiles: -
2015-02-09 21:12:04belopolskysetfiles: +
2015-02-09 21:08:04belopolskysetfiles: +
2015-02-09 21:07:54belopolskysetfiles: +
2015-02-09 21:06:45belopolskycreate