From 6e05a15b8b7432bf4aeaabeff78ce646a035f434 Mon Sep 17 00:00:00 2001 From: Buck Golemon Date: Wed, 19 Nov 2014 10:27:54 -0800 Subject: [PATCH] use relocatable again, add regression test --- .travis/test.sh | 2 +- tests/functional/relocation_test.py | 15 +++++++++++++++ venv_update.py | 13 +++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 tests/functional/relocation_test.py diff --git a/.travis/test.sh b/.travis/test.sh index f6516fa..9d5d0f6 100755 --- a/.travis/test.sh +++ b/.travis/test.sh @@ -13,4 +13,4 @@ py.test -n $NCPU \ --cov --cov-config=$TOP/.coveragerc --cov-report='' \ "$@" $TOP/tests $SITEPACKAGES/${PROJECT}.py coverage combine -coverage report --rcfile=$TOP/.coveragerc --fail-under 95 # FIXME: should be 100 +coverage report --rcfile=$TOP/.coveragerc --fail-under 97 # FIXME: should be 100 diff --git a/tests/functional/relocation_test.py b/tests/functional/relocation_test.py new file mode 100644 index 0000000..76f7d04 --- /dev/null +++ b/tests/functional/relocation_test.py @@ -0,0 +1,15 @@ +from py._path.local import LocalPath as Path + +from testing import get_scenario, run, venv_update + + +def test_is_relocatable(tmpdir): + tmpdir.chdir() + get_scenario('trivial') + venv_update() + + Path('virtualenv_run').rename('relocated') + + pip = 'relocated/bin/pip' + assert Path(pip).exists() + run(pip, '--version') diff --git a/venv_update.py b/venv_update.py index 1dae428..4571af4 100644 --- a/venv_update.py +++ b/venv_update.py @@ -153,6 +153,7 @@ def pip(args): exit(result) +@contextmanager def clean_venv(venv_path, venv_args): """Make a clean virtualenv.""" from os.path import isdir @@ -165,6 +166,11 @@ def clean_venv(venv_path, venv_args): virtualenv = ('virtualenv', venv_path) run(virtualenv + venv_args) + yield + + # Postprocess: Make our venv relocatable, since we do plan to relocate it, sometimes. + run(virtualenv + ('--relocatable',)) + def do_install(reqs): from os import environ @@ -241,11 +247,10 @@ def venv_update(stage, venv_path, reqs, venv_args): from os.path import join, abspath venv_python = abspath(join(venv_path, 'bin', 'python')) if stage == 1: - # we have a random python interpreter active, (possibly) outside the virtualenv we want + # we have a random python interpreter active, (possibly) outside the virtualenv we want. # make a fresh venv at the right spot, and use it to perform stage 2 - clean_venv(venv_path, venv_args) - - run((venv_python, dotpy(__file__), '--stage2', venv_path) + reqs + venv_args) + with clean_venv(venv_path, venv_args): + run((venv_python, dotpy(__file__), '--stage2', venv_path) + reqs + venv_args) elif stage == 2: import sys assert sys.executable == venv_python, "Executable not in venv: %s != %s" % (sys.executable, venv_python)