Exemplo n.º 1
0
def unpack_url(link, location, download_dir=None,
               only_download=False, session=None):
    """Unpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion
    """
    # non-editable vcs urls
    if is_vcs_url(link):
        unpack_vcs_link(link, location, only_download)

    # file urls
    elif is_file_url(link):
        unpack_file_url(link, location, download_dir)
        if only_download:
            write_delete_marker_file(location)

    # http urls
    else:
        if session is None:
            session = PipSession()

        unpack_http_url(
            link,
            location,
            download_dir,
            session,
        )
        if only_download:
            write_delete_marker_file(location)
Exemplo n.º 2
0
def test_pip_wheel_fail_cause_of_previous_build_dir(script, data):
    """
    Test when 'pip wheel' tries to install a package that has a previous build
    directory
    """

    script.pip("install", "wheel")

    # Given that I have a previous build dir of the `simple` package
    build = script.venv_path / "build" / "simple"
    os.makedirs(build)
    write_delete_marker_file(script.venv_path / "build")
    build.join("setup.py").write("#")

    # When I call pip trying to install things again
    result = script.pip(
        "wheel",
        "--no-index",
        "--find-links=%s" % data.find_links,
        "--build",
        script.venv_path / "build",
        "simple==3.0",
        expect_error=True,
    )

    # Then I see that the error code is the right one
    assert result.returncode == PREVIOUS_BUILD_DIR_ERROR, result
Exemplo n.º 3
0
def test_pip_wheel_fail_cause_of_previous_build_dir(script, data):
    """
    Test when 'pip wheel' tries to install a package that has a previous build
    directory
    """

    script.pip('install', 'wheel')

    # Given that I have a previous build dir of the `simple` package
    build = script.venv_path / 'build' / 'simple'
    os.makedirs(build)
    write_delete_marker_file(script.venv_path / 'build')
    build.join('setup.py').write('#')

    # When I call pip trying to install things again
    result = script.pip(
        'wheel',
        '--no-index',
        '--find-links=%s' % data.find_links,
        '--build',
        script.venv_path / 'build',
        'simple==3.0',
        expect_error=True,
    )

    # Then I see that the error code is the right one
    assert result.returncode == PREVIOUS_BUILD_DIR_ERROR, result
Exemplo n.º 4
0
    def unpack_url(self, link, location, download_dir=None,
                   only_download=False):
        if download_dir is None:
            download_dir = self.download_dir

        # non-editable vcs urls
        if is_vcs_url(link):
            if only_download:
                loc = download_dir
            else:
                loc = location
            unpack_vcs_link(link, loc, only_download)

        # file urls
        elif is_file_url(link):
            unpack_file_url(link, location, download_dir)
            if only_download:
                write_delete_marker_file(location)

        # http urls
        else:
            unpack_http_url(
                link,
                location,
                self.download_cache,
                download_dir,
                self.session,
            )
            if only_download:
                write_delete_marker_file(location)
Exemplo n.º 5
0
def test_cleanup_prevented_upon_build_dir_exception(script, data):
    """
    Test no cleanup occurs after a PreviousBuildDirError
    """
    build = script.venv_path/'build'/'simple'
    os.makedirs(build)
    write_delete_marker_file(script.venv_path/'build')
    build.join("setup.py").write("#")
    result = script.pip('install', '-f', data.find_links, '--no-index', 'simple', expect_error=True)

    assert result.returncode == PREVIOUS_BUILD_DIR_ERROR
    assert "pip can't proceed" in result.stdout, result.stdout
    assert exists(build)
