
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
When building a virtual environment, I'd like to be able to store global distutils configuration options which are custom to that environment. However, both setuptools and distutils expect to read / write that file relative to the directory of 'distutils.__file__', which is located in the *source* environment under virtualenv 0.8.4::
$ ~/projects/source/bin/virtualenv /tmp/virtual New python executable in /tmp/virtual/bin/python Installing setuptools.............done. [/tmp] $ cd /tmp/virtual/ [/tmp/virtual] $ bin/python -c "import distutils; print distutils.__file__" /home/tseaver/projects/source/lib/python2.4/distutils/__init__.pyc
The simplest way I can think of to make 'distutils.__file__' local to the virtual environment is to make an empty local 'distutils' package, which pulls in the source version by hacking '__path__'. However, because the virtual environment forces the 'real_prefix' library so high in the path, I also need to hack my own library in higher (in 'sitecustomize.py')::
[/tmp/virtual] $ patch -p1 < ../local_distutils.patch patching file lib/python2.4/distutils/__init__.py patching file lib/python2.4/sitecustomize.py [/tmp/virtual] $ bin/python -c "import distutils; print distutils.__file__" /tmp/virtual/lib/python2.4/distutils/__init__.py [/tmp/virtual]
Probably it would make more sense to fix the path in the SITE_PY inside virtualenv's support-files; virtualenv could then just make the near-empty local 'distutils' package with the correct '__path__'.
I have attached the patch I used to fix up the local environment ('local_distutils.patch' in the example above).
Tres.
- -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com

Tres Seaver wrote:
When building a virtual environment, I'd like to be able to store global distutils configuration options which are custom to that environment. However, both setuptools and distutils expect to read / write that file relative to the directory of 'distutils.__file__', which is located in the *source* environment under virtualenv 0.8.4::
This should be working in virtualenv trunk; I had to switch up the way sys.path was constructed some, because the way it was the system path came before the virtualenv path, so a virtual distutils wouldn't be seen.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Ian Bicking wrote:
Tres Seaver wrote:
When building a virtual environment, I'd like to be able to store global distutils configuration options which are custom to that environment. However, both setuptools and distutils expect to read / write that file relative to the directory of 'distutils.__file__', which is located in the *source* environment under virtualenv 0.8.4::
This should be working in virtualenv trunk; I had to switch up the way sys.path was constructed some, because the way it was the system path came before the virtualenv path, so a virtual distutils wouldn't be seen.
Cool. Where is the trunk SVN, by the way?
Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com

At 12:05 PM 10/9/2007 -0400, Tres Seaver wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Ian Bicking wrote:
Tres Seaver wrote:
When building a virtual environment, I'd like to be able to store global distutils configuration options which are custom to that environment. However, both setuptools and distutils expect to read / write that file relative to the directory of 'distutils.__file__', which is located in the *source* environment under virtualenv 0.8.4::
This should be working in virtualenv trunk; I had to switch up the way sys.path was constructed some, because the way it was the system path came before the virtualenv path, so a virtual distutils wouldn't be seen.
Cool. Where is the trunk SVN, by the way?
By the way, at OSAF we had a similar issue recently with needing a local distutils.cfg; the recipe for creating a simple "virtual distutils" in case anyone needs it is:
distutils.py: __path__ = ['/path/to/the/real/distutils'] # yes, it ends with 'distutils' from distutils.__init__ import __version__, __revision__, __doc__
You can then put a distutils.cfg alongside it, in a directory that's on sys.path *before* the real disutils. (And you'll need, of course, to know where the real distutils is.)

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Phillip J. Eby wrote:
By the way, at OSAF we had a similar issue recently with needing a local distutils.cfg; the recipe for creating a simple "virtual distutils" in case anyone needs it is:
distutils.py: __path__ = ['/path/to/the/real/distutils'] # yes, it ends with 'distutils' from distutils.__init__ import __version__, __revision__, __doc__
You can then put a distutils.cfg alongside it, in a directory that's on sys.path *before* the real disutils. (And you'll need, of course, to know where the real distutils is.)
Cool, thanks. That solution (importing the other names into the virtual module) probably suppresses some weird edge-case bugs I hadn't stumbled over in mine yet.
Ian, I withdraw my "motion" in favor of Phillip's "friendly amendment." ;)
Ters. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com

Tres Seaver wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Ian Bicking wrote:
Tres Seaver wrote:
When building a virtual environment, I'd like to be able to store global distutils configuration options which are custom to that environment. However, both setuptools and distutils expect to read / write that file relative to the directory of 'distutils.__file__', which is located in the *source* environment under virtualenv 0.8.4::
This should be working in virtualenv trunk; I had to switch up the way sys.path was constructed some, because the way it was the system path came before the virtualenv path, so a virtual distutils wouldn't be seen.
Cool. Where is the trunk SVN, by the way?
At http://svn.colorstudy.com/virtualenv/trunk

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Ian Bicking wrote:
Tres Seaver wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Ian Bicking wrote:
Tres Seaver wrote:
When building a virtual environment, I'd like to be able to store global distutils configuration options which are custom to that environment. However, both setuptools and distutils expect to read / write that file relative to the directory of 'distutils.__file__', which is located in the *source* environment under virtualenv 0.8.4::
This should be working in virtualenv trunk; I had to switch up the way sys.path was constructed some, because the way it was the system path came before the virtualenv path, so a virtual distutils wouldn't be seen.
Cool. Where is the trunk SVN, by the way?
Thanks. Here's a small bugfix:
Index: virtualenv.py =================================================================== - --- virtualenv.py (revision 3045) +++ virtualenv.py (working copy) @@ -482,7 +482,7 @@ call_subprocess( ["install_name_tool", "-change", os.path.join(sys.prefix, 'Python'), - - os.path.abspath(os.path.join(frmdir, 'Python')) + os.path.abspath(os.path.join(frmdir, 'Python')), py_executable]) except: logger.fatal(
Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com
participants (3)
-
Ian Bicking
-
Phillip J. Eby
-
Tres Seaver