コード例 #1
0
def test_new_resolver_ignores_unneeded_conflicting_constraints(script):
    version_1 = create_basic_wheel_for_package(
        script,
        "test_pkg",
        "0.1.0",
    )
    version_2 = create_basic_wheel_for_package(
        script,
        "test_pkg",
        "0.2.0",
    )
    create_basic_wheel_for_package(
        script,
        "installed",
        "0.1.0",
    )

    constraints = [
        "test_pkg @ " + path_to_url(version_1),
        "test_pkg @ " + path_to_url(version_2),
    ]

    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text("\n".join(constraints))

    script.pip("install", "--no-cache-dir", "--no-index", "--find-links",
               script.scratch_path, "-c", constraints_file, "installed")

    assert_not_installed(script, "test_pkg")
    assert_installed(script, installed="0.1.0")
コード例 #2
0
def test_freeze_git_remote(script: PipTestEnvironment) -> None:
    """
    Test freezing a Git clone.
    """
    # Returns path to a generated package called "version_pkg"
    pkg_version = _create_test_package(script)

    result = script.run(
        "git",
        "clone",
        pkg_version,
        "pip-test-package",
        expect_stderr=True,
    )
    repo_dir = script.scratch_path / "pip-test-package"
    result = script.run(
        "python",
        "setup.py",
        "develop",
        cwd=repo_dir,
        expect_stderr=True,
    )
    origin_remote = pkg_version
    # check frozen remote after clone
    result = script.pip("freeze", expect_stderr=True)
    expected = (textwrap.dedent("""
            ...-e git+{remote}@...#egg=version_pkg
            ...
        """).format(remote=path_to_url(origin_remote)).strip())
    _check_output(result.stdout, expected)
    # check frozen remote when there is no remote named origin
    script.run("git", "remote", "rename", "origin", "other", cwd=repo_dir)
    result = script.pip("freeze", expect_stderr=True)
    expected = (textwrap.dedent("""
            ...-e git+{remote}@...#egg=version_pkg
            ...
        """).format(remote=path_to_url(origin_remote)).strip())
    _check_output(result.stdout, expected)
    # When the remote is a local path, it must exist.
    # If it doesn't, it gets flagged as invalid.
    other_remote = pkg_version + "-other"
    script.run("git", "remote", "set-url", "other", other_remote, cwd=repo_dir)
    result = script.pip("freeze", expect_stderr=True)
    expected = os.path.normcase(
        textwrap.dedent(f"""
            ...# Editable Git...(version-pkg...)...
            # '{other_remote}'
            -e {repo_dir}...
        """).strip())
    _check_output(os.path.normcase(result.stdout), expected)
    # when there are more than one origin, priority is given to the
    # remote named origin
    script.run("git", "remote", "add", "origin", origin_remote, cwd=repo_dir)
    result = script.pip("freeze", expect_stderr=True)
    expected = (textwrap.dedent("""
            ...-e git+{remote}@...#egg=version_pkg
            ...
        """).format(remote=path_to_url(origin_remote)).strip())
    _check_output(result.stdout, expected)
