コード例 #1
0
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
コード例 #2
0
ファイル: faster.py プロジェクト: jolynch/pip-faster
    def clean():
        venv = tmpdir.join('venv')
        assert venv.isdir()
        venv.remove()
        assert not venv.exists()
        enable_coverage(tmpdir)

        # copy the bootstrap-essential wheels to the wheelhouse where they can be found.
        # FIXME: pip7 has the behavior we want: wheel anything we install
        from glob import glob

        for package in (
                'argparse',
                'pip',
                'pip_faster',
                'virtualenv-1.11.6',
                'wheel',
        ):
            pattern = str(pypi_packages.join(package + '-*.whl'))
            wheel = glob(pattern)
            assert len(wheel) == 1, (pattern, wheel)
            wheel = wheel[0]

            from shutil import copy
            copy(wheel, str(tmpdir.join('home/.cache/pip-faster/wheelhouse')))
コード例 #3
0
ファイル: simple_test.py プロジェクト: jolynch/pip-faster
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')
コード例 #4
0
ファイル: simple_test.py プロジェクト: jolynch/pip-faster
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()
コード例 #5
0
ファイル: venv_update.py プロジェクト: jolynch/pip-faster
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()
コード例 #6
0
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()
コード例 #7
0
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
コード例 #8
0
def test_args_backward(tmpdir):
    tmpdir.chdir()
    enable_coverage()
    requirements('')

    with pytest.raises(CalledProcessError) as excinfo:
        venv_update('venv=', 'requirements.txt')

    # py26 doesn't have a consistent exit code:
    #   http://bugs.python.org/issue15033
    assert excinfo.value.returncode != 0
    out, err = excinfo.value.result
    err = strip_coverage_warnings(err)
    err = strip_pip_warnings(err)
    assert err == ''
    out = uncolor(out)
    assert out.rsplit('\n', 4)[-4:] == [
        '> virtualenv requirements.txt',
        'ERROR: File already exists and is not a directory.',
        'Please provide a different path or delete the file.',
        '',
    ]

    assert Path('requirements.txt').isfile()
    assert Path('requirements.txt').read() == ''
    assert not Path('myvenv').exists()
コード例 #9
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
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
コード例 #10
0
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()
コード例 #11
0
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
コード例 #12
0
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()
コード例 #13
0
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()
コード例 #14
0
    def clean():
        venv = tmpdir.join('venv')
        assert venv.isdir()
        venv.remove()
        assert not venv.exists()
        enable_coverage(tmpdir)

        # copy the bootstrap-essential wheels to the wheelhouse where they can be found.
        # FIXME: pip7 has the behavior we want: wheel anything we install
        from glob import glob

        for package in (
                'argparse',
                'pip',
                'pip_faster',
                'virtualenv-1.11.6',
                'wheel',
        ):
            pattern = str(pypi_packages.join(package + '-*.whl'))
            wheel = glob(pattern)
            assert len(wheel) == 1, (pattern, wheel)
            wheel = wheel[0]

            from shutil import copy
            copy(wheel, str(tmpdir.join('home/.cache/pip-faster/wheelhouse')))
コード例 #15
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 == ''

        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')
コード例 #16
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==')
コード例 #17
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
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==')
コード例 #18
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_not_installable_thing(tmpdir):
    tmpdir.chdir()
    enable_coverage()

    install_coverage()

    requirements('not-a-real-package-plz')
    with pytest.raises(CalledProcessError):
        venv_update()
コード例 #19
0
ファイル: pip_faster.py プロジェクト: Yelp/venv-update
def make_venv():
    enable_coverage()
    venv = Path('venv')
    run('virtualenv', venv.strpath)
    install_coverage(venv.strpath)

    pip = venv.join('bin/pip').strpath
    run(pip, 'install', 'venv-update==' + __version__)
    return venv
