At 03:00 PM 10/4/2007 -0600, zooko wrote:
On Oct 3, 2007, at 5:20 PM, Phillip J. Eby wrote:
after upgrading setuptools, as long as it wasn't there to start with.
There's something about this that I don't understand. How is deleting the name from sys.modules different from reloading it, which as you already explained  is not going to work?
This won't work for that either, so that's not why I'm suggesting deleting it. The reason I'm suggesting it for this scenario is to ensure that pkg_resources initializes with clean module contents, which won't happen in a reload().
I can think of two approaches that will work for python >= 2.3:
- Import setuptools to get a copy of its __version__ attribute,
It's not necessary to import setuptools. Using pkg_resources.require() is sufficient to do the job, and will get the actual version (including dev-r### tags). The only reason ez_setup uses __version__ is to find a *legacy* setuptools (i.e. version 0.0.1) -- and that is the only thing __version__ should be used for.
import pkg_resources to use its parse_version() function, then del them from sys.modules. (As above, I don't understand how deleting them from sys.modules and then importing them is different from reloading them.)
With regard to whether it's safe to do it, there is no difference. If they were in sys.modules to start with, it's not safe to reload() or delete them. If they *weren't* there, then it's okay to reload() or delete them.
- Use os.system() instead of subprocess() to get the version of the
installed setuptools, include a copy of the parse_version() function from pkg_resources.
It's not necessary to do that, because it doesn't help to have another process. If setuptools or pkg_resources are already in sys.modules when a setup.py runs, it's already too late to upgrade safely.