def it_installs_stuff(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) assert pip_freeze(str(venv)) == '''\ appdirs==1.4.0 coverage==4.3.4 coverage-enable-subprocess==1.0 packaging==16.8 pip==9.0.1 pyparsing==2.1.10 setuptools==34.1.1 six==1.10.0 wheel==0.29.0 ''' pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) assert [req.split('==')[0] for req in pip_freeze(str(venv)).split()] == [ 'appdirs', 'coverage', 'coverage-enable-subprocess', 'packaging', 'pip', 'pyparsing', 'setuptools', 'six', 'venv-update', 'wheel', ] run(str(venv.join('bin/pip-faster')), 'install', 'pure_python_package') assert 'pure-python-package==0.2.1' in pip_freeze(str(venv)).split('\n')
def test_update_while_active(tmpdir): tmpdir.chdir() enable_coverage() requirements('') venv_update() assert 'project-with-c' not in pip_freeze() # An arbitrary small package: project_with_c requirements('project_with_c') venv_update_symlink_pwd() out, err = run( 'sh', '-c', '. venv/bin/activate && python venv_update.py venv= venv --python=venv/bin/python' ) out = uncolor(out) err = strip_pip_warnings(err) assert err == '' assert out.startswith('''\ > virtualenv venv --python=venv/bin/python Keeping valid virtualenv from previous run. ''') assert 'project-with-c' in pip_freeze()
def test_update_invalidated_while_active(tmpdir): tmpdir.chdir() enable_coverage() requirements('') venv_update() assert 'project-with-c' not in pip_freeze() # An arbitrary small package: project_with_c requirements('project-with-c') venv_update_symlink_pwd() out, err = run( 'sh', '-c', '. venv/bin/activate && python venv_update.py venv= --system-site-packages venv' ) err = strip_pip_warnings(err) assert err == '' out = uncolor(out) assert out.startswith('''\ > virtualenv --system-site-packages venv Removing invalidated virtualenv. (system-site-packages changed, to True) ''') assert 'project-with-c' in pip_freeze()
def time_savings(tmpdir, between): """install twice, and the second one should be faster, due to whl caching""" with tmpdir.as_cwd(): enable_coverage() install_coverage() requirements('\n'.join( ('project_with_c', 'pure_python_package==0.2.0', 'slow_python_package==0.1.0', 'dependant_package', 'many_versions_package>=2,<3', ''))) from time import time start = time() venv_update( PIP_VERBOSE='1', PIP_RETRIES='0', PIP_TIMEOUT='0', ) time1 = time() - start expected = '\n'.join( ('dependant-package==1', 'implicit-dependency==1', 'many-versions-package==2.1', 'project-with-c==0.1.0', 'pure-python-package==0.2.0', 'slow-python-package==0.1.0', 'venv-update==%s' % __version__, 'wheel==0.29.0', '')) assert pip_freeze() == expected between() install_coverage() start = time() # second install should also need no network access # these are localhost addresses with arbitrary invalid ports venv_update( PIP_VERBOSE='1', PIP_RETRIES='0', PIP_TIMEOUT='0', http_proxy='http://127.0.0.1:111111', https_proxy='https://127.0.0.1:222222', ftp_proxy='ftp://127.0.0.1:333333', ) time2 = time() - start assert pip_freeze() == expected print() print('%.3fs originally' % time1) print('%.3fs subsequently' % time2) difference = time1 - time2 print('%.2fs speedup' % difference) ratio = time1 / time2 percent = (ratio - 1) * 100 print('%.2f%% speedup' % percent) return difference
def test_eggless_url(tmpdir): tmpdir.chdir() enable_coverage(tmpdir) assert 'pure-python-package' not in pip_freeze() # An arbitrary url requirement. requirements('-e file://' + str(TOP / 'tests/testing/packages/pure_python_package')) venv_update() assert 'pure-python-package' in pip_freeze()
def it_can_handle_requirements_already_met(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) requirements('many-versions-package==1') run(str(venv.join('bin/pip-faster')), 'install', '-r', 'requirements.txt') assert 'many-versions-package==1\n' in pip_freeze(str(venv)) run(str(venv.join('bin/pip-faster')), 'install', '-r', 'requirements.txt') assert 'many-versions-package==1\n' in pip_freeze(str(venv))
def flake8_newer(): requirements('''\ flake8==2.2.5 # we expect 0.8.1 pyflakes<=0.8.1 # simply to prevent these from drifting: mccabe<=0.3 pep8<=1.5.7 -r %s/requirements.d/coverage.txt ''' % TOP) venv_update() assert pip_freeze() == '\n'.join(( 'coverage==4.0.3', 'coverage-enable-subprocess==0', 'flake8==2.2.5', 'mccabe==0.3', 'pep8==1.5.7', 'pip-faster==' + __version__, 'pyflakes==0.8.1', 'virtualenv==1.11.6', 'wheel==0.29.0', '' ))
def flake8_older(): requirements('''\ flake8==2.0 # last pyflakes release before 0.8 was 0.7.3 pyflakes<0.8 # simply to prevent these from drifting: mccabe<=0.3 pep8<=1.5.7 -r %s/requirements.d/coverage.txt ''' % TOP) venv_update() assert pip_freeze() == '\n'.join(( 'coverage==4.0.3', 'coverage-enable-subprocess==0', 'flake8==2.0', 'mccabe==0.3', 'pep8==1.5.7', 'pip-faster==' + __version__, 'pyflakes==0.7.3', 'virtualenv==1.11.6', 'wheel==0.29.0', '' ))
def test_circular_dependencies(): """pip-faster should be able to install packages with circular dependencies.""" venv = make_venv() out, err = run( venv.join('bin/pip-faster').strpath, 'install', '-vv', # show debug logging 'circular-dep-a', ) err = strip_pip_warnings(err) assert err.strip() == ( 'Circular dependency! circular-dep-a==1.0 ' '(from circular-dep-b==1.0->circular-dep-a)' ) out = uncolor(out) assert ''' tracing: circular-dep-a already queued: circular-dep-b==1.0 (from circular-dep-a) tracing: circular-dep-b==1.0 (from circular-dep-a) ''' in out frozen_requirements = pip_freeze(str(venv)).split('\n') assert 'circular-dep-a==1.0' in frozen_requirements assert 'circular-dep-b==1.0' in frozen_requirements
def test_circular_dependencies(tmpdir): """pip-faster should be able to install packages with circular dependencies.""" tmpdir.chdir() venv = enable_coverage(tmpdir, 'venv') pip = venv.join('bin/pip').strpath run(pip, 'install', 'pip-faster==' + __version__) out, err = run( venv.join('bin/pip-faster').strpath, 'install', '-vv', # show debug logging 'circular-dep-a', ) assert err == '' out = uncolor(out) assert out.endswith(''' tracing: circular-dep-a adding sub-requirement circular-dep-b==1.0 (from circular-dep-a) tracing: circular-dep-b==1.0 (from circular-dep-a) adding sub-requirement circular-dep-a==1.0 (from circular-dep-b==1.0->circular-dep-a) already analyzed: circular-dep-b==1.0 (from circular-dep-a) tracing: circular-dep-a==1.0 (from circular-dep-b==1.0->circular-dep-a) Circular dependency! circular-dep-a==1.0 (from circular-dep-b==1.0->circular-dep-a) ''') frozen_requirements = pip_freeze(str(venv)).split('\n') assert 'circular-dep-a==1.0' in frozen_requirements assert 'circular-dep-b==1.0' in frozen_requirements
def test_override_requirements_file(tmpdir): tmpdir.chdir() enable_coverage() requirements('') Path('.').join('requirements-bootstrap.txt').write('''\ venv-update==%s pure_python_package ''' % __version__) out, err = venv_update( 'bootstrap-deps=', '-r', 'requirements-bootstrap.txt', ) err = strip_pip_warnings(err) # pip>=10 doesn't complain about installing an empty requirements file. assert err == '' out = uncolor(out) # installing venv-update may downgrade / upgrade pip out = re.sub(' pip-[0-9.]+ ', ' ', out) assert '\n> pip install -r requirements-bootstrap.txt\n' in out assert ( '\nSuccessfully installed pure-python-package-0.2.1 venv-update-%s' % __version__ ) in out assert '\n Successfully uninstalled pure-python-package-0.2.1\n' in out expected = '\n'.join(( 'venv-update==' + __version__, '' )) assert pip_freeze() == expected
def venv_setup(): # First just set up a blank virtualenv, this'll bypass the # bootstrap when we're actually testing for speed if not Path('venv').exists(): requirements('') venv_update() install_coverage() # Now the actual requirements we'll install requirements('\n'.join(( 'project_with_c', 'pure_python_package==0.2.1', 'slow_python_package==0.1.0', 'dependant_package', 'many_versions_package>=2,<3', '' ))) yield expected = '\n'.join(( 'dependant-package==1', 'implicit-dependency==1', 'many-versions-package==2.1', 'project-with-c==0.1.0', 'pure-python-package==0.2.1', 'slow-python-package==0.1.0', 'venv-update==%s' % __version__, '' )) assert pip_freeze() == expected
def test_package_name_normalization(tmpdir): with tmpdir.as_cwd(): enable_coverage(tmpdir) requirements('WEIRD_cAsing-packAge') venv_update() assert '\nweird-CASING-pACKage==' in pip_freeze()
def test_circular_dependencies(): """pip-faster should be able to install packages with circular dependencies.""" venv = make_venv() out, err = run( venv.join('bin/pip-faster').strpath, 'install', '-vv', # show debug logging 'circular-dep-a', ) err = strip_pip_warnings(err) assert err == ( 'Circular dependency! circular-dep-a==1.0 ' '(from circular-dep-b==1.0->circular-dep-a)\n' ) out = uncolor(out) assert out.endswith(''' tracing: circular-dep-a already queued: circular-dep-b==1.0 (from circular-dep-a) tracing: circular-dep-b==1.0 (from circular-dep-a) ''') frozen_requirements = pip_freeze(str(venv)).split('\n') assert 'circular-dep-a==1.0' in frozen_requirements assert 'circular-dep-b==1.0' in frozen_requirements
def it_doesnt_wheel_local_dirs(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) run( venv.join('bin/pip-faster').strpath, 'install', TOP.join('tests/testing/packages/dependant_package').strpath, ) frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == set([ 'coverage==4.0.3', 'coverage-enable-subprocess==0', 'dependant-package==1', 'implicit-dependency==1', 'many-versions-package==3', 'pure-python-package==0.2.0', 'venv-update==' + __version__, 'wheel==0.29.0', '', ]) wheelhouse = tmpdir.join('home', '.cache', 'pip-faster', 'wheelhouse') assert set(Wheel(f.basename).name for f in wheelhouse.listdir()) == set([ 'implicit-dependency', 'many-versions-package', 'pure-python-package', ])
def test_cant_wheel_package(tmpdir): with tmpdir.as_cwd(): enable_coverage(tmpdir) requirements('cant-wheel-package\npure-python-package') out, err = venv_update() assert err == '' out = uncolor(out) # for unknown reasons, py27 has an extra line with four spaces in this output, where py26 does not. out = out.replace('\n \n', '\n') assert ''' ---------------------------------------- Failed building wheel for cant-wheel-package Running setup.py bdist_wheel for pure-python-package Destination directory: %s/home/.cache/pip-faster/wheelhouse''' % tmpdir + ''' SLOW!! no wheel found after building (couldn't be wheeled?): cant-wheel-package (from -r requirements.txt (line 1)) Installing collected packages: cant-wheel-package, pure-python-package Running setup.py install for cant-wheel-package Could not find .egg-info directory in install record for cant-wheel-package (from -r requirements.txt (line 1)) Successfully installed cant-wheel-package pure-python-package Cleaning up... > pip uninstall --yes coverage coverage-enable-subprocess ''' in out # noqa assert pip_freeze().startswith('cant-wheel-package==0.1.0\n')
def it_doesnt_wheel_local_dirs(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) run( venv.join('bin/pip-faster').strpath, 'install', TOP.join('tests/testing/packages/dependant_package').strpath, ) frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == { 'coverage==ANY', 'coverage-enable-subprocess==1.0', 'dependant-package==1', 'implicit-dependency==1', 'many-versions-package==3', 'pure-python-package==0.2.1', 'venv-update==' + __version__, '', } assert {wheel.name for wheel in cached_wheels(tmpdir)} == { 'implicit-dependency', 'many-versions-package', 'pure-python-package', }
def it_installs_stuff_with_dash_e_without_wheeling(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) # Install a package from git with no extra dependencies in editable mode. # # We need to install a package from VCS instead of the filesystem because # otherwise we aren't testing that editable requirements aren't wheeled # (and instead might just be testing that local paths aren't wheeled). requirements('-e git+git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb-init') # noqa run(str(venv.join('bin/pip-faster')), 'install', '-r', 'requirements.txt') frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == { '-e git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb_init', # noqa 'coverage-enable-subprocess==1.0', 'coverage==ANY', 'venv-update==' + __version__, '', } # we shouldn't wheel things installed editable assert not tuple(cached_wheels(tmpdir))
def test_override_requirements_file(tmpdir): tmpdir.chdir() enable_coverage() requirements('') Path('.').join('requirements-bootstrap.txt').write('''\ venv-update==%s pure_python_package ''' % __version__) out, err = venv_update( 'bootstrap-deps=', '-r', 'requirements-bootstrap.txt', ) err = strip_pip_warnings(err) assert err == ('You must give at least one requirement to install ' '(see "pip help install")\n') out = uncolor(out) assert '\n> pip install -r requirements-bootstrap.txt\n' in out assert ( '\nSuccessfully installed pure-python-package-0.2.1 venv-update-%s' % __version__) in out assert '\n Successfully uninstalled pure-python-package-0.2.1\n' in out expected = '\n'.join( ('appdirs==1.4.0', 'packaging==16.8', 'pip==9.0.1', 'pyparsing==2.1.10', 'setuptools==34.1.1', 'six==1.10.0', 'venv-update==' + __version__, 'wheel==0.29.0', '')) assert pip_freeze() == expected
def it_installs_stuff_with_dash_e_without_wheeling(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) # Install a package from git with no extra dependencies in editable mode. # # We need to install a package from VCS instead of the filesystem because # otherwise we aren't testing that editable requirements aren't wheeled # (and instead might just be testing that local paths aren't wheeled). requirements( '-e git+git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb-init' ) # noqa run(str(venv.join('bin/pip-faster')), 'install', '-r', 'requirements.txt') frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == { '-e git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb_init', # noqa 'coverage-enable-subprocess==1.0', 'coverage==ANY', 'venv-update==' + __version__, '', } # we shouldn't wheel things installed editable assert not tuple(cached_wheels(tmpdir))
def it_doesnt_wheel_git_repos(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) run( venv.join('bin/pip-faster').strpath, 'install', 'git+git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb-init', # noqa ) frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == set([ 'appdirs==1.4.0', 'coverage-enable-subprocess==1.0', 'coverage==4.3.4', 'dumb-init==0.5.0', 'packaging==16.8', 'pip==9.0.1', 'pyparsing==2.1.10', 'setuptools==34.1.1', 'six==1.10.0', 'venv-update==' + __version__, 'wheel==0.29.0', '', ]) assert not tuple(cached_wheels(tmpdir))
def test_bad_symlink_can_be_fixed(tmpdir): """If the symlink at ~/.config/venv-update/$version/venv-update is wrong, we should be able to fix it and keep going. https://github.com/Yelp/pip-faster/issues/98 """ tmpdir.chdir() scratch_dir = tmpdir.join('home', '.cache').ensure_dir('venv-update').ensure_dir(__version__) symlink = scratch_dir.join('venv-update') # run a trivial venv-update to populate the cache and create a proper symlink assert not symlink.exists() requirements('') venv_update() assert symlink.exists() # break the symlink by hand (in real life, this can happen if mounting # things into Docker containers, for example) symlink.remove() symlink.mksymlinkto('/nonexist') assert not symlink.exists() # a simple venv-update should install packages and fix the symlink enable_coverage(tmpdir) requirements('pure-python-package') venv_update() assert '\npure-python-package==0.2.0\n' in pip_freeze() assert symlink.exists()
def test_bad_symlink_can_be_fixed(tmpdir): """If the symlink at ~/.config/venv-update/$version/venv-update is wrong, we should be able to fix it and keep going. https://github.com/Yelp/pip-faster/issues/98 """ tmpdir.chdir() scratch_dir = tmpdir.join( 'home', '.cache').ensure_dir('venv-update').ensure_dir(__version__) symlink = scratch_dir.join('venv-update') # run a trivial venv-update to populate the cache and create a proper symlink assert not symlink.exists() requirements('') venv_update() assert symlink.exists() # break the symlink by hand (in real life, this can happen if mounting # things into Docker containers, for example) symlink.remove() symlink.mksymlinkto('/nonexist') assert not symlink.exists() # a simple venv-update should install packages and fix the symlink enable_coverage(tmpdir) requirements('pure-python-package') venv_update() assert '\npure-python-package==0.2.0\n' in pip_freeze() assert symlink.exists()
def test_cant_wheel_package(tmpdir): with tmpdir.as_cwd(): enable_coverage() install_coverage() requirements('cant-wheel-package\npure-python-package') out, err = venv_update() err = strip_pip_warnings(err) assert err == '' out = uncolor(out) # for unknown reasons, py27 has an extra line with four spaces in this output, where py26 does not. out = out.replace('\n \n', '\n') assert ''' ---------------------------------------- Failed building wheel for cant-wheel-package Running setup.py bdist_wheel for pure-python-package Destination directory: %s/home/.cache/pip-faster/wheelhouse''' % tmpdir + ''' SLOW!! no wheel found after building (couldn't be wheeled?): cant-wheel-package==0.1.0 Installing collected packages: cant-wheel-package, pure-python-package Running setup.py install for cant-wheel-package Could not find .egg-info directory in install record for cant-wheel-package (from -r requirements.txt (line 1)) Successfully installed cant-wheel-package pure-python-package Cleaning up... ''' in out # noqa assert pip_freeze().startswith('cant-wheel-package==0.1.0\n')
def test_override_requirements_file(tmpdir): tmpdir.chdir() enable_coverage() requirements('') Path('.').ensure_dir('requirements.d').join('venv-update.txt').write('''\ venv-update==%s pure_python_package ''' % __version__) out, err = venv_update() err = strip_pip_warnings(err) assert err == '' out = uncolor(out) assert ( '\n> pip install --find-links=file://%s/home/.cache/pip-faster/wheelhouse -r requirements.d/venv-update.txt\n' % tmpdir ) in out assert ( '\nSuccessfully installed pip-1.5.6 pure-python-package-0.2.0 venv-update-%s' % __version__ ) in out assert '\n Successfully uninstalled pure-python-package\n' in out expected = '\n'.join(( 'venv-update==%s' % __version__, 'wheel==0.29.0', '' )) assert pip_freeze() == expected
def venv_setup(): # First just set up a blank virtualenv, this'll bypass the # bootstrap when we're actually testing for speed if not Path('venv').exists(): requirements('') venv_update() install_coverage() # Now the actual requirements we'll install requirements('\n'.join( ('project_with_c', 'pure_python_package==0.2.1', 'slow_python_package==0.1.0', 'dependant_package', 'many_versions_package>=2,<3', ''))) yield expected = '\n'.join( ('appdirs==1.4.3', 'dependant-package==1', 'implicit-dependency==1', 'many-versions-package==2.1', 'packaging==16.8', 'pip==9.0.1', 'project-with-c==0.1.0', 'pure-python-package==0.2.1', 'pyparsing==2.2.0', 'setuptools==35.0.2', 'six==1.10.0', 'slow-python-package==0.1.0', 'venv-update==%s' % __version__, 'wheel==0.29.0', '')) assert pip_freeze() == expected
def it_can_handle_a_bad_findlink(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) out, err = run( str(venv.join('bin/pip-faster')), 'install', '-vvv', '--find-links', 'git+wat://not/a/thing', 'pure-python-package', ) out = uncolor(out) err = strip_pip_warnings(err) expected = '''\ Successfully built pure-python-package Installing collected packages: pure-python-package ''' assert expected in out # Between this there's: # 'changing mode of .../venv/bin/pure-python-script to 775' # but that depends on umask _, rest = out.split(expected) expected2 = '''\ Successfully installed pure-python-package-0.2.1 Cleaning up... ''' assert expected2 in rest assert "Url 'git+wat://not/a/thing' is ignored." in err assert 'pure-python-package==0.2.1' in pip_freeze(str(venv)).split('\n')
def it_installs_stuff(tmpdir): venv = tmpdir.join('venv') run('virtualenv', str(venv)) assert pip_freeze(str(venv)) == '''\ ''' pip = venv.join('bin/pip').strpath run(pip, 'install', 'pip-faster==' + __version__) assert [req.split('==')[0] for req in pip_freeze(str(venv)).split() ] == ['pip-faster', 'virtualenv', 'wheel'] run(str(venv.join('bin/pip-faster')), 'install', 'pure_python_package') assert 'pure-python-package==0.2.0' in pip_freeze(str(venv)).split('\n')
def test_package_name_normalization(tmpdir): with tmpdir.as_cwd(): enable_coverage() requirements('WEIRD_cAsing-packAge') venv_update() assert '\nweird-CASING-pACKage==' in pip_freeze()
def test_override_requirements_file(tmpdir): tmpdir.chdir() requirements('') Path('.').ensure_dir('requirements.d').join('venv-update.txt').write('''\ pip-faster==%s pure_python_package ''' % __version__) out, err = venv_update() err = strip_pip_warnings(err) assert err == '' out = uncolor(out) assert ' '.join(( '\n> venv/bin/python -m pip.__main__ install', '-r requirements.d/venv-update.txt\n', )) in out expected = ('\nSuccessfully installed pip-1.5.6 pip-faster-%s pure-python-package-0.2.0 virtualenv-1.11.6' % __version__) assert expected in out assert '\n Successfully uninstalled pure-python-package\n' in out expected = '\n'.join(( 'pip-faster==%s' % __version__, 'virtualenv==1.11.6', 'wheel==0.29.0', '' )) assert pip_freeze() == expected
def test_override_requirements_file(tmpdir): tmpdir.chdir() enable_coverage() requirements('') Path('.').join('requirements-bootstrap.txt').write('''\ venv-update==%s pure_python_package ''' % __version__) out, err = venv_update( 'bootstrap-deps=', '-r', 'requirements-bootstrap.txt', ) err = strip_pip_warnings(err) # pip>=10 doesn't complain about installing an empty requirements file. assert err == '' out = uncolor(out) assert '\n> pip install -r requirements-bootstrap.txt\n' in out assert ( '\nSuccessfully installed pure-python-package-0.2.1 venv-update-%s' % __version__ ) in out assert '\n Successfully uninstalled pure-python-package-0.2.1\n' in out expected = '\n'.join(( 'venv-update==' + __version__, '' )) assert pip_freeze() == expected
def it_can_handle_a_bad_findlink(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) out, err = run( str(venv.join('bin/pip-faster')), 'install', '-vvv', '--find-links', 'git+wat://not/a/thing', 'pure-python-package', ) out = uncolor(out) err = strip_pip_warnings(err) expected = '''\ Successfully built pure-python-package Installing collected packages: pure-python-package ''' assert expected in out # Between this there's: # 'changing mode of .../venv/bin/pure-python-script to 775' # but that depends on umask _, rest = out.split(expected) expected2 = '''\ Successfully installed pure-python-package-0.2.1 Cleaning up... ''' assert expected2 in rest assert err == ( " Url 'git+wat://not/a/thing' is ignored. " 'It is either a non-existing path or lacks a specific scheme.\n' ) assert 'pure-python-package==0.2.1' in pip_freeze(str(venv)).split('\n')
def flake8_newer(): requirements('''\ flake8==2.2.5 # we expect 0.8.1 pyflakes<=0.8.1 # simply to prevent these from drifting: mccabe<=0.3 pep8<=1.5.7 -r %s/requirements.d/coverage.txt ''' % TOP) venv_update() assert pip_freeze() == '\n'.join(( 'appdirs==1.4.3', 'coverage==4.4.1', 'coverage-enable-subprocess==1.0', 'flake8==2.2.5', 'mccabe==0.3', 'packaging==16.8', 'pep8==1.5.7', 'pip==9.0.1', 'pyflakes==0.8.1', 'pyparsing==2.2.0', 'setuptools==35.0.2', 'six==1.10.0', 'venv-update==' + __version__, 'wheel==0.29.0', '' ))
def test_package_name_normalization_with_dots(tmpdir, install_req): """Packages with dots should be installable with either dots or dashes.""" with tmpdir.as_cwd(): enable_coverage() requirements(install_req) venv_update() assert pip_freeze().startswith('dotted.package-name==')
def test_update_while_active(tmpdir): tmpdir.chdir() requirements('virtualenv<2') venv_update() assert 'project-with-c' not in pip_freeze() # An arbitrary small package: project_with_c requirements('project_with_c') venv_update_symlink_pwd() out, err = run('sh', '-c', '. venv/bin/activate && python venv_update.py') out = uncolor(out) assert err == '' assert out.startswith('> virtualenv\nKeeping valid virtualenv from previous run.\n') assert 'project-with-c' in pip_freeze()
def test_update_while_active(tmpdir): tmpdir.chdir() requirements('virtualenv<2') venv_update() assert 'project-with-c' not in pip_freeze() # An arbitrary small package: project_with_c requirements('project_with_c') venv_update_symlink_pwd() out, err = run('sh', '-c', '. venv/bin/activate && python venv_update.py') out = uncolor(out) assert err == '' assert out.startswith( '> virtualenv\nKeeping valid virtualenv from previous run.\n') assert 'project-with-c' in pip_freeze()
def it_installs_stuff(tmpdir): venv = tmpdir.join('venv') run('virtualenv', str(venv)) assert pip_freeze(str(venv)) == '''\ ''' pip = venv.join('bin/pip').strpath run(pip, 'install', 'pip-faster==' + __version__) assert [ req.split('==')[0] for req in pip_freeze(str(venv)).split() ] == ['pip-faster', 'virtualenv', 'wheel'] run(str(venv.join('bin/pip-faster')), 'install', 'pure_python_package') assert 'pure-python-package==0.2.0' in pip_freeze(str(venv)).split('\n')
def it_installs_stuff(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) assert pip_freeze(str(venv)) == '''\ coverage==4.0.3 coverage-enable-subprocess==0 ''' pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) assert [req.split('==')[0] for req in pip_freeze(str(venv)).split()] == [ 'coverage', 'coverage-enable-subprocess', 'venv-update', 'wheel' ] run(str(venv.join('bin/pip-faster')), 'install', 'pure_python_package') assert 'pure-python-package==0.2.0' in pip_freeze(str(venv)).split('\n')
def test_install_custom_path_and_requirements(tmpdir): """Show that we can install to a custom directory with a custom requirements file.""" tmpdir.chdir() requirements( 'mccabe==0.6.0\n', path='requirements2.txt', ) enable_coverage() venv_update('venv=', 'venv2', 'install=', '-r', 'requirements2.txt') assert pip_freeze('venv2') == '\n'.join( ('mccabe==0.6.0', 'venv-update==' + __version__, ''))
def test_update_invalidated_while_active(tmpdir): tmpdir.chdir() requirements('virtualenv<2') venv_update() assert 'project-with-c' not in pip_freeze() # An arbitrary small package: project_with_c requirements('project-with-c') venv_update_symlink_pwd() out, err = run('sh', '-c', '. venv/bin/activate && python venv_update.py --system-site-packages') err = strip_pip_warnings(err) assert err == '' out = uncolor(out) assert out.startswith('''\ > virtualenv --system-site-packages Removing invalidated virtualenv. ''') assert 'project-with-c' in pip_freeze()
def test_update_while_active(tmpdir): tmpdir.chdir() enable_coverage() requirements('') venv_update() assert 'project-with-c' not in pip_freeze() # An arbitrary small package: project_with_c requirements('project_with_c') venv_update_symlink_pwd() out, err = run('sh', '-c', '. venv/bin/activate && python venv_update.py venv= venv --python=venv/bin/python') out = uncolor(out) err = strip_pip_warnings(err) assert err == '' assert out.startswith('''\ > virtualenv venv --python=venv/bin/python Keeping valid virtualenv from previous run. ''') assert 'project-with-c' in pip_freeze()
def test_has_extras(tmpdir): with tmpdir.as_cwd(): enable_coverage() install_coverage() requirements('pure-python-package[my-extra]') for _ in range(2): venv_update() expected = '\n'.join( ('implicit-dependency==1', 'pure-python-package==0.2.1', 'venv-update==' + __version__, '')) assert pip_freeze() == expected
def test_install_custom_path_and_requirements(tmpdir): """Show that we can install to a custom directory with a custom requirements file.""" tmpdir.chdir() requirements( 'mccabe==0.6.0\n', path='requirements2.txt', ) enable_coverage() venv_update('venv=', 'venv2', 'install=', '-r', 'requirements2.txt') assert pip_freeze('venv2') == '\n'.join(( 'mccabe==0.6.0', 'venv-update==' + __version__, '' ))
def it_installs_stuff(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) assert pip_freeze(str(venv)) == '''\ coverage==ANY coverage-enable-subprocess==1.0 ''' pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) assert [ req.split('==')[0] for req in pip_freeze(str(venv)).split() ] == [ 'coverage', 'coverage-enable-subprocess', 'venv-update', ] run(str(venv.join('bin/pip-faster')), 'install', 'pure_python_package') assert 'pure-python-package==0.2.1' in pip_freeze(str(venv)).split('\n')
def test_has_extras(tmpdir): with tmpdir.as_cwd(): enable_coverage() install_coverage() requirements('pure-python-package[my-extra]') for _ in range(2): venv_update() expected = '\n'.join(( 'implicit-dependency==1', 'pure-python-package==0.2.1', 'venv-update==' + __version__, '' )) assert pip_freeze() == expected
def it_considers_equals_star_not_pinned(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) run( str(venv.join('bin/pip-faster')), 'install', 'many-versions-package==2', ) run( str(venv.join('bin/pip-faster')), 'install', '--upgrade', 'many-versions-package==2.*', ) assert 'many-versions-package==2.1' in pip_freeze(str(venv)).split('\n')
def it_installs_stuff_from_requirements_file(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) # An arbitrary small package: pure_python_package requirements('pure_python_package\nproject_with_c') run(str(venv.join('bin/pip-faster')), 'install', '-r', 'requirements.txt') frozen_requirements = pip_freeze(str(venv)).split('\n') assert 'pure-python-package==0.2.1' in frozen_requirements assert 'project-with-c==0.1.0' in frozen_requirements
def test_install_custom_path_and_requirements(tmpdir): """Show that we can install to a custom directory with a custom requirements file.""" tmpdir.chdir() requirements( 'six==1.8.0\n', path='requirements2.txt', ) enable_coverage(tmpdir, 'venv2') venv_update('venv2', '--', '-r', 'requirements2.txt') assert pip_freeze('venv2') == '\n'.join(( 'pip-faster==' + __version__, 'six==1.8.0', 'virtualenv==1.11.6', 'wheel==0.29.0', '' ))
def test_cant_wheel_package(tmpdir): with tmpdir.as_cwd(): enable_coverage() install_coverage() requirements('cant-wheel-package\npure-python-package') out, err = venv_update() err = strip_pip_warnings(err) assert err == ' Failed building wheel for cant-wheel-package\n' out = uncolor(out) assert '''\ Installing collected packages: cant-wheel-package, pure-python-package Running setup.py install for cant-wheel-package ... done Successfully installed cant-wheel-package-0.1.0 pure-python-package-0.2.1 ''' in out # noqa assert pip_freeze().startswith( 'cant-wheel-package==0.1.0\n' )
def test_old_pip_and_setuptools(tmpdir, reqs): """We should be able to use pip-faster's wheel building even if we have ancient pip and setuptools. https://github.com/Yelp/pip-faster/issues/33 """ tmpdir.chdir() # 1. Create an empty virtualenv. # 2. Install old pip/setuptools that don't support wheel building. # 3. Install pip-faster. # 4. Install pure-python-package and assert it was wheeled during install. venv = tmpdir.join('venv') run('virtualenv', venv.strpath) # We need to add public PyPI as an extra URL since we're installing # packages (setuptools and pip) which aren't available from our PyPI fixture. from os import environ environ['PIP_EXTRA_INDEX_URL'] = 'https://pypi.python.org/simple/' try: pip = venv.join('bin/pip').strpath for req in reqs: run(pip, 'install', '--', req) # wheel needs argparse but it won't get installed if sys.version_info < (2, 7): run(pip, 'install', 'argparse') run(pip, 'install', 'pip-faster==' + __version__) finally: del environ['PIP_EXTRA_INDEX_URL'] run(str(venv.join('bin/pip-faster')), 'install', 'pure_python_package') # it was installed assert 'pure-python-package==0.2.0' in pip_freeze(str(venv)).split('\n') # it was wheeled from pip.wheel import Wheel wheelhouse = tmpdir.join('home', '.cache', 'pip-faster', 'wheelhouse') assert 'pure-python-package' in [ Wheel(f.basename).name for f in wheelhouse.listdir() ]
def it_doesnt_wheel_local_dirs(tmpdir): from pip.wheel import Wheel tmpdir.chdir() venv = enable_coverage(tmpdir, 'venv') pip = venv.join('bin/pip').strpath run(pip, 'install', 'pip-faster==' + __version__) run( venv.join('bin/pip-faster').strpath, 'install', TOP.join('tests/testing/packages/dependant_package').strpath, ) frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == set([ 'coverage==4.0.3', 'coverage-enable-subprocess==0', 'dependant-package==1', 'implicit-dependency==1', 'many-versions-package==3', 'pip-faster==' + __version__, 'pure-python-package==0.2.0', 'virtualenv==1.11.6', 'wheel==0.29.0', '', ]) wheelhouse = tmpdir.join('home', '.cache', 'pip-faster', 'wheelhouse') assert set(Wheel(f.basename).name for f in wheelhouse.listdir()) == set([ 'coverage', 'coverage-enable-subprocess', 'implicit-dependency', 'many-versions-package', 'pure-python-package', ])
def it_doesnt_wheel_git_repos(tmpdir): venv = tmpdir.join('venv') install_coverage(venv) pip = venv.join('bin/pip').strpath run(pip, 'install', 'venv-update==' + __version__) run( venv.join('bin/pip-faster').strpath, 'install', 'git+git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb-init', # noqa ) frozen_requirements = pip_freeze(str(venv)).split('\n') assert set(frozen_requirements) == { 'coverage-enable-subprocess==1.0', 'coverage==ANY', 'dumb-init==0.5.0', 'venv-update==' + __version__, '', } assert not tuple(cached_wheels(tmpdir))