3

The large corporation that I work for uses a custom version of Setuptools. This private fork of setuptools is intended to deal with certain networking and security difficulties that are unique to our organization. The bottom line is that neither the standard Setuptools nor Distribute would work as expected on our environment.

Id like to start using Ian Bicking's excellent VirtualEnv tool on systems, particularly in our test systems where we need to be able to set up a large number of sandboxed areas for test-code - e.g. in our continuous integration environment.

Unfortunately any time I try to build a new virtual environment the virtualenv tool tries to obtain and install the latest official version of Setuptools. This would fail for the reason stated above, and also because the corporate firewall would block the action.

Instead of installing the official version:

setuptools-0.6c11-py2.4.egg

I'd like to install our customized version which might be called something like:

setuptools-foo-0.6c11-py2.4.egg

This egg can always be guaranteed to be found in the system's global site-packages. I can also guarantee that it's present in all of our corporate egg servers.

Can you help me make my virtualenv use my customized setuptools instead of the regular version of setuptools.

Salim Fadhley
  • 22,020
  • 23
  • 75
  • 102

3 Answers3

2

The name is hardcoded in virtualenv.py. You have to either patch virtualenv.py or name your patched setuptools egg 'setuptools-0.6c11-py2.4.egg'

Igor Nazarenko
  • 2,184
  • 13
  • 10
1

I've taken to writing my own wrapper scripts which import virtualenv. The main reason is that I use dpkgs to install most of my dependencies, including distribute, so I like to avoid downloading additional copies when I create a new environment - this has a bonus that it runs much faster.

Here is a baseline wrapper you can use to start with. I've added a comment where you could insert some code to symlink/copy your custom setuptools code into the virtualenv:

import os, subprocess, sys, virtualenv

# virtualenv changed its internal api slightly after 1.5. 
NEW_API = (1, 5)

def get_version(version):
    return tuple([int(v) for v in version.split('.')])

def main():
    # set the logging level here
    level = virtualenv.Logger.level_for_integer(0)
    logger = virtualenv.Logger([(level, sys.stdout)])
    virtualenv.logger = logger

    # insert your command-line parsing code here, if needed
    root = sys.argv[1]

    home, lib, inc, bin = virtualenv.path_locations(root)
    result = virtualenv.install_python(home, lib, inc, bin,
            site_packages=True, clear=False)
    pyexec = os.path.abspath(result)
    version = get_version(virtualenv.virtualenv_version)
    if version < NEW_API:
        virtualenv.install_distutils(lib, home)
    else:
        virtualenv.install_distutils(home)
    virtualenv.install_activate(home, bin)

    # insert whatever post-virtualenv-setup code you need here 

if __name__ == '__main__':
    main()

Usage:

% python wrapper.py [path]
samplebias
  • 37,113
  • 6
  • 107
  • 103
0

There's the option --extra-search-dir that allows to define a local directory containing the desired version of setuptools. This is explained in the docs.

Philipp Zedler
  • 1,660
  • 1
  • 17
  • 36