On 28 February 2013 20:53, Daniel Holth <dholth@gmail.com> wrote:
Sorry, I wasn't clear. I know about that, but I don't know how to set up a site directory *before* starting the Python process. Thinking about it, I guess I could do the addsitedir thing and then execfile setup.py. Put all of that into a -c script. That's probably OK, just a bit messy. Particularly as execfile is no longer a builtin.
It is messy but you will probably wind up doing what pip does in several places, for example:
python -c "import setuptools; __file__=%r; exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py
setup_dir, setup = os.path.split(setup_py) args = [self.python, setup, 'install'] for loc in locations: args.append('--install-' + loc + '=' + paths[loc]) if setuptools: script = """\ import sys import site here, setup = sys.argv[1:3] del sys.argv[1:3] site.addsitedir(here, known_paths=None) sys.path.append(here) __file__ = setup if sys.version_info[0] < 3: execfile(setup) else: import tokenize with open(setup, 'rb') as fp: encoding, lines = tokenize.detect_encoding(fp.readline) with open(setup, 'r', encoding=encoding) as fp: exec(compile(fp.read(), setup, 'exec')) """ args[1:1] = ['-c', script, here] args.append('--single-version-externally-managed') args.append('--record=' + os.path.join(paths['prefix'], 'RECORD')) subprocess.check_call(args, cwd=setup_dir)
Why not just reserve a separate virtualenv for building?
Because (a) I want to run this on machines without virtualenv available, and (b) I'd need multiple virtualenvs, for Pythons 2.6, 2.7, 3.2 and 3.3. Bootstrapping issues, basically. Paul