Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
use relocatable again, add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Nov 19, 2014
1 parent aa997b4 commit 6e05a15
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis/test.sh
Expand Up @@ -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
15 changes: 15 additions & 0 deletions 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')
13 changes: 9 additions & 4 deletions venv_update.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e05a15

Please sign in to comment.