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

Commit

Permalink
back out the system-site-packages special case
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Nov 25, 2014
1 parent e55d234 commit e0e009a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 97 deletions.
18 changes: 6 additions & 12 deletions .travis.yml
Expand Up @@ -15,14 +15,7 @@ matrix:
# pylint has dropped 2.6 support -.-
- python: "2.6"
env: TOXENV=lint
install:
- pip install -r requirements.d/travis.txt
# My tests need some package to be reliably installed to system-site-packages.
# This should maybe be a fixture of some kind,
# but I'd have to build python from source I think =/
- SYS_REAL_PREFIX=$(python -c 'import sys; print(sys.real_prefix)')
- echo $SYS_REAL_PREFIX
- sudo $SYS_REAL_PREFIX/bin/pip install virtualenv
install: pip install -r requirements.d/travis.txt
script: tox
after_success:
- find -name '.coverage*' | xargs mv -t .
Expand All @@ -32,11 +25,12 @@ after_failure:
# attempt to show any pip.log on failure
- find -name pip.log | xargs -r tail -n99999

sudo: true

# public caches only supported under sudo:false currently
# closest thing to documentation:
# http://blog.travis-ci.com/2014-10-07-free-builds-for-students-github-student-developer-pack
sudo: false
cache:
# public caches only supported under sudo:false currently
# closest thing to documentation:
# http://blog.travis-ci.com/2014-10-07-free-builds-for-students-github-student-developer-pack
directories:
- $HOME/.pip
- $HOME/.pre-commit
7 changes: 1 addition & 6 deletions requirements.d/_lint.txt
@@ -1,12 +1,7 @@
# packages needed for linting, but not for prod
flake8
pre-commit

# pylint # PR merged: https://bitbucket.org/logilab/pylint/pull-request/186/fixed_up_import_test-and-tests/diff
# pending fresh release: https://bitbucket.org/logilab/pylint/issue/363/please-cut-a-release-131
# note: pylint is set up such that -e simply doesn't work. Their __init__ is in their top directory.
hg+https://bitbucket.org/logilab/pylint@58c66aa083777059a2e6b46f6a0545a2f4977097#egg=pylint

# astroid 1.3.0 is broken.
# see: https://bitbucket.org/logilab/astroid/issue/55/astroid-130-explodes-on-import-pytest
astroid!=1.3.0
pre-commit
39 changes: 0 additions & 39 deletions tests/functional/relocation_test.py
Expand Up @@ -34,42 +34,3 @@ def test_is_relocatable_different_python_version(tmpdir):
venv_update(python_arg)

run('sh', '-c', '. virtualenv_run/bin/activate && doge --help')


def _get_virtualenv_data(capfd):
out, err = capfd.readouterr() # flush buffers
Path('assertions.py').write('''
import json
import sys, virtualenv
print(json.dumps((virtualenv.__file__, sys.prefix, sys.real_prefix)))
''')
run('virtualenv_run/bin/python', 'assertions.py')

out, err = capfd.readouterr()
assert err == ''

from json import loads
lastline = out.splitlines()[-1]
return loads(lastline)


def path_is_within(path, within):
from os.path import relpath
return not relpath(path, within).startswith('..')


def test_is_relocatable_system_site_packages(tmpdir, capfd):
tmpdir.chdir()
requirements = Path('requirements.txt')

# first show that virtualenv is installed to the system python
# then show that virtualenv is installed to the virtualenv python, when it's required
for reqs, invenv in (
('', False),
('virtualenv\n', True),
):
requirements.write(reqs)
venv_update('--system-site-packages')
virtualenv__file__, prefix, real_prefix = _get_virtualenv_data(capfd)
assert path_is_within(virtualenv__file__, prefix) == invenv
assert path_is_within(virtualenv__file__, real_prefix) == (not invenv)
28 changes: 1 addition & 27 deletions tests/functional/simple_test.py
Expand Up @@ -4,7 +4,7 @@
import pytest

from testing import (
get_scenario, run, strip_coverage_warnings, venv_update, venv_update_script, TOP,
get_scenario, run, strip_coverage_warnings, venv_update, TOP,
)

from sys import version_info
Expand Down Expand Up @@ -242,29 +242,3 @@ def test_uncolored_pipe():
out = pipe_output(read, write)

assert not unprintable(out), out


@pytest.mark.parametrize("options,expected", [
(('--system-site-packages',), True),
((), False),
])
def test_venv_uses_system_site_packages(capfd, tmpdir, options, expected):
tmpdir.chdir()
Path('requirements.txt').write('')

for options, expected in (
(options, expected),
# also show that going back and forth works
((), False),
(('--system-site-packages',), True),
):
venv_update(*options)

out, err = capfd.readouterr() # flush buffers
venv_update_script('''\
from venv_update import venv_uses_system_site_packages
print(venv_uses_system_site_packages())''')

out, err = capfd.readouterr() # flush buffers
assert err == ''
assert out == '%s\n' % expected
13 changes: 0 additions & 13 deletions venv_update.py
Expand Up @@ -255,12 +255,6 @@ def venv(venv_path, venv_args):
)


def venv_uses_system_site_packages():
from glob import glob
from sys import prefix
return not glob(prefix + '/lib/python*/no-global-site-packages.txt')


def do_install(reqs):
from os import environ

Expand Down Expand Up @@ -296,13 +290,6 @@ def do_install(reqs):

# 3) Install: Use our well-populated cache (only) to do the installations.
install_opts += ('--upgrade', '--no-index',)
if venv_uses_system_site_packages():
# In the worst case, a --system-site-packages venv will be missing packages because it was built in an
# environment which satisfied requirements at the system level, then be relocated to a system that doesn't have
# the requirement, breaking it. This has bitten us before. --ignore-installed avoids the issue.
print('Detected --system-site-packages; using --ignore-installed. This makes things slower.')
install_opts += ('--ignore-installed',)

recently_installed = pip_install(install_opts + requirements_as_options)

required_with_deps = trace_requirements(
Expand Down

0 comments on commit e0e009a

Please sign in to comment.