コード例 #20
0
def test_not_installable_thing(tmpdir):
    tmpdir.chdir()
    enable_coverage()

    install_coverage()

    requirements('not-a-real-package-plz')
    with pytest.raises(CalledProcessError):
        venv_update()
コード例 #21
0
def make_venv():
    enable_coverage()
    venv = Path('venv')
    run('virtualenv', venv.strpath)
    install_coverage(venv.strpath)

    pip = venv.join('bin/pip').strpath
    run(pip, 'install', 'venv-update==' + __version__)
    return venv
コード例 #22
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_eggless_url(tmpdir):
    tmpdir.chdir()

    enable_coverage()

    # An arbitrary url requirement.
    requirements('-e file://' + str(TOP / 'tests/testing/packages/pure_python_package'))

    venv_update()
    assert '#egg=pure_python_package' in pip_freeze()
コード例 #23
0
def test_eggless_url(tmpdir):
    tmpdir.chdir()

    enable_coverage()

    # An arbitrary url requirement.
    requirements('-e file://' + str(TOP / 'tests/testing/packages/pure_python_package'))

    venv_update()
    assert '#egg=pure_python_package' in pip_freeze()
コード例 #24
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_trivial(tmpdir):
    tmpdir.chdir()
    requirements('')
    enable_coverage()
    venv_update()
    # Originally suggested by none other than @bukzor in:
    # https://github.com/pypa/virtualenv/issues/118
    # This directory now just causes problems (especially with relocating)
    # since the debian issue has been fixed.
    assert not tmpdir.join('venv', 'local').exists()
コード例 #25
0
def test_trivial(tmpdir):
    tmpdir.chdir()
    requirements('')
    enable_coverage()
    venv_update()
    # Originally suggested by none other than @bukzor in:
    # https://github.com/pypa/virtualenv/issues/118
    # This directory now just causes problems (especially with relocating)
    # since the debian issue has been fixed.
    assert not tmpdir.join('venv', 'local').exists()
コード例 #26
0
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
コード例 #27
0
ファイル: conflict_test.py プロジェクト: ydxt25/venv-update
def test_editable_egg_conflict(tmpdir):
    conflicting_package = tmpdir / 'tmp/conflicting_package'
    many_versions_package_2 = tmpdir / 'tmp/many_versions_package_2'

    from shutil import copytree
    copytree(
        str(T.TOP / 'tests/testing/packages/conflicting_package'),
        str(conflicting_package),
    )

    copytree(
        str(T.TOP / 'tests/testing/packages/many_versions_package_2'),
        str(many_versions_package_2),
    )

    with many_versions_package_2.as_cwd():
        from sys import executable as python
        T.run(python, 'setup.py', 'bdist_egg', '--dist-dir',
              str(conflicting_package))

    with tmpdir.as_cwd():
        T.enable_coverage()
        T.requirements('-e %s' % conflicting_package)
        with pytest.raises(CalledProcessError) as excinfo:
            T.venv_update()
        assert excinfo.value.returncode == 1
        out, err = excinfo.value.result

        err = T.strip_coverage_warnings(err)
        err = T.strip_pip_warnings(err)
        assert err == ''

        out = T.uncolor(out)
        expected = '\nSuccessfully installed many-versions-package conflicting-package\n'
        assert expected in out
        rest = out.rsplit(expected, 1)[-1]

        if True:  # :pragma:nocover:pylint:disable=using-constant-test
            # Debian de-vendorizes the version of pip it ships
            try:
                from sysconfig import get_python_version
            except ImportError:  # <= python2.6
                from distutils.sysconfig import get_python_version
        assert (
            '''\
Cleaning up...
Error: version conflict: many-versions-package 2 (tmp/conflicting_package/many_versions_package-2-py{0}.egg)'''
            ''' <-> many-versions-package<2 (from conflicting-package==1->-r requirements.txt (line 1))
Storing debug log for failure in {1}/home/.pip/pip.log

Something went wrong! Sending 'venv' back in time, so make knows it's invalid.
'''.format(get_python_version(), tmpdir)) == rest

        assert_venv_marked_invalid(tmpdir.join('venv'))