Exemplo n.º 6
0
def test_pip_wheel_fail_cause_of_previous_build_dir(script, data):
    """Test when 'pip wheel' tries to install a package that has a previous build directory"""

    script.pip('install', 'wheel')

    # Given that I have a previous build dir of the `simple` package
    build = script.venv_path / 'build' / 'simple'
    os.makedirs(build)
    write_delete_marker_file(script.venv_path / 'build')
    build.join('setup.py').write('#')

    # When I call pip trying to install things again
    result = script.pip('wheel', '--no-index', '--find-links=%s' % data.find_links, 'simple==3.0', expect_error=True)

    # Then I see that the error code is the right one
    assert result.returncode == PREVIOUS_BUILD_DIR_ERROR
Exemplo n.º 7
0
def test_cleanup_prevented_upon_build_dir_exception(script, data):
    """
    Test no cleanup occurs after a PreviousBuildDirError
    """
    build = script.venv_path / 'build'
    build_simple = build / 'simple'
    os.makedirs(build_simple)
    write_delete_marker_file(build)
    build_simple.join("setup.py").write("#")
    result = script.pip(
        'install', '-f', data.find_links, '--no-index', 'simple',
        '--build', build,
        expect_error=True,
    )

    assert result.returncode == PREVIOUS_BUILD_DIR_ERROR
    assert "pip can't proceed" in result.stdout, result.stdout
    assert exists(build_simple)
Exemplo n.º 8
0
def unpack_url(link,
               location,
               download_dir=None,
               only_download=False,
               session=None,
               hashes=None,
               progress_bar="on"):
    """Unpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    """
    # non-editable vcs urls
    if is_vcs_url(link):
        unpack_vcs_link(link, location)

    # file urls
    elif is_file_url(link):
        unpack_file_url(link, location, download_dir, hashes=hashes)

    # http urls
    else:
        if session is None:
            session = PipSession()

        unpack_http_url(link,
                        location,
                        download_dir,
                        session,
                        hashes=hashes,
                        progress_bar=progress_bar)
    if only_download:
        write_delete_marker_file(location)
Exemplo n.º 9
0
def unpack_url(link, location, download_dir=None,
               only_download=False, session=None, hashes=None,
               progress_bar="on"):
    """Unpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    """
    # non-editable vcs urls
    if is_vcs_url(link):
        unpack_vcs_link(link, location)

    # file urls
    elif is_file_url(link):
        unpack_file_url(link, location, download_dir, hashes=hashes)

    # http urls
    else:
        if session is None:
            session = PipSession()

        unpack_http_url(
            link,
            location,
            download_dir,
            session,
            hashes=hashes,
            progress_bar=progress_bar
        )
    if only_download:
        write_delete_marker_file(location)
Exemplo n.º 10
0
def _make_build_dir(build_dir):
    os.makedirs(build_dir)
    write_delete_marker_file(build_dir)
def _make_build_dir(build_dir):
    os.makedirs(build_dir)
    write_delete_marker_file(build_dir)
Exemplo n.º 12
0
    encodings = ['utf-8', locale.getpreferredencoding(False), 'latin1']
    for enc in encodings:
        try:
            data = data.decode(enc)
        except UnicodeDecodeError:
            continue
        break

    assert type(data) != bytes  # Latin1 should have worked.
    return data


def _make_build_dir(build_dir):
    os.makedirs(build_dir)
    write_delete_marker_file(build_dir)


class FakeFile(object):
    """Wrap a list of lines in an object with readline() to make
    ConfigParser happy."""
    def __init__(self, lines):
        self._gen = (l for l in lines)

    def readline(self):
        try:
            try:
                return next(self._gen)
            except NameError:
                return self._gen.next()
        except StopIteration:
Exemplo n.º 13
0
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion
    """
    # non-editable vcs urls
    if is_vcs_url(link):
        unpack_vcs_link(link, location, only_download)

    # file urls
    elif is_file_url(link):
        unpack_file_url(link, location, download_dir)
        if only_download:
            write_delete_marker_file(location)

    # http urls
    else:
        if session is None:
            session = PipSession()

        unpack_http_url(
            link,
            location,
            download_dir,
            session,
        )
        if only_download:
            write_delete_marker_file(location)