コード例 #3
0
ファイル: test_freeze.py プロジェクト: cjc7373/pip
def test_freeze_git_remote(script, tmpdir):
    """
    Test freezing a Git clone.
    """
    # Returns path to a generated package called "version_pkg"
    pkg_version = _create_test_package(script)

    result = script.run(
        'git',
        'clone',
        pkg_version,
        'pip-test-package',
        expect_stderr=True,
    )
    repo_dir = script.scratch_path / 'pip-test-package'
    result = script.run(
        'python',
        'setup.py',
        'develop',
        cwd=repo_dir,
        expect_stderr=True,
    )
    origin_remote = pkg_version
    # check frozen remote after clone
    result = script.pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""
            ...-e git+{remote}@...#egg=version_pkg
            ...
        """).format(remote=path_to_url(origin_remote)).strip()
    _check_output(result.stdout, expected)
    # check frozen remote when there is no remote named origin
    script.run('git', 'remote', 'rename', 'origin', 'other', cwd=repo_dir)
    result = script.pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""
            ...-e git+{remote}@...#egg=version_pkg
            ...
        """).format(remote=path_to_url(origin_remote)).strip()
    _check_output(result.stdout, expected)
    # When the remote is a local path, it must exist.
    # If it doesn't, it gets flagged as invalid.
    other_remote = pkg_version + '-other'
    script.run('git', 'remote', 'set-url', 'other', other_remote, cwd=repo_dir)
    result = script.pip('freeze', expect_stderr=True)
    expected = os.path.normcase(
        textwrap.dedent(f"""
            ...# Editable Git...(version-pkg...)...
            # '{other_remote}'
            -e {repo_dir}...
        """).strip())
    _check_output(os.path.normcase(result.stdout), expected)
    # when there are more than one origin, priority is given to the
    # remote named origin
    script.run('git', 'remote', 'add', 'origin', origin_remote, cwd=repo_dir)
    result = script.pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""
            ...-e git+{remote}@...#egg=version_pkg
            ...
        """).format(remote=path_to_url(origin_remote)).strip()
    _check_output(result.stdout, expected)
コード例 #4
0
ファイル: test_wheel.py プロジェクト: Basis/pip
def test_pip_wheel_ignore_wheels_editables():
    """
    Test 'pip wheel' ignores editables and *.whl files in requirements
    """
    env = reset_env()
    pip_install_local('wheel')

    local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % find_links
    local_editable = os.path.abspath(os.path.join(tests_data, 'packages', 'FSPkg'))
    write_file('reqs.txt', textwrap.dedent("""\
        %s
        -e %s
        simple
        """ % (local_wheel, local_editable)))
    result = run_pip('wheel', '--no-index', '-f', find_links, '-r', env.scratch_path / 'reqs.txt')
    wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
    wheel_file_path = env.scratch/'wheelhouse'/wheel_file_name
    assert wheel_file_path in result.files_created, (wheel_file_path, result.files_created)
    assert "Successfully built simple" in result.stdout, result.stdout
    assert "Failed to build" not in result.stdout, result.stdout
    assert "ignoring %s" % local_wheel in result.stdout
    ignore_editable = "ignoring %s" % path_to_url(local_editable)
    #TODO: understand this divergence
    if sys.platform == 'win32':
        ignore_editable = "ignoring %s" % path_to_url_d(local_editable)
    assert ignore_editable in result.stdout, result.stdout
コード例 #5
0
ファイル: test_wheel.py プロジェクト: ronnix/pip
def test_pip_wheel_ignore_wheels_editables():
    """
    Test 'pip wheel' ignores editables and *.whl files in requirements
    """
    env = reset_env()
    pip_install_local('wheel')

    local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % find_links
    local_editable = os.path.abspath(
        os.path.join(tests_data, 'packages', 'FSPkg'))
    write_file(
        'reqs.txt',
        textwrap.dedent("""\
        %s
        -e %s
        simple
        """ % (local_wheel, local_editable)))
    result = run_pip('wheel', '--no-index', '-f', find_links, '-r',
                     env.scratch_path / 'reqs.txt')
    wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
    wheel_file_path = env.scratch / 'wheelhouse' / wheel_file_name
    assert wheel_file_path in result.files_created, (wheel_file_path,
                                                     result.files_created)
    assert "Successfully built simple" in result.stdout, result.stdout
    assert "Failed to build" not in result.stdout, result.stdout
    assert "ignoring %s" % local_wheel in result.stdout
    ignore_editable = "ignoring %s" % path_to_url(local_editable)
    #TODO: understand this divergence
    if sys.platform == 'win32':
        ignore_editable = "ignoring %s" % path_to_url_d(local_editable)
    assert ignore_editable in result.stdout, result.stdout
コード例 #6
0
def test_pip_wheel_ignore_wheels_editables(script, data):
    """
    Test 'pip wheel' ignores editables
    """
    script.pip('install', 'wheel')

    local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % data.find_links
    local_editable = data.packages.join("FSPkg")
    script.scratch_path.join("reqs.txt").write(
        textwrap.dedent("""\
        %s
        -e %s
        simple
        """ % (local_wheel, local_editable)))
    result = script.pip('wheel', '--no-index', '-f', data.find_links, '-r',
                        script.scratch_path / 'reqs.txt')
    wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
    wheel_file_path = script.scratch / 'wheelhouse' / wheel_file_name
    assert wheel_file_path in result.files_created, (wheel_file_path,
                                                     result.files_created)
    assert "Successfully built simple" in result.stdout, result.stdout
    assert "Failed to build" not in result.stdout, result.stdout
    ignore_editable = "ignoring %s" % path_to_url(local_editable)
    #TODO: understand this divergence
    if sys.platform == 'win32':
        ignore_editable = "ignoring %s" % path_to_url_d(local_editable)
    assert ignore_editable in result.stdout, result.stdout
コード例 #7
0
def test_install_vcs_editable_no_direct_url(script, with_wheel):
    pkg_path = _create_test_package(script, name="testpkg")
    args = ["install", "-e", "git+%s#egg=testpkg" % path_to_url(pkg_path)]
    result = script.pip(*args)
    # legacy editable installs do not generate .dist-info,
    # hence no direct_url.json
    assert not get_created_direct_url(result, "testpkg")
コード例 #8
0
ファイル: local_repos.py プロジェクト: yangyang14641/pip
def _get_vcs_and_checkout_url(remote_repository, directory):
    vcs_classes = {
        'svn': subversion.Subversion,
        'git': git.Git,
        'bzr': bazaar.Bazaar,
        'hg': mercurial.Mercurial
    }
    default_vcs = 'svn'
    if '+' not in remote_repository:
        remote_repository = '%s+%s' % (default_vcs, remote_repository)
    vcs, repository_path = remote_repository.split('+', 1)
    vcs_class = vcs_classes[vcs]
    branch = ''
    if vcs == 'svn':
        branch = os.path.basename(remote_repository)
        # remove the slash
        repository_name = os.path.basename(remote_repository[:-len(branch) -
                                                             1])
    else:
        repository_name = os.path.basename(remote_repository)

    destination_path = os.path.join(directory, repository_name)
    if not os.path.exists(destination_path):
        vcs_class(remote_repository).obtain(destination_path)
    return '%s+%s' % (
        vcs,
        path_to_url('/'.join([directory, repository_name, branch])),
    )
コード例 #9
0
def test_new_resolver_reinstall_link_requirement_with_constraint(script):
    installed_path = create_basic_wheel_for_package(
        script,
        "installed",
        "0.1.0",
    )

    cr_file = script.scratch_path / "constraints.txt"
    cr_file.write_text("installed @ " + path_to_url(installed_path))

    script.pip(
        "install",
        "--no-cache-dir",
        "--no-index",
        "-r",
        cr_file,
    )

    script.pip(
        "install",
        "--no-cache-dir",
        "--no-index",
        "-c",
        cr_file,
        "-r",
        cr_file,
    )
    # TODO: strengthen assertion to "second invocation does no work"
    # I don't think this is true yet, but it should be in the future.

    assert_installed(script, installed="0.1.0")
コード例 #10
0
def test_new_resolver_prefers_url_constraint_on_update(script):
    installed_path = create_basic_wheel_for_package(
        script,
        "test_pkg",
        "0.1.0",
    )
    not_installed_path = create_basic_wheel_for_package(
        script,
        "test_pkg",
        "0.2.0",
    )

    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text("test_pkg @ " + path_to_url(installed_path))

    (script.scratch_path / "index").mkdir()
    not_installed_path.rename(script.scratch_path / "index" /
                              not_installed_path.name)

    script.pip("install", "--no-cache-dir", "--no-index", "--find-links",
               script.scratch_path / "index", "test_pkg")

    assert_installed(script, test_pkg="0.2.0")

    script.pip("install", "--no-cache-dir", "--no-index", "--find-links",
               script.scratch_path / "index", "-c", constraints_file,
               "test_pkg")

    assert_installed(script, test_pkg="0.1.0")
コード例 #11
0
def test_new_resolver_does_not_install_unneeded_packages_with_url_constraint(
        script):
    archive_path = create_basic_wheel_for_package(
        script,
        "installed",
        "0.1.0",
    )
    not_installed_path = create_basic_wheel_for_package(
        script,
        "not_installed",
        "0.1.0",
    )

    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text("not_installed @ " +
                                path_to_url(not_installed_path))

    (script.scratch_path / "index").mkdir()
    archive_path.rename(script.scratch_path / "index" / archive_path.name)

    script.pip("install", "--no-cache-dir", "--no-index", "--find-links",
               script.scratch_path / "index", "-c", constraints_file,
               "installed")

    assert_installed(script, installed="0.1.0")
    assert_not_installed(script, "not_installed")
コード例 #12
0
def test_install_vcs_constraint_direct_file_url(script, with_wheel):
    pkg_path = _create_test_package(script, name="testpkg")
    url = path_to_url(pkg_path)
    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text(f"git+{url}#egg=testpkg")
    result = script.pip("install", "testpkg", "-c", constraints_file)
    assert get_created_direct_url(result, "testpkg")
コード例 #13
0
ファイル: local_repos.py プロジェクト: astrojuanlu/pip
def local_checkout(
    remote_repo: str,
    temp_path: Path,
) -> str:
    """
    :param temp_path: the return value of the tmpdir fixture, which is a
        temp directory Path object unique to each test function invocation,
        created as a sub directory of the base temp directory.
    """
    assert "+" in remote_repo
    vcs_name = remote_repo.split("+", 1)[0]
    repository_name = os.path.basename(remote_repo)

    directory = temp_path.joinpath("cache")
    repo_url_path = os.path.join(directory, repository_name)
    assert not os.path.exists(repo_url_path)

    if not os.path.exists(directory):
        os.mkdir(directory)

    if vcs_name == "svn":
        assert repository_name == "INITools"
        _create_svn_initools_repo(repo_url_path)
        repo_url_path = os.path.join(repo_url_path, "trunk")
    else:
        vcs_backend = vcs.get_backend(vcs_name)
        assert vcs_backend is not None
        vcs_backend.obtain(repo_url_path, url=hide_url(remote_repo), verbosity=0)

    return "{}+{}".format(vcs_name, path_to_url(repo_url_path))
コード例 #14
0
ファイル: test_wheel.py プロジェクト: Aneudylab/pip
def test_pip_wheel_ignore_wheels_editables(script, data):
    """
    Test 'pip wheel' ignores editables and *.whl files in requirements
    """
    script.pip('install', 'wheel')

    local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % data.find_links
    local_editable = data.packages.join("FSPkg")
    script.scratch_path.join("reqs.txt").write(textwrap.dedent("""\
        %s
        -e %s
        simple
        """ % (local_wheel, local_editable)))
    result = script.pip('wheel', '--no-index', '-f', data.find_links, '-r', script.scratch_path / 'reqs.txt')
    wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
    wheel_file_path = script.scratch/'wheelhouse'/wheel_file_name
    assert wheel_file_path in result.files_created, (wheel_file_path, result.files_created)
    assert "Successfully built simple" in result.stdout, result.stdout
    assert "Failed to build" not in result.stdout, result.stdout
    assert "ignoring %s" % local_wheel in result.stdout
    ignore_editable = "ignoring %s" % path_to_url(local_editable)
    #TODO: understand this divergence
    if sys.platform == 'win32':
        ignore_editable = "ignoring %s" % path_to_url_d(local_editable)
    assert ignore_editable in result.stdout, result.stdout
コード例 #15
0
def test_freeze_direct_url_archive(script: PipTestEnvironment,
                                   shared_data: TestData) -> None:
    req = "simple @ " + path_to_url(shared_data.packages / "simple-2.0.tar.gz")
    assert req.startswith("simple @ file://")
    script.pip("install", req)
    result = script.pip("freeze")
    assert req in result.stdout
コード例 #16
0
ファイル: local_repos.py プロジェクト: uranusjr/pip
def local_checkout(
        remote_repo,  # type: str
        temp_path,  # type: Path
):
    # type: (...) -> str
    """
    :param temp_path: the return value of the tmpdir fixture, which is a
        temp directory Path object unique to each test function invocation,
        created as a sub directory of the base temp directory.
    """
    assert '+' in remote_repo
    vcs_name = remote_repo.split('+', 1)[0]
    repository_name = os.path.basename(remote_repo)

    directory = temp_path.joinpath('cache')
    repo_url_path = os.path.join(directory, repository_name)
    assert not os.path.exists(repo_url_path)

    if not os.path.exists(directory):
        os.mkdir(directory)

    if vcs_name == 'svn':
        assert repository_name == 'INITools'
        _create_svn_initools_repo(repo_url_path)
        repo_url_path = os.path.join(repo_url_path, 'trunk')
    else:
        vcs_backend = vcs.get_backend(vcs_name)
        vcs_backend.obtain(repo_url_path, url=hide_url(remote_repo))

    return '{}+{}'.format(vcs_name, path_to_url(repo_url_path))
コード例 #17
0
ファイル: local_repos.py プロジェクト: alquerci/pip
def _get_vcs_and_checkout_url(remote_repository, directory):
    vcs_classes = {'svn': subversion.Subversion,
                   'git': git.Git,
                   'bzr': bazaar.Bazaar,
                   'hg': mercurial.Mercurial}
    default_vcs = 'svn'
    if '+' not in remote_repository:
        remote_repository = '%s+%s' % (default_vcs, remote_repository)
    vcs, repository_path = remote_repository.split('+', 1)
    vcs_class = vcs_classes[vcs]
    branch = ''
    if vcs == 'svn':
        branch = os.path.basename(remote_repository)
        # remove the slash
        repository_name = os.path.basename(
            remote_repository[:-len(branch) - 1]
        )
    else:
        repository_name = os.path.basename(remote_repository)

    destination_path = os.path.join(directory, repository_name)
    if not os.path.exists(destination_path):
        vcs_class(remote_repository).obtain(destination_path)
    return '%s+%s' % (
        vcs,
        path_to_url('/'.join([directory, repository_name, branch])),
    )
コード例 #18
0
def test_new_resolver_handles_incompatible_wheel_tags_in_constraint_url(
        script, make_fake_wheel):
    initial_path = make_fake_wheel("base", "0.1.0", "fakepy1-fakeabi-fakeplat")

    constrained = script.scratch_path / "constrained"
    constrained.mkdir()

    final_path = constrained / initial_path.name

    initial_path.rename(final_path)

    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text("base @ " + path_to_url(final_path))

    result = script.pip(
        "install",
        "--no-cache-dir",
        "--no-index",
        "-c",
        constraints_file,
        "base",
        expect_error=True,
    )

    assert (
        "Cannot install base because these package versions have conflicting "
        "dependencies.") in result.stderr, str(result)

    assert_not_installed(script, "base")
コード例 #19
0
def test_new_resolver_succeeds_on_matching_constraint_and_requirement(
        script, editable):
    if editable:
        source_dir = create_test_package_with_setup(script,
                                                    name="test_pkg",
                                                    version="0.1.0")
    else:
        source_dir = create_basic_wheel_for_package(
            script,
            "test_pkg",
            "0.1.0",
        )

    req_line = "test_pkg @ " + path_to_url(source_dir)

    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text(req_line)

    if editable:
        last_args = ("-e", source_dir)
    else:
        last_args = (req_line, )

    script.pip(
        "install",
        "--no-cache-dir",
        "--no-index",
        "-c",
        constraints_file,
        *last_args,
    )

    assert_installed(script, test_pkg="0.1.0")
    if editable:
        assert_editable(script, "test-pkg")
コード例 #20
0
def test_new_resolver_fails_on_needed_conflicting_constraints(script):
    version_1 = create_basic_wheel_for_package(
        script,
        "test_pkg",
        "0.1.0",
    )
    version_2 = create_basic_wheel_for_package(
        script,
        "test_pkg",
        "0.2.0",
    )

    constraints = [
        "test_pkg @ " + path_to_url(version_1),
        "test_pkg @ " + path_to_url(version_2),
    ]

    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text("\n".join(constraints))

    result = script.pip(
        "install",
        "--no-cache-dir",
        "--no-index",
        "--find-links",
        script.scratch_path,
        "-c",
        constraints_file,
        "test_pkg",
        expect_error=True,
    )

    assert (
        "Cannot install test_pkg because these package versions have conflicting "
        "dependencies.") in result.stderr, str(result)

    assert_not_installed(script, "test_pkg")

    # Assert that pip works properly in the absence of the constraints file.
    script.pip(
        "install",
        "--no-cache-dir",
        "--no-index",
        "--find-links",
        script.scratch_path,
        "test_pkg",
    )
コード例 #21
0
ファイル: test_install_reqs.py プロジェクト: jonparrott/pip
def test_install_with_extras_from_install(script, data):
    to_install = data.packages.join("LocalExtras")
    script.scratch_path.join("constraints.txt").write(
        "%s#egg=LocalExtras" % path_to_url(to_install)
    )
    result = script.pip_install_local(
        '-c', script.scratch_path / 'constraints.txt', 'LocalExtras[baz]')
    assert script.site_packages / 'singlemodule.py'in result.files_created
コード例 #22
0
def test_install_local_editable_with_subdirectory(script):
    version_pkg_path = _create_test_package_with_subdirectory(
        script, 'version_subdir')
    result = script.pip(
        'install', '-e', '%s#egg=version_subpkg&subdirectory=version_subdir' %
        ('git+%s' % path_to_url(version_pkg_path), ))

    result.assert_installed('version-subpkg', sub_dir='version_subdir')
コード例 #23
0
ファイル: test_index.py プロジェクト: Basis/pip
def test_sort_locations_file_not_find_link():
    """
    Test that a file:// url dir that's not a find-link, doesn't get a listdir run
    """
    index_url = path_to_url(os.path.join(tests_data, 'indexes', 'empty_with_pkg'))
    finder = PackageFinder([], [])
    files, urls = finder._sort_locations([index_url])
    assert urls and not files, "urls, but not files should have been found"
コード例 #24
0
def test_install_local_with_subdirectory(script):
    version_pkg_path = _create_test_package_with_subdirectory(
        script, 'version_subdir')
    result = script.pip(
        'install', '%s#egg=version_subpkg&subdirectory=version_subdir' %
        ('git+' + path_to_url(version_pkg_path), ))

    result.assert_installed('version_subpkg.py', editable=False)
コード例 #25
0
def test_constraints_constrain_to_local(script, data):
    to_install = data.src.join("singlemodule")
    script.scratch_path.join("constraints.txt").write("%s#egg=singlemodule" %
                                                      path_to_url(to_install))
    result = script.pip('install', '--no-index', '-f', data.find_links, '-c',
                        script.scratch_path / 'constraints.txt',
                        'singlemodule')
    assert 'Running setup.py install for singlemodule' in result.stdout
コード例 #26
0
def test_constrained_to_url_install_same_url(script, data):
    to_install = data.src.join("singlemodule")
    constraints = path_to_url(to_install) + "#egg=singlemodule"
    script.scratch_path.join("constraints.txt").write(constraints)
    result = script.pip('install', '--no-index', '-f', data.find_links, '-c',
                        script.scratch_path / 'constraints.txt', to_install)
    assert ('Running setup.py install for singlemodule'
            in result.stdout), str(result)
コード例 #27
0
def _test_install_editable_from_git(script, tmpdir, wheel):
    """Test cloning from Git."""
    if wheel:
        script.pip('install', 'wheel')
    pkg_path = _create_test_package(script, name='testpackage', vcs='git')
    args = ['install', '-e', 'git+%s#egg=testpackage' % path_to_url(pkg_path)]
    result = script.pip(*args, **{"expect_error": True})
    result.assert_installed('testpackage', with_files=['.git'])
コード例 #28
0
def test_install_with_extras_from_install(script, data):
    to_install = data.packages.joinpath("LocalExtras")
    script.scratch_path.joinpath("constraints.txt").write_text(
        "{url}#egg=LocalExtras".format(url=path_to_url(to_install)))
    result = script.pip_install_local('-c',
                                      script.scratch_path / 'constraints.txt',
                                      'LocalExtras[baz]')
    result.did_create(script.site_packages / 'singlemodule.py')
コード例 #29
0
def test_constraints_constrain_to_local_editable(script, data):
    to_install = data.src.joinpath("singlemodule")
    script.scratch_path.joinpath("constraints.txt").write_text(
        "-e {url}#egg=singlemodule".format(url=path_to_url(to_install)))
    result = script.pip('install', '--no-index', '-f', data.find_links, '-c',
                        script.scratch_path / 'constraints.txt',
                        'singlemodule')
    assert 'Running setup.py develop for singlemodule' in result.stdout
コード例 #30
0
def test_install_with_extras_from_install(script, data):
    to_install = data.packages.join("LocalExtras")
    script.scratch_path.join("constraints.txt").write("%s#egg=LocalExtras" %
                                                      path_to_url(to_install))
    result = script.pip_install_local('-c',
                                      script.scratch_path / 'constraints.txt',
                                      'LocalExtras[baz]')
    assert script.site_packages / 'singlemodule.py' in result.files_created
コード例 #31
0
def test_install_with_extras_from_constraints(script, data):
    to_install = data.packages.joinpath("LocalExtras")
    script.scratch_path.joinpath("constraints.txt").write_text(
        "%s#egg=LocalExtras[bar]" % path_to_url(to_install))
    result = script.pip_install_local('-c',
                                      script.scratch_path / 'constraints.txt',
                                      'LocalExtras')
    assert script.site_packages / 'simple' in result.files_created
コード例 #32
0
ファイル: test_install.py プロジェクト: rowhit/pip
def test_vcs_url_final_slash_normalization(script, tmpdir):
    """
    Test that presence or absence of final slash in VCS URL is normalized.
    """
    pkg_path = _create_test_package(script, name='testpackage', vcs='hg')
    args = ['install', '-e', 'hg+%s/#egg=testpackage' % path_to_url(pkg_path)]
    result = script.pip(*args, **{"expect_error": True})
    result.assert_installed('testpackage', with_files=['.hg'])
コード例 #33
0
def test_install_from_file_index_hash_link():
    """
    Test that a pkg can be installed from a file:// index using a link with a hash
    """
    env = reset_env()
    index_url = path_to_url(os.path.join(tests_data, 'indexes', 'simple'))
    result = run_pip('install', '-i', index_url, 'simple==1.0')
    egg_info_folder = env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
    assert egg_info_folder in result.files_created, str(result)
コード例 #34
0
def test_file_index_url_quoting():
    """
    Test url quoting of file index url with a space
    """
    index_url = path_to_url(os.path.join(tests_data, 'indexes', urllib.quote('in dex')))
    env = reset_env()
    result = run_pip('install', '-vvv', '--index-url', index_url, 'simple', expect_error=False)
    assert (env.site_packages/'simple') in result.files_created, str(result.stdout)
    assert (env.site_packages/'simple-1.0-py%s.egg-info' % pyversion) in result.files_created, str(result)
コード例 #35
0
def test_install_vcs_non_editable_direct_url(script, with_wheel):
    pkg_path = _create_test_package(script, name="testpkg")
    url = path_to_url(pkg_path)
    args = ["install", f"git+{url}#egg=testpkg"]
    result = script.pip(*args)
    direct_url = get_created_direct_url(result, "testpkg")
    assert direct_url
    assert direct_url.url == url
    assert direct_url.info.vcs == "git"
コード例 #36
0
ファイル: test_install_reqs.py プロジェクト: jonparrott/pip
def test_constrained_to_url_install_same_url(script, data):
    to_install = data.src.join("singlemodule")
    constraints = path_to_url(to_install) + "#egg=singlemodule"
    script.scratch_path.join("constraints.txt").write(constraints)
    result = script.pip(
        'install', '--no-index', '-f', data.find_links, '-c',
        script.scratch_path / 'constraints.txt', to_install)
    assert ('Running setup.py install for singlemodule'
            in result.stdout), str(result)
コード例 #37
0
ファイル: test_install_reqs.py プロジェクト: jonparrott/pip
def test_constraints_constrain_to_local(script, data):
    to_install = data.src.join("singlemodule")
    script.scratch_path.join("constraints.txt").write(
        "%s#egg=singlemodule" % path_to_url(to_install)
    )
    result = script.pip(
        'install', '--no-index', '-f', data.find_links, '-c',
        script.scratch_path / 'constraints.txt', 'singlemodule')
    assert 'Running setup.py install for singlemodule' in result.stdout
コード例 #38
0
ファイル: test_install_reqs.py プロジェクト: jonparrott/pip
def test_install_local_editable_with_subdirectory(script):
    version_pkg_path = _create_test_package_with_subdirectory(script,
                                                              'version_subdir')
    result = script.pip(
        'install', '-e',
        '%s#egg=version_subpkg&subdirectory=version_subdir' %
        ('git+%s' % path_to_url(version_pkg_path),)
    )

    result.assert_installed('version-subpkg', sub_dir='version_subdir')
コード例 #39
0
ファイル: test_install_reqs.py プロジェクト: jonparrott/pip
def test_install_local_with_subdirectory(script):
    version_pkg_path = _create_test_package_with_subdirectory(script,
                                                              'version_subdir')
    result = script.pip(
        'install',
        '%s#egg=version_subpkg&subdirectory=version_subdir' %
        ('git+' + path_to_url(version_pkg_path),)
    )

    result.assert_installed('version_subpkg.py', editable=False)
コード例 #40
0
ファイル: test_finder.py プロジェクト: Basis/pip
def test_finder_ignores_external_links():
    """
    Tests that PackageFinder ignores external links, with or without hashes.
    """
    req = InstallRequirement.from_line("bar", None)

    # using a local index
    index_url = path_to_url(os.path.join(tests_data, "indexes", "externals"))
    finder = PackageFinder([], [index_url])
    link = finder.find_requirement(req, False)
    assert link.filename == "bar-1.0.tar.gz"
コード例 #41
0
ファイル: test_finder.py プロジェクト: Basis/pip
def test_finder_finds_external_links_with_hashes_all():
    """
    Tests that PackageFinder finds external links but only if they have a hash
    using the all externals flag.
    """
    req = InstallRequirement.from_line("bar", None)

    # using a local index
    index_url = path_to_url(os.path.join(tests_data, "indexes", "externals"))
    finder = PackageFinder([], [index_url], allow_all_external=True)
    link = finder.find_requirement(req, False)
    assert link.filename == "bar-2.0.tar.gz"
コード例 #42
0
ファイル: test_finder.py プロジェクト: Basis/pip
def test_finder_installs_dev_releases():
    """
    Test PackageFinder finds dev releases if asked to.
    """

    req = InstallRequirement.from_line("bar", None, prereleases=True)

    # using a local index (that has dev releases)
    index_url = path_to_url(os.path.join(tests_data, 'indexes', 'dev'))
    finder = PackageFinder([], [index_url])
    link = finder.find_requirement(req, False)
    assert link.url.endswith("bar-2.0.dev1.tar.gz"), link.url
コード例 #43
0
ファイル: test_install_reqs.py プロジェクト: Basis/pip
def test_relative_requirements_file():
    """
    Test installing from a requirements file with a relative path with an egg= definition..

    """
    url = path_to_url(os.path.join(tests_data, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg'
    env = reset_env()
    write_file('file-egg-req.txt', textwrap.dedent("""\
        %s
        """ % url))
    result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
    assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
    assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
コード例 #44
0
ファイル: test_finder.py プロジェクト: Basis/pip
def test_finder_finds_external_links_without_hashes_per_project():
    """
    Tests that PackageFinder finds external links if they do not have a hash
    """
    req = InstallRequirement.from_line("bar==3.0", None)

    # using a local index
    index_url = path_to_url(os.path.join(tests_data, "indexes", "externals"))
    finder = PackageFinder([], [index_url],
                allow_external=["bar"],
                allow_insecure=["bar"],
            )
    link = finder.find_requirement(req, False)
    assert link.filename == "bar-3.0.tar.gz"
コード例 #45
0
ファイル: test_finder.py プロジェクト: Basis/pip
def test_finder_finds_external_links_without_hashes_scraped_per_project_all_insecure():
    """
    Tests that PackageFinder finds externally scraped links
    """
    req = InstallRequirement.from_line("bar", None)

    # using a local index
    index_url = path_to_url(os.path.join(tests_data, "indexes", "externals"))
    finder = PackageFinder([], [index_url],
                allow_external=["bar"],
                allow_all_insecure=True,
            )
    link = finder.find_requirement(req, False)
    assert link.filename == "bar-4.0.tar.gz"
コード例 #46
0
ファイル: test_yaml.py プロジェクト: akaihola/pip
def handle_install_request(script, requirement):
    assert isinstance(requirement, str), (
        "Need install requirement to be a string only"
    )
    result = script.pip(
        "install",
        "--no-index", "--find-links", path_to_url(script.scratch_path),
        requirement
    )

    retval = {}
    if result.returncode == 0:
        # Check which packages got installed
        retval["install"] = []

        for path in result.files_created:
            if path.endswith(".dist-info"):
                name, version = (
                    os.path.basename(path)[:-len(".dist-info")]
                ).rsplit("-", 1)

                # TODO: information about extras.

                retval["install"].append(" ".join((name, version)))

        retval["install"].sort()

        # TODO: Support checking uninstallations
        # retval["uninstall"] = []

    elif "conflicting" in result.stderr.lower():
        retval["conflicting"] = []

        message = result.stderr.rsplit("\n", 1)[-1]

        # XXX: There might be a better way than parsing the message
        for match in re.finditer(message, _conflict_finder_re):
            di = match.groupdict()
            retval["conflicting"].append(
                {
                    "required_by": "{} {}".format(di["name"], di["version"]),
                    "selector": di["selector"]
                }
            )

    return retval
コード例 #47
0
ファイル: test_install.py プロジェクト: alquerci/pip
def test_hashed_install_success(script, data, tmpdir):
    """
    Test that installing various sorts of requirements with correct hashes
    works.

    Test file URLs and index packages (which become HTTP URLs behind the
    scenes).

    """
    file_url = path_to_url(
        (data.packages / 'simple-1.0.tar.gz').abspath)
    with requirements_file(
            'simple2==1.0 --hash=sha256:9336af72ca661e6336eb87bc7de3e8844d853e'
            '3848c2b9bbd2e8bf01db88c2c7\n'
            '{simple} --hash=sha256:393043e672415891885c9a2a0929b1af95fb866d6c'
            'a016b42d2e6ce53619b653'.format(simple=file_url),
            tmpdir) as reqs_file:
        script.pip_install_local('-r', reqs_file.abspath, expect_error=False)
コード例 #48
0
ファイル: test_freeze.py プロジェクト: jaraco/pip
def test_freeze_with_requirement_option_file_url_egg_not_installed(script):
    """
    Test "freeze -r requirements.txt" with a local file URL whose egg name
    is not installed.
    """

    url = path_to_url('my-package.tar.gz') + '#egg=Does.Not-Exist'
    requirements_path = script.scratch_path.join('requirements.txt')
    requirements_path.write(url + '\n')

    result = script.pip(
        'freeze', '--requirement', 'requirements.txt', expect_stderr=True,
    )
    expected_err = (
        'Requirement file [requirements.txt] contains {}, but package '
        "'Does.Not-Exist' is not installed\n"
    ).format(url)
    assert result.stderr == expected_err
コード例 #49
0
ファイル: test_install_reqs.py プロジェクト: pypa/pip
def test_relative_requirements_file(script, data):
    """
    Test installing from a requirements file with a relative path with an
    egg= definition..

    """
    url = path_to_url(os.path.join(data.root, "packages", "..", "packages", "FSPkg")) + "#egg=FSPkg"
    script.scratch_path.join("file-egg-req.txt").write(
        textwrap.dedent(
            """\
        %s
        """
            % url
        )
    )
    result = script.pip("install", "-vvv", "-r", script.scratch_path / "file-egg-req.txt")
    assert (script.site_packages / "FSPkg-0.1.dev0-py%s.egg-info" % pyversion) in result.files_created, str(result)
    assert (script.site_packages / "fspkg") in result.files_created, str(result.stdout)
コード例 #50
0
ファイル: test_pep517.py プロジェクト: mkurnikov/pip
def test_conflicting_pep517_backend_requirements(script, tmpdir, data):
    project_dir = make_project(
        tmpdir, requires=['test_backend', 'simplewheel==1.0'],
        backend="test_backend"
    )
    project_dir.join("backend_reqs.txt").write("simplewheel==2.0")
    result = script.pip(
        'install', '--no-index',
        '-f', data.backends,
        '-f', data.packages,
        project_dir,
        expect_error=True
    )
    assert (
        result.returncode != 0 and
        ('Some build dependencies for %s conflict with the backend '
         'dependencies: simplewheel==1.0 is incompatible with '
         'simplewheel==2.0.' % path_to_url(project_dir)) in result.stderr
    ), str(result)
コード例 #51
0
ファイル: test_finder.py プロジェクト: Basis/pip
def test_finder_installs_pre_releases():
    """
    Test PackageFinder finds pre-releases if asked to.
    """

    req = InstallRequirement.from_line("bar", None, prereleases=True)

    # using a local index (that has pre & dev releases)
    index_url = path_to_url(os.path.join(tests_data, 'indexes', 'pre'))
    finder = PackageFinder([], [index_url])
    link = finder.find_requirement(req, False)
    assert link.url.endswith("bar-2.0b1.tar.gz"), link.url

    # using find-links
    links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
    finder = PackageFinder(links, [])
    link = finder.find_requirement(req, False)
    assert link.url == "https://foo/bar-2.0b1.tar.gz"
    links.reverse()
    finder = PackageFinder(links, [])
    link = finder.find_requirement(req, False)
    assert link.url == "https://foo/bar-2.0b1.tar.gz"
コード例 #52
0
ファイル: test_install.py プロジェクト: alquerci/pip
def test_install_editable_from_bazaar(script, tmpdir):
    """Test checking out from Bazaar."""
    pkg_path = _create_test_package(script, name='testpackage', vcs='bazaar')
    args = ['install', '-e', 'bzr+%s/#egg=testpackage' % path_to_url(pkg_path)]
    result = script.pip(*args, **{"expect_error": True})
    result.assert_installed('testpackage', with_files=['.bzr'])
コード例 #53
0
ファイル: test_install.py プロジェクト: alquerci/pip
def test_install_editable_from_hg(script, tmpdir):
    """Test cloning from Mercurial."""
    pkg_path = _create_test_package(script, name='testpackage', vcs='hg')
    args = ['install', '-e', 'hg+%s#egg=testpackage' % path_to_url(pkg_path)]
    result = script.pip(*args, **{"expect_error": True})
    result.assert_installed('testpackage', with_files=['.hg'])