コード例 #28
0
def test_recreate_active_virtualenv(tmpdir):
    with tmpdir.as_cwd():
        enable_coverage()

        run('virtualenv', 'venv')
        run('venv/bin/pip', 'install', '-r', str(TOP / 'requirements.d/coverage.txt'))

        requirements('project_with_c')
        venv_update_symlink_pwd()
        run('venv/bin/python', 'venv_update.py')

        assert_c_extension_runs()
コード例 #29
0
ファイル: simple_test.py プロジェクト: eagle-r/venv-update
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__, ''))
コード例 #30
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_extra_index_url_doesnt_cache(tmpdir):
    tmpdir.chdir()
    enable_coverage()
    install_coverage()

    requirements('pure-python-package==0.2.1')
    venv_update(
        'pip-command=', 'pip-faster', 'install',
        '--extra-index-url=https://pypi.python.org/simple',
    )

    assert not tuple(cached_wheels(tmpdir))
コード例 #31
0
ファイル: validation.py プロジェクト: Yelp/venv-update
def test_recreate_active_virtualenv(tmpdir):
    with tmpdir.as_cwd():
        enable_coverage()

        run('virtualenv', 'venv')
        run('venv/bin/pip', 'install', '-r', str(TOP / 'requirements.d/coverage.txt'))

        requirements('project_with_c')
        venv_update_symlink_pwd()
        run('venv/bin/python', 'venv_update.py')

        assert_c_extension_runs()
コード例 #32
0
def test_extra_index_url_doesnt_cache(tmpdir):
    tmpdir.chdir()
    enable_coverage()
    install_coverage()

    requirements('pure-python-package==0.2.1')
    venv_update(
        'pip-command=', 'pip-faster', 'install',
        '--extra-index-url=https://pypi.python.org/simple',
    )

    assert not tuple(cached_wheels(tmpdir))
コード例 #33
0
ファイル: simple_test.py プロジェクト: eagle-r/venv-update
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
コード例 #34
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_arguments_version(tmpdir):
    """Show that we can pass arguments through to virtualenv"""
    tmpdir.chdir()
    enable_coverage()

    # should show virtualenv version, successfully
    out, err = venv_update('venv=', '--version')
    err = strip_pip_warnings(err)
    assert err == ''

    out = uncolor(out)
    lines = out.splitlines()
    assert lines[-2] == '> virtualenv --version', repr(lines)
コード例 #35
0
ファイル: simple_test.py プロジェクト: eagle-r/venv-update
def test_arguments_version(tmpdir):
    """Show that we can pass arguments through to virtualenv"""
    tmpdir.chdir()
    enable_coverage()

    # should show virtualenv version, successfully
    out, err = venv_update('venv=', '--version')
    err = strip_pip_warnings(err)
    assert err == ''

    out = uncolor(out)
    lines = out.splitlines()
    assert lines[-2] == '> virtualenv --version', repr(lines)
コード例 #36
0
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(
        ('appdirs==1.4.0', 'mccabe==0.6.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', ''))
コード例 #37
0
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(
                ('appdirs==1.4.0', 'implicit-dependency==1', 'packaging==16.8',
                 'pip==9.0.1', 'pure-python-package==0.2.1',
                 'pyparsing==2.1.10', 'setuptools==34.1.1', 'six==1.10.0',
                 'venv-update==' + __version__, 'wheel==0.29.0', ''))
            assert pip_freeze() == expected
コード例 #38
0
def test_doesnt_use_cache_without_index_server(tmpdir):
    tmpdir.chdir()
    enable_coverage()

    requirements('pure-python-package==0.2.1')
    venv_update()

    tmpdir.join('venv').remove()
    install_coverage()

    cmd = ('pip-command=', 'pip-faster', 'install')
    with pytest.raises(CalledProcessError):
        venv_update(*(cmd + ('--no-index',)))
    # But it would succeed if we gave it an index
    venv_update(*cmd)
