classification
Title: run_setup is broken in distutils
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.4, Python 3.5, Python 2.7
process
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 2015-07-28 04:00 by rbcollins. This issue is now closed.

Files
File name Uploaded Description Edit
setup1.py belopolsky, 2015-02-09 21:08
setup.py 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 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 "<stdin>", line 1, in <module>
  File "Lib/distutils/core.py", line 216, in run_setup
    exec(f.read(), 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 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']
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.
https://hg.python.org/cpython/rev/d8950778e3c2
History
Date User Action Args
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: - setup.py
2015-02-09 21:12:04belopolskysetfiles: + setup.py
2015-02-09 21:08:04belopolskysetfiles: + setup1.py
2015-02-09 21:07:54belopolskysetfiles: + setup.py
2015-02-09 21:06:45belopolskycreate