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.

Author l
Recipients eric.araujo, l, tarek
Date 2013-09-08.13:36:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378647391.64.0.940770484425.issue18970@psf.upfronthosting.co.za>
In-reply-to
Content
The principle of least surprise suggests that run_setup() should behave equivalently to a command line invocation of setup.py. However there are currently (at least) two issues preventing this:


(a) When calling exec(), both a globals and a locals dict is passed.

According to the documentation: "If exec gets two separate objects as globals and locals, the code will be executed as if it were embedded in a class definition." [1] Consequence: "The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods". [2]

One example where this is relevant is the "MarkupSafe" PyPI package [3]: Its setup.py defines a class BuildFailed which is used in other methods defined in setup.py. Calling run_setup() with this setup.py will therefore fail. Calling setup.py from the command line works.

Solution: Only pass a globals dict to exec().


(b) The globals dict does not contain '__name__':'__main__'.

Many setup.py scripts use the idiomatic 'conditional script' stanza "if __name__ == '__main__'". An example is the "PyYAML" PyPI package. [4] In these cases, run_setup() will raise a RuntimeError exception ("'distutils.core.setup()' was never called").

Solution: Add '__name__':'__main__' to the globals dict.


Attached are patches to fix these issues in Python 2.6 to 3.4.


[1] http://docs.python.org/3/library/functions.html#exec
[2] http://docs.python.org/reference/executionmodel.html#naming-and-binding
[3] https://pypi.python.org/pypi/MarkupSafe
[4] https://pypi.python.org/pypi/PyYAML
History
Date User Action Args
2013-09-08 13:36:31lsetrecipients: + l, tarek, eric.araujo
2013-09-08 13:36:31lsetmessageid: <1378647391.64.0.940770484425.issue18970@psf.upfronthosting.co.za>
2013-09-08 13:36:31llinkissue18970 messages
2013-09-08 13:36:31lcreate