コード例 #39
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
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__,
        ''
    ))
コード例 #40
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_doesnt_use_cache_without_index_server(tmpdir):
    tmpdir.chdir()
    enable_coverage()

    requirements('pure-python-package==0.2.1')
    venv_update()

    tmpdir.join('venv').remove()
    install_coverage()

    cmd = ('pip-command=', 'pip-faster', 'install')
    with pytest.raises(CalledProcessError):
        venv_update(*(cmd + ('--no-index',)))
    # But it would succeed if we gave it an index
    venv_update(*cmd)
コード例 #41
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
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
コード例 #42
0
ファイル: pip_faster.py プロジェクト: jolynch/pip-faster
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
コード例 #43
0
ファイル: pip_faster.py プロジェクト: jolynch/pip-faster
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
コード例 #44
0
ファイル: validation.py プロジェクト: Yelp/venv-update
def test_update_invalidated_missing_activate(tmpdir):
    with tmpdir.as_cwd():
        enable_coverage()
        requirements('')

        venv_update()
        tmpdir.join('venv/bin/activate').remove()

        out, err = venv_update()
        err = strip_pip_warnings(err)
        assert err == "sh: 1: .: Can't open venv/bin/activate\n"
        out = uncolor(out)
        assert out.startswith('''\
> virtualenv venv
Removing invalidated virtualenv. (could not inspect metadata)
''')
コード例 #45
0
def test_update_invalidated_missing_activate(tmpdir):
    with tmpdir.as_cwd():
        enable_coverage()
        requirements('')

        venv_update()
        tmpdir.join('venv/bin/activate').remove()

        out, err = venv_update()
        err = strip_pip_warnings(err)
        assert err == "sh: 1: .: Can't open venv/bin/activate\n"
        out = uncolor(out)
        assert out.startswith('''\
> virtualenv venv
Removing invalidated virtualenv. (could not inspect metadata)
''')
コード例 #46
0
ファイル: simple_test.py プロジェクト: jolynch/pip-faster
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',
        ''
    ))
コード例 #47
0
ファイル: conflict_test.py プロジェクト: Yelp/venv-update
def test_multiple_issues(tmpdir):
    # Make it a bit worse. The output should show all three issues.
    tmpdir.chdir()
    T.enable_coverage()

    T.requirements('dependant_package\n-r %s/requirements.d/coverage.txt' % T.TOP)
    T.venv_update()

    T.run('./venv/bin/pip', 'uninstall', '--yes', 'implicit_dependency')
    T.requirements('''
dependant_package
conflicting_package
pure_python_package==0.1.0
''')

    with pytest.raises(CalledProcessError) as excinfo:
        T.venv_update()
    assert excinfo.value.returncode == 1
    out, err = excinfo.value.result

    err = T.strip_coverage_warnings(err)
    err = T.strip_pip_warnings(err)

    err = err.splitlines()
    # pip outputs conflict lines in a non-consistent order
    assert set(err[:3]) == {
        "conflicting-package 1 has requirement many-versions-package<2, but you'll have many-versions-package 3 which is incompatible.",  # noqa
        "dependant-package 1 has requirement pure-python-package>=0.2.1, but you'll have pure-python-package 0.1.0 which is incompatible.",  # noqa
        'Error: version conflict: pure-python-package 0.1.0 (venv/{lib}) <-> pure-python-package>=0.2.1 (from dependant_package->-r requirements.txt (line 2))'.format(  # noqa
            lib=PYTHON_LIB,
        ),
    }
    # TODO: do we still need to append our own error?
    assert '\n'.join(err[3:]) == (
        'Error: version conflict: many-versions-package 3 '
        '(venv/{lib}) <-> many-versions-package<2 '
        '(from conflicting_package->-r requirements.txt (line 3))'.format(
            lib=PYTHON_LIB,
        )
    )

    out = T.uncolor(out)
    assert_something_went_wrong(out)

    assert_venv_marked_invalid(tmpdir.join('venv'))
コード例 #48
0
def test_multiple_issues(tmpdir):
    # Make it a bit worse. The output should show all three issues.
    tmpdir.chdir()
    T.enable_coverage()

    T.requirements('dependant_package\n-r %s/requirements.d/coverage.txt' %
                   T.TOP)
    T.venv_update()

    T.run('./venv/bin/pip', 'uninstall', '--yes', 'implicit_dependency')
    T.requirements('''
dependant_package
conflicting_package
pure_python_package==0.1.0
''')

    with pytest.raises(CalledProcessError) as excinfo:
        T.venv_update()
    assert excinfo.value.returncode == 1
    out, err = excinfo.value.result

    err = T.strip_coverage_warnings(err)
    err = T.strip_pip_warnings(err)

    err = err.splitlines()
    # pip outputs conflict lines in a non-consistent order
    assert set(err[:3]) == {
        'dependant-package 1 requires implicit-dependency, which is not installed.',
        "dependant-package 1 has requirement pure-python-package>=0.2.1, but you'll have pure-python-package 0.1.0 which is incompatible.",  # noqa
        "conflicting-package 1 has requirement many-versions-package<2, but you'll have many-versions-package 3 which is incompatible.",  # noqa
    }
    # TODO: do we still need to append our own error?
    assert '\n'.join(err[3:]) == (
        'Error: version conflict: pure-python-package 0.1.0 '
        '(venv/{lib}) <-> pure-python-package>=0.2.1 '
        '(from dependant_package->-r requirements.txt (line 2))\n'
        'Error: version conflict: many-versions-package 3 '
        '(venv/{lib}) <-> many-versions-package<2 '
        '(from conflicting_package->-r requirements.txt (line 3))'.format(
            lib=PYTHON_LIB, ))

    out = T.uncolor(out)
    assert_something_went_wrong(out)

    assert_venv_marked_invalid(tmpdir.join('venv'))
コード例 #49
0
ファイル: simple_test.py プロジェクト: eagle-r/venv-update
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')
コード例 #50
0
ファイル: validation.py プロジェクト: Yelp/venv-update
def test_python_versions(tmpdir):
    tmpdir.chdir()
    enable_coverage()
    requirements('project-with-c')

    other_python = OtherPython()
    venv_update('venv=', '--python=' + other_python.interpreter, 'venv')
    assert_c_extension_runs()
    assert_python_version(other_python.version_prefix)

    from sys import executable as python
    venv_update('venv=', '--python=' + python, 'venv')
    assert_c_extension_runs()
    from sys import version
    assert_python_version(version)

    venv_update('venv=', '--python=' + other_python.interpreter, 'venv')
    assert_c_extension_runs()
    assert_python_version(other_python.version_prefix)
コード例 #51
0
ファイル: conflict_test.py プロジェクト: Yelp/venv-update
def test_editable_egg_conflict(tmpdir):
    conflicting_package = tmpdir / 'tmp/conflicting_package'
    many_versions_package_2 = tmpdir / 'tmp/many_versions_package_2'

    from shutil import copytree
    copytree(
        str(T.TOP / 'tests/testing/packages/conflicting_package'),
        str(conflicting_package),
    )

    copytree(
        str(T.TOP / 'tests/testing/packages/many_versions_package_2'),
        str(many_versions_package_2),
    )

    with many_versions_package_2.as_cwd():
        from sys import executable as python
        T.run(python, 'setup.py', 'bdist_egg', '--dist-dir', str(conflicting_package))

    with tmpdir.as_cwd():
        T.enable_coverage()
        T.requirements('-e %s' % conflicting_package)
        with pytest.raises(CalledProcessError) as excinfo:
            T.venv_update()
        assert excinfo.value.returncode == 1
        out, err = excinfo.value.result

        err = T.strip_coverage_warnings(err)
        err = T.strip_pip_warnings(err)
        assert err == (
            'Error: version conflict: many-versions-package 2 '
            '(tmp/conflicting_package/many_versions_package-2-py{}.egg) '
            '<-> many_versions_package<2 '
            '(from conflicting-package==1->-r requirements.txt (line 1))\n'.format(
                get_python_version(),
            )
        )

        out = T.uncolor(out)
        assert_something_went_wrong(out)

        assert_venv_marked_invalid(tmpdir.join('venv'))
コード例 #52
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
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'
        )
コード例 #53
0
ファイル: validation.py プロジェクト: Yelp/venv-update
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()
コード例 #54
0
ファイル: validation.py プロジェクト: Yelp/venv-update
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()
コード例 #55
0
ファイル: validation.py プロジェクト: Yelp/venv-update
def test_virtualenv_moved(tmpdir):
    """if you move the virtualenv and venv-update again, the old will be blown away, and things will work"""
    original_path = 'original'
    new_path = 'new_dir'

    with tmpdir.mkdir(original_path).as_cwd():
        enable_coverage()
        requirements('project_with_c')
        venv_update()
        assert_c_extension_runs()

    with tmpdir.as_cwd():
        Path(original_path).rename(new_path)

    with tmpdir.join(new_path).as_cwd():
        with pytest.raises(OSError) as excinfo:
            assert_c_extension_runs()
        # python >= 3.3 raises FileNotFoundError
        assert excinfo.type.__name__ in ('OSError', 'FileNotFoundError')
        assert excinfo.value.args[0] == 2  # no such file

        venv_update()
        assert_c_extension_runs()
コード例 #56
0
ファイル: pip_faster.py プロジェクト: jolynch/pip-faster
def it_can_handle_requirements_already_met(tmpdir):
    tmpdir.chdir()

    venv = enable_coverage(tmpdir, 'venv')

    pip = venv.join('bin/pip').strpath
    run(pip, 'install', 'pip-faster==' + __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))
コード例 #57
0
ファイル: simple_test.py プロジェクト: Yelp/venv-update
def test_args_backward(tmpdir):
    tmpdir.chdir()
    enable_coverage()
    requirements('')

    with pytest.raises(CalledProcessError) as excinfo:
        venv_update('venv=', 'requirements.txt')

    assert excinfo.value.returncode == 3
    out, err = excinfo.value.result
    err = strip_coverage_warnings(err)
    err = strip_pip_warnings(err)
    assert err == ''
    out = uncolor(out)
    assert out.rsplit('\n', 4)[-4:] == [
        '> virtualenv requirements.txt',
        'ERROR: File already exists and is not a directory.',
        'Please provide a different path or delete the file.',
        '',
    ]

    assert Path('requirements.txt').isfile()
    assert Path('requirements.txt').read() == ''
    assert not Path('myvenv').exists()
コード例 #58
0
ファイル: pip_faster.py プロジェクト: jolynch/pip-faster
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',
    ])
コード例 #59
0
ファイル: pip_faster.py プロジェクト: jolynch/pip-faster
def it_installs_stuff_with_dash_e_without_wheeling(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__)

    # 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) == set([
        '-e git://github.com/Yelp/dumb-init.git@87545be699a13d0fd31f67199b7782ebd446437e#egg=dumb_init-dev',  # noqa
        'coverage-enable-subprocess==0',
        'coverage==4.0.3',
        'pip-faster==' + __version__,
        'virtualenv==1.11.6',
        'wheel==0.29.0',
        '',
    ])

    # we shouldn't wheel things installed editable
    wheelhouse = tmpdir.join('home', '.cache', 'pip-faster', 'wheelhouse')
    assert set(Wheel(f.basename).name for f in wheelhouse.listdir()) == set([
        'coverage',
        'coverage-enable-subprocess',
    ])