classification
Title: run_setup can fail if the setup script uses __file__
Type: crash Stage:
Components: Distutils Versions: Python 2.6
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: fdrake Nosy List: fdrake, tarek
Priority: low Keywords: patch

Created on 2008-03-18 10:24 by tarek, last changed 2009-02-28 18:02 by tarek. This issue is now closed.

Files
File name Uploaded Description Edit
2008-03-28-distutils.core.patch tarek, 2008-03-22 14:59
run_script-restores-cwd.patch fdrake, 2008-04-04 11:43 restore cwd after script
Messages (8)
msg63906 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2008-03-18 10:24
When calling run_setup, the execfile does not set the __file__ global
variable, that is often used in setup.py modules (for instance to load a
text file from the package to be used in the long_description)

This patch adds this global variable so it does not fail. 

No test provided (distutils would need a test_core.py). 

I could work on some tests, but the previous test_* files I have added
are not in yet, so i'd rather wait for that before proposing new tests
modules.
msg64328 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2008-03-22 14:59
new patch that adds __main__ and __file__, and make a chdir, so the
function is called in a realistic way.

this patch also adds test_core.py for this change.
msg64916 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-04-04 05:42
I don't think these are the right thing to do.

1. Your run_setup() changes add a os.chdir(), but then uses the path to
   the script as passed in; this assumes that the provided path is
   absolute, which is not a good assumption.  That is not currently
   required.  The effect is that a path that works currently may not
   work after the change.  A relative path will not be usable to locate
   support files in this case, since it no longer refers to the
   directory is used to.

   Also, the way you restore the current directory doesn't work;
   os.curdir isn't what you think it is.  This isn't covered in the
   test, either.

2. Apparently there are setup.py scripts that test __name__ (this
   surprised me, but Google Code Search says there are many:
   http://www.google.com/codesearch?q=file%3Asetup.py+%22__main__%22).
   This change would affect those that are currently seeing
   "__builtin__" (picked up from the built-in namespace).

Arguably, it's reasonable to expect run_setup() to restore the current
directory if a setup.py script does change it, but it's not clear that
the change in behavior wouldn't cause problems for existing scripts.

I've adjusted the patch so that the __file__ is supported, but the other
behaviors are omitted.  This has been commited in revision 62142 on the
trunk.
msg64917 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-04-04 05:52
Here's a patch that restores the current directory after running the
script.  The distutils-sig should probably determine if that's the right
thing to do.  Includes test.
msg64924 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-04-04 11:34
Of course, my previous commit did what I said it should not in #1 above:
it changed the current directory to the directory in which the setup.py
script lived (which made __file__ wrong).

Fixed in revision 62147, including test that checks that the script is
run in the current directory of the caller.
msg64925 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2008-04-04 11:42
right, I misused os.curdir, I wanted the current working directory.
(getcwd())

Thanks for correcting it and making it a separate patch
msg64927 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-04-04 11:43
Updated patch to add restoring the current directory after running the
setup.py script in run_script.
msg64928 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-04-04 12:34
It's also arguable that not providing __file__ was a bug, in which case
that should be backported to Python 2.5.x.
History
Date User Action Args
2009-02-28 18:02:33tareksetstatus: open -> closed
2008-04-04 12:34:21fdrakesetmessages: + msg64928
2008-04-04 11:44:14fdrakesetfiles: - run_script-restores-cwd.patch
2008-04-04 11:43:24fdrakesetfiles: + run_script-restores-cwd.patch
messages: + msg64927
2008-04-04 11:42:07tareksetmessages: + msg64925
2008-04-04 11:34:38fdrakesetmessages: + msg64924
2008-04-04 05:52:11fdrakesetfiles: + run_script-restores-cwd.patch
messages: + msg64917
2008-04-04 05:42:37fdrakesetpriority: low
assignee: fdrake
messages: + msg64916
nosy: + fdrake
2008-03-22 14:59:31tareksetfiles: - distutils.core.patch
2008-03-22 14:59:24tareksetfiles: + 2008-03-28-distutils.core.patch
messages: + msg64328
2008-03-18 10:24:33tarekcreate