/home/lnzliplg/public_html/req.tar
req_set.py000064400000104036151733105630006570 0ustar00from __future__ import absolute_import

from collections import defaultdict
from itertools import chain
import logging
import os

from pip._vendor import pkg_resources
from pip._vendor import requests

from pip.compat import expanduser
from pip.download import (is_file_url, is_dir_url, is_vcs_url, url_to_path,
                          unpack_url)
from pip.exceptions import (InstallationError, BestVersionAlreadyInstalled,
                            DistributionNotFound, PreviousBuildDirError,
                            HashError, HashErrors, HashUnpinned,
                            DirectoryUrlHashUnsupported, VcsHashUnsupported,
                            UnsupportedPythonVersion)
from pip.req.req_install import InstallRequirement
from pip.utils import (
    display_path, dist_in_usersite, dist_in_install_path, ensure_dir,
    normalize_path)
from pip.utils.hashes import MissingHashes
from pip.utils.logging import indent_log
from pip.utils.packaging import check_dist_requires_python
from pip.vcs import vcs
from pip.wheel import Wheel

logger = logging.getLogger(__name__)


class Requirements(object):

    def __init__(self):
        self._keys = []
        self._dict = {}

    def keys(self):
        return self._keys

    def values(self):
        return [self._dict[key] for key in self._keys]

    def __contains__(self, item):
        return item in self._keys

    def __setitem__(self, key, value):
        if key not in self._keys:
            self._keys.append(key)
        self._dict[key] = value

    def __getitem__(self, key):
        return self._dict[key]

    def __repr__(self):
        values = ['%s: %s' % (repr(k), repr(self[k])) for k in self.keys()]
        return 'Requirements({%s})' % ', '.join(values)


class DistAbstraction(object):
    """Abstracts out the wheel vs non-wheel prepare_files logic.

    The requirements for anything installable are as follows:
     - we must be able to determine the requirement name
       (or we can't correctly handle the non-upgrade case).
     - we must be able to generate a list of run-time dependencies
       without installing any additional packages (or we would
       have to either burn time by doing temporary isolated installs
       or alternatively violate pips 'don't start installing unless
       all requirements are available' rule - neither of which are
       desirable).
     - for packages with setup requirements, we must also be able
       to determine their requirements without installing additional
       packages (for the same reason as run-time dependencies)
     - we must be able to create a Distribution object exposing the
       above metadata.
    """

    def __init__(self, req_to_install):
        self.req_to_install = req_to_install

    def dist(self, finder):
        """Return a setuptools Dist object."""
        raise NotImplementedError(self.dist)

    def prep_for_dist(self):
        """Ensure that we can get a Dist for this requirement."""
        raise NotImplementedError(self.dist)


def make_abstract_dist(req_to_install):
    """Factory to make an abstract dist object.

    Preconditions: Either an editable req with a source_dir, or satisfied_by or
    a wheel link, or a non-editable req with a source_dir.

    :return: A concrete DistAbstraction.
    """
    if req_to_install.editable:
        return IsSDist(req_to_install)
    elif req_to_install.link and req_to_install.link.is_wheel:
        return IsWheel(req_to_install)
    else:
        return IsSDist(req_to_install)


class IsWheel(DistAbstraction):

    def dist(self, finder):
        return list(pkg_resources.find_distributions(
            self.req_to_install.source_dir))[0]

    def prep_for_dist(self):
        # FIXME:https://github.com/pypa/pip/issues/1112
        pass


class IsSDist(DistAbstraction):

    def dist(self, finder):
        dist = self.req_to_install.get_dist()
        # FIXME: shouldn't be globally added:
        if dist.has_metadata('dependency_links.txt'):
            finder.add_dependency_links(
                dist.get_metadata_lines('dependency_links.txt')
            )
        return dist

    def prep_for_dist(self):
        self.req_to_install.run_egg_info()
        self.req_to_install.assert_source_matches_version()


class Installed(DistAbstraction):

    def dist(self, finder):
        return self.req_to_install.satisfied_by

    def prep_for_dist(self):
        pass


class RequirementSet(object):

    def __init__(self, build_dir, src_dir, download_dir, upgrade=False,
                 upgrade_strategy=None, ignore_installed=False, as_egg=False,
                 target_dir=None, ignore_dependencies=False,
                 force_reinstall=False, use_user_site=False, session=None,
                 pycompile=True, isolated=False, wheel_download_dir=None,
                 wheel_cache=None, require_hashes=False,
                 ignore_requires_python=False):
        """Create a RequirementSet.

        :param wheel_download_dir: Where still-packed .whl files should be
            written to. If None they are written to the download_dir parameter.
            Separate to download_dir to permit only keeping wheel archives for
            pip wheel.
        :param download_dir: Where still packed archives should be written to.
            If None they are not saved, and are deleted immediately after
            unpacking.
        :param wheel_cache: The pip wheel cache, for passing to
            InstallRequirement.
        """
        if session is None:
            raise TypeError(
                "RequirementSet() missing 1 required keyword argument: "
                "'session'"
            )

        self.build_dir = build_dir
        self.src_dir = src_dir
        # XXX: download_dir and wheel_download_dir overlap semantically and may
        # be combined if we're willing to have non-wheel archives present in
        # the wheelhouse output by 'pip wheel'.
        self.download_dir = download_dir
        self.upgrade = upgrade
        self.upgrade_strategy = upgrade_strategy
        self.ignore_installed = ignore_installed
        self.force_reinstall = force_reinstall
        self.requirements = Requirements()
        # Mapping of alias: real_name
        self.requirement_aliases = {}
        self.unnamed_requirements = []
        self.ignore_dependencies = ignore_dependencies
        self.ignore_requires_python = ignore_requires_python
        self.successfully_downloaded = []
        self.successfully_installed = []
        self.reqs_to_cleanup = []
        self.as_egg = as_egg
        self.use_user_site = use_user_site
        self.target_dir = target_dir  # set from --target option
        self.session = session
        self.pycompile = pycompile
        self.isolated = isolated
        if wheel_download_dir:
            wheel_download_dir = normalize_path(wheel_download_dir)
        self.wheel_download_dir = wheel_download_dir
        self._wheel_cache = wheel_cache
        self.require_hashes = require_hashes
        # Maps from install_req -> dependencies_of_install_req
        self._dependencies = defaultdict(list)

    def __str__(self):
        reqs = [req for req in self.requirements.values()
                if not req.comes_from]
        reqs.sort(key=lambda req: req.name.lower())
        return ' '.join([str(req.req) for req in reqs])

    def __repr__(self):
        reqs = [req for req in self.requirements.values()]
        reqs.sort(key=lambda req: req.name.lower())
        reqs_str = ', '.join([str(req.req) for req in reqs])
        return ('<%s object; %d requirement(s): %s>'
                % (self.__class__.__name__, len(reqs), reqs_str))

    def add_requirement(self, install_req, parent_req_name=None,
                        extras_requested=None):
        """Add install_req as a requirement to install.

        :param parent_req_name: The name of the requirement that needed this
            added. The name is used because when multiple unnamed requirements
            resolve to the same name, we could otherwise end up with dependency
            links that point outside the Requirements set. parent_req must
            already be added. Note that None implies that this is a user
            supplied requirement, vs an inferred one.
        :param extras_requested: an iterable of extras used to evaluate the
            environement markers.
        :return: Additional requirements to scan. That is either [] if
            the requirement is not applicable, or [install_req] if the
            requirement is applicable and has just been added.
        """
        name = install_req.name
        if not install_req.match_markers(extras_requested):
            logger.warning("Ignoring %s: markers '%s' don't match your "
                           "environment", install_req.name,
                           install_req.markers)
            return []

        # This check has to come after we filter requirements with the
        # environment markers.
        if install_req.link and install_req.link.is_wheel:
            wheel = Wheel(install_req.link.filename)
            if not wheel.supported():
                raise InstallationError(
                    "%s is not a supported wheel on this platform." %
                    wheel.filename
                )

        install_req.as_egg = self.as_egg
        install_req.use_user_site = self.use_user_site
        install_req.target_dir = self.target_dir
        install_req.pycompile = self.pycompile
        install_req.is_direct = (parent_req_name is None)

        if not name:
            # url or path requirement w/o an egg fragment
            self.unnamed_requirements.append(install_req)
            return [install_req]
        else:
            try:
                existing_req = self.get_requirement(name)
            except KeyError:
                existing_req = None
            if (parent_req_name is None and existing_req and not
                    existing_req.constraint and
                    existing_req.extras == install_req.extras and not
                    existing_req.req.specifier == install_req.req.specifier):
                raise InstallationError(
                    'Double requirement given: %s (already in %s, name=%r)'
                    % (install_req, existing_req, name))
            if not existing_req:
                # Add requirement
                self.requirements[name] = install_req
                # FIXME: what about other normalizations?  E.g., _ vs. -?
                if name.lower() != name:
                    self.requirement_aliases[name.lower()] = name
                result = [install_req]
            else:
                # Assume there's no need to scan, and that we've already
                # encountered this for scanning.
                result = []
                if not install_req.constraint and existing_req.constraint:
                    if (install_req.link and not (existing_req.link and
                       install_req.link.path == existing_req.link.path)):
                        self.reqs_to_cleanup.append(install_req)
                        raise InstallationError(
                            "Could not satisfy constraints for '%s': "
                            "installation from path or url cannot be "
                            "constrained to a version" % name)
                    # If we're now installing a constraint, mark the existing
                    # object for real installation.
                    existing_req.constraint = False
                    existing_req.extras = tuple(
                        sorted(set(existing_req.extras).union(
                               set(install_req.extras))))
                    logger.debug("Setting %s extras to: %s",
                                 existing_req, existing_req.extras)
                    # And now we need to scan this.
                    result = [existing_req]
                # Canonicalise to the already-added object for the backref
                # check below.
                install_req = existing_req
            if parent_req_name:
                parent_req = self.get_requirement(parent_req_name)
                self._dependencies[parent_req].append(install_req)
            return result

    def has_requirement(self, project_name):
        name = project_name.lower()
        if (name in self.requirements and
           not self.requirements[name].constraint or
           name in self.requirement_aliases and
           not self.requirements[self.requirement_aliases[name]].constraint):
            return True
        return False

    @property
    def has_requirements(self):
        return list(req for req in self.requirements.values() if not
                    req.constraint) or self.unnamed_requirements

    @property
    def is_download(self):
        if self.download_dir:
            self.download_dir = expanduser(self.download_dir)
            if os.path.exists(self.download_dir):
                return True
            else:
                logger.critical('Could not find download directory')
                raise InstallationError(
                    "Could not find or access download directory '%s'"
                    % display_path(self.download_dir))
        return False

    def get_requirement(self, project_name):
        for name in project_name, project_name.lower():
            if name in self.requirements:
                return self.requirements[name]
            if name in self.requirement_aliases:
                return self.requirements[self.requirement_aliases[name]]
        raise KeyError("No project with the name %r" % project_name)

    def uninstall(self, auto_confirm=False):
        for req in self.requirements.values():
            if req.constraint:
                continue
            req.uninstall(auto_confirm=auto_confirm)
            req.commit_uninstall()

    def prepare_files(self, finder):
        """
        Prepare process. Create temp directories, download and/or unpack files.
        """
        # make the wheelhouse
        if self.wheel_download_dir:
            ensure_dir(self.wheel_download_dir)

        # If any top-level requirement has a hash specified, enter
        # hash-checking mode, which requires hashes from all.
        root_reqs = self.unnamed_requirements + self.requirements.values()
        require_hashes = (self.require_hashes or
                          any(req.has_hash_options for req in root_reqs))
        if require_hashes and self.as_egg:
            raise InstallationError(
                '--egg is not allowed with --require-hashes mode, since it '
                'delegates dependency resolution to setuptools and could thus '
                'result in installation of unhashed packages.')

        # Actually prepare the files, and collect any exceptions. Most hash
        # exceptions cannot be checked ahead of time, because
        # req.populate_link() needs to be called before we can make decisions
        # based on link type.
        discovered_reqs = []
        hash_errors = HashErrors()
        for req in chain(root_reqs, discovered_reqs):
            try:
                discovered_reqs.extend(self._prepare_file(
                    finder,
                    req,
                    require_hashes=require_hashes,
                    ignore_dependencies=self.ignore_dependencies))
            except HashError as exc:
                exc.req = req
                hash_errors.append(exc)

        if hash_errors:
            raise hash_errors

    def _is_upgrade_allowed(self, req):
        return self.upgrade and (
            self.upgrade_strategy == "eager" or (
                self.upgrade_strategy == "only-if-needed" and req.is_direct
            )
        )

    def _check_skip_installed(self, req_to_install, finder):
        """Check if req_to_install should be skipped.

        This will check if the req is installed, and whether we should upgrade
        or reinstall it, taking into account all the relevant user options.

        After calling this req_to_install will only have satisfied_by set to
        None if the req_to_install is to be upgraded/reinstalled etc. Any
        other value will be a dist recording the current thing installed that
        satisfies the requirement.

        Note that for vcs urls and the like we can't assess skipping in this
        routine - we simply identify that we need to pull the thing down,
        then later on it is pulled down and introspected to assess upgrade/
        reinstalls etc.

        :return: A text reason for why it was skipped, or None.
        """
        # Check whether to upgrade/reinstall this req or not.
        req_to_install.check_if_exists()
        if req_to_install.satisfied_by:
            upgrade_allowed = self._is_upgrade_allowed(req_to_install)

            # Is the best version is installed.
            best_installed = False

            if upgrade_allowed:
                # For link based requirements we have to pull the
                # tree down and inspect to assess the version #, so
                # its handled way down.
                if not (self.force_reinstall or req_to_install.link):
                    try:
                        finder.find_requirement(
                            req_to_install, upgrade_allowed)
                    except BestVersionAlreadyInstalled:
                        best_installed = True
                    except DistributionNotFound:
                        # No distribution found, so we squash the
                        # error - it will be raised later when we
                        # re-try later to do the install.
                        # Why don't we just raise here?
                        pass

                if not best_installed:
                    # don't uninstall conflict if user install and
                    # conflict is not user install or conflict lives
                    # in a different path (/usr/lib vs /usr/local/lib/)
                    if not (self.use_user_site and not
                            dist_in_usersite(req_to_install.satisfied_by) or not
                            dist_in_install_path(req_to_install.satisfied_by)):
                        req_to_install.conflicts_with = \
                            req_to_install.satisfied_by
                    req_to_install.satisfied_by = None

            # Figure out a nice message to say why we're skipping this.
            if best_installed:
                skip_reason = 'already up-to-date'
            elif self.upgrade_strategy == "only-if-needed":
                skip_reason = 'not upgraded as not directly required'
            else:
                skip_reason = 'already satisfied'

            return skip_reason
        else:
            return None

    def _prepare_file(self,
                      finder,
                      req_to_install,
                      require_hashes=False,
                      ignore_dependencies=False):
        """Prepare a single requirements file.

        :return: A list of additional InstallRequirements to also install.
        """
        # Tell user what we are doing for this requirement:
        # obtain (editable), skipping, processing (local url), collecting
        # (remote url or package name)
        if req_to_install.constraint or req_to_install.prepared:
            return []

        req_to_install.prepared = True

        # ###################### #
        # # print log messages # #
        # ###################### #
        if req_to_install.editable:
            logger.info('Obtaining %s', req_to_install)
        else:
            # satisfied_by is only evaluated by calling _check_skip_installed,
            # so it must be None here.
            assert req_to_install.satisfied_by is None
            if not self.ignore_installed:
                skip_reason = self._check_skip_installed(
                    req_to_install, finder)

            if req_to_install.satisfied_by:
                assert skip_reason is not None, (
                    '_check_skip_installed returned None but '
                    'req_to_install.satisfied_by is set to %r'
                    % (req_to_install.satisfied_by,))
                logger.info(
                    'Requirement %s: %s', skip_reason,
                    req_to_install)
            else:
                if (req_to_install.link and
                        req_to_install.link.scheme == 'file'):
                    path = url_to_path(req_to_install.link.url)
                    logger.info('Processing %s', display_path(path))
                else:
                    logger.info('Collecting %s', req_to_install)

        with indent_log():
            # ################################ #
            # # vcs update or unpack archive # #
            # ################################ #
            if req_to_install.editable:
                if require_hashes:
                    raise InstallationError(
                        'The editable requirement %s cannot be installed when '
                        'requiring hashes, because there is no single file to '
                        'hash.' % req_to_install)
                req_to_install.ensure_has_source_dir(self.src_dir)
                req_to_install.update_editable(not self.is_download)
                abstract_dist = make_abstract_dist(req_to_install)
                abstract_dist.prep_for_dist()
                if self.is_download:
                    req_to_install.archive(self.download_dir)
                req_to_install.check_if_exists()
            elif req_to_install.satisfied_by:
                if require_hashes:
                    logger.debug(
                        'Since it is already installed, we are trusting this '
                        'package without checking its hash. To ensure a '
                        'completely repeatable environment, install into an '
                        'empty virtualenv.')
                abstract_dist = Installed(req_to_install)
            else:
                # @@ if filesystem packages are not marked
                # editable in a req, a non deterministic error
                # occurs when the script attempts to unpack the
                # build directory
                req_to_install.ensure_has_source_dir(self.build_dir)
                # If a checkout exists, it's unwise to keep going.  version
                # inconsistencies are logged later, but do not fail the
                # installation.
                # FIXME: this won't upgrade when there's an existing
                # package unpacked in `req_to_install.source_dir`
                if os.path.exists(
                        os.path.join(req_to_install.source_dir, 'setup.py')):
                    raise PreviousBuildDirError(
                        "pip can't proceed with requirements '%s' due to a"
                        " pre-existing build directory (%s). This is "
                        "likely due to a previous installation that failed"
                        ". pip is being responsible and not assuming it "
                        "can delete this. Please delete it and try again."
                        % (req_to_install, req_to_install.source_dir)
                    )
                req_to_install.populate_link(
                    finder,
                    self._is_upgrade_allowed(req_to_install),
                    require_hashes
                )
                # We can't hit this spot and have populate_link return None.
                # req_to_install.satisfied_by is None here (because we're
                # guarded) and upgrade has no impact except when satisfied_by
                # is not None.
                # Then inside find_requirement existing_applicable -> False
                # If no new versions are found, DistributionNotFound is raised,
                # otherwise a result is guaranteed.
                assert req_to_install.link
                link = req_to_install.link

                # Now that we have the real link, we can tell what kind of
                # requirements we have and raise some more informative errors
                # than otherwise. (For example, we can raise VcsHashUnsupported
                # for a VCS URL rather than HashMissing.)
                if require_hashes:
                    # We could check these first 2 conditions inside
                    # unpack_url and save repetition of conditions, but then
                    # we would report less-useful error messages for
                    # unhashable requirements, complaining that there's no
                    # hash provided.
                    if is_vcs_url(link):
                        raise VcsHashUnsupported()
                    elif is_file_url(link) and is_dir_url(link):
                        raise DirectoryUrlHashUnsupported()
                    if (not req_to_install.original_link and
                            not req_to_install.is_pinned):
                        # Unpinned packages are asking for trouble when a new
                        # version is uploaded. This isn't a security check, but
                        # it saves users a surprising hash mismatch in the
                        # future.
                        #
                        # file:/// URLs aren't pinnable, so don't complain
                        # about them not being pinned.
                        raise HashUnpinned()
                hashes = req_to_install.hashes(
                    trust_internet=not require_hashes)
                if require_hashes and not hashes:
                    # Known-good hashes are missing for this requirement, so
                    # shim it with a facade object that will provoke hash
                    # computation and then raise a HashMissing exception
                    # showing the user what the hash should be.
                    hashes = MissingHashes()

                try:
                    download_dir = self.download_dir
                    # We always delete unpacked sdists after pip ran.
                    autodelete_unpacked = True
                    if req_to_install.link.is_wheel \
                            and self.wheel_download_dir:
                        # when doing 'pip wheel` we download wheels to a
                        # dedicated dir.
                        download_dir = self.wheel_download_dir
                    if req_to_install.link.is_wheel:
                        if download_dir:
                            # When downloading, we only unpack wheels to get
                            # metadata.
                            autodelete_unpacked = True
                        else:
                            # When installing a wheel, we use the unpacked
                            # wheel.
                            autodelete_unpacked = False
                    unpack_url(
                        req_to_install.link, req_to_install.source_dir,
                        download_dir, autodelete_unpacked,
                        session=self.session, hashes=hashes)
                except requests.HTTPError as exc:
                    logger.critical(
                        'Could not install requirement %s because '
                        'of error %s',
                        req_to_install,
                        exc,
                    )
                    raise InstallationError(
                        'Could not install requirement %s because '
                        'of HTTP error %s for URL %s' %
                        (req_to_install, exc, req_to_install.link)
                    )
                abstract_dist = make_abstract_dist(req_to_install)
                abstract_dist.prep_for_dist()
                if self.is_download:
                    # Make a .zip of the source_dir we already created.
                    if req_to_install.link.scheme in vcs.all_schemes:
                        req_to_install.archive(self.download_dir)
                # req_to_install.req is only avail after unpack for URL
                # pkgs repeat check_if_exists to uninstall-on-upgrade
                # (#14)
                if not self.ignore_installed:
                    req_to_install.check_if_exists()
                if req_to_install.satisfied_by:
                    if self.upgrade or self.ignore_installed:
                        # don't uninstall conflict if user install and
                        # conflict is not user install or conflict lives
                        # in a different path (/usr/lib vs /usr/local/lib/)
                        if not (self.use_user_site and not
                                dist_in_usersite(
                                    req_to_install.satisfied_by) or not
                                dist_in_install_path(req_to_install.satisfied_by)):
                            req_to_install.conflicts_with = \
                                req_to_install.satisfied_by
                        req_to_install.satisfied_by = None
                    else:
                        logger.info(
                            'Requirement already satisfied (use '
                            '--upgrade to upgrade): %s',
                            req_to_install,
                        )

            # ###################### #
            # # parse dependencies # #
            # ###################### #
            dist = abstract_dist.dist(finder)
            try:
                check_dist_requires_python(dist)
            except UnsupportedPythonVersion as e:
                if self.ignore_requires_python:
                    logger.warning(e.args[0])
                else:
                    req_to_install.remove_temporary_source()
                    raise
            more_reqs = []

            def add_req(subreq, extras_requested):
                sub_install_req = InstallRequirement(
                    str(subreq),
                    req_to_install,
                    isolated=self.isolated,
                    wheel_cache=self._wheel_cache,
                )
                more_reqs.extend(self.add_requirement(
                    sub_install_req, req_to_install.name,
                    extras_requested=extras_requested))

            # We add req_to_install before its dependencies, so that we
            # can refer to it when adding dependencies.
            if not self.has_requirement(req_to_install.name):
                # 'unnamed' requirements will get added here
                self.add_requirement(req_to_install, None)

            if not ignore_dependencies:
                if (req_to_install.extras):
                    logger.debug(
                        "Installing extra requirements: %r",
                        ','.join(req_to_install.extras),
                    )
                missing_requested = sorted(
                    set(req_to_install.extras) - set(dist.extras)
                )
                for missing in missing_requested:
                    logger.warning(
                        '%s does not provide the extra \'%s\'',
                        dist, missing
                    )

                available_requested = sorted(
                    set(dist.extras) & set(req_to_install.extras)
                )
                for subreq in dist.requires(available_requested):
                    add_req(subreq, extras_requested=available_requested)

            # cleanup tmp src
            self.reqs_to_cleanup.append(req_to_install)

            if not req_to_install.editable and not req_to_install.satisfied_by:
                # XXX: --no-install leads this to report 'Successfully
                # downloaded' for only non-editable reqs, even though we took
                # action on them.
                self.successfully_downloaded.append(req_to_install)

        return more_reqs

    def cleanup_files(self):
        """Clean up files, remove builds."""
        logger.debug('Cleaning up...')
        with indent_log():
            for req in self.reqs_to_cleanup:
                req.remove_temporary_source()

    def _to_install(self):
        """Create the installation order.

        The installation order is topological - requirements are installed
        before the requiring thing. We break cycles at an arbitrary point,
        and make no other guarantees.
        """
        # The current implementation, which we may change at any point
        # installs the user specified things in the order given, except when
        # dependencies must come earlier to achieve topological order.
        order = []
        ordered_reqs = set()

        def schedule(req):
            if req.satisfied_by or req in ordered_reqs:
                return
            if req.constraint:
                return
            ordered_reqs.add(req)
            for dep in self._dependencies[req]:
                schedule(dep)
            order.append(req)
        for install_req in self.requirements.values():
            schedule(install_req)
        return order

    def install(self, install_options, global_options=(), *args, **kwargs):
        """
        Install everything in this set (after having downloaded and unpacked
        the packages)
        """
        to_install = self._to_install()

        if to_install:
            logger.info(
                'Installing collected packages: %s',
                ', '.join([req.name for req in to_install]),
            )

        with indent_log():
            for requirement in to_install:
                if requirement.conflicts_with:
                    logger.info(
                        'Found existing installation: %s',
                        requirement.conflicts_with,
                    )
                    with indent_log():
                        requirement.uninstall(auto_confirm=True)
                try:
                    requirement.install(
                        install_options,
                        global_options,
                        *args,
                        **kwargs
                    )
                except:
                    # if install did not succeed, rollback previous uninstall
                    if (requirement.conflicts_with and not
                            requirement.install_succeeded):
                        requirement.rollback_uninstall()
                    raise
                else:
                    if (requirement.conflicts_with and
                            requirement.install_succeeded):
                        requirement.commit_uninstall()
                requirement.remove_temporary_source()

        self.successfully_installed = to_install
__pycache__/req_file.cpython-36.opt-1.pyc000064400000020322151733105630014132 0ustar003

�Pf�.�@sxdZddlmZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlZddlmZddlmZddlmZdd	lmZdd
lmZdgZejdej�Zejd
�Zejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1gZ2ej3ej4ej5gZ6dd�e6D�Z7d dd�Z8dd�Z9d!dd�Z:dd�Z;dd�Z<dd�Z=dd�Z>dd�Z?dS)"z
Requirements file parsing
�)�absolute_importN)�parse)�filterfalse)�get_file_content)�InstallRequirement)�RequirementsFileParseError)�RemovedInPip10Warning)�
cmdoptions�parse_requirementsz^(http|https|file):z(^|\s)+#.*$cCsg|]}|�j�qS�)�dest)�.0�orr�/usr/lib/python3.6/req_file.py�
<listcomp>=srFccsp|dkrtd��t|||d�\}}t||�}	x>|	D]6\}
}t|||
||||||d�	}x|D]
}
|
VqZWq2WdS)a�Parse a requirements file and yield InstallRequirement instances.

    :param filename:    Path or url of requirements file.
    :param finder:      Instance of pip.index.PackageFinder.
    :param comes_from:  Origin description of requirements.
    :param options:     cli options.
    :param session:     Instance of pip.download.PipSession.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    :param wheel_cache: Instance of pip.wheel.WheelCache
    NzCparse_requirements() missing 1 required keyword argument: 'session')�
comes_from�session)�
constraint)�	TypeErrorr�
preprocess�process_line)�filename�finderr�optionsrr�wheel_cache�_�content�
lines_enum�line_number�lineZreq_iter�reqrrrr
@s



cCs.t|j�dd�}t|�}t|�}t||�}|S)z�Split, filter, and join lines, and return a line iterator

    :param content: the content of the requirements file
    :param options: cli options
    �)�start)�	enumerate�
splitlines�
join_lines�ignore_comments�
skip_regex)rrrrrrras

rc		cs
t�}	|	j�}
d|
_|r |j|
_t|�\}}tjdkr@|jd�}|	jt	j
|�|
�\}
}d|r`dnd||f}|r�|rz|jnd	}|r�tj
||
�i}x.tD]&}||
jkr�|
j|r�|
j|||<q�Wtj||||||d
�V�n(|
j�r&|r�|jnd	}|�r|jnd}tj|
jd|||||d�V�n�|
j�s6|
j�r�|
j�rN|
jd}d	}n|
jd}d
}tj|��rvtj||�}n"tj|��s�tjjtjj|�|�}t|||||||d�}	x|	D]}|V�q�W�n>|
j �r�|
j |_ �n*|�r|
j!�r�t"j#dt$�|
j%�r
t"j#dt$�|
j&�rt"j#dt$�|
j�r0|
jg|_'|
j(d	k�rPd	|_(t)j*j+|j�|
j,d
k�rbg|_'|
j-�rx|j'j.|
j-�|
j/�r�|
j/d}tjjtjj0|��}tjj||�}tjj1|��r�|}|j/j2|�|
j3�r�d
|_4|
j5�r�d
|_5|
j6�r|j7j.dd�|
j6D��dS)a#Process a single requirements line; This can result in creating/yielding
    requirements, or updating the finder.

    For lines that contain requirements, the only options that have an effect
    are from SUPPORTED_OPTIONS_REQ, and they are scoped to the
    requirement. Other options from SUPPORTED_OPTIONS may be present, but are
    ignored.

    For lines that do not contain requirements, the only options that have an
    effect are from SUPPORTED_OPTIONS. Options from SUPPORTED_OPTIONS_REQ may
    be present, but are ignored. These lines may contain multiple options
    (although our docs imply only one is supported), and all our parsed and
    affect the finder.

    :param constraint: If True, parsing a constraints file.
    :param options: OptionParser options that we may update
    N����utf8z%s %s (line %s)z-cz-rF)r�isolatedrrr)rr�default_vcsr,rT)rrz�--allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z�--allow-all-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z�--allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.css|]}d|dfVqdS)�*Nr)r
�hostrrr�	<genexpr>�szprocess_line.<locals>.<genexpr>)r(r)r*)8�build_parserZget_default_values�	index_urlZformat_control�break_args_options�sys�version_info�encode�
parse_args�shlex�splitZ
isolated_moder	Zcheck_install_build_global�SUPPORTED_OPTIONS_REQ_DEST�__dict__rZ	from_lineZ	editablesr-Z
from_editable�requirements�constraints�	SCHEME_RE�search�urllib_parseZurljoin�os�path�join�dirnamer
�require_hashes�allow_external�warnings�warnr�allow_all_externalZallow_unverifiedZ
index_urls�	use_wheel�pip�indexZfmt_ctl_no_use_wheel�no_indexZextra_index_urls�extend�
find_links�abspath�exists�append�preZallow_all_prereleases�process_dependency_linksZ
trusted_hostsZsecure_origins)rrrrrrrrr�parserZdefaultsZargs_strZoptions_strZoptsrZline_comes_fromr,Zreq_optionsrr-Zreq_pathZnested_constraintr �valueZreq_dirZrelative_to_reqs_filerrrrns�










rcCsh|jd�}g}|dd�}x8|D]0}|jd�s8|jd�r<Pq |j|�|jd�q Wdj|�dj|�fS)z�Break up the line into an args and options string.  We only want to shlex
    (and then optparse) the options, not the args.  args can contain markers
    which are corrupted by shlex.
    � N�-z--r)r9�
startswithrR�poprC)r�tokens�argsr�tokenrrrr3�s


r3cCsDtjdd�}tt}x|D]}|�}|j|�qWdd�}||_|S)z7
    Return a parser for parsing requirement lines
    F)Zadd_help_optioncSst|��dS)N)r)�self�msgrrr�parser_exitsz!build_parser.<locals>.parser_exit)�optparseZOptionParser�SUPPORTED_OPTIONS�SUPPORTED_OPTIONS_REQZ
add_option�exit)rUZoption_factoriesZoption_factoryZoptionr`rrrr1s
r1ccs�d}g}x�|D]x\}}|jd�s,tj|�rntj|�r>d|}|rb|j|�|dj|�fVg}q�||fVq|sv|}|j|jd��qW|r�|dj|�fVdS)z�Joins a line ending in '' with the previous line (except when following
    comments).  The joined line takes on the index of the first line.
    N�\rW�)�endswith�
COMMENT_RE�matchrRrC�strip)rZprimary_line_numberZnew_linerrrrrr%"s 

r%ccs8x2|D]*\}}tjd|�}|j�}|r||fVqWdS)z1
    Strips comments and filter empty lines.
    rfN)rh�subrj)rrrrrrr&?s
r&cs2|r
|jnd}|r.tj|��t�fdd�|�}|S)zs
    Skip lines that match '--skip-requirements-regex' pattern

    Note: the regex pattern is only built once
    Ncs�j|d�S)Nr!)r?)�e)�patternrr�<lambda>Tszskip_regex.<locals>.<lambda>)Zskip_requirements_regex�re�compiler)rrr'r)rmrr'Js

r')NNNNFN)NNNNNF)@�__doc__Z
__future__rrAror8r4rarGZpip._vendor.six.moves.urllibrr@Zpip._vendor.six.movesrrKZpip.downloadrZpip.req.req_installrZpip.exceptionsrZpip.utils.deprecationrr	�__all__rp�Ir>rhr=Zeditabler<rMr2rOZextra_index_urlrFrIZno_allow_externalZallow_unsafeZno_allow_unsaferJZno_use_wheelZalways_unzipZ	no_binaryZonly_binaryrSrTZtrusted_hostrErbZinstall_optionsZglobal_options�hashrcr:r
rrr3r1r%r&r'rrrr�<module>sn

 

__pycache__/req_uninstall.cpython-36.opt-1.pyc000064400000014171151733105640015232 0ustar003

�Pf��@s�ddlmZddlZddlZddlZddlmZmZmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZeje�ZGdd�de�ZGd	d
�d
e�ZdS)�)�absolute_importN)�uses_pycache�WINDOWS�cache_from_source)�UninstallationError)�rmtree�ask�is_local�renames�normalize_path)�
indent_logc@sZeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�Zdd�ZdS)�UninstallPathSetzMA set of file paths to be removed in the uninstallation of a
    requirement.cCs,t�|_t�|_i|_||_d|_g|_dS)N)�set�paths�_refuse�pth�dist�save_dir�_moved_paths)�selfr�r�#/usr/lib/python3.6/req_uninstall.py�__init__szUninstallPathSet.__init__cCst|�S)zs
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        )r	)r�pathrrr�
_permittedszUninstallPathSet._permittedcCs�tjj|�\}}tjjt|�tjj|��}tjj|�s:dS|j|�rR|jj	|�n|j
j	|�tjj|�ddkr�tr�|j	t
|��dS)N�z.py)�osr�split�joinr�normcase�existsrr�addr�splitextrr)rr�head�tailrrrr!#s
zUninstallPathSet.addcCsLt|�}|j|�r<||jkr*t|�|j|<|j|j|�n|jj|�dS)N)rrr�UninstallPthEntriesr!r)r�pth_file�entryrrr�add_pth6s

zUninstallPathSet.add_pthcs@t�}x4t|td�D]$�t�fdd�|D��s|j��qW|S)z�Compact a path set to contain the minimal number of paths
        necessary to contain all paths in the set. If /a/path/ and
        /a/path/to/a/file.txt are both in the set, leave only the
        shorter path.)�keycs4g|],}�j|�o.�t|jtjj��tjjk�qSr)�
startswith�len�rstriprr�sep)�.0Z	shortpath)rrr�
<listcomp>Gsz,UninstallPathSet.compact.<locals>.<listcomp>)r�sortedr+�anyr!)rrZshort_pathsr)rr�compact?s

zUninstallPathSet.compactcCs&tjj|jtjj|�djtjj��S)Nr)rrrr�
splitdrive�lstripr-)rrrrr�_stashMszUninstallPathSet._stashFcCs:|jstjd|jj�dStjd|jj|jj�t���t|j|j��}|rRd}n"x|D]}tj|�qXWt	dd
�}|j
r�tjd�x|j|j
�D]}tj|�q�W|dk�r,tjdd	d
�|_
x8|D]0}|j|�}tjd|�|jj|�t||�q�Wx|jj�D]}|j��qWtjd|jj|jj�WdQRXdS)z[Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True).z7Can't uninstall '%s'. No files were found to uninstall.NzUninstalling %s-%s:�yzProceed (y/n)? �nz.Not removing or modifying (outside of prefix):z
-uninstallzpip-)�suffix�prefixzRemoving file or directory %szSuccessfully uninstalled %s-%s)r6r7)r�logger�infor�project_name�versionrr0r2rr�tempfileZmkdtemprr5�debugr�appendr
r�values�remove)rZauto_confirmrZresponser�new_pathrrrrrBQs@







zUninstallPathSet.removecCs~|jdkrtjd|jj�dStjd|jj�x.|jD]$}|j|�}tjd|�t	||�q6Wx|j
j�D]}|j�qjWdS)z1Rollback the changes previously made by remove().Nz'Can't roll back %s; was not uninstalledFzRolling back uninstall of %szReplacing %s)
rr:�errorrr<r;rr5r?r
rrA�rollback)rrZtmp_pathrrrrrE{s


zUninstallPathSet.rollbackcCs$|jdk	r t|j�d|_g|_dS)z?Remove temporary save dir: rollback will no longer be possible.N)rrr)rrrr�commit�s

zUninstallPathSet.commitN)F)
�__name__�
__module__�__qualname__�__doc__rrr!r(r2r5rBrErFrrrrr
s	
*r
c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
r%cCs0tjj|�std|��||_t�|_d|_dS)Nz.Cannot remove entries from nonexistent file %s)rr�isfiler�filer�entries�_saved_lines)rr&rrrr�s
zUninstallPthEntries.__init__cCs>tjj|�}tr.tjj|�dr.|jdd�}|jj|�dS)Nr�\�/)rrrrr3�replacerMr!)rr'rrrr!�szUninstallPthEntries.addcCs�tjd|j�t|jd��}|j�}||_WdQRXtdd�|D��rLd}nd}xH|jD]>}y$tjd|�|j||j	d��WqXt
k
r�YqXXqXWt|jd	��}|j|�WdQRXdS)
NzRemoving pth entries from %s:�rbcss|]}d|kVqdS)s
Nr)r.�linerrr�	<genexpr>�sz-UninstallPthEntries.remove.<locals>.<genexpr>z
�
zRemoving entry: %szutf-8�wb)r:r?rL�open�	readlinesrNr1rMrB�encode�
ValueError�
writelines)r�fh�linesZendliner'rrrrB�s
zUninstallPthEntries.removec	CsR|jdkrtjd|j�dStjd|j�t|jd��}|j|j�WdQRXdS)Nz.Cannot roll back changes to %s, none were madeFz!Rolling %s back to previous staterVT)rNr:rDrLr?rWr[)rr\rrrrE�s

zUninstallPthEntries.rollbackN)rGrHrIrr!rBrErrrrr%�s	
r%)Z
__future__rZloggingrr>Z
pip.compatrrrZpip.exceptionsrZ	pip.utilsrrr	r
rZpip.utils.loggingrZ	getLoggerrGr:�objectr
r%rrrr�<module>s
__pycache__/__init__.cpython-36.pyc000064400000000603151733105640013145 0ustar003

�Pf�@sDddlmZddlmZddlmZmZddlmZdddd	gZ	d
S)�)�absolute_import�)�InstallRequirement)�RequirementSet�Requirements)�parse_requirementsrrrrN)
Z
__future__rZreq_installrZreq_setrrZreq_filer�__all__�r	r	�/usr/lib/python3.6/__init__.py�<module>s
__pycache__/req_install.cpython-36.opt-1.pyc000064400000071670151733105640014676 0ustar003

�Pf���@s0ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZmZddlmZddlmZdd	lmZmZdd
lmZddlmZmZ ddl!m"Z"ddl#Z$dd
l%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGddlHmIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddl#mVZVmWZWejXeY�ZZej[j\j]�Z^dd�Z_dd�Z`Gdd�dea�Zbd d!�Zcd$d"d#�ZddS)%�)�absolute_importN)�	sysconfig)�change_root)�
FeedParser)�
pkg_resources�six)�
specifiers)�Marker)�InvalidRequirement�Requirement)�canonicalize_name)�Version�parse)�configparser)�
native_str�
get_stdlib�WINDOWS)�is_url�url_to_path�path_to_url�is_archive_file)�InstallationError�UninstallationError)�bin_py�running_under_virtualenv�PIP_DELETE_MARKER_FILENAME�bin_user)�display_path�rmtree�ask_path_exists�
backup_dir�is_installable_dir�dist_in_usersite�dist_in_site_packages�dist_in_install_path�
egg_link_path�call_subprocess�read_text_file�FakeFile�_make_build_dir�
ensure_dir�get_installed_version�normalize_path�
dist_is_local)�Hashes)�RemovedInPip10Warning)�
indent_log)�SETUPTOOLS_SHIM)�open_spinner)�UninstallPathSet)�vcs)�move_wheel_files�WheelcCs6tjd|�}d}|r*|jd�}|jd�}n|}||fS)Nz^(.+)(\[[^\]]+\])$��)�re�match�group)�path�m�extrasZpath_no_extras�r?�!/usr/lib/python3.6/req_install.py�
_strip_extras9s
rAcCstdd�|D��S)Ncss|]}tj|�VqdS)N)rZ
safe_extra)�.0�extrar?r?r@�	<genexpr>Fsz_safe_extras.<locals>.<genexpr>)�set)r>r?r?r@�_safe_extrasEsrFc@s�eZdZdQdd�ZedRdd��ZedSdd	��Zd
d�Zdd
�Zdd�Z	e
dd��Ze
dd��Zdd�Z
dd�Zdd�Ze
dd��Ze
dd��Ze
dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zejd(�Ze
d)d*��Zd+d,�ZdTd-d.�ZdUd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!dVd9d:�Z"gdddfd;d<�Z#d=d>�Z$d?d@�Z%dAdB�Z&fdfdCdD�Z'dEdF�Z(e
dGdH��Z)dWdIdJ�Z*dKdL�Z+e
dMdN��Z,dXdOdP�Z-dS)Y�InstallRequirementNFTcsJf|_t�tj�r�yt���Wndtk
r�tjj�kr@d}n.d�krft	�fdd�t
D��rfd}ntj�}t
d�|f��YnXt�j�|_�|_||_|
|_||_||_||_||_|_||_|	dk	r�|	|_n�oވj|_d|_d|_d|_d|_d|_||_d|_ d|_!d|_"d|_#d|_$|�r.|ni|_%||_&d|_'|
|_(dS)Nz%It looks like a path. Does it exist ?�=c3s|]}|�kVqdS)Nr?)rB�op)�reqr?r@rDVsz.InstallRequirement.__init__.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s'
%sF))r>�
isinstancer�string_typesrr
�osr<�sep�any�	operators�	traceback�
format_excrrFrJ�
comes_from�
constraint�
source_dir�editable�_wheel_cache�link�
original_link�as_egg�markers�marker�_egg_info_path�satisfied_by�conflicts_with�_temp_build_dir�_ideal_build_dir�update�install_succeeded�uninstalled�nothing_to_uninstall�
use_user_site�
target_dir�options�	pycompileZprepared�isolated)�selfrJrSrUrVrXrZrbrir[rjrh�wheel_cacherT�add_msgr?)rJr@�__init__KsN zInstallRequirement.__init__cCspddlm}t||�\}	}
}|
jd�r0t|
�}nd}||	||d||
�|||rP|ni|d�	}
|dk	rlt|�|
_|
S)Nr)�Linkzfile:T)rUrVrXrTrjrhrl)�	pip.indexro�parse_editable�
startswithrrFr>)�cls�editable_reqrS�default_vcsrjrhrlrTro�name�urlZextras_overriderU�resr?r?r@�
from_editable�s 



z InstallRequirement.from_editablec
Cs�ddlm}t|�rd}nd}||krR|j|d�\}}	|	j�}	|	sHd}	qVt|	�}	nd}	|j�}d}
tjjtjj	|��}d}d}
t|�r�||�}n�t
|�\}}
tjj|�r�tjj|ks�|j
d�r�t|�s�td|��|t|��}n0t|��rtjj|��stjd	|�|t|��}|�r||jd
k�rPtjd|j��rP|ttjjtjj	|j����}|j�rtt|j�}d|j|jf}
n|j}
n|}
|�r�|ni}||
|||	||||d
�}|
�r�tt d|
�j!�|_!|S)z�Creates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.
        r)roz; �;r7N�.z;Directory %r is not installable. File 'setup.py' not found.zARequirement %r looks like a filename, but the file does not exist�filez\.\./z%s==%s)rXr[rjrhrlrT�placeholder)"rpror�split�stripr	rMr<�normpath�abspathrA�isdirrNrrr!rrr�isfile�logger�warning�schemer9�searchrw�is_wheelr6�filenamerv�version�egg_fragmentrFrr>)rsrvrSrjrhrlrTroZ
marker_sepr[rJr<rXr>�p�wheelrxr?r?r@�	from_line�sb





zInstallRequirement.from_linecCs�|jr(t|j�}|jr:|d|jj7}n|jr6|jjnd}|jdk	rX|dt|jj�7}|jr�t|jt	j
�rt|j}n
|jj�}|r�|d|7}|S)Nz from %sz in %sz
 (from %s))rJ�strrXrwr^r�locationrSrKrrL�	from_path)rk�srSr?r?r@�__str__�s


zInstallRequirement.__str__cCsd|jjt|�|jfS)Nz<%s object: %s editable=%r>)�	__class__�__name__r�rV)rkr?r?r@�__repr__szInstallRequirement.__repr__cCs^|jdkr|j||�|_|jdk	rZ|rZ|j}|jj|j|j�|_||jkrZtjd|j�dS)aEnsure that if a link can be found for this, that it is found.

        Note that self.link may still be None - if Upgrade is False and the
        requirement is already installed.

        If require_hashes is True, don't use the wheel cache, because cached
        wheels, always built locally, have different hashes than the files
        downloaded from the index server and thus throw false hash mismatches.
        Furthermore, cached wheels at present have undeterministic contents due
        to file modification times.
        NzUsing cached wheel link: %s)rXZfind_requirementrWZcached_wheelrvr��debug)rk�finderZupgradeZrequire_hashesZold_linkr?r?r@�
populate_link	s

z InstallRequirement.populate_linkcCs|jjS)N)rJ�	specifier)rkr?r?r@r�szInstallRequirement.specifiercCs$|j}t|�dko"tt|��jdkS)z�Return whether I am pinned to an exact version.

        For example, some-package==1.2 is pinned; some-package>1.2 is not.
        r7�==�===)r�r�)r��len�next�iter�operator)rkrr?r?r@�	is_pinned!szInstallRequirement.is_pinnedcCsR|jdkrdSt|j�}|jrNt|jtj�r4|j}n
|jj�}|rN|d|7}|S)Nz->)rJr�rSrKrrLr�)rkr�rSr?r?r@r�+s


zInstallRequirement.from_pathcCs�|jdk	r|jS|jdkr<tjjtjdd��|_||_|jS|jrN|j	j
�}n|j	}tjj|�sttj
d|�t|�tjj||�S)Nz-buildzpip-zCreating directory %s)r`rJrMr<�realpath�tempfile�mkdtemprarVrv�lower�existsr�r�r)�join)rk�	build_dirrvr?r?r@�build_location8s

z!InstallRequirement.build_locationcCs�|jdk	rdS|j}d|_|j|j�}tjj|�rBtdt|���t	j
d|t|�t|��tj||�||_d|_||_d|_
dS)a�Move self._temp_build_dir to self._ideal_build_dir/self.req.name

        For some requirements (e.g. a path to a directory), the name of the
        package is not available until we run egg_info, so the build_location
        will return a temporary directory and store the _ideal_build_dir.

        This is only called by self.egg_info_path to fix the temporary build
        directory.
        Nz<A package already exists in %s; please remove it to continuez,Moving package %s from %s to new location %s)rUr`r�rarMr<r�rrr�r��shutil�mover])rkZold_locationZnew_locationr?r?r@�_correct_build_locationSs"

z*InstallRequirement._correct_build_locationcCs |jdkrdSttj|jj��S)N)rJrrZ	safe_namerv)rkr?r?r@rvss
zInstallRequirement.namecCstjj|j|jr|jjpd�S)N�)rMr<r�rUrXZsubdirectory_fragment)rkr?r?r@�setup_py_diryszInstallRequirement.setup_py_dircCs|yddl}Wn:tk
rFtd�dkr.d}ntj�}td|��YnXtjj|j	d�}t
jrxt|t
j
�rx|jtj��}|S)Nr�
setuptoolszPlease install setuptools.zWCould not import setuptools which is required to install from a source distribution.
%szsetup.py)r��ImportErrorr+rQrRrrMr<r�r�r�PY2rKZ	text_type�encode�sys�getfilesystemencoding)rkr�rm�setup_pyr?r?r@r�szInstallRequirement.setup_pyc
CsP|jrtjd|j|j�ntjd|j|j�t��xt|j}tjd|g}|j	rZ|dg7}|dg}|j
rpg}n tjj
|jd�}t|�ddg}t|||jdd	d
�WdQRX|j�stt|j�d�t�r�d}nd
}tdj
|j�d||j�dg��|_|j�nDt|j�d�}t|jj�|k�rLtjd|j|j||j�t|�|_dS)Nz2Running setup.py (path:%s) egg_info for package %sz7Running setup.py (path:%s) egg_info for package from %sz-cz
--no-user-cfg�egg_infozpip-egg-infoz
--egg-baseFzpython setup.py egg_info)�cwd�show_stdoutZcommand_descr
z==z===r��NamezuRunning setup.py (path:%s) egg_info for package %s produced metadata for project name %s. Fix your #egg=%s fragments.)rvr�r�r�rXr0r1r��
executablerjrVrMr<r�r�r*r&rJrK�
parse_version�pkg_infor
rr�rr�)rk�scriptZbase_cmdZegg_info_cmdZegg_base_option�egg_info_dirrIZ
metadata_namer?r?r@�run_egg_info�sN




zInstallRequirement.run_egg_infocCsL|jdk	r&|jj|�sdS|jj|�S|j|�}tjj|�s@dSt|�}|S)N)r^�has_metadata�get_metadata�
egg_info_pathrMr<r�r')rkr��datar?r?r@�
egg_info_data�s

z InstallRequirement.egg_info_datacsf|jdk�rV|jr|j}ntjj|jd�}tj|�}|j�rg}x�tj|�D]�\�}}x t	j
D]}||kr^|j|�q^Wxjt|�D]^}tjj
tjj�|dd��s�tjjtjj�|dd��r�|j|�q�|dks�|dkr�|j|�q�W|j�fdd	�|D��qLWd
d	�|D�}|�s$td||f��t|�dk�rB|jd
d�d�tjj||d�|_tjj|j|�S)Nzpip-egg-info�bin�pythonZScriptsz
Python.exeZtestZtestscsg|]}tjj�|��qSr?)rMr<r�)rB�dir)�rootr?r@�
<listcomp>�sz4InstallRequirement.egg_info_path.<locals>.<listcomp>cSsg|]}|jd�r|�qS)z	.egg-info)�endswith)rB�fr?r?r@r��sz$No files/directories in %s (from %s)r7cSs(|jtjj�tjjr"|jtjj�p$dS)Nr)�countrMr<rN�altsep)�xr?r?r@�<lambda>
sz2InstallRequirement.egg_info_path.<locals>.<lambda>)�keyr)r]rVrUrMr<r�r��listdir�walkr4�dirnames�remove�list�lexistsr��extendrr��sort)rkr��base�	filenames�dirs�filesr�r?)r�r@r��s>
z InstallRequirement.egg_info_pathcCs@t�}|jd�}|s*tjdt|jd���|j|p4d�|j�S)NzPKG-INFOzNo PKG-INFO file found in %sr�)rr�r�r�rr�Zfeed�close)rkr�r�r?r?r@r�s
zInstallRequirement.pkg_infoz	\[(.*?)\]cCs
t|j�S)N)r+rv)rkr?r?r@�installed_version sz$InstallRequirement.installed_versioncCsL|j�d}|jjr2||jjkr2tjd||j�ntjdt|j�||�dS)Nr�z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)	r�rJr�r�r�r�r�rrU)rkr�r?r?r@�assert_source_matches_version$s
z0InstallRequirement.assert_source_matches_versioncCs�|jstjd|j�dS|jjdkr(dS|js2dS|jjjdd�\}}tj	|�}|r�||jj�}|rr|j
|j�q�|j|j�ndS)Nz>Cannot update repository at %s; repository location is unknownr|�+r7)rXr�r�rUr�rbrwr~r4�get_backend�obtainZexport)rkr��vc_typerw�backendZvcs_backendr?r?r@�update_editable5s"
z"InstallRequirement.update_editablecsT|j�std|jf��|jp"|j}t|j�}t|�sTtj	d|j
|tj�d|_
dS|t�krxtj	d|j
|�d|_
dSt|�}t|�}djtj|j��}|jo�tjj|j�}t|jdd�}|o�|jjd�o�|jj|��r�|j|j�|jd	��r2x�|jd	�j�D](}	tjj tjj!|j|	��}
|j|
��qWn�|jd
��r�|jd��rV|jd��ng�xj�fdd
�|jd
�j�D�D]J}tjj!|j|�}
|j|
�|j|
d�|j|
d�|j|
d��qxW�n$|�r�t"j#dj|j�t$�|j|�n�|jjd��rF|j|j�tjj%|j�d}tjj!tjj&|j�d�}
|j'|
d|�n�|�r~|jjd��r~x�t(j)j*|�D]}
|j|
��qhWnp|�r�t+|d��}tjj,|j-�j.��}WdQRX|j|�tjj!tjj&|�d�}
|j'|
|j�ntj/d||j�|jd��rb|j0d��rbxZ|j1d�D]L}t2|��r&t3}nt4}|jtjj!||��t5�r|jtjj!||�d��qW|jd��r@t6j7�r|i}ndd"i}t8j9f|�}|j:t;|j<d���|j=d��r@x�|j>d�D]�\}}t2|��r�t3}nt4}|jtjj!||��t5�r�|jtjj!||�d�|jtjj!||�d �|jtjj!||�d!��q�W|j?|�||_@dS)#a�
        Uninstall the distribution currently satisfying this requirement.

        Prompts before removing or modifying files unless
        ``auto_confirm`` is True.

        Refuses to delete or modify files outside of ``sys.prefix`` -
        thus uninstallation within a virtual environment can only
        modify that virtual environment, even if the virtualenv is
        linked to global site-packages.

        z.Cannot uninstall requirement %s, not installedz1Not uninstalling %s at %s, outside environment %sTNz<Not uninstalling %s at %s, as it is in the standard library.z{0}.egg-infor<z	.egg-infozinstalled-files.txtz
top_level.txtznamespace_packages.txtcsg|]}|r|�kr|�qSr?r?)rBr�)�
namespacesr?r@r��sz0InstallRequirement.uninstall.<locals>.<listcomp>z.pyz.pycz.pyoz�Uninstalling a distutils installed project ({0}) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.z.eggr7zeasy-install.pthz./z
.dist-info�rz)Not sure how to uninstall: %s - Check: %s�scriptsz.batzentry_points.txtZ
delimitersrHZconsole_scriptsz.exez
.exe.manifestz
-script.py)rH)A�check_if_existsrrvr^r_r,r�r-r��infor�r��prefixrerr3r%�formatrZto_filename�project_namer�rMr<r��getattrZ	_providerr��addr�r��
splitlinesr�r��warnings�warnr/r~�dirnameZadd_pth�pipr�Zuninstallation_paths�open�normcase�readlinerr�Zmetadata_isdirZmetadata_listdirr"rrrrr�rZSafeConfigParserZreadfpr(Zget_metadata_linesZhas_section�itemsr�rd)rkZauto_confirmZdistZ	dist_pathZpaths_to_removeZdevelop_egg_linkZdevelop_egg_link_egg_infoZegg_info_existsZdistutils_egg_infoZinstalled_filer<Z
top_level_pkgZeasy_install_eggZeasy_install_pthZfhZlink_pointerr�Zbin_dirrh�configrv�valuer?)r�r@�	uninstallRs�









zInstallRequirement.uninstallcCs$|jr|jj�ntjd|j�dS)Nz'Can't rollback %s, nothing uninstalled.)rdZrollbackr��errorrv)rkr?r?r@�rollback_uninstall�sz%InstallRequirement.rollback_uninstallcCs*|jr|jj�n|js&tjd|j�dS)Nz%Can't commit %s, nothing uninstalled.)rdZcommitrer�r�rv)rkr?r?r@�commit_uninstall�s
z#InstallRequirement.commit_uninstallcCs�d}d|j|j�df}tjj||�}tjj|�r�tdt|�d�}|dkrTd	}nj|dkrxtj	d
t|��tj
|�nF|dkr�t|�}tj	dt|�t|��tj
||�n|dkr�tjd�|�r�tj|dtjdd
�}tjjtjj|j��}x�tj|�D]�\}	}
}d|
k�r|
j
d�xR|
D]J}tjj|	|�}|j||�}
tj|jd|
d�}d|_|j|d��qWxL|D]D}|tk�r��qrtjj|	|�}|j||�}
|j||jd|
��qrW�q�W|j�tjdt|��dS)NTz	%s-%s.zipr�z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort �i�w�b�aFzDeleting %szBacking up %s to %sr7)Z
allowZip64zpip-egg-info�/i��r�zSaved %s)r�rrr���i�)rvr�rMr<r�r�rrr�r�r�r r�r�r��exit�zipfileZZipFileZZIP_DEFLATEDr�r�r�r��_clean_zip_nameZZipInfoZ
external_attrZwritestrr�writer�r�)rkr�Zcreate_archiveZarchive_nameZarchive_pathZresponseZ	dest_file�zipr��dirpathr�r�r�rvZzipdirr�r?r?r@�archivesV






"zInstallRequirement.archivecCs(|t|�dd�}|jtjjd�}|S)Nr7r)r��replacerMr<rN)rkrvr�r?r?r@r5sz"InstallRequirement._clean_zip_namecs0|sd}�jdk	r(t�fdd�|D��SdSdS)Nr�c3s|]}�jjd|i�VqdS)rCN)r[Zevaluate)rBrC)rkr?r@rDDsz3InstallRequirement.match_markers.<locals>.<genexpr>T)r�)r[rO)rkZextras_requestedr?)rkr@�
match_markers=s


z InstallRequirement.match_markersc,s`|jr|j|||d�dS|jr\tjj|j�}tjj||j�|j	|j�||d�d|_
dS||jjdg�7}||jjdg�7}|j
r�t|�dg}tjdd�}tjj|d	�}�z�|j||�|�}	d
|jf}
t|
��.}t��t|	||jd|d�WdQRXWdQRXtjj|��s(tjd
|�dSd|_
|j�r:dS�fdd�}t|��H}
x@|
D](}tjj|�}|jd��rV||�}P�qVWtj d|�dSWdQRXg}t|��P}
xH|
D]@}|j!�}tjj"|��r�|tjj#7}|j$tjj%||�|���q�WWdQRXtjj|d�}t|d��}
|
j&dj|�d�WdQRXWdtjj|��rRtj'|�t(|�XdS)N)r�)r�r��strip_file_prefixT�global_options�install_optionsz
--no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)r�r��spinnerzRecord file %s not foundcs(�dkstjj|�r|St�|�SdS)N)rMr<�isabsr)r<)r�r?r@�prepend_root~sz0InstallRequirement.install.<locals>.prepend_rootz	.egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr�
))rV�install_editabler�r�r�Z
wheel_versionrUZcheck_compatibilityrvr5rcrh�getrjr�r�r�rMr<r��get_install_argsr2r0r&r�r�r�r�rZr�r�r�r�rr�rN�append�relpathr	r�r)rkrrr�r�rr�Z
temp_location�record_filename�install_args�msgrrr��lineZ	directoryr�Z	new_linesr�Zinst_files_pathr?)r�r@�installIs~




"
zInstallRequirement.installcCs|jdkr|j|�|_|jS)aAEnsure that a source_dir is set.

        This will create a temporary build dir if the name of the requirement
        isn't known yet.

        :param parent_dir: The ideal pip parent_dir for the source_dir.
            Generally src_dir for editables and build_dir for sdists.
        :return: self.source_dir
        N)rUr�)rkZ
parent_dirr?r?r@�ensure_has_source_dir�s

z(InstallRequirement.ensure_has_source_dircCs�tjdg}|jd�|jt|j�|t|�dd|g7}|jsJ|dg7}|dk	r^|d|g7}|dk	rr|d|g7}|jr�|dg7}n
|d	g7}t�r�d
t	j
�}|dtjj
tjdd
||j�g7}|S)Nz-uz-crz--recordz#--single-version-externally-managedz--rootz--prefixz	--compilez--no-compiler�z--install-headers�includeZsite)r�r�rr1r�r�rZrirr�get_python_versionrMr<r�r�rv)rkrrr�r�rZ
py_ver_strr?r?r@r�s(



z#InstallRequirement.get_install_argscCsd|jr6tjjtjj|jt��r6tjd|j�t|j�d|_|j	rZtjj|j	�rZt|j	�d|_	dS)zVRemove the source files from this requirement, if they are marked
        for deletionzRemoving source in %sN)
rUrMr<r�r�rr�r�rr`)rkr?r?r@�remove_temporary_source�s

z*InstallRequirement.remove_temporary_sourcecCs�tjd|j�|jr"t|�dg}|r>dj|�g}t|�|}t��<ttj	dt
|jgt|�ddgt|�|jdd�WdQRXd	|_
dS)
NzRunning setup.py develop for %sz
--no-user-cfgz--prefix={0}z-cZdevelopz	--no-depsF)r�r�T)r�r�rvrjr�r�r0r&r�r�r1r�r�rc)rkrrr�Zprefix_paramr?r?r@r�s z#InstallRequirement.install_editablecCs�|jdkrdSyFtt|j��}d|_tjt|��|_|jrR|jrR|j|_d|_dSWn�tj	k
rjdStj
k
r�tj|jj�}|jr�t
|�r�||_q�t�r�t|�r�td|j|jf��nt|�r�||_YnXdS)z�Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        NFTzVWill not install to the user site because it will lack sys.path precedence to %s in %s)rJrr�r\rZget_distributionr^rVr_ZDistributionNotFoundZVersionConflictrvrfr"rr#rr�r�r$)rkZ	no_markerZ
existing_distr?r?r@r��s4

z"InstallRequirement.check_if_existscCs|jo|jjS)N)rXr�)rkr?r?r@r� szInstallRequirement.is_wheelcCs,t|j|j||j|j|||j|j|d�
dS)N)�user�homer�r�rirjr)r5rvrJrfrgrirj)rkZwheeldirr�r�rr?r?r@r5$s
z#InstallRequirement.move_wheel_filescCsX|jd�jd�}tjj|�}tj||�}tjjtjj|��d}tj	tjj|�||d�S)zAReturn a pkg_resources.Distribution built from self.egg_info_pathr�rr)r��metadata)
r��rstriprMr<r�rZPathMetadata�splitext�basenameZDistribution)rkr�Zbase_dirr&Z	dist_namer?r?r@�get_dist0s
zInstallRequirement.get_distcCst|jjdi��S)z�Return whether any known-good hashes are specified as options.

        These activate --require-hashes mode; hashes specified as part of a
        URL do not.

        �hashes)�boolrhr)rkr?r?r@�has_hash_options;sz#InstallRequirement.has_hash_optionscCsJ|jjdi�j�}|r|jn|j}|rB|jrB|j|jg�j|j�t	|�S)a�Return a hash-comparer that considers my option- and URL-based
        hashes to be known-good.

        Hashes in URLs--ones embedded in the requirements file, not ones
        downloaded from an index server--are almost peers with ones from
        flags. They satisfy --require-hashes (whether it was implicitly or
        explicitly activated) but do not activate it. md5 and sha224 are not
        allowed in flags, which should nudge people toward good algos. We
        always OR all hashes together, even ones from URLs.

        :param trust_internet: Whether to trust URL-based (#md5=...) hashes
            downloaded from the internet, as by populate_link()

        r+)
rhr�copyrXrY�hash�
setdefaultZ	hash_namerr.)rkZtrust_internetZgood_hashesrXr?r?r@r+Es

zInstallRequirement.hashes)NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NNN)T).r��
__module__�__qualname__rn�classmethodryr�r�r�r��propertyr�r�r�r�r�rvr�r�r�r�r�r�r9�compileZ_requirements_section_rer�r�r�r�r�r�rrrrr rr#rr�r�r5r*r-r+r?r?r?r@rGIs`
;M

 :6


$0
\
)

rGcCstjd|�}|r|jd�}|S)z2
        Strip req postfix ( -dev, 0.2, etc )
    z^(.*?)(?:-dev|-\d.*)$r7)r9r�r;)rJr:r?r?r@�_strip_postfix[s
r6cCs�ddlm}|}d}tjd|�}|r:|jd�}|jd�}n|}tjj|�rttjjtjj	|d��slt
d|��t|�}|j�j
d	�r�||�j}|r�||td
|j��jfS||dfSx,tD]$}|j�j
d|�r�d||f}Pq�Wd
|k�r|�r
tjdt�|d
|}nt
d|��|jd
d�dj�}	tj|	��s`d|dj	dd�tjD��d}
t
|
��||�j}|�sxt
d��|�s�t
d|��t|�|dfS)aParses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    r)roNz^(.+)(\[[^\]]+\])$r7r8zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:r}z%s:z%s+%sr�zD--default-vcs has been deprecated and will be removed in the future.zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+zFor --editable=%s only z, cSsg|]}|jd�qS)z+URL)rv)rBr�r?r?r@r��sz"parse_editable.<locals>.<listcomp>z is currently supportedz@Could not detect requirement name, please specify one with #egg=z@--editable=%s is not the right format; it must have #egg=Package)rpror9r:r;rMr<r�r�r�rrr�rrr�rr>r4r�r�r/r~r�Zbackendsr6)rtrurorwr>r=Z
url_no_extrasZpackage_nameZversion_controlr�Z
error_messager?r?r@rqgs`





rq)N)eZ
__future__rZloggingrMr9r�r�r�rQr�rZ	distutilsrZdistutils.utilrZemail.parserrZpip._vendorrrZpip._vendor.packagingrZpip._vendor.packaging.markersr	Z"pip._vendor.packaging.requirementsr
rZpip._vendor.packaging.utilsrZpip._vendor.packaging.versionr
rr�Zpip._vendor.six.movesrZ	pip.wheelr�Z
pip.compatrrrZpip.downloadrrrrZpip.exceptionsrrZ
pip.locationsrrrrZ	pip.utilsrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-Zpip.utils.hashesr.Zpip.utils.deprecationr/Zpip.utils.loggingr0Zpip.utils.setuptools_buildr1Zpip.utils.uir2Zpip.req.req_uninstallr3Zpip.vcsr4r5r6Z	getLoggerr�r�Z	SpecifierZ
_operators�keysrPrArF�objectrGr6rqr?r?r?r@�<module>s`L
__pycache__/req_uninstall.cpython-36.pyc000064400000014171151733105640014273 0ustar003

�Pf��@s�ddlmZddlZddlZddlZddlmZmZmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZeje�ZGdd�de�ZGd	d
�d
e�ZdS)�)�absolute_importN)�uses_pycache�WINDOWS�cache_from_source)�UninstallationError)�rmtree�ask�is_local�renames�normalize_path)�
indent_logc@sZeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�Zdd�ZdS)�UninstallPathSetzMA set of file paths to be removed in the uninstallation of a
    requirement.cCs,t�|_t�|_i|_||_d|_g|_dS)N)�set�paths�_refuse�pth�dist�save_dir�_moved_paths)�selfr�r�#/usr/lib/python3.6/req_uninstall.py�__init__szUninstallPathSet.__init__cCst|�S)zs
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        )r	)r�pathrrr�
_permittedszUninstallPathSet._permittedcCs�tjj|�\}}tjjt|�tjj|��}tjj|�s:dS|j|�rR|jj	|�n|j
j	|�tjj|�ddkr�tr�|j	t
|��dS)N�z.py)�osr�split�joinr�normcase�existsrr�addr�splitextrr)rr�head�tailrrrr!#s
zUninstallPathSet.addcCsLt|�}|j|�r<||jkr*t|�|j|<|j|j|�n|jj|�dS)N)rrr�UninstallPthEntriesr!r)r�pth_file�entryrrr�add_pth6s

zUninstallPathSet.add_pthcs@t�}x4t|td�D]$�t�fdd�|D��s|j��qW|S)z�Compact a path set to contain the minimal number of paths
        necessary to contain all paths in the set. If /a/path/ and
        /a/path/to/a/file.txt are both in the set, leave only the
        shorter path.)�keycs4g|],}�j|�o.�t|jtjj��tjjk�qSr)�
startswith�len�rstriprr�sep)�.0Z	shortpath)rrr�
<listcomp>Gsz,UninstallPathSet.compact.<locals>.<listcomp>)r�sortedr+�anyr!)rrZshort_pathsr)rr�compact?s

zUninstallPathSet.compactcCs&tjj|jtjj|�djtjj��S)Nr)rrrr�
splitdrive�lstripr-)rrrrr�_stashMszUninstallPathSet._stashFcCs:|jstjd|jj�dStjd|jj|jj�t���t|j|j��}|rRd}n"x|D]}tj|�qXWt	dd
�}|j
r�tjd�x|j|j
�D]}tj|�q�W|dk�r,tjdd	d
�|_
x8|D]0}|j|�}tjd|�|jj|�t||�q�Wx|jj�D]}|j��qWtjd|jj|jj�WdQRXdS)z[Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True).z7Can't uninstall '%s'. No files were found to uninstall.NzUninstalling %s-%s:�yzProceed (y/n)? �nz.Not removing or modifying (outside of prefix):z
-uninstallzpip-)�suffix�prefixzRemoving file or directory %szSuccessfully uninstalled %s-%s)r6r7)r�logger�infor�project_name�versionrr0r2rr�tempfileZmkdtemprr5�debugr�appendr
r�values�remove)rZauto_confirmrZresponser�new_pathrrrrrBQs@







zUninstallPathSet.removecCs~|jdkrtjd|jj�dStjd|jj�x.|jD]$}|j|�}tjd|�t	||�q6Wx|j
j�D]}|j�qjWdS)z1Rollback the changes previously made by remove().Nz'Can't roll back %s; was not uninstalledFzRolling back uninstall of %szReplacing %s)
rr:�errorrr<r;rr5r?r
rrA�rollback)rrZtmp_pathrrrrrE{s


zUninstallPathSet.rollbackcCs$|jdk	r t|j�d|_g|_dS)z?Remove temporary save dir: rollback will no longer be possible.N)rrr)rrrr�commit�s

zUninstallPathSet.commitN)F)
�__name__�
__module__�__qualname__�__doc__rrr!r(r2r5rBrErFrrrrr
s	
*r
c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
r%cCs0tjj|�std|��||_t�|_d|_dS)Nz.Cannot remove entries from nonexistent file %s)rr�isfiler�filer�entries�_saved_lines)rr&rrrr�s
zUninstallPthEntries.__init__cCs>tjj|�}tr.tjj|�dr.|jdd�}|jj|�dS)Nr�\�/)rrrrr3�replacerMr!)rr'rrrr!�szUninstallPthEntries.addcCs�tjd|j�t|jd��}|j�}||_WdQRXtdd�|D��rLd}nd}xH|jD]>}y$tjd|�|j||j	d��WqXt
k
r�YqXXqXWt|jd	��}|j|�WdQRXdS)
NzRemoving pth entries from %s:�rbcss|]}d|kVqdS)s
Nr)r.�linerrr�	<genexpr>�sz-UninstallPthEntries.remove.<locals>.<genexpr>z
�
zRemoving entry: %szutf-8�wb)r:r?rL�open�	readlinesrNr1rMrB�encode�
ValueError�
writelines)r�fh�linesZendliner'rrrrB�s
zUninstallPthEntries.removec	CsR|jdkrtjd|j�dStjd|j�t|jd��}|j|j�WdQRXdS)Nz.Cannot roll back changes to %s, none were madeFz!Rolling %s back to previous staterVT)rNr:rDrLr?rWr[)rr\rrrrE�s

zUninstallPthEntries.rollbackN)rGrHrIrr!rBrErrrrr%�s	
r%)Z
__future__rZloggingrr>Z
pip.compatrrrZpip.exceptionsrZ	pip.utilsrrr	r
rZpip.utils.loggingrZ	getLoggerrGr:�objectr
r%rrrr�<module>s
__pycache__/__init__.cpython-36.opt-1.pyc000064400000000603151733105640014104 0ustar003

�Pf�@sDddlmZddlmZddlmZmZddlmZdddd	gZ	d
S)�)�absolute_import�)�InstallRequirement)�RequirementSet�Requirements)�parse_requirementsrrrrN)
Z
__future__rZreq_installrZreq_setrrZreq_filer�__all__�r	r	�/usr/lib/python3.6/__init__.py�<module>s
__pycache__/req_file.cpython-36.pyc000064400000020322151733105650013175 0ustar003

�Pf�.�@sxdZddlmZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlZddlmZddlmZddlmZdd	lmZdd
lmZdgZejdej�Zejd
�Zejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1gZ2ej3ej4ej5gZ6dd�e6D�Z7d dd�Z8dd�Z9d!dd�Z:dd�Z;dd�Z<dd�Z=dd�Z>dd�Z?dS)"z
Requirements file parsing
�)�absolute_importN)�parse)�filterfalse)�get_file_content)�InstallRequirement)�RequirementsFileParseError)�RemovedInPip10Warning)�
cmdoptions�parse_requirementsz^(http|https|file):z(^|\s)+#.*$cCsg|]}|�j�qS�)�dest)�.0�orr�/usr/lib/python3.6/req_file.py�
<listcomp>=srFccsp|dkrtd��t|||d�\}}t||�}	x>|	D]6\}
}t|||
||||||d�	}x|D]
}
|
VqZWq2WdS)a�Parse a requirements file and yield InstallRequirement instances.

    :param filename:    Path or url of requirements file.
    :param finder:      Instance of pip.index.PackageFinder.
    :param comes_from:  Origin description of requirements.
    :param options:     cli options.
    :param session:     Instance of pip.download.PipSession.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    :param wheel_cache: Instance of pip.wheel.WheelCache
    NzCparse_requirements() missing 1 required keyword argument: 'session')�
comes_from�session)�
constraint)�	TypeErrorr�
preprocess�process_line)�filename�finderr�optionsrr�wheel_cache�_�content�
lines_enum�line_number�lineZreq_iter�reqrrrr
@s



cCs.t|j�dd�}t|�}t|�}t||�}|S)z�Split, filter, and join lines, and return a line iterator

    :param content: the content of the requirements file
    :param options: cli options
    �)�start)�	enumerate�
splitlines�
join_lines�ignore_comments�
skip_regex)rrrrrrras

rc		cs
t�}	|	j�}
d|
_|r |j|
_t|�\}}tjdkr@|jd�}|	jt	j
|�|
�\}
}d|r`dnd||f}|r�|rz|jnd	}|r�tj
||
�i}x.tD]&}||
jkr�|
j|r�|
j|||<q�Wtj||||||d
�V�n(|
j�r&|r�|jnd	}|�r|jnd}tj|
jd|||||d�V�n�|
j�s6|
j�r�|
j�rN|
jd}d	}n|
jd}d
}tj|��rvtj||�}n"tj|��s�tjjtjj|�|�}t|||||||d�}	x|	D]}|V�q�W�n>|
j �r�|
j |_ �n*|�r|
j!�r�t"j#dt$�|
j%�r
t"j#dt$�|
j&�rt"j#dt$�|
j�r0|
jg|_'|
j(d	k�rPd	|_(t)j*j+|j�|
j,d
k�rbg|_'|
j-�rx|j'j.|
j-�|
j/�r�|
j/d}tjjtjj0|��}tjj||�}tjj1|��r�|}|j/j2|�|
j3�r�d
|_4|
j5�r�d
|_5|
j6�r|j7j.dd�|
j6D��dS)a#Process a single requirements line; This can result in creating/yielding
    requirements, or updating the finder.

    For lines that contain requirements, the only options that have an effect
    are from SUPPORTED_OPTIONS_REQ, and they are scoped to the
    requirement. Other options from SUPPORTED_OPTIONS may be present, but are
    ignored.

    For lines that do not contain requirements, the only options that have an
    effect are from SUPPORTED_OPTIONS. Options from SUPPORTED_OPTIONS_REQ may
    be present, but are ignored. These lines may contain multiple options
    (although our docs imply only one is supported), and all our parsed and
    affect the finder.

    :param constraint: If True, parsing a constraints file.
    :param options: OptionParser options that we may update
    N����utf8z%s %s (line %s)z-cz-rF)r�isolatedrrr)rr�default_vcsr,rT)rrz�--allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z�--allow-all-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z�--allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.css|]}d|dfVqdS)�*Nr)r
�hostrrr�	<genexpr>�szprocess_line.<locals>.<genexpr>)r(r)r*)8�build_parserZget_default_values�	index_urlZformat_control�break_args_options�sys�version_info�encode�
parse_args�shlex�splitZ
isolated_moder	Zcheck_install_build_global�SUPPORTED_OPTIONS_REQ_DEST�__dict__rZ	from_lineZ	editablesr-Z
from_editable�requirements�constraints�	SCHEME_RE�search�urllib_parseZurljoin�os�path�join�dirnamer
�require_hashes�allow_external�warnings�warnr�allow_all_externalZallow_unverifiedZ
index_urls�	use_wheel�pip�indexZfmt_ctl_no_use_wheel�no_indexZextra_index_urls�extend�
find_links�abspath�exists�append�preZallow_all_prereleases�process_dependency_linksZ
trusted_hostsZsecure_origins)rrrrrrrrr�parserZdefaultsZargs_strZoptions_strZoptsrZline_comes_fromr,Zreq_optionsrr-Zreq_pathZnested_constraintr �valueZreq_dirZrelative_to_reqs_filerrrrns�










rcCsh|jd�}g}|dd�}x8|D]0}|jd�s8|jd�r<Pq |j|�|jd�q Wdj|�dj|�fS)z�Break up the line into an args and options string.  We only want to shlex
    (and then optparse) the options, not the args.  args can contain markers
    which are corrupted by shlex.
    � N�-z--r)r9�
startswithrR�poprC)r�tokens�argsr�tokenrrrr3�s


r3cCsDtjdd�}tt}x|D]}|�}|j|�qWdd�}||_|S)z7
    Return a parser for parsing requirement lines
    F)Zadd_help_optioncSst|��dS)N)r)�self�msgrrr�parser_exitsz!build_parser.<locals>.parser_exit)�optparseZOptionParser�SUPPORTED_OPTIONS�SUPPORTED_OPTIONS_REQZ
add_option�exit)rUZoption_factoriesZoption_factoryZoptionr`rrrr1s
r1ccs�d}g}x�|D]x\}}|jd�s,tj|�rntj|�r>d|}|rb|j|�|dj|�fVg}q�||fVq|sv|}|j|jd��qW|r�|dj|�fVdS)z�Joins a line ending in '' with the previous line (except when following
    comments).  The joined line takes on the index of the first line.
    N�\rW�)�endswith�
COMMENT_RE�matchrRrC�strip)rZprimary_line_numberZnew_linerrrrrr%"s 

r%ccs8x2|D]*\}}tjd|�}|j�}|r||fVqWdS)z1
    Strips comments and filter empty lines.
    rfN)rh�subrj)rrrrrrr&?s
r&cs2|r
|jnd}|r.tj|��t�fdd�|�}|S)zs
    Skip lines that match '--skip-requirements-regex' pattern

    Note: the regex pattern is only built once
    Ncs�j|d�S)Nr!)r?)�e)�patternrr�<lambda>Tszskip_regex.<locals>.<lambda>)Zskip_requirements_regex�re�compiler)rrr'r)rmrr'Js

r')NNNNFN)NNNNNF)@�__doc__Z
__future__rrAror8r4rarGZpip._vendor.six.moves.urllibrr@Zpip._vendor.six.movesrrKZpip.downloadrZpip.req.req_installrZpip.exceptionsrZpip.utils.deprecationrr	�__all__rp�Ir>rhr=Zeditabler<rMr2rOZextra_index_urlrFrIZno_allow_externalZallow_unsafeZno_allow_unsaferJZno_use_wheelZalways_unzipZ	no_binaryZonly_binaryrSrTZtrusted_hostrErbZinstall_optionsZglobal_options�hashrcr:r
rrr3r1r%r&r'rrrr�<module>sn

 

__pycache__/req_set.cpython-36.opt-1.pyc000064400000050573151733105650014023 0ustar003

�Pf��@s~ddlmZddlmZddlmZddlZddlZddlm	Z	ddlm
Z
ddlmZddl
mZmZmZmZmZdd	lmZmZmZmZmZmZmZmZmZmZdd
lmZddl m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ej0e1�Z2Gdd�de3�Z4Gdd�de3�Z5dd�Z6Gdd�de5�Z7Gdd�de5�Z8Gdd�de5�Z9Gdd�de3�Z:dS)�)�absolute_import)�defaultdict)�chainN)�
pkg_resources)�requests)�
expanduser)�is_file_url�
is_dir_url�
is_vcs_url�url_to_path�
unpack_url)
�InstallationError�BestVersionAlreadyInstalled�DistributionNotFound�PreviousBuildDirError�	HashError�
HashErrors�HashUnpinned�DirectoryUrlHashUnsupported�VcsHashUnsupported�UnsupportedPythonVersion)�InstallRequirement)�display_path�dist_in_usersite�dist_in_install_path�
ensure_dir�normalize_path)�
MissingHashes)�
indent_log)�check_dist_requires_python)�vcs)�Wheelc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�RequirementscCsg|_i|_dS)N)�_keys�_dict)�self�r&�/usr/lib/python3.6/req_set.py�__init__"szRequirements.__init__cCs|jS)N)r#)r%r&r&r'�keys&szRequirements.keyscs�fdd��jD�S)Ncsg|]}�j|�qSr&)r$)�.0�key)r%r&r'�
<listcomp>*sz'Requirements.values.<locals>.<listcomp>)r#)r%r&)r%r'�values)szRequirements.valuescCs
||jkS)N)r#)r%�itemr&r&r'�__contains__,szRequirements.__contains__cCs$||jkr|jj|�||j|<dS)N)r#�appendr$)r%r+�valuer&r&r'�__setitem__/s
zRequirements.__setitem__cCs
|j|S)N)r$)r%r+r&r&r'�__getitem__4szRequirements.__getitem__cs$�fdd��j�D�}ddj|�S)Ncs$g|]}dt|�t�|�f�qS)z%s: %s)�repr)r*�k)r%r&r'r,8sz)Requirements.__repr__.<locals>.<listcomp>zRequirements({%s})z, )r)�join)r%r-r&)r%r'�__repr__7szRequirements.__repr__N)
�__name__�
__module__�__qualname__r(r)r-r/r2r3r7r&r&r&r'r" sr"c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�DistAbstractionatAbstracts out the wheel vs non-wheel prepare_files logic.

    The requirements for anything installable are as follows:
     - we must be able to determine the requirement name
       (or we can't correctly handle the non-upgrade case).
     - we must be able to generate a list of run-time dependencies
       without installing any additional packages (or we would
       have to either burn time by doing temporary isolated installs
       or alternatively violate pips 'don't start installing unless
       all requirements are available' rule - neither of which are
       desirable).
     - for packages with setup requirements, we must also be able
       to determine their requirements without installing additional
       packages (for the same reason as run-time dependencies)
     - we must be able to create a Distribution object exposing the
       above metadata.
    cCs
||_dS)N)�req_to_install)r%r<r&r&r'r(OszDistAbstraction.__init__cCst|j��dS)z Return a setuptools Dist object.N)�NotImplementedError�dist)r%�finderr&r&r'r>RszDistAbstraction.distcCst|j��dS)z3Ensure that we can get a Dist for this requirement.N)r=r>)r%r&r&r'�
prep_for_distVszDistAbstraction.prep_for_distN)r8r9r:�__doc__r(r>r@r&r&r&r'r;<sr;cCs0|jrt|�S|jr$|jjr$t|�St|�SdS)z�Factory to make an abstract dist object.

    Preconditions: Either an editable req with a source_dir, or satisfied_by or
    a wheel link, or a non-editable req with a source_dir.

    :return: A concrete DistAbstraction.
    N)�editable�IsSDist�link�is_wheel�IsWheel)r<r&r&r'�make_abstract_dist[s
rGc@seZdZdd�Zdd�ZdS)rFcCsttj|jj��dS)Nr)�listrZfind_distributionsr<�
source_dir)r%r?r&r&r'r>mszIsWheel.distcCsdS)Nr&)r%r&r&r'r@qszIsWheel.prep_for_distN)r8r9r:r>r@r&r&r&r'rFksrFc@seZdZdd�Zdd�ZdS)rCcCs(|jj�}|jd�r$|j|jd��|S)Nzdependency_links.txt)r<Zget_distZhas_metadataZadd_dependency_linksZget_metadata_lines)r%r?r>r&r&r'r>xs


zIsSDist.distcCs|jj�|jj�dS)N)r<Zrun_egg_infoZassert_source_matches_version)r%r&r&r'r@�s
zIsSDist.prep_for_distN)r8r9r:r>r@r&r&r&r'rCvs	rCc@seZdZdd�Zdd�ZdS)�	InstalledcCs|jjS)N)r<�satisfied_by)r%r?r&r&r'r>�szInstalled.distcCsdS)Nr&)r%r&r&r'r@�szInstalled.prep_for_distN)r8r9r:r>r@r&r&r&r'rJ�srJc@s�eZdZd$dd�Zdd�Zdd	�Zd%d
d�Zdd
�Zedd��Z	edd��Z
dd�Zd&dd�Zdd�Z
dd�Zdd�Zd'dd�Zdd�Zd d!�Zffd"d#�ZdS)(�RequirementSetFNTcCs�|dkrtd��||_||_||_||_||_||_|
|_t�|_	i|_
g|_|	|_||_
g|_g|_g|_||_||_||_||_|
|_||_|r�t|�}||_||_||_tt�|_dS)a3Create a RequirementSet.

        :param wheel_download_dir: Where still-packed .whl files should be
            written to. If None they are written to the download_dir parameter.
            Separate to download_dir to permit only keeping wheel archives for
            pip wheel.
        :param download_dir: Where still packed archives should be written to.
            If None they are not saved, and are deleted immediately after
            unpacking.
        :param wheel_cache: The pip wheel cache, for passing to
            InstallRequirement.
        Nz?RequirementSet() missing 1 required keyword argument: 'session')�	TypeError�	build_dir�src_dir�download_dir�upgrade�upgrade_strategy�ignore_installed�force_reinstallr"�requirements�requirement_aliases�unnamed_requirements�ignore_dependencies�ignore_requires_python�successfully_downloaded�successfully_installed�reqs_to_cleanup�as_egg�
use_user_site�
target_dir�session�	pycompile�isolatedr�wheel_download_dir�_wheel_cache�require_hashesrrH�
_dependencies)r%rNrOrPrQrRrSr]r_rXrTr^r`rarbrc�wheel_cachererYr&r&r'r(�s<zRequirementSet.__init__cCs8dd�|jj�D�}|jdd�d�djdd�|D��S)NcSsg|]}|js|�qSr&)Z
comes_from)r*�reqr&r&r'r,�sz*RequirementSet.__str__.<locals>.<listcomp>cSs
|jj�S)N)�name�lower)rhr&r&r'�<lambda>�sz(RequirementSet.__str__.<locals>.<lambda>)r+� cSsg|]}t|j��qSr&)�strrh)r*rhr&r&r'r,�s)rUr-�sortr6)r%�reqsr&r&r'�__str__�szRequirementSet.__str__cCsNdd�|jj�D�}|jdd�d�djdd�|D��}d|jjt|�|fS)	NcSsg|]}|�qSr&r&)r*rhr&r&r'r,�sz+RequirementSet.__repr__.<locals>.<listcomp>cSs
|jj�S)N)rirj)rhr&r&r'rk�sz)RequirementSet.__repr__.<locals>.<lambda>)r+z, cSsg|]}t|j��qSr&)rmrh)r*rhr&r&r'r,�sz"<%s object; %d requirement(s): %s>)rUr-rnr6�	__class__r8�len)r%roZreqs_strr&r&r'r7�s
zRequirementSet.__repr__c	
Cs�|j}|j|�s&tjd|j|j�gS|jrV|jjrVt|jj�}|j	�sVt
d|j��|j|_|j|_|j
|_
|j|_|dk|_|s�|jj|�|gSy|j|�}Wntk
r�d}YnX|dko�|o�|jo�|j|jko�|jj|jjk�rt
d|||f��|�s8||j|<|j�|k�r0||j|j�<|g}n�g}|j�r�|j�r�|j�r�|j�ol|jj|jjk�r�|jj|�t
d|��d|_ttt|j�j t|j����|_tj!d||j�|g}|}|�r�|j|�}|j"|j|�|SdS)a'Add install_req as a requirement to install.

        :param parent_req_name: The name of the requirement that needed this
            added. The name is used because when multiple unnamed requirements
            resolve to the same name, we could otherwise end up with dependency
            links that point outside the Requirements set. parent_req must
            already be added. Note that None implies that this is a user
            supplied requirement, vs an inferred one.
        :param extras_requested: an iterable of extras used to evaluate the
            environement markers.
        :return: Additional requirements to scan. That is either [] if
            the requirement is not applicable, or [install_req] if the
            requirement is applicable and has just been added.
        z6Ignoring %s: markers '%s' don't match your environmentz-%s is not a supported wheel on this platform.Nz5Double requirement given: %s (already in %s, name=%r)zhCould not satisfy constraints for '%s': installation from path or url cannot be constrained to a versionFzSetting %s extras to: %s)#riZ
match_markers�logger�warningZmarkersrDrEr!�filenameZ	supportedr
r]r^r_ra�	is_directrWr0�get_requirement�KeyError�
constraint�extrasrhZ	specifierrUrjrV�pathr\�tuple�sorted�set�union�debugrf)	r%�install_reqZparent_req_name�extras_requestedriZwheelZexisting_req�resultZ
parent_reqr&r&r'�add_requirement�sp






zRequirementSet.add_requirementcCsF|j�}||jkr |j|js>||jkrB|j|j|jrBdSdS)NTF)rjrUryrV)r%�project_namerir&r&r'�has_requirement4s

zRequirementSet.has_requirementcCstdd�|jj�D��p|jS)Ncss|]}|js|VqdS)N)ry)r*rhr&r&r'�	<genexpr>?sz2RequirementSet.has_requirements.<locals>.<genexpr>)rHrUr-rW)r%r&r&r'�has_requirements=szRequirementSet.has_requirementscCsD|jr@t|j�|_tjj|j�r$dStjd�tdt|j���dS)NTz!Could not find download directoryz0Could not find or access download directory '%s'F)	rPr�osr{�existsrs�criticalr
r)r%r&r&r'�is_downloadBs
zRequirementSet.is_downloadcCsTxB||j�fD]2}||jkr&|j|S||jkr|j|j|SqWtd|��dS)NzNo project with the name %r)rjrUrVrx)r%r�rir&r&r'rwOs


zRequirementSet.get_requirementcCs4x.|jj�D] }|jrq|j|d�|j�qWdS)N)�auto_confirm)rUr-ry�	uninstall�commit_uninstall)r%r�rhr&r&r'r�Ws
zRequirementSet.uninstallcCs�|jrt|j�|j|jj�}|jp6tdd�|D��}|rJ|jrJtd��g}t	�}xdt
||�D]V}y|j|j||||j
d��Wq`tk
r�}z||_|j|�WYdd}~Xq`Xq`W|r�|�dS)zY
        Prepare process. Create temp directories, download and/or unpack files.
        css|]}|jVqdS)N)Zhas_hash_options)r*rhr&r&r'r�jsz/RequirementSet.prepare_files.<locals>.<genexpr>z�--egg is not allowed with --require-hashes mode, since it delegates dependency resolution to setuptools and could thus result in installation of unhashed packages.)rerXN)rcrrWrUr-re�anyr]r
rr�extend�
_prepare_filerXrrhr0)r%r?Z	root_reqsreZdiscovered_reqsZhash_errorsrh�excr&r&r'�
prepare_files^s,

 zRequirementSet.prepare_filescCs |jo|jdkp|jdko|jS)NZeagerzonly-if-needed)rQrRrv)r%rhr&r&r'�_is_upgrade_allowed�s
z"RequirementSet._is_upgrade_allowedcCs�|j�|jr�|j|�}d}|r�|jp*|jshy|j||�Wn*tk
rTd}Yntk
rfYnX|s�|jr~t	|j�p�t
|j�s�|j|_d|_|r�d}n|jdkr�d}nd}|SdSdS)aCheck if req_to_install should be skipped.

        This will check if the req is installed, and whether we should upgrade
        or reinstall it, taking into account all the relevant user options.

        After calling this req_to_install will only have satisfied_by set to
        None if the req_to_install is to be upgraded/reinstalled etc. Any
        other value will be a dist recording the current thing installed that
        satisfies the requirement.

        Note that for vcs urls and the like we can't assess skipping in this
        routine - we simply identify that we need to pull the thing down,
        then later on it is pulled down and introspected to assess upgrade/
        reinstalls etc.

        :return: A text reason for why it was skipped, or None.
        FTNzalready up-to-datezonly-if-neededz%not upgraded as not directly requiredzalready satisfied)
�check_if_existsrKr�rTrDZfind_requirementrrr^rr�conflicts_withrR)r%r<r?Zupgrade_allowedZbest_installed�skip_reasonr&r&r'�_check_skip_installed�s4

z$RequirementSet._check_skip_installedc(st�js�jrgSd�_�jr*tjd��nd�js<�j�|�}�jrRtjd|��n<�jr��jj	dkr�t
�jj�}tjdt|��ntjd��t
�����jr�|r�td����j�j��j�j�t��}|j��jr�j�j��j��n$�j�r|�rtjd�t��}�n�j�j�tjjtjj�jd	���rRt d
��jf���j!|�j"��|��j}|�r�t#|��r�t$��nt%|��r�t&|��r�t'���j(�r��j)�r�t*���j+|d�}	|�r�|	�r�t,�}	yZ�j}
d}�jj-�r��j.�r��j.}
�jj-�r|
�rd}nd}t/�j�j|
|�j0|	d
�WnHt1j2k
�r|}z(tj3d�|�td�|�jf��WYdd}~XnXt��}|j��j�r��jj	t4j5k�r��j�j��j�sˆj��j�r�j6�sڈj�r�j7�r�t8�j��p�t9�j��s�j�_:d�_ntjd��|j;|�}
yt<|
�WnHt=k
�rx}z*�j>�r^tj?|j@d�n
�jA��WYdd}~XnXg����fdd�}�jB�jC��s��jD�d�|�s:�jE�r�tjddj�jE��tFtG�jE�tG|
jE��}x|D]}tj?d|
|��q�WtFtG|
jE�tG�jE�@�}x |
jH|�D]}|||d��q$W�jIjJ���j�rf�j�rf�jKjJ��WdQRX�S)zxPrepare a single requirements file.

        :return: A list of additional InstallRequirements to also install.
        TzObtaining %szRequirement %s: %s�filez
Processing %sz
Collecting %szoThe editable requirement %s cannot be installed when requiring hashes, because there is no single file to hash.z�Since it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.zsetup.pyz�pip can't proceed with requirements '%s' due to a pre-existing build directory (%s). This is likely due to a previous installation that failed. pip is being responsible and not assuming it can delete this. Please delete it and try again.)Ztrust_internetF)r`�hashesz4Could not install requirement %s because of error %szDCould not install requirement %s because of HTTP error %s for URL %sNz<Requirement already satisfied (use --upgrade to upgrade): %srcs4tt|���j�jd�}�j�j|�j|d��dS)N)rbrg)r�)rrmrbrdr�r�ri)�subreqr�Zsub_install_req)�	more_reqsr<r%r&r'�add_req�s
z-RequirementSet._prepare_file.<locals>.add_reqz!Installing extra requirements: %r�,z"%s does not provide the extra '%s')r�)LryZpreparedrBrs�inforSr�rKrD�schemerZurlrrr
Zensure_has_source_dirrOZupdate_editabler�rGr@�archiverPr�r�rJrNr�r{r�r6rIrZ
populate_linkr�r
rrr	rZ
original_linkZ	is_pinnedrr�rrErcrr`rZ	HTTPErrorr�r Zall_schemesrQr^rrr�r>rrrYrt�args�remove_temporary_sourcer�rir�rzr}r~Zrequiresr\r0rZ)r%r?r<rerXr�r{Z
abstract_distrDr�rPZautodelete_unpackedr�r>�er�Zmissing_requestedZmissingZavailable_requestedr�r&)r�r<r%r'r��s







"


zRequirementSet._prepare_filec	Cs8tjd�t��x|jD]}|j�qWWdQRXdS)zClean up files, remove builds.zCleaning up...N)rsr�rr\r�)r%rhr&r&r'�
cleanup_files�s
zRequirementSet.cleanup_filescs<g�t������fdd��x�jj�D]}�|�q(W�S)z�Create the installation order.

        The installation order is topological - requirements are installed
        before the requiring thing. We break cycles at an arbitrary point,
        and make no other guarantees.
        csP|js|�krdS|jrdS�j|�x�j|D]}�|�q2W�j|�dS)N)rKry�addrfr0)rhZdep)�order�ordered_reqs�scheduler%r&r'r��s
z,RequirementSet._to_install.<locals>.schedule)r~rUr-)r%r�r&)r�r�r�r%r'�_to_install�s
	zRequirementSet._to_installcOs�|j�}|r(tjddjdd�|D���t���x�|D]�}|jrltjd|j�t��|jdd�WdQRXy|j||f|�|�Wn$|jr�|jr�|j	��YnX|jr�|jr�|j
�|j�q6WWdQRX||_dS)	zl
        Install everything in this set (after having downloaded and unpacked
        the packages)
        z!Installing collected packages: %sz, cSsg|]
}|j�qSr&)ri)r*rhr&r&r'r,sz*RequirementSet.install.<locals>.<listcomp>zFound existing installation: %sT)r�N)
r�rsr�r6rr�r��installZinstall_succeededZrollback_uninstallr�r�r[)r%Zinstall_optionsZglobal_optionsr��kwargsZ
to_installZrequirementr&r&r'r��s:

zRequirementSet.install)FNFFNFFFNTFNNFF)NN)F)FF)r8r9r:r(rpr7r�r��propertyr�r�rwr�r�r�r�r�r�r�r�r&r&r&r'rL�s4
4
[	

'E
	rL);Z
__future__r�collectionsr�	itertoolsrZloggingr�Zpip._vendorrrZ
pip.compatrZpip.downloadrr	r
rrZpip.exceptionsr
rrrrrrrrrZpip.req.req_installrZ	pip.utilsrrrrrZpip.utils.hashesrZpip.utils.loggingrZpip.utils.packagingrZpip.vcsr Z	pip.wheelr!Z	getLoggerr8rs�objectr"r;rGrFrCrJrLr&r&r&r'�<module>s00
	__pycache__/req_install.cpython-36.pyc000064400000072766151733105650013747 0ustar003

�Pf���@s0ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZmZddlmZddlmZdd	lmZmZdd
lmZddlmZmZ ddl!m"Z"ddl#Z$dd
l%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGddlHmIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddl#mVZVmWZWejXeY�ZZej[j\j]�Z^dd�Z_dd�Z`Gdd�dea�Zbd d!�Zcd$d"d#�ZddS)%�)�absolute_importN)�	sysconfig)�change_root)�
FeedParser)�
pkg_resources�six)�
specifiers)�Marker)�InvalidRequirement�Requirement)�canonicalize_name)�Version�parse)�configparser)�
native_str�
get_stdlib�WINDOWS)�is_url�url_to_path�path_to_url�is_archive_file)�InstallationError�UninstallationError)�bin_py�running_under_virtualenv�PIP_DELETE_MARKER_FILENAME�bin_user)�display_path�rmtree�ask_path_exists�
backup_dir�is_installable_dir�dist_in_usersite�dist_in_site_packages�dist_in_install_path�
egg_link_path�call_subprocess�read_text_file�FakeFile�_make_build_dir�
ensure_dir�get_installed_version�normalize_path�
dist_is_local)�Hashes)�RemovedInPip10Warning)�
indent_log)�SETUPTOOLS_SHIM)�open_spinner)�UninstallPathSet)�vcs)�move_wheel_files�WheelcCs6tjd|�}d}|r*|jd�}|jd�}n|}||fS)Nz^(.+)(\[[^\]]+\])$��)�re�match�group)�path�m�extrasZpath_no_extras�r?�!/usr/lib/python3.6/req_install.py�
_strip_extras9s
rAcCstdd�|D��S)Ncss|]}tj|�VqdS)N)rZ
safe_extra)�.0�extrar?r?r@�	<genexpr>Fsz_safe_extras.<locals>.<genexpr>)�set)r>r?r?r@�_safe_extrasEsrFc@s�eZdZdQdd�ZedRdd��ZedSdd	��Zd
d�Zdd
�Zdd�Z	e
dd��Ze
dd��Zdd�Z
dd�Zdd�Ze
dd��Ze
dd��Ze
dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zejd(�Ze
d)d*��Zd+d,�ZdTd-d.�ZdUd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!dVd9d:�Z"gdddfd;d<�Z#d=d>�Z$d?d@�Z%dAdB�Z&fdfdCdD�Z'dEdF�Z(e
dGdH��Z)dWdIdJ�Z*dKdL�Z+e
dMdN��Z,dXdOdP�Z-dS)Y�InstallRequirementNFTcsJf|_t�tj�r�yt���Wndtk
r�tjj�kr@d}n.d�krft	�fdd�t
D��rfd}ntj�}t
d�|f��YnXt�j�|_�|_||_|
|_||_||_||_||_|_||_|	dk	r�|	|_n�oވj|_d|_d|_d|_d|_d|_||_d|_ d|_!d|_"d|_#d|_$|�r.|ni|_%||_&d|_'|
|_(dS)Nz%It looks like a path. Does it exist ?�=c3s|]}|�kVqdS)Nr?)rB�op)�reqr?r@rDVsz.InstallRequirement.__init__.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s'
%sF))r>�
isinstancer�string_typesrr
�osr<�sep�any�	operators�	traceback�
format_excrrFrJ�
comes_from�
constraint�
source_dir�editable�_wheel_cache�link�
original_link�as_egg�markers�marker�_egg_info_path�satisfied_by�conflicts_with�_temp_build_dir�_ideal_build_dir�update�install_succeeded�uninstalled�nothing_to_uninstall�
use_user_site�
target_dir�options�	pycompileZprepared�isolated)�selfrJrSrUrVrXrZrbrir[rjrh�wheel_cacherT�add_msgr?)rJr@�__init__KsN zInstallRequirement.__init__cCspddlm}t||�\}	}
}|
jd�r0t|
�}nd}||	||d||
�|||rP|ni|d�	}
|dk	rlt|�|
_|
S)Nr)�Linkzfile:T)rUrVrXrTrjrhrl)�	pip.indexro�parse_editable�
startswithrrFr>)�cls�editable_reqrS�default_vcsrjrhrlrTro�name�urlZextras_overriderU�resr?r?r@�
from_editable�s 



z InstallRequirement.from_editablec
Cs�ddlm}t|�rd}nd}||krR|j|d�\}}	|	j�}	|	sHd}	qVt|	�}	nd}	|j�}d}
tjjtjj	|��}d}d}
t|�r�||�}n�t
|�\}}
tjj|�r�tjj|ks�|j
d�r�t|�s�td|��|t|��}n0t|��rtjj|��stjd	|�|t|��}|�r||jd
k�rPtjd|j��rP|ttjjtjj	|j����}|j�rtt|j�}d|j|jf}
n|j}
n|}
|�r�|ni}||
|||	||||d
�}|
�r�tt d|
�j!�|_!|S)z�Creates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.
        r)roz; �;r7N�.z;Directory %r is not installable. File 'setup.py' not found.zARequirement %r looks like a filename, but the file does not exist�filez\.\./z%s==%s)rXr[rjrhrlrT�placeholder)"rpror�split�stripr	rMr<�normpath�abspathrA�isdirrNrrr!rrr�isfile�logger�warning�schemer9�searchrw�is_wheelr6�filenamerv�version�egg_fragmentrFrr>)rsrvrSrjrhrlrTroZ
marker_sepr[rJr<rXr>�p�wheelrxr?r?r@�	from_line�sb





zInstallRequirement.from_linecCs�|jr(t|j�}|jr:|d|jj7}n|jr6|jjnd}|jdk	rX|dt|jj�7}|jr�t|jt	j
�rt|j}n
|jj�}|r�|d|7}|S)Nz from %sz in %sz
 (from %s))rJ�strrXrwr^r�locationrSrKrrL�	from_path)rk�srSr?r?r@�__str__�s


zInstallRequirement.__str__cCsd|jjt|�|jfS)Nz<%s object: %s editable=%r>)�	__class__�__name__r�rV)rkr?r?r@�__repr__szInstallRequirement.__repr__cCs^|jdkr|j||�|_|jdk	rZ|rZ|j}|jj|j|j�|_||jkrZtjd|j�dS)aEnsure that if a link can be found for this, that it is found.

        Note that self.link may still be None - if Upgrade is False and the
        requirement is already installed.

        If require_hashes is True, don't use the wheel cache, because cached
        wheels, always built locally, have different hashes than the files
        downloaded from the index server and thus throw false hash mismatches.
        Furthermore, cached wheels at present have undeterministic contents due
        to file modification times.
        NzUsing cached wheel link: %s)rXZfind_requirementrWZcached_wheelrvr��debug)rk�finderZupgradeZrequire_hashesZold_linkr?r?r@�
populate_link	s

z InstallRequirement.populate_linkcCs|jjS)N)rJ�	specifier)rkr?r?r@r�szInstallRequirement.specifiercCs$|j}t|�dko"tt|��jdkS)z�Return whether I am pinned to an exact version.

        For example, some-package==1.2 is pinned; some-package>1.2 is not.
        r7�==�===)r�r�)r��len�next�iter�operator)rkrr?r?r@�	is_pinned!szInstallRequirement.is_pinnedcCsR|jdkrdSt|j�}|jrNt|jtj�r4|j}n
|jj�}|rN|d|7}|S)Nz->)rJr�rSrKrrLr�)rkr�rSr?r?r@r�+s


zInstallRequirement.from_pathcCs�|jdk	r|jS|jdkr<tjjtjdd��|_||_|jS|jrN|j	j
�}n|j	}tjj|�sttj
d|�t|�tjj||�S)Nz-buildzpip-zCreating directory %s)r`rJrMr<�realpath�tempfile�mkdtemprarVrv�lower�existsr�r�r)�join)rk�	build_dirrvr?r?r@�build_location8s

z!InstallRequirement.build_locationcCs�|jdk	rdS|jdk	st�|js&t�|js0t�|j}d|_|j|j�}tjj|�rdt	dt
|���tjd|t
|�t
|��t
j||�||_d|_||_d|_dS)a�Move self._temp_build_dir to self._ideal_build_dir/self.req.name

        For some requirements (e.g. a path to a directory), the name of the
        package is not available until we run egg_info, so the build_location
        will return a temporary directory and store the _ideal_build_dir.

        This is only called by self.egg_info_path to fix the temporary build
        directory.
        Nz<A package already exists in %s; please remove it to continuez,Moving package %s from %s to new location %s)rUrJ�AssertionErrorr`rar�rMr<r�rrr�r��shutil�mover])rkZold_locationZnew_locationr?r?r@�_correct_build_locationSs(



z*InstallRequirement._correct_build_locationcCs |jdkrdSttj|jj��S)N)rJrrZ	safe_namerv)rkr?r?r@rvss
zInstallRequirement.namecCstjj|j|jr|jjpd�S)N�)rMr<r�rUrXZsubdirectory_fragment)rkr?r?r@�setup_py_diryszInstallRequirement.setup_py_dircCs�|jstd|��yddl}Wn:tk
rXtd�dkr@d}ntj�}td|��YnXtj	j
|jd�}tj
r�t|tj�r�|jtj��}|S)NzNo source dir for %sr�
setuptoolszPlease install setuptools.zWCould not import setuptools which is required to install from a source distribution.
%szsetup.py)rUr�r��ImportErrorr+rQrRrrMr<r�r�r�PY2rKZ	text_type�encode�sys�getfilesystemencoding)rkr�rm�setup_pyr?r?r@r�szInstallRequirement.setup_pyc
CsZ|js
t�|jr$tjd|j|j�ntjd|j|j�t��xt|j}t	j
d|g}|jrd|dg7}|dg}|jrzg}n t
jj|jd�}t|�ddg}t|||jdd	d
�WdQRX|j�stt|j�d�t�r�d}nd
}tdj|j�d||j�dg��|_|j�nDt|j�d�}t|jj�|k�rVtjd|j|j||j�t|�|_dS)Nz2Running setup.py (path:%s) egg_info for package %sz7Running setup.py (path:%s) egg_info for package from %sz-cz
--no-user-cfg�egg_infozpip-egg-infoz
--egg-baseFzpython setup.py egg_info)�cwd�show_stdoutZcommand_descr
z==z===r��NamezuRunning setup.py (path:%s) egg_info for package %s produced metadata for project name %s. Fix your #egg=%s fragments.)rUr�rvr�r�r�rXr0r1r��
executablerjrVrMr<r�r�r*r&rJrK�
parse_version�pkg_infor
rr�rr�)rk�scriptZbase_cmdZegg_info_cmdZegg_base_option�egg_info_dirrIZ
metadata_namer?r?r@�run_egg_info�sP





zInstallRequirement.run_egg_infocCsV|jdk	r&|jj|�sdS|jj|�S|js0t�|j|�}tjj|�sJdSt	|�}|S)N)
r^�has_metadata�get_metadatarUr��
egg_info_pathrMr<r�r')rkr��datar?r?r@�
egg_info_data�s


z InstallRequirement.egg_info_datacs||jdk�rl|jr|j}ntjj|jd�}tj|�}|j�rg}x�tj|�D]�\�}}x t	j
D]}||kr^|j|�q^Wxjt|�D]^}tjj
tjj�|dd��s�tjjtjj�|dd��r�|j|�q�|dks�|dkr�|j|�q�W|j�fdd	�|D��qLWd
d	�|D�}|�s$td||f��|�s:td||f��t|�dk�rX|jd
d�d�tjj||d�|_tjj|j|�S)Nzpip-egg-info�bin�pythonZScriptsz
Python.exeZtestZtestscsg|]}tjj�|��qSr?)rMr<r�)rB�dir)�rootr?r@�
<listcomp>�sz4InstallRequirement.egg_info_path.<locals>.<listcomp>cSsg|]}|jd�r|�qS)z	.egg-info)�endswith)rB�fr?r?r@r��sz$No files/directories in %s (from %s)r7cSs(|jtjj�tjjr"|jtjj�p$dS)Nr)�countrMr<rN�altsep)�xr?r?r@�<lambda>
sz2InstallRequirement.egg_info_path.<locals>.<lambda>)�keyr)r]rVrUrMr<r�r��listdir�walkr4�dirnames�remove�list�lexistsr��extendrr�r��sort)rkr��base�	filenames�dirs�filesr�r?)r�r@r��sB
z InstallRequirement.egg_info_pathcCs@t�}|jd�}|s*tjdt|jd���|j|p4d�|j�S)NzPKG-INFOzNo PKG-INFO file found in %sr�)rr�r�r�rr�Zfeed�close)rkr�r�r?r?r@r�s
zInstallRequirement.pkg_infoz	\[(.*?)\]cCs
t|j�S)N)r+rv)rkr?r?r@�installed_version sz$InstallRequirement.installed_versioncCsV|js
t�|j�d}|jjr<||jjkr<tjd||j�ntjdt	|j�||�dS)Nr�z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)
rUr�r�rJr�r�r�r�r�r)rkr�r?r?r@�assert_source_matches_version$s

z0InstallRequirement.assert_source_matches_versioncCs�|jstjd|j�dS|js"t�|js,t�|jjdkr<dSd|jjksXtd|jj��|jsbdS|jjj	dd�\}}t
j|�}|r�||jj�}|r�|j|j�q�|j
|j�nds�td|j|f��dS)Nz>Cannot update repository at %s; repository location is unknownr|�+zbad url: %rr7rz+Unexpected version control type (in %s): %s)rXr�r�rUrVr�r�rwrbr~r4�get_backend�obtainZexport)rkr��vc_typerw�backendZvcs_backendr?r?r@�update_editable5s,


z"InstallRequirement.update_editablecsx|j�std|jf��|jp"|j}t|j�}t|�sTtj	d|j
|tj�d|_
dS|t�krxtj	d|j
|�d|_
dSt|�}t|�}djtj|j��}|jo�tjj|j�}t|jdd�}|o�|jjd�o�|jj|��r�|j|j�|jd	��r2x�|jd	�j�D](}	tjj tjj!|j|	��}
|j|
��qWn�|jd
��r|jd��rV|jd��ng�xj�fdd
�|jd
�j�D�D]J}tjj!|j|�}
|j|
�|j|
d�|j|
d�|j|
d��qxW�nH|�r�t"j#dj|j�t$�|j|��n |jjd��rH|j|j�tjj%|j�d}tjj!tjj&|j�d�}
|j'|
d|�n�|�r�|jjd��r�x�t(j)j*|�D]}
|j|
��qjWn�|�rt+|d��}tjj,|j-�j.��}WdQRX||jk�s�t/d||j|jf��|j|�tjj!tjj&|�d�}
|j'|
|j�ntj0d||j�|jd��r�|j1d��r�xZ|j2d�D]L}t3|��rJt4}nt5}|jtjj!||��t6�r6|jtjj!||�d��q6W|jd��rdt7j8�r�i}ndd#i}t9j:f|�}|j;t<|j=d���|j>d��rdx�|j?d�D]�\}}t3|��r�t4}nt5}|jtjj!||��t6�r�|jtjj!||�d �|jtjj!||�d!�|jtjj!||�d"��q�W|j@|�||_AdS)$a�
        Uninstall the distribution currently satisfying this requirement.

        Prompts before removing or modifying files unless
        ``auto_confirm`` is True.

        Refuses to delete or modify files outside of ``sys.prefix`` -
        thus uninstallation within a virtual environment can only
        modify that virtual environment, even if the virtualenv is
        linked to global site-packages.

        z.Cannot uninstall requirement %s, not installedz1Not uninstalling %s at %s, outside environment %sTNz<Not uninstalling %s at %s, as it is in the standard library.z{0}.egg-infor<z	.egg-infozinstalled-files.txtz
top_level.txtznamespace_packages.txtcsg|]}|r|�kr|�qSr?r?)rBr�)�
namespacesr?r@r��sz0InstallRequirement.uninstall.<locals>.<listcomp>z.pyz.pycz.pyoz�Uninstalling a distutils installed project ({0}) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.z.eggr7zeasy-install.pthz./z
.dist-info�rz;Egg-link %s does not match installed location of %s (at %s)z)Not sure how to uninstall: %s - Check: %s�scriptsz.batzentry_points.txtZ
delimitersrHZconsole_scriptsz.exez
.exe.manifestz
-script.py)rH)B�check_if_existsrrvr^r_r,r�r-r��infor�r��prefixrerr3r%�formatrZto_filename�project_namer�rMr<r��getattrZ	_providerr��addr�r��
splitlinesr�r��warnings�warnr/r~�dirnameZadd_pth�pipr�Zuninstallation_paths�open�normcase�readlinerr�r�Zmetadata_isdirZmetadata_listdirr"rrrrr�rZSafeConfigParserZreadfpr(Zget_metadata_linesZhas_section�itemsr�rd)rkZauto_confirmZdistZ	dist_pathZpaths_to_removeZdevelop_egg_linkZdevelop_egg_link_egg_infoZegg_info_existsZdistutils_egg_infoZinstalled_filer<Z
top_level_pkgZeasy_install_eggZeasy_install_pthZfhZlink_pointerr�Zbin_dirrh�configrv�valuer?)r�r@�	uninstallRs�









zInstallRequirement.uninstallcCs$|jr|jj�ntjd|j�dS)Nz'Can't rollback %s, nothing uninstalled.)rdZrollbackr��errorrv)rkr?r?r@�rollback_uninstall�sz%InstallRequirement.rollback_uninstallcCs*|jr|jj�n|js&tjd|j�dS)Nz%Can't commit %s, nothing uninstalled.)rdZcommitrer�r�rv)rkr?r?r@�commit_uninstall�s
z#InstallRequirement.commit_uninstallcCs�|js
t�d}d|j|j�df}tjj||�}tjj|�r�tdt	|�d�}|dkr^d	}nj|dkr�t
jd
t	|��tj|�nF|dkr�t
|�}t
jdt	|�t	|��tj||�n|dkr�tjd�|�r�tj|dtjdd
�}tjjtjj|j��}x�tj|�D]�\}	}
}d|
k�r"|
jd�xR|
D]J}tjj|	|�}|j||�}
tj|jd|
d�}d|_|j|d��q(WxL|D]D}|tk�r��q|tjj|	|�}|j||�}
|j||jd|
��q|W�qW|j�t
j dt	|��dS)NTz	%s-%s.zipr�z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort �i�w�b�aFzDeleting %szBacking up %s to %sr7)Z
allowZip64zpip-egg-info�/i��r�zSaved %s)rrrr���i�)!rUr�rvr�rMr<r�r�rrr�r�r�r r�r�r��exit�zipfileZZipFileZZIP_DEFLATEDr�r�r�r��_clean_zip_nameZZipInfoZ
external_attrZwritestrr�writer�r�)rkr�Zcreate_archiveZarchive_nameZarchive_pathZresponseZ	dest_file�zipr��dirpathr�r�r�rvZzipdirr�r?r?r@�archivesX







"zInstallRequirement.archivecCsJ|j|tjj�s"td||f��|t|�dd�}|jtjjd�}|S)Nz$name %r doesn't start with prefix %rr7r)rrrMr<rNr�r��replace)rkrvr�r?r?r@r	5s
z"InstallRequirement._clean_zip_namecs0|sd}�jdk	r(t�fdd�|D��SdSdS)Nr�c3s|]}�jjd|i�VqdS)rCN)r[Zevaluate)rBrC)rkr?r@rDDsz3InstallRequirement.match_markers.<locals>.<genexpr>T)r�)r[rO)rkZextras_requestedr?)rkr@�
match_markers=s


z InstallRequirement.match_markersc,s`|jr|j|||d�dS|jr\tjj|j�}tjj||j�|j	|j�||d�d|_
dS||jjdg�7}||jjdg�7}|j
r�t|�dg}tjdd�}tjj|d	�}�z�|j||�|�}	d
|jf}
t|
��.}t��t|	||jd|d�WdQRXWdQRXtjj|��s(tjd
|�dSd|_
|j�r:dS�fdd�}t|��H}
x@|
D](}tjj|�}|jd��rV||�}P�qVWtj d|�dSWdQRXg}t|��P}
xH|
D]@}|j!�}tjj"|��r�|tjj#7}|j$tjj%||�|���q�WWdQRXtjj|d�}t|d��}
|
j&dj|�d�WdQRXWdtjj|��rRtj'|�t(|�XdS)N)r�)r�r��strip_file_prefixT�global_options�install_optionsz
--no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)r�r��spinnerzRecord file %s not foundcs(�dkstjj|�r|St�|�SdS)N)rMr<�isabsr)r<)r�r?r@�prepend_root~sz0InstallRequirement.install.<locals>.prepend_rootz	.egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr�
))rV�install_editabler�r�r�Z
wheel_versionrUZcheck_compatibilityrvr5rcrh�getrjr�r�r�rMr<r��get_install_argsr2r0r&r�r�r�r�rZr�r�r�r�rr�rN�append�relpathr
r�r)rkrrr�r�rr�Z
temp_location�record_filename�install_args�msgrrr��lineZ	directoryr�Z	new_linesr�Zinst_files_pathr?)r�r@�installIs~




"
zInstallRequirement.installcCs|jdkr|j|�|_|jS)aAEnsure that a source_dir is set.

        This will create a temporary build dir if the name of the requirement
        isn't known yet.

        :param parent_dir: The ideal pip parent_dir for the source_dir.
            Generally src_dir for editables and build_dir for sdists.
        :return: self.source_dir
        N)rUr�)rkZ
parent_dirr?r?r@�ensure_has_source_dir�s

z(InstallRequirement.ensure_has_source_dircCs�tjdg}|jd�|jt|j�|t|�dd|g7}|jsJ|dg7}|dk	r^|d|g7}|dk	rr|d|g7}|jr�|dg7}n
|d	g7}t�r�d
t	j
�}|dtjj
tjdd
||j�g7}|S)Nz-uz-cr z--recordz#--single-version-externally-managedz--rootz--prefixz	--compilez--no-compiler�z--install-headers�includeZsite)r�r�rr1r�r�rZrirr�get_python_versionrMr<r�r�rv)rkrrr�r�rZ
py_ver_strr?r?r@r�s(



z#InstallRequirement.get_install_argscCsd|jr6tjjtjj|jt��r6tjd|j�t|j�d|_|j	rZtjj|j	�rZt|j	�d|_	dS)zVRemove the source files from this requirement, if they are marked
        for deletionzRemoving source in %sN)
rUrMr<r�r�rr�r�rr`)rkr?r?r@�remove_temporary_source�s

z*InstallRequirement.remove_temporary_sourcecCs�tjd|j�|jr"t|�dg}|r>dj|�g}t|�|}t��<ttj	dt
|jgt|�ddgt|�|jdd�WdQRXd	|_
dS)
NzRunning setup.py develop for %sz
--no-user-cfgz--prefix={0}z-cZdevelopz	--no-depsF)r�r�T)r�r�rvrjr�r�r0r&r�r�r1r�r�rc)rkrrr�Zprefix_paramr?r?r@r�s z#InstallRequirement.install_editablecCs�|jdkrdSyFtt|j��}d|_tjt|��|_|jrR|jrR|j|_d|_dSWn�tj	k
rjdStj
k
r�tj|jj�}|jr�t
|�r�||_q�t�r�t|�r�td|j|jf��nt|�r�||_YnXdS)z�Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        NFTzVWill not install to the user site because it will lack sys.path precedence to %s in %s)rJrr�r\rZget_distributionr^rVr_ZDistributionNotFoundZVersionConflictrvrfr"rr#rr�r�r$)rkZ	no_markerZ
existing_distr?r?r@r��s4

z"InstallRequirement.check_if_existscCs|jo|jjS)N)rXr�)rkr?r?r@r� szInstallRequirement.is_wheelcCs,t|j|j||j|j|||j|j|d�
dS)N)�user�homer�r�rirjr)r5rvrJrfrgrirj)rkZwheeldirr�r�rr?r?r@r5$s
z#InstallRequirement.move_wheel_filescCsX|jd�jd�}tjj|�}tj||�}tjjtjj|��d}tj	tjj|�||d�S)zAReturn a pkg_resources.Distribution built from self.egg_info_pathr�rr)r��metadata)
r��rstriprMr<r�rZPathMetadata�splitext�basenameZDistribution)rkr�Zbase_dirr'Z	dist_namer?r?r@�get_dist0s
zInstallRequirement.get_distcCst|jjdi��S)z�Return whether any known-good hashes are specified as options.

        These activate --require-hashes mode; hashes specified as part of a
        URL do not.

        �hashes)�boolrhr)rkr?r?r@�has_hash_options;sz#InstallRequirement.has_hash_optionscCsJ|jjdi�j�}|r|jn|j}|rB|jrB|j|jg�j|j�t	|�S)a�Return a hash-comparer that considers my option- and URL-based
        hashes to be known-good.

        Hashes in URLs--ones embedded in the requirements file, not ones
        downloaded from an index server--are almost peers with ones from
        flags. They satisfy --require-hashes (whether it was implicitly or
        explicitly activated) but do not activate it. md5 and sha224 are not
        allowed in flags, which should nudge people toward good algos. We
        always OR all hashes together, even ones from URLs.

        :param trust_internet: Whether to trust URL-based (#md5=...) hashes
            downloaded from the internet, as by populate_link()

        r,)
rhr�copyrXrY�hash�
setdefaultZ	hash_namerr.)rkZtrust_internetZgood_hashesrXr?r?r@r,Es

zInstallRequirement.hashes)NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NNN)T).r��
__module__�__qualname__rn�classmethodryr�r�r�r��propertyr�r�r�r�r�rvr�r�r�r�r�r�r9�compileZ_requirements_section_rer�r�r�r�r�r�r
r	rr r!rr$rr�r�r5r+r.r,r?r?r?r@rGIs`
;M

 :6


$0
\
)

rGcCstjd|�}|r|jd�}|S)z2
        Strip req postfix ( -dev, 0.2, etc )
    z^(.*?)(?:-dev|-\d.*)$r7)r9r�r;)rJr:r?r?r@�_strip_postfix[s
r7cCs�ddlm}|}d}tjd|�}|r:|jd�}|jd�}n|}tjj|�rttjjtjj	|d��slt
d|��t|�}|j�j
d	�r�||�j}|r�||td
|j��jfS||dfSx,tD]$}|j�j
d|�r�d||f}Pq�Wd
|k�r|�r
tjdt�|d
|}nt
d|��|jd
d�dj�}	tj|	��s`d|dj	dd�tjD��d}
t
|
��||�j}|�sxt
d��|�s�t
d|��t|�|dfS)aParses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    r)roNz^(.+)(\[[^\]]+\])$r7r8zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:r}z%s:z%s+%sr�zD--default-vcs has been deprecated and will be removed in the future.zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+zFor --editable=%s only z, cSsg|]}|jd�qS)z+URL)rv)rBr�r?r?r@r��sz"parse_editable.<locals>.<listcomp>z is currently supportedz@Could not detect requirement name, please specify one with #egg=z@--editable=%s is not the right format; it must have #egg=Package)rpror9r:r;rMr<r�r�r�rrr�rrr�rr>r4r�r�r/r~r�Zbackendsr7)rtrurorwr>r=Z
url_no_extrasZpackage_nameZversion_controlr�Z
error_messager?r?r@rqgs`





rq)N)eZ
__future__rZloggingrMr9r�r�r�rQr�rZ	distutilsrZdistutils.utilrZemail.parserrZpip._vendorrrZpip._vendor.packagingrZpip._vendor.packaging.markersr	Z"pip._vendor.packaging.requirementsr
rZpip._vendor.packaging.utilsrZpip._vendor.packaging.versionr
rr�Zpip._vendor.six.movesrZ	pip.wheelr�Z
pip.compatrrrZpip.downloadrrrrZpip.exceptionsrrZ
pip.locationsrrrrZ	pip.utilsrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-Zpip.utils.hashesr.Zpip.utils.deprecationr/Zpip.utils.loggingr0Zpip.utils.setuptools_buildr1Zpip.utils.uir2Zpip.req.req_uninstallr3Zpip.vcsr4r5r6Z	getLoggerr�r�Z	SpecifierZ
_operators�keysrPrArF�objectrGr7rqr?r?r?r@�<module>s`L
__pycache__/req_set.cpython-36.pyc000064400000051035151733105650013056 0ustar003

�Pf��@s~ddlmZddlmZddlmZddlZddlZddlm	Z	ddlm
Z
ddlmZddl
mZmZmZmZmZdd	lmZmZmZmZmZmZmZmZmZmZdd
lmZddl m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ej0e1�Z2Gdd�de3�Z4Gdd�de3�Z5dd�Z6Gdd�de5�Z7Gdd�de5�Z8Gdd�de5�Z9Gdd�de3�Z:dS)�)�absolute_import)�defaultdict)�chainN)�
pkg_resources)�requests)�
expanduser)�is_file_url�
is_dir_url�
is_vcs_url�url_to_path�
unpack_url)
�InstallationError�BestVersionAlreadyInstalled�DistributionNotFound�PreviousBuildDirError�	HashError�
HashErrors�HashUnpinned�DirectoryUrlHashUnsupported�VcsHashUnsupported�UnsupportedPythonVersion)�InstallRequirement)�display_path�dist_in_usersite�dist_in_install_path�
ensure_dir�normalize_path)�
MissingHashes)�
indent_log)�check_dist_requires_python)�vcs)�Wheelc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�RequirementscCsg|_i|_dS)N)�_keys�_dict)�self�r&�/usr/lib/python3.6/req_set.py�__init__"szRequirements.__init__cCs|jS)N)r#)r%r&r&r'�keys&szRequirements.keyscs�fdd��jD�S)Ncsg|]}�j|�qSr&)r$)�.0�key)r%r&r'�
<listcomp>*sz'Requirements.values.<locals>.<listcomp>)r#)r%r&)r%r'�values)szRequirements.valuescCs
||jkS)N)r#)r%�itemr&r&r'�__contains__,szRequirements.__contains__cCs$||jkr|jj|�||j|<dS)N)r#�appendr$)r%r+�valuer&r&r'�__setitem__/s
zRequirements.__setitem__cCs
|j|S)N)r$)r%r+r&r&r'�__getitem__4szRequirements.__getitem__cs$�fdd��j�D�}ddj|�S)Ncs$g|]}dt|�t�|�f�qS)z%s: %s)�repr)r*�k)r%r&r'r,8sz)Requirements.__repr__.<locals>.<listcomp>zRequirements({%s})z, )r)�join)r%r-r&)r%r'�__repr__7szRequirements.__repr__N)
�__name__�
__module__�__qualname__r(r)r-r/r2r3r7r&r&r&r'r" sr"c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�DistAbstractionatAbstracts out the wheel vs non-wheel prepare_files logic.

    The requirements for anything installable are as follows:
     - we must be able to determine the requirement name
       (or we can't correctly handle the non-upgrade case).
     - we must be able to generate a list of run-time dependencies
       without installing any additional packages (or we would
       have to either burn time by doing temporary isolated installs
       or alternatively violate pips 'don't start installing unless
       all requirements are available' rule - neither of which are
       desirable).
     - for packages with setup requirements, we must also be able
       to determine their requirements without installing additional
       packages (for the same reason as run-time dependencies)
     - we must be able to create a Distribution object exposing the
       above metadata.
    cCs
||_dS)N)�req_to_install)r%r<r&r&r'r(OszDistAbstraction.__init__cCst|j��dS)z Return a setuptools Dist object.N)�NotImplementedError�dist)r%�finderr&r&r'r>RszDistAbstraction.distcCst|j��dS)z3Ensure that we can get a Dist for this requirement.N)r=r>)r%r&r&r'�
prep_for_distVszDistAbstraction.prep_for_distN)r8r9r:�__doc__r(r>r@r&r&r&r'r;<sr;cCs0|jrt|�S|jr$|jjr$t|�St|�SdS)z�Factory to make an abstract dist object.

    Preconditions: Either an editable req with a source_dir, or satisfied_by or
    a wheel link, or a non-editable req with a source_dir.

    :return: A concrete DistAbstraction.
    N)�editable�IsSDist�link�is_wheel�IsWheel)r<r&r&r'�make_abstract_dist[s
rGc@seZdZdd�Zdd�ZdS)rFcCsttj|jj��dS)Nr)�listrZfind_distributionsr<�
source_dir)r%r?r&r&r'r>mszIsWheel.distcCsdS)Nr&)r%r&r&r'r@qszIsWheel.prep_for_distN)r8r9r:r>r@r&r&r&r'rFksrFc@seZdZdd�Zdd�ZdS)rCcCs(|jj�}|jd�r$|j|jd��|S)Nzdependency_links.txt)r<Zget_distZhas_metadataZadd_dependency_linksZget_metadata_lines)r%r?r>r&r&r'r>xs


zIsSDist.distcCs|jj�|jj�dS)N)r<Zrun_egg_infoZassert_source_matches_version)r%r&r&r'r@�s
zIsSDist.prep_for_distN)r8r9r:r>r@r&r&r&r'rCvs	rCc@seZdZdd�Zdd�ZdS)�	InstalledcCs|jjS)N)r<�satisfied_by)r%r?r&r&r'r>�szInstalled.distcCsdS)Nr&)r%r&r&r'r@�szInstalled.prep_for_distN)r8r9r:r>r@r&r&r&r'rJ�srJc@s�eZdZd$dd�Zdd�Zdd	�Zd%d
d�Zdd
�Zedd��Z	edd��Z
dd�Zd&dd�Zdd�Z
dd�Zdd�Zd'dd�Zdd�Zd d!�Zffd"d#�ZdS)(�RequirementSetFNTcCs�|dkrtd��||_||_||_||_||_||_|
|_t�|_	i|_
g|_|	|_||_
g|_g|_g|_||_||_||_||_|
|_||_|r�t|�}||_||_||_tt�|_dS)a3Create a RequirementSet.

        :param wheel_download_dir: Where still-packed .whl files should be
            written to. If None they are written to the download_dir parameter.
            Separate to download_dir to permit only keeping wheel archives for
            pip wheel.
        :param download_dir: Where still packed archives should be written to.
            If None they are not saved, and are deleted immediately after
            unpacking.
        :param wheel_cache: The pip wheel cache, for passing to
            InstallRequirement.
        Nz?RequirementSet() missing 1 required keyword argument: 'session')�	TypeError�	build_dir�src_dir�download_dir�upgrade�upgrade_strategy�ignore_installed�force_reinstallr"�requirements�requirement_aliases�unnamed_requirements�ignore_dependencies�ignore_requires_python�successfully_downloaded�successfully_installed�reqs_to_cleanup�as_egg�
use_user_site�
target_dir�session�	pycompile�isolatedr�wheel_download_dir�_wheel_cache�require_hashesrrH�
_dependencies)r%rNrOrPrQrRrSr]r_rXrTr^r`rarbrc�wheel_cachererYr&r&r'r(�s<zRequirementSet.__init__cCs8dd�|jj�D�}|jdd�d�djdd�|D��S)NcSsg|]}|js|�qSr&)Z
comes_from)r*�reqr&r&r'r,�sz*RequirementSet.__str__.<locals>.<listcomp>cSs
|jj�S)N)�name�lower)rhr&r&r'�<lambda>�sz(RequirementSet.__str__.<locals>.<lambda>)r+� cSsg|]}t|j��qSr&)�strrh)r*rhr&r&r'r,�s)rUr-�sortr6)r%�reqsr&r&r'�__str__�szRequirementSet.__str__cCsNdd�|jj�D�}|jdd�d�djdd�|D��}d|jjt|�|fS)	NcSsg|]}|�qSr&r&)r*rhr&r&r'r,�sz+RequirementSet.__repr__.<locals>.<listcomp>cSs
|jj�S)N)rirj)rhr&r&r'rk�sz)RequirementSet.__repr__.<locals>.<lambda>)r+z, cSsg|]}t|j��qSr&)rmrh)r*rhr&r&r'r,�sz"<%s object; %d requirement(s): %s>)rUr-rnr6�	__class__r8�len)r%roZreqs_strr&r&r'r7�s
zRequirementSet.__repr__c	
Cs�|j}|j|�s&tjd|j|j�gS|jrV|jjrVt|jj�}|j	�sVt
d|j��|j|_|j|_|j
|_
|j|_|dk|_|s�|jj|�|gSy|j|�}Wntk
r�d}YnX|dko�|o�|jo�|j|jko�|jj|jjk�rt
d|||f��|�s8||j|<|j�|k�r0||j|j�<|g}n�g}|j�r�|j�r�|j�r�|j�ol|jj|jjk�r�|jj|�t
d|��d|_ttt|j�j t|j����|_tj!d||j�|g}|}|�r�|j|�}|j"|j|�|SdS)a'Add install_req as a requirement to install.

        :param parent_req_name: The name of the requirement that needed this
            added. The name is used because when multiple unnamed requirements
            resolve to the same name, we could otherwise end up with dependency
            links that point outside the Requirements set. parent_req must
            already be added. Note that None implies that this is a user
            supplied requirement, vs an inferred one.
        :param extras_requested: an iterable of extras used to evaluate the
            environement markers.
        :return: Additional requirements to scan. That is either [] if
            the requirement is not applicable, or [install_req] if the
            requirement is applicable and has just been added.
        z6Ignoring %s: markers '%s' don't match your environmentz-%s is not a supported wheel on this platform.Nz5Double requirement given: %s (already in %s, name=%r)zhCould not satisfy constraints for '%s': installation from path or url cannot be constrained to a versionFzSetting %s extras to: %s)#riZ
match_markers�logger�warningZmarkersrDrEr!�filenameZ	supportedr
r]r^r_ra�	is_directrWr0�get_requirement�KeyError�
constraint�extrasrhZ	specifierrUrjrV�pathr\�tuple�sorted�set�union�debugrf)	r%�install_reqZparent_req_name�extras_requestedriZwheelZexisting_req�resultZ
parent_reqr&r&r'�add_requirement�sp






zRequirementSet.add_requirementcCsF|j�}||jkr |j|js>||jkrB|j|j|jrBdSdS)NTF)rjrUryrV)r%�project_namerir&r&r'�has_requirement4s

zRequirementSet.has_requirementcCstdd�|jj�D��p|jS)Ncss|]}|js|VqdS)N)ry)r*rhr&r&r'�	<genexpr>?sz2RequirementSet.has_requirements.<locals>.<genexpr>)rHrUr-rW)r%r&r&r'�has_requirements=szRequirementSet.has_requirementscCsD|jr@t|j�|_tjj|j�r$dStjd�tdt|j���dS)NTz!Could not find download directoryz0Could not find or access download directory '%s'F)	rPr�osr{�existsrs�criticalr
r)r%r&r&r'�is_downloadBs
zRequirementSet.is_downloadcCsTxB||j�fD]2}||jkr&|j|S||jkr|j|j|SqWtd|��dS)NzNo project with the name %r)rjrUrVrx)r%r�rir&r&r'rwOs


zRequirementSet.get_requirementcCs4x.|jj�D] }|jrq|j|d�|j�qWdS)N)�auto_confirm)rUr-ry�	uninstall�commit_uninstall)r%r�rhr&r&r'r�Ws
zRequirementSet.uninstallcCs�|jrt|j�|j|jj�}|jp6tdd�|D��}|rJ|jrJtd��g}t	�}xdt
||�D]V}y|j|j||||j
d��Wq`tk
r�}z||_|j|�WYdd}~Xq`Xq`W|r�|�dS)zY
        Prepare process. Create temp directories, download and/or unpack files.
        css|]}|jVqdS)N)Zhas_hash_options)r*rhr&r&r'r�jsz/RequirementSet.prepare_files.<locals>.<genexpr>z�--egg is not allowed with --require-hashes mode, since it delegates dependency resolution to setuptools and could thus result in installation of unhashed packages.)rerXN)rcrrWrUr-re�anyr]r
rr�extend�
_prepare_filerXrrhr0)r%r?Z	root_reqsreZdiscovered_reqsZhash_errorsrh�excr&r&r'�
prepare_files^s,

 zRequirementSet.prepare_filescCs |jo|jdkp|jdko|jS)NZeagerzonly-if-needed)rQrRrv)r%rhr&r&r'�_is_upgrade_allowed�s
z"RequirementSet._is_upgrade_allowedcCs�|j�|jr�|j|�}d}|r�|jp*|jshy|j||�Wn*tk
rTd}Yntk
rfYnX|s�|jr~t	|j�p�t
|j�s�|j|_d|_|r�d}n|jdkr�d}nd}|SdSdS)aCheck if req_to_install should be skipped.

        This will check if the req is installed, and whether we should upgrade
        or reinstall it, taking into account all the relevant user options.

        After calling this req_to_install will only have satisfied_by set to
        None if the req_to_install is to be upgraded/reinstalled etc. Any
        other value will be a dist recording the current thing installed that
        satisfies the requirement.

        Note that for vcs urls and the like we can't assess skipping in this
        routine - we simply identify that we need to pull the thing down,
        then later on it is pulled down and introspected to assess upgrade/
        reinstalls etc.

        :return: A text reason for why it was skipped, or None.
        FTNzalready up-to-datezonly-if-neededz%not upgraded as not directly requiredzalready satisfied)
�check_if_existsrKr�rTrDZfind_requirementrrr^rr�conflicts_withrR)r%r<r?Zupgrade_allowedZbest_installed�skip_reasonr&r&r'�_check_skip_installed�s4

z$RequirementSet._check_skip_installedc(s��js�jrgSd�_�jr*tjd��n��jdks8t��jsJ�j�|�}�jrx|dk	shtd�jf��tjd|��n<�j	r��j	j
dkr�t�j	j�}tjdt
|��ntjd��t�����j�r |r�td	����j�j��j�j�t��}|j��j�r�j�j��j��n0�j�rD|�r8tjd
�t��}�n�j�j�tjjtjj�j d���r|t!d��j f���j"|�j#��|��j	�s�t��j	}|�r�t$|��r�t%��nt&|��r�t'|��r�t(���j)�r�j*�r�t+���j,|d
�}	|�r|	�rt-�}	yZ�j}
d}�j	j.�r4�j/�r4�j/}
�j	j.�rN|
�rJd}nd}t0�j	�j |
|�j1|	d�WnHt2j3k
�r�}z(tj4d�|�td�|�j	f��WYdd}~XnXt��}|j��j�r�j	j
t5j6k�r�j�j��j�s��j��j�rP�j7�s�j�rD�j8�r&t9�j��p0t:�j��s<�j�_;d�_ntjd��|j<|�}
yt=|
�WnHt>k
�r�}z*�j?�r�tj@|jAd�n
�jB��WYdd}~XnXg����fdd�}�jC�jD��sވjE�d�|�sp�jF�rtjddj�jF��tGtH�jF�tH|
jF��}x|D]}tj@d|
|��qWtGtH|
jF�tH�jF�@�}x |
jI|�D]}|||d��qZW�jJjK���j�r��j�r��jLjK��WdQRX�S)zxPrepare a single requirements file.

        :return: A list of additional InstallRequirements to also install.
        TzObtaining %sNzP_check_skip_installed returned None but req_to_install.satisfied_by is set to %rzRequirement %s: %s�filez
Processing %sz
Collecting %szoThe editable requirement %s cannot be installed when requiring hashes, because there is no single file to hash.z�Since it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.zsetup.pyz�pip can't proceed with requirements '%s' due to a pre-existing build directory (%s). This is likely due to a previous installation that failed. pip is being responsible and not assuming it can delete this. Please delete it and try again.)Ztrust_internetF)r`�hashesz4Could not install requirement %s because of error %szDCould not install requirement %s because of HTTP error %s for URL %sz<Requirement already satisfied (use --upgrade to upgrade): %srcs4tt|���j�jd�}�j�j|�j|d��dS)N)rbrg)r�)rrmrbrdr�r�ri)�subreqr�Zsub_install_req)�	more_reqsr<r%r&r'�add_req�s
z-RequirementSet._prepare_file.<locals>.add_reqz!Installing extra requirements: %r�,z"%s does not provide the extra '%s')r�)MryZpreparedrBrs�inforK�AssertionErrorrSr�rD�schemerZurlrrr
Zensure_has_source_dirrOZupdate_editabler�rGr@�archiverPr�r�rJrNr�r{r�r6rIrZ
populate_linkr�r
rrr	rZ
original_linkZ	is_pinnedrr�rrErcrr`rZ	HTTPErrorr�r Zall_schemesrQr^rrr�r>rrrYrt�args�remove_temporary_sourcer�rir�rzr}r~Zrequiresr\r0rZ)r%r?r<rerXr�r{Z
abstract_distrDr�rPZautodelete_unpackedr�r>�er�Zmissing_requestedZmissingZavailable_requestedr�r&)r�r<r%r'r��s

	





"


zRequirementSet._prepare_filec	Cs8tjd�t��x|jD]}|j�qWWdQRXdS)zClean up files, remove builds.zCleaning up...N)rsr�rr\r�)r%rhr&r&r'�
cleanup_files�s
zRequirementSet.cleanup_filescs<g�t������fdd��x�jj�D]}�|�q(W�S)z�Create the installation order.

        The installation order is topological - requirements are installed
        before the requiring thing. We break cycles at an arbitrary point,
        and make no other guarantees.
        csP|js|�krdS|jrdS�j|�x�j|D]}�|�q2W�j|�dS)N)rKry�addrfr0)rhZdep)�order�ordered_reqs�scheduler%r&r'r��s
z,RequirementSet._to_install.<locals>.schedule)r~rUr-)r%r�r&)r�r�r�r%r'�_to_install�s
	zRequirementSet._to_installcOs�|j�}|r(tjddjdd�|D���t���x�|D]�}|jrltjd|j�t��|jdd�WdQRXy|j||f|�|�Wn$|jr�|jr�|j	��YnX|jr�|jr�|j
�|j�q6WWdQRX||_dS)	zl
        Install everything in this set (after having downloaded and unpacked
        the packages)
        z!Installing collected packages: %sz, cSsg|]
}|j�qSr&)ri)r*rhr&r&r'r,sz*RequirementSet.install.<locals>.<listcomp>zFound existing installation: %sT)r�N)
r�rsr�r6rr�r��installZinstall_succeededZrollback_uninstallr�r�r[)r%Zinstall_optionsZglobal_optionsr��kwargsZ
to_installZrequirementr&r&r'r��s:

zRequirementSet.install)FNFFNFFFNTFNNFF)NN)F)FF)r8r9r:r(rpr7r�r��propertyr�r�rwr�r�r�r�r�r�r�r�r&r&r&r'rL�s4
4
[	

'E
	rL);Z
__future__r�collectionsr�	itertoolsrZloggingr�Zpip._vendorrrZ
pip.compatrZpip.downloadrr	r
rrZpip.exceptionsr
rrrrrrrrrZpip.req.req_installrZ	pip.utilsrrrrrZpip.utils.hashesrZpip.utils.loggingrZpip.utils.packagingrZpip.vcsr Z	pip.wheelr!Z	getLoggerr8rs�objectr"r;rGrFrCrJrLr&r&r&r'�<module>s00
	req_install.py000064400000133225151733105650007447 0ustar00from __future__ import absolute_import

import logging
import os
import re
import shutil
import sys
import tempfile
import traceback
import warnings
import zipfile

from distutils import sysconfig
from distutils.util import change_root
from email.parser import FeedParser

from pip._vendor import pkg_resources, six
from pip._vendor.packaging import specifiers
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.packaging.version import Version, parse as parse_version
from pip._vendor.six.moves import configparser

import pip.wheel

from pip.compat import native_str, get_stdlib, WINDOWS
from pip.download import is_url, url_to_path, path_to_url, is_archive_file
from pip.exceptions import (
    InstallationError, UninstallationError,
)
from pip.locations import (
    bin_py, running_under_virtualenv, PIP_DELETE_MARKER_FILENAME, bin_user,
)
from pip.utils import (
    display_path, rmtree, ask_path_exists, backup_dir, is_installable_dir,
    dist_in_usersite, dist_in_site_packages, dist_in_install_path, egg_link_path,
    call_subprocess, read_text_file, FakeFile, _make_build_dir, ensure_dir,
    get_installed_version, normalize_path, dist_is_local,
)

from pip.utils.hashes import Hashes
from pip.utils.deprecation import RemovedInPip10Warning
from pip.utils.logging import indent_log
from pip.utils.setuptools_build import SETUPTOOLS_SHIM
from pip.utils.ui import open_spinner
from pip.req.req_uninstall import UninstallPathSet
from pip.vcs import vcs
from pip.wheel import move_wheel_files, Wheel


logger = logging.getLogger(__name__)

operators = specifiers.Specifier._operators.keys()


def _strip_extras(path):
    m = re.match(r'^(.+)(\[[^\]]+\])$', path)
    extras = None
    if m:
        path_no_extras = m.group(1)
        extras = m.group(2)
    else:
        path_no_extras = path

    return path_no_extras, extras


def _safe_extras(extras):
    return set(pkg_resources.safe_extra(extra) for extra in extras)


class InstallRequirement(object):

    def __init__(self, req, comes_from, source_dir=None, editable=False,
                 link=None, as_egg=False, update=True,
                 pycompile=True, markers=None, isolated=False, options=None,
                 wheel_cache=None, constraint=False):
        self.extras = ()
        if isinstance(req, six.string_types):
            try:
                req = Requirement(req)
            except InvalidRequirement:
                if os.path.sep in req:
                    add_msg = "It looks like a path. Does it exist ?"
                elif '=' in req and not any(op in req for op in operators):
                    add_msg = "= is not a valid operator. Did you mean == ?"
                else:
                    add_msg = traceback.format_exc()
                raise InstallationError(
                    "Invalid requirement: '%s'\n%s" % (req, add_msg))
            self.extras = _safe_extras(req.extras)

        self.req = req
        self.comes_from = comes_from
        self.constraint = constraint
        self.source_dir = source_dir
        self.editable = editable

        self._wheel_cache = wheel_cache
        self.link = self.original_link = link
        self.as_egg = as_egg
        if markers is not None:
            self.markers = markers
        else:
            self.markers = req and req.marker
        self._egg_info_path = None
        # This holds the pkg_resources.Distribution object if this requirement
        # is already available:
        self.satisfied_by = None
        # This hold the pkg_resources.Distribution object if this requirement
        # conflicts with another installed distribution:
        self.conflicts_with = None
        # Temporary build location
        self._temp_build_dir = None
        # Used to store the global directory where the _temp_build_dir should
        # have been created. Cf _correct_build_location method.
        self._ideal_build_dir = None
        # True if the editable should be updated:
        self.update = update
        # Set to True after successful installation
        self.install_succeeded = None
        # UninstallPathSet of uninstalled distribution (for possible rollback)
        self.uninstalled = None
        # Set True if a legitimate do-nothing-on-uninstall has happened - e.g.
        # system site packages, stdlib packages.
        self.nothing_to_uninstall = False
        self.use_user_site = False
        self.target_dir = None
        self.options = options if options else {}
        self.pycompile = pycompile
        # Set to True after successful preparation of this requirement
        self.prepared = False

        self.isolated = isolated

    @classmethod
    def from_editable(cls, editable_req, comes_from=None, default_vcs=None,
                      isolated=False, options=None, wheel_cache=None,
                      constraint=False):
        from pip.index import Link

        name, url, extras_override = parse_editable(
            editable_req, default_vcs)
        if url.startswith('file:'):
            source_dir = url_to_path(url)
        else:
            source_dir = None

        res = cls(name, comes_from, source_dir=source_dir,
                  editable=True,
                  link=Link(url),
                  constraint=constraint,
                  isolated=isolated,
                  options=options if options else {},
                  wheel_cache=wheel_cache)

        if extras_override is not None:
            res.extras = _safe_extras(extras_override)

        return res

    @classmethod
    def from_line(
            cls, name, comes_from=None, isolated=False, options=None,
            wheel_cache=None, constraint=False):
        """Creates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.
        """
        from pip.index import Link

        if is_url(name):
            marker_sep = '; '
        else:
            marker_sep = ';'
        if marker_sep in name:
            name, markers = name.split(marker_sep, 1)
            markers = markers.strip()
            if not markers:
                markers = None
            else:
                markers = Marker(markers)
        else:
            markers = None
        name = name.strip()
        req = None
        path = os.path.normpath(os.path.abspath(name))
        link = None
        extras = None

        if is_url(name):
            link = Link(name)
        else:
            p, extras = _strip_extras(path)
            if (os.path.isdir(p) and
                    (os.path.sep in name or name.startswith('.'))):

                if not is_installable_dir(p):
                    raise InstallationError(
                        "Directory %r is not installable. File 'setup.py' "
                        "not found." % name
                    )
                link = Link(path_to_url(p))
            elif is_archive_file(p):
                if not os.path.isfile(p):
                    logger.warning(
                        'Requirement %r looks like a filename, but the '
                        'file does not exist',
                        name
                    )
                link = Link(path_to_url(p))

        # it's a local file, dir, or url
        if link:
            # Handle relative file URLs
            if link.scheme == 'file' and re.search(r'\.\./', link.url):
                link = Link(
                    path_to_url(os.path.normpath(os.path.abspath(link.path))))
            # wheel file
            if link.is_wheel:
                wheel = Wheel(link.filename)  # can raise InvalidWheelFilename
                req = "%s==%s" % (wheel.name, wheel.version)
            else:
                # set the req to the egg fragment.  when it's not there, this
                # will become an 'unnamed' requirement
                req = link.egg_fragment

        # a requirement specifier
        else:
            req = name

        options = options if options else {}
        res = cls(req, comes_from, link=link, markers=markers,
                  isolated=isolated, options=options,
                  wheel_cache=wheel_cache, constraint=constraint)

        if extras:
            res.extras = _safe_extras(
                Requirement('placeholder' + extras).extras)

        return res

    def __str__(self):
        if self.req:
            s = str(self.req)
            if self.link:
                s += ' from %s' % self.link.url
        else:
            s = self.link.url if self.link else None
        if self.satisfied_by is not None:
            s += ' in %s' % display_path(self.satisfied_by.location)
        if self.comes_from:
            if isinstance(self.comes_from, six.string_types):
                comes_from = self.comes_from
            else:
                comes_from = self.comes_from.from_path()
            if comes_from:
                s += ' (from %s)' % comes_from
        return s

    def __repr__(self):
        return '<%s object: %s editable=%r>' % (
            self.__class__.__name__, str(self), self.editable)

    def populate_link(self, finder, upgrade, require_hashes):
        """Ensure that if a link can be found for this, that it is found.

        Note that self.link may still be None - if Upgrade is False and the
        requirement is already installed.

        If require_hashes is True, don't use the wheel cache, because cached
        wheels, always built locally, have different hashes than the files
        downloaded from the index server and thus throw false hash mismatches.
        Furthermore, cached wheels at present have undeterministic contents due
        to file modification times.
        """
        if self.link is None:
            self.link = finder.find_requirement(self, upgrade)
        if self._wheel_cache is not None and not require_hashes:
            old_link = self.link
            self.link = self._wheel_cache.cached_wheel(self.link, self.name)
            if old_link != self.link:
                logger.debug('Using cached wheel link: %s', self.link)

    @property
    def specifier(self):
        return self.req.specifier

    @property
    def is_pinned(self):
        """Return whether I am pinned to an exact version.

        For example, some-package==1.2 is pinned; some-package>1.2 is not.
        """
        specifiers = self.specifier
        return (len(specifiers) == 1 and
                next(iter(specifiers)).operator in ('==', '==='))

    def from_path(self):
        if self.req is None:
            return None
        s = str(self.req)
        if self.comes_from:
            if isinstance(self.comes_from, six.string_types):
                comes_from = self.comes_from
            else:
                comes_from = self.comes_from.from_path()
            if comes_from:
                s += '->' + comes_from
        return s

    def build_location(self, build_dir):
        if self._temp_build_dir is not None:
            return self._temp_build_dir
        if self.req is None:
            # for requirement via a path to a directory: the name of the
            # package is not available yet so we create a temp directory
            # Once run_egg_info will have run, we'll be able
            # to fix it via _correct_build_location
            # Some systems have /tmp as a symlink which confuses custom
            # builds (such as numpy). Thus, we ensure that the real path
            # is returned.
            self._temp_build_dir = os.path.realpath(
                tempfile.mkdtemp('-build', 'pip-')
            )
            self._ideal_build_dir = build_dir
            return self._temp_build_dir
        if self.editable:
            name = self.name.lower()
        else:
            name = self.name
        # FIXME: Is there a better place to create the build_dir? (hg and bzr
        # need this)
        if not os.path.exists(build_dir):
            logger.debug('Creating directory %s', build_dir)
            _make_build_dir(build_dir)
        return os.path.join(build_dir, name)

    def _correct_build_location(self):
        """Move self._temp_build_dir to self._ideal_build_dir/self.req.name

        For some requirements (e.g. a path to a directory), the name of the
        package is not available until we run egg_info, so the build_location
        will return a temporary directory and store the _ideal_build_dir.

        This is only called by self.egg_info_path to fix the temporary build
        directory.
        """
        if self.source_dir is not None:
            return
        assert self.req is not None
        assert self._temp_build_dir
        assert self._ideal_build_dir
        old_location = self._temp_build_dir
        self._temp_build_dir = None
        new_location = self.build_location(self._ideal_build_dir)
        if os.path.exists(new_location):
            raise InstallationError(
                'A package already exists in %s; please remove it to continue'
                % display_path(new_location))
        logger.debug(
            'Moving package %s from %s to new location %s',
            self, display_path(old_location), display_path(new_location),
        )
        shutil.move(old_location, new_location)
        self._temp_build_dir = new_location
        self._ideal_build_dir = None
        self.source_dir = new_location
        self._egg_info_path = None

    @property
    def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name))

    @property
    def setup_py_dir(self):
        return os.path.join(
            self.source_dir,
            self.link and self.link.subdirectory_fragment or '')

    @property
    def setup_py(self):
        assert self.source_dir, "No source dir for %s" % self
        try:
            import setuptools  # noqa
        except ImportError:
            if get_installed_version('setuptools') is None:
                add_msg = "Please install setuptools."
            else:
                add_msg = traceback.format_exc()
            # Setuptools is not available
            raise InstallationError(
                "Could not import setuptools which is required to "
                "install from a source distribution.\n%s" % add_msg
            )

        setup_py = os.path.join(self.setup_py_dir, 'setup.py')

        # Python2 __file__ should not be unicode
        if six.PY2 and isinstance(setup_py, six.text_type):
            setup_py = setup_py.encode(sys.getfilesystemencoding())

        return setup_py

    def run_egg_info(self):
        assert self.source_dir
        if self.name:
            logger.debug(
                'Running setup.py (path:%s) egg_info for package %s',
                self.setup_py, self.name,
            )
        else:
            logger.debug(
                'Running setup.py (path:%s) egg_info for package from %s',
                self.setup_py, self.link,
            )

        with indent_log():
            script = SETUPTOOLS_SHIM % self.setup_py
            base_cmd = [sys.executable, '-c', script]
            if self.isolated:
                base_cmd += ["--no-user-cfg"]
            egg_info_cmd = base_cmd + ['egg_info']
            # We can't put the .egg-info files at the root, because then the
            # source code will be mistaken for an installed egg, causing
            # problems
            if self.editable:
                egg_base_option = []
            else:
                egg_info_dir = os.path.join(self.setup_py_dir, 'pip-egg-info')
                ensure_dir(egg_info_dir)
                egg_base_option = ['--egg-base', 'pip-egg-info']
            call_subprocess(
                egg_info_cmd + egg_base_option,
                cwd=self.setup_py_dir,
                show_stdout=False,
                command_desc='python setup.py egg_info')

        if not self.req:
            if isinstance(parse_version(self.pkg_info()["Version"]), Version):
                op = "=="
            else:
                op = "==="
            self.req = Requirement(
                "".join([
                    self.pkg_info()["Name"],
                    op,
                    self.pkg_info()["Version"],
                ])
            )
            self._correct_build_location()
        else:
            metadata_name = canonicalize_name(self.pkg_info()["Name"])
            if canonicalize_name(self.req.name) != metadata_name:
                logger.warning(
                    'Running setup.py (path:%s) egg_info for package %s '
                    'produced metadata for project name %s. Fix your '
                    '#egg=%s fragments.',
                    self.setup_py, self.name, metadata_name, self.name
                )
                self.req = Requirement(metadata_name)

    def egg_info_data(self, filename):
        if self.satisfied_by is not None:
            if not self.satisfied_by.has_metadata(filename):
                return None
            return self.satisfied_by.get_metadata(filename)
        assert self.source_dir
        filename = self.egg_info_path(filename)
        if not os.path.exists(filename):
            return None
        data = read_text_file(filename)
        return data

    def egg_info_path(self, filename):
        if self._egg_info_path is None:
            if self.editable:
                base = self.source_dir
            else:
                base = os.path.join(self.setup_py_dir, 'pip-egg-info')
            filenames = os.listdir(base)
            if self.editable:
                filenames = []
                for root, dirs, files in os.walk(base):
                    for dir in vcs.dirnames:
                        if dir in dirs:
                            dirs.remove(dir)
                    # Iterate over a copy of ``dirs``, since mutating
                    # a list while iterating over it can cause trouble.
                    # (See https://github.com/pypa/pip/pull/462.)
                    for dir in list(dirs):
                        # Don't search in anything that looks like a virtualenv
                        # environment
                        if (
                                os.path.lexists(
                                    os.path.join(root, dir, 'bin', 'python')
                                ) or
                                os.path.exists(
                                    os.path.join(
                                        root, dir, 'Scripts', 'Python.exe'
                                    )
                                )):
                            dirs.remove(dir)
                        # Also don't search through tests
                        elif dir == 'test' or dir == 'tests':
                            dirs.remove(dir)
                    filenames.extend([os.path.join(root, dir)
                                     for dir in dirs])
                filenames = [f for f in filenames if f.endswith('.egg-info')]

            if not filenames:
                raise InstallationError(
                    'No files/directories in %s (from %s)' % (base, filename)
                )
            assert filenames, \
                "No files/directories in %s (from %s)" % (base, filename)

            # if we have more than one match, we pick the toplevel one.  This
            # can easily be the case if there is a dist folder which contains
            # an extracted tarball for testing purposes.
            if len(filenames) > 1:
                filenames.sort(
                    key=lambda x: x.count(os.path.sep) +
                    (os.path.altsep and x.count(os.path.altsep) or 0)
                )
            self._egg_info_path = os.path.join(base, filenames[0])
        return os.path.join(self._egg_info_path, filename)

    def pkg_info(self):
        p = FeedParser()
        data = self.egg_info_data('PKG-INFO')
        if not data:
            logger.warning(
                'No PKG-INFO file found in %s',
                display_path(self.egg_info_path('PKG-INFO')),
            )
        p.feed(data or '')
        return p.close()

    _requirements_section_re = re.compile(r'\[(.*?)\]')

    @property
    def installed_version(self):
        return get_installed_version(self.name)

    def assert_source_matches_version(self):
        assert self.source_dir
        version = self.pkg_info()['version']
        if self.req.specifier and version not in self.req.specifier:
            logger.warning(
                'Requested %s, but installing version %s',
                self,
                self.installed_version,
            )
        else:
            logger.debug(
                'Source in %s has version %s, which satisfies requirement %s',
                display_path(self.source_dir),
                version,
                self,
            )

    def update_editable(self, obtain=True):
        if not self.link:
            logger.debug(
                "Cannot update repository at %s; repository location is "
                "unknown",
                self.source_dir,
            )
            return
        assert self.editable
        assert self.source_dir
        if self.link.scheme == 'file':
            # Static paths don't get updated
            return
        assert '+' in self.link.url, "bad url: %r" % self.link.url
        if not self.update:
            return
        vc_type, url = self.link.url.split('+', 1)
        backend = vcs.get_backend(vc_type)
        if backend:
            vcs_backend = backend(self.link.url)
            if obtain:
                vcs_backend.obtain(self.source_dir)
            else:
                vcs_backend.export(self.source_dir)
        else:
            assert 0, (
                'Unexpected version control type (in %s): %s'
                % (self.link, vc_type))

    def uninstall(self, auto_confirm=False):
        """
        Uninstall the distribution currently satisfying this requirement.

        Prompts before removing or modifying files unless
        ``auto_confirm`` is True.

        Refuses to delete or modify files outside of ``sys.prefix`` -
        thus uninstallation within a virtual environment can only
        modify that virtual environment, even if the virtualenv is
        linked to global site-packages.

        """
        if not self.check_if_exists():
            raise UninstallationError(
                "Cannot uninstall requirement %s, not installed" % (self.name,)
            )
        dist = self.satisfied_by or self.conflicts_with

        dist_path = normalize_path(dist.location)
        if not dist_is_local(dist):
            logger.info(
                "Not uninstalling %s at %s, outside environment %s",
                dist.key,
                dist_path,
                sys.prefix,
            )
            self.nothing_to_uninstall = True
            return

        if dist_path in get_stdlib():
            logger.info(
                "Not uninstalling %s at %s, as it is in the standard library.",
                dist.key,
                dist_path,
            )
            self.nothing_to_uninstall = True
            return

        paths_to_remove = UninstallPathSet(dist)
        develop_egg_link = egg_link_path(dist)
        develop_egg_link_egg_info = '{0}.egg-info'.format(
            pkg_resources.to_filename(dist.project_name))
        egg_info_exists = dist.egg_info and os.path.exists(dist.egg_info)
        # Special case for distutils installed package
        distutils_egg_info = getattr(dist._provider, 'path', None)

        # Uninstall cases order do matter as in the case of 2 installs of the
        # same package, pip needs to uninstall the currently detected version
        if (egg_info_exists and dist.egg_info.endswith('.egg-info') and
                not dist.egg_info.endswith(develop_egg_link_egg_info)):
            # if dist.egg_info.endswith(develop_egg_link_egg_info), we
            # are in fact in the develop_egg_link case
            paths_to_remove.add(dist.egg_info)
            if dist.has_metadata('installed-files.txt'):
                for installed_file in dist.get_metadata(
                        'installed-files.txt').splitlines():
                    path = os.path.normpath(
                        os.path.join(dist.egg_info, installed_file)
                    )
                    paths_to_remove.add(path)
            # FIXME: need a test for this elif block
            # occurs with --single-version-externally-managed/--record outside
            # of pip
            elif dist.has_metadata('top_level.txt'):
                if dist.has_metadata('namespace_packages.txt'):
                    namespaces = dist.get_metadata('namespace_packages.txt')
                else:
                    namespaces = []
                for top_level_pkg in [
                        p for p
                        in dist.get_metadata('top_level.txt').splitlines()
                        if p and p not in namespaces]:
                    path = os.path.join(dist.location, top_level_pkg)
                    paths_to_remove.add(path)
                    paths_to_remove.add(path + '.py')
                    paths_to_remove.add(path + '.pyc')
                    paths_to_remove.add(path + '.pyo')

        elif distutils_egg_info:
            warnings.warn(
                "Uninstalling a distutils installed project ({0}) has been "
                "deprecated and will be removed in a future version. This is "
                "due to the fact that uninstalling a distutils project will "
                "only partially uninstall the project.".format(self.name),
                RemovedInPip10Warning,
            )
            paths_to_remove.add(distutils_egg_info)

        elif dist.location.endswith('.egg'):
            # package installed by easy_install
            # We cannot match on dist.egg_name because it can slightly vary
            # i.e. setuptools-0.6c11-py2.6.egg vs setuptools-0.6rc11-py2.6.egg
            paths_to_remove.add(dist.location)
            easy_install_egg = os.path.split(dist.location)[1]
            easy_install_pth = os.path.join(os.path.dirname(dist.location),
                                            'easy-install.pth')
            paths_to_remove.add_pth(easy_install_pth, './' + easy_install_egg)

        elif egg_info_exists and dist.egg_info.endswith('.dist-info'):
            for path in pip.wheel.uninstallation_paths(dist):
                paths_to_remove.add(path)

        elif develop_egg_link:
            # develop egg
            with open(develop_egg_link, 'r') as fh:
                link_pointer = os.path.normcase(fh.readline().strip())
            assert (link_pointer == dist.location), (
                'Egg-link %s does not match installed location of %s '
                '(at %s)' % (link_pointer, self.name, dist.location)
            )
            paths_to_remove.add(develop_egg_link)
            easy_install_pth = os.path.join(os.path.dirname(develop_egg_link),
                                            'easy-install.pth')
            paths_to_remove.add_pth(easy_install_pth, dist.location)

        else:
            logger.debug(
                'Not sure how to uninstall: %s - Check: %s',
                dist, dist.location)

        # find distutils scripts= scripts
        if dist.has_metadata('scripts') and dist.metadata_isdir('scripts'):
            for script in dist.metadata_listdir('scripts'):
                if dist_in_usersite(dist):
                    bin_dir = bin_user
                else:
                    bin_dir = bin_py
                paths_to_remove.add(os.path.join(bin_dir, script))
                if WINDOWS:
                    paths_to_remove.add(os.path.join(bin_dir, script) + '.bat')

        # find console_scripts
        if dist.has_metadata('entry_points.txt'):
            if six.PY2:
                options = {}
            else:
                options = {"delimiters": ('=', )}
            config = configparser.SafeConfigParser(**options)
            config.readfp(
                FakeFile(dist.get_metadata_lines('entry_points.txt'))
            )
            if config.has_section('console_scripts'):
                for name, value in config.items('console_scripts'):
                    if dist_in_usersite(dist):
                        bin_dir = bin_user
                    else:
                        bin_dir = bin_py
                    paths_to_remove.add(os.path.join(bin_dir, name))
                    if WINDOWS:
                        paths_to_remove.add(
                            os.path.join(bin_dir, name) + '.exe'
                        )
                        paths_to_remove.add(
                            os.path.join(bin_dir, name) + '.exe.manifest'
                        )
                        paths_to_remove.add(
                            os.path.join(bin_dir, name) + '-script.py'
                        )

        paths_to_remove.remove(auto_confirm)
        self.uninstalled = paths_to_remove

    def rollback_uninstall(self):
        if self.uninstalled:
            self.uninstalled.rollback()
        else:
            logger.error(
                "Can't rollback %s, nothing uninstalled.", self.name,
            )

    def commit_uninstall(self):
        if self.uninstalled:
            self.uninstalled.commit()
        elif not self.nothing_to_uninstall:
            logger.error(
                "Can't commit %s, nothing uninstalled.", self.name,
            )

    def archive(self, build_dir):
        assert self.source_dir
        create_archive = True
        archive_name = '%s-%s.zip' % (self.name, self.pkg_info()["version"])
        archive_path = os.path.join(build_dir, archive_name)
        if os.path.exists(archive_path):
            response = ask_path_exists(
                'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort ' %
                display_path(archive_path), ('i', 'w', 'b', 'a'))
            if response == 'i':
                create_archive = False
            elif response == 'w':
                logger.warning('Deleting %s', display_path(archive_path))
                os.remove(archive_path)
            elif response == 'b':
                dest_file = backup_dir(archive_path)
                logger.warning(
                    'Backing up %s to %s',
                    display_path(archive_path),
                    display_path(dest_file),
                )
                shutil.move(archive_path, dest_file)
            elif response == 'a':
                sys.exit(-1)
        if create_archive:
            zip = zipfile.ZipFile(
                archive_path, 'w', zipfile.ZIP_DEFLATED,
                allowZip64=True
            )
            dir = os.path.normcase(os.path.abspath(self.setup_py_dir))
            for dirpath, dirnames, filenames in os.walk(dir):
                if 'pip-egg-info' in dirnames:
                    dirnames.remove('pip-egg-info')
                for dirname in dirnames:
                    dirname = os.path.join(dirpath, dirname)
                    name = self._clean_zip_name(dirname, dir)
                    zipdir = zipfile.ZipInfo(self.name + '/' + name + '/')
                    zipdir.external_attr = 0x1ED << 16  # 0o755
                    zip.writestr(zipdir, '')
                for filename in filenames:
                    if filename == PIP_DELETE_MARKER_FILENAME:
                        continue
                    filename = os.path.join(dirpath, filename)
                    name = self._clean_zip_name(filename, dir)
                    zip.write(filename, self.name + '/' + name)
            zip.close()
            logger.info('Saved %s', display_path(archive_path))

    def _clean_zip_name(self, name, prefix):
        assert name.startswith(prefix + os.path.sep), (
            "name %r doesn't start with prefix %r" % (name, prefix)
        )
        name = name[len(prefix) + 1:]
        name = name.replace(os.path.sep, '/')
        return name

    def match_markers(self, extras_requested=None):
        if not extras_requested:
            # Provide an extra to safely evaluate the markers
            # without matching any extra
            extras_requested = ('',)
        if self.markers is not None:
            return any(
                self.markers.evaluate({'extra': extra})
                for extra in extras_requested)
        else:
            return True

    def install(self, install_options, global_options=[], root=None, prefix=None, strip_file_prefix=None):
        if self.editable:
            self.install_editable(
                install_options, global_options, prefix=prefix)
            return
        if self.is_wheel:
            version = pip.wheel.wheel_version(self.source_dir)
            pip.wheel.check_compatibility(version, self.name)

            self.move_wheel_files(
                self.source_dir,
                root=root,
                prefix=prefix,
                strip_file_prefix=strip_file_prefix
            )
            self.install_succeeded = True
            return

        # Extend the list of global and install options passed on to
        # the setup.py call with the ones from the requirements file.
        # Options specified in requirements file override those
        # specified on the command line, since the last option given
        # to setup.py is the one that is used.
        global_options += self.options.get('global_options', [])
        install_options += self.options.get('install_options', [])

        if self.isolated:
            global_options = list(global_options) + ["--no-user-cfg"]

        temp_location = tempfile.mkdtemp('-record', 'pip-')
        record_filename = os.path.join(temp_location, 'install-record.txt')
        try:
            install_args = self.get_install_args(
                global_options, record_filename, root, prefix)
            msg = 'Running setup.py install for %s' % (self.name,)
            with open_spinner(msg) as spinner:
                with indent_log():
                    call_subprocess(
                        install_args + install_options,
                        cwd=self.setup_py_dir,
                        show_stdout=False,
                        spinner=spinner,
                    )

            if not os.path.exists(record_filename):
                logger.debug('Record file %s not found', record_filename)
                return
            self.install_succeeded = True
            if self.as_egg:
                # there's no --always-unzip option we can pass to install
                # command so we unable to save the installed-files.txt
                return

            def prepend_root(path):
                if root is None or not os.path.isabs(path):
                    return path
                else:
                    return change_root(root, path)

            with open(record_filename) as f:
                for line in f:
                    directory = os.path.dirname(line)
                    if directory.endswith('.egg-info'):
                        egg_info_dir = prepend_root(directory)
                        break
                else:
                    logger.warning(
                        'Could not find .egg-info directory in install record'
                        ' for %s',
                        self,
                    )
                    # FIXME: put the record somewhere
                    # FIXME: should this be an error?
                    return
            new_lines = []
            with open(record_filename) as f:
                for line in f:
                    filename = line.strip()
                    if os.path.isdir(filename):
                        filename += os.path.sep
                    new_lines.append(
                        os.path.relpath(
                            prepend_root(filename), egg_info_dir)
                    )
            inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
            with open(inst_files_path, 'w') as f:
                f.write('\n'.join(new_lines) + '\n')
        finally:
            if os.path.exists(record_filename):
                os.remove(record_filename)
            rmtree(temp_location)

    def ensure_has_source_dir(self, parent_dir):
        """Ensure that a source_dir is set.

        This will create a temporary build dir if the name of the requirement
        isn't known yet.

        :param parent_dir: The ideal pip parent_dir for the source_dir.
            Generally src_dir for editables and build_dir for sdists.
        :return: self.source_dir
        """
        if self.source_dir is None:
            self.source_dir = self.build_location(parent_dir)
        return self.source_dir

    def get_install_args(self, global_options, record_filename, root, prefix):
        install_args = [sys.executable, "-u"]
        install_args.append('-c')
        install_args.append(SETUPTOOLS_SHIM % self.setup_py)
        install_args += list(global_options) + \
            ['install', '--record', record_filename]

        if not self.as_egg:
            install_args += ['--single-version-externally-managed']

        if root is not None:
            install_args += ['--root', root]
        if prefix is not None:
            install_args += ['--prefix', prefix]

        if self.pycompile:
            install_args += ["--compile"]
        else:
            install_args += ["--no-compile"]

        if running_under_virtualenv():
            py_ver_str = 'python' + sysconfig.get_python_version()
            install_args += ['--install-headers',
                             os.path.join(sys.prefix, 'include', 'site',
                                          py_ver_str, self.name)]

        return install_args

    def remove_temporary_source(self):
        """Remove the source files from this requirement, if they are marked
        for deletion"""
        if self.source_dir and os.path.exists(
                os.path.join(self.source_dir, PIP_DELETE_MARKER_FILENAME)):
            logger.debug('Removing source in %s', self.source_dir)
            rmtree(self.source_dir)
        self.source_dir = None
        if self._temp_build_dir and os.path.exists(self._temp_build_dir):
            rmtree(self._temp_build_dir)
        self._temp_build_dir = None

    def install_editable(self, install_options,
                         global_options=(), prefix=None):
        logger.info('Running setup.py develop for %s', self.name)

        if self.isolated:
            global_options = list(global_options) + ["--no-user-cfg"]

        if prefix:
            prefix_param = ['--prefix={0}'.format(prefix)]
            install_options = list(install_options) + prefix_param

        with indent_log():
            # FIXME: should we do --install-headers here too?
            call_subprocess(
                [
                    sys.executable,
                    '-c',
                    SETUPTOOLS_SHIM % self.setup_py
                ] +
                list(global_options) +
                ['develop', '--no-deps'] +
                list(install_options),

                cwd=self.setup_py_dir,
                show_stdout=False)

        self.install_succeeded = True

    def check_if_exists(self):
        """Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        """
        if self.req is None:
            return False
        try:
            # get_distribution() will resolve the entire list of requirements
            # anyway, and we've already determined that we need the requirement
            # in question, so strip the marker so that we don't try to
            # evaluate it.
            no_marker = Requirement(str(self.req))
            no_marker.marker = None
            self.satisfied_by = pkg_resources.get_distribution(str(no_marker))
            if self.editable and self.satisfied_by:
                self.conflicts_with = self.satisfied_by
                # when installing editables, nothing pre-existing should ever
                # satisfy
                self.satisfied_by = None
                return True
        except pkg_resources.DistributionNotFound:
            return False
        except pkg_resources.VersionConflict:
            existing_dist = pkg_resources.get_distribution(
                self.req.name
            )
            if self.use_user_site:
                if dist_in_usersite(existing_dist):
                    self.conflicts_with = existing_dist
                elif (running_under_virtualenv() and
                        dist_in_site_packages(existing_dist)):
                    raise InstallationError(
                        "Will not install to the user site because it will "
                        "lack sys.path precedence to %s in %s" %
                        (existing_dist.project_name, existing_dist.location)
                    )
            elif dist_in_install_path(existing_dist):
                self.conflicts_with = existing_dist
        return True

    @property
    def is_wheel(self):
        return self.link and self.link.is_wheel

    def move_wheel_files(self, wheeldir, root=None, prefix=None, strip_file_prefix=None):
        move_wheel_files(
            self.name, self.req, wheeldir,
            user=self.use_user_site,
            home=self.target_dir,
            root=root,
            prefix=prefix,
            pycompile=self.pycompile,
            isolated=self.isolated,
            strip_file_prefix=strip_file_prefix,
        )

    def get_dist(self):
        """Return a pkg_resources.Distribution built from self.egg_info_path"""
        egg_info = self.egg_info_path('').rstrip('/')
        base_dir = os.path.dirname(egg_info)
        metadata = pkg_resources.PathMetadata(base_dir, egg_info)
        dist_name = os.path.splitext(os.path.basename(egg_info))[0]
        return pkg_resources.Distribution(
            os.path.dirname(egg_info),
            project_name=dist_name,
            metadata=metadata)

    @property
    def has_hash_options(self):
        """Return whether any known-good hashes are specified as options.

        These activate --require-hashes mode; hashes specified as part of a
        URL do not.

        """
        return bool(self.options.get('hashes', {}))

    def hashes(self, trust_internet=True):
        """Return a hash-comparer that considers my option- and URL-based
        hashes to be known-good.

        Hashes in URLs--ones embedded in the requirements file, not ones
        downloaded from an index server--are almost peers with ones from
        flags. They satisfy --require-hashes (whether it was implicitly or
        explicitly activated) but do not activate it. md5 and sha224 are not
        allowed in flags, which should nudge people toward good algos. We
        always OR all hashes together, even ones from URLs.

        :param trust_internet: Whether to trust URL-based (#md5=...) hashes
            downloaded from the internet, as by populate_link()

        """
        good_hashes = self.options.get('hashes', {}).copy()
        link = self.link if trust_internet else self.original_link
        if link and link.hash:
            good_hashes.setdefault(link.hash_name, []).append(link.hash)
        return Hashes(good_hashes)


def _strip_postfix(req):
    """
        Strip req postfix ( -dev, 0.2, etc )
    """
    # FIXME: use package_to_requirement?
    match = re.search(r'^(.*?)(?:-dev|-\d.*)$', req)
    if match:
        # Strip off -dev, -0.2, etc.
        req = match.group(1)
    return req


def parse_editable(editable_req, default_vcs=None):
    """Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    """

    from pip.index import Link

    url = editable_req
    extras = None

    # If a file path is specified with extras, strip off the extras.
    m = re.match(r'^(.+)(\[[^\]]+\])$', url)
    if m:
        url_no_extras = m.group(1)
        extras = m.group(2)
    else:
        url_no_extras = url

    if os.path.isdir(url_no_extras):
        if not os.path.exists(os.path.join(url_no_extras, 'setup.py')):
            raise InstallationError(
                "Directory %r is not installable. File 'setup.py' not found." %
                url_no_extras
            )
        # Treating it as code that has already been checked out
        url_no_extras = path_to_url(url_no_extras)

    if url_no_extras.lower().startswith('file:'):
        package_name = Link(url_no_extras).egg_fragment
        if extras:
            return (
                package_name,
                url_no_extras,
                Requirement("placeholder" + extras.lower()).extras,
            )
        else:
            return package_name, url_no_extras, None

    for version_control in vcs:
        if url.lower().startswith('%s:' % version_control):
            url = '%s+%s' % (version_control, url)
            break

    if '+' not in url:
        if default_vcs:
            warnings.warn(
                "--default-vcs has been deprecated and will be removed in "
                "the future.",
                RemovedInPip10Warning,
            )
            url = default_vcs + '+' + url
        else:
            raise InstallationError(
                '%s should either be a path to a local project or a VCS url '
                'beginning with svn+, git+, hg+, or bzr+' %
                editable_req
            )

    vc_type = url.split('+', 1)[0].lower()

    if not vcs.get_backend(vc_type):
        error_message = 'For --editable=%s only ' % editable_req + \
            ', '.join([backend.name + '+URL' for backend in vcs.backends]) + \
            ' is currently supported'
        raise InstallationError(error_message)

    package_name = Link(url).egg_fragment
    if not package_name:
        raise InstallationError(
            "Could not detect requirement name, please specify one with #egg="
        )
    if not package_name:
        raise InstallationError(
            '--editable=%s is not the right format; it must have '
            '#egg=Package' % editable_req
        )
    return _strip_postfix(package_name), url, None
__init__.py000064400000000424151733105660006664 0ustar00from __future__ import absolute_import

from .req_install import InstallRequirement
from .req_set import RequirementSet, Requirements
from .req_file import parse_requirements

__all__ = [
    "RequirementSet", "Requirements", "InstallRequirement",
    "parse_requirements",
]
req_uninstall.py000064400000015361151733105660010013 0ustar00from __future__ import absolute_import

import logging
import os
import tempfile

from pip.compat import uses_pycache, WINDOWS, cache_from_source
from pip.exceptions import UninstallationError
from pip.utils import rmtree, ask, is_local, renames, normalize_path
from pip.utils.logging import indent_log


logger = logging.getLogger(__name__)


class UninstallPathSet(object):
    """A set of file paths to be removed in the uninstallation of a
    requirement."""
    def __init__(self, dist):
        self.paths = set()
        self._refuse = set()
        self.pth = {}
        self.dist = dist
        self.save_dir = None
        self._moved_paths = []

    def _permitted(self, path):
        """
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        """
        return is_local(path)

    def add(self, path):
        head, tail = os.path.split(path)

        # we normalize the head to resolve parent directory symlinks, but not
        # the tail, since we only want to uninstall symlinks, not their targets
        path = os.path.join(normalize_path(head), os.path.normcase(tail))

        if not os.path.exists(path):
            return
        if self._permitted(path):
            self.paths.add(path)
        else:
            self._refuse.add(path)

        # __pycache__ files can show up after 'installed-files.txt' is created,
        # due to imports
        if os.path.splitext(path)[1] == '.py' and uses_pycache:
            self.add(cache_from_source(path))

    def add_pth(self, pth_file, entry):
        pth_file = normalize_path(pth_file)
        if self._permitted(pth_file):
            if pth_file not in self.pth:
                self.pth[pth_file] = UninstallPthEntries(pth_file)
            self.pth[pth_file].add(entry)
        else:
            self._refuse.add(pth_file)

    def compact(self, paths):
        """Compact a path set to contain the minimal number of paths
        necessary to contain all paths in the set. If /a/path/ and
        /a/path/to/a/file.txt are both in the set, leave only the
        shorter path."""
        short_paths = set()
        for path in sorted(paths, key=len):
            if not any([
                    (path.startswith(shortpath) and
                     path[len(shortpath.rstrip(os.path.sep))] == os.path.sep)
                    for shortpath in short_paths]):
                short_paths.add(path)
        return short_paths

    def _stash(self, path):
        return os.path.join(
            self.save_dir, os.path.splitdrive(path)[1].lstrip(os.path.sep))

    def remove(self, auto_confirm=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""
        if not self.paths:
            logger.info(
                "Can't uninstall '%s'. No files were found to uninstall.",
                self.dist.project_name,
            )
            return
        logger.info(
            'Uninstalling %s-%s:',
            self.dist.project_name, self.dist.version
        )

        with indent_log():
            paths = sorted(self.compact(self.paths))

            if auto_confirm:
                response = 'y'
            else:
                for path in paths:
                    logger.info(path)
                response = ask('Proceed (y/n)? ', ('y', 'n'))
            if self._refuse:
                logger.info('Not removing or modifying (outside of prefix):')
                for path in self.compact(self._refuse):
                    logger.info(path)
            if response == 'y':
                self.save_dir = tempfile.mkdtemp(suffix='-uninstall',
                                                 prefix='pip-')
                for path in paths:
                    new_path = self._stash(path)
                    logger.debug('Removing file or directory %s', path)
                    self._moved_paths.append(path)
                    renames(path, new_path)
                for pth in self.pth.values():
                    pth.remove()
                logger.info(
                    'Successfully uninstalled %s-%s',
                    self.dist.project_name, self.dist.version
                )

    def rollback(self):
        """Rollback the changes previously made by remove()."""
        if self.save_dir is None:
            logger.error(
                "Can't roll back %s; was not uninstalled",
                self.dist.project_name,
            )
            return False
        logger.info('Rolling back uninstall of %s', self.dist.project_name)
        for path in self._moved_paths:
            tmp_path = self._stash(path)
            logger.debug('Replacing %s', path)
            renames(tmp_path, path)
        for pth in self.pth.values():
            pth.rollback()

    def commit(self):
        """Remove temporary save dir: rollback will no longer be possible."""
        if self.save_dir is not None:
            rmtree(self.save_dir)
            self.save_dir = None
            self._moved_paths = []


class UninstallPthEntries(object):
    def __init__(self, pth_file):
        if not os.path.isfile(pth_file):
            raise UninstallationError(
                "Cannot remove entries from nonexistent file %s" % pth_file
            )
        self.file = pth_file
        self.entries = set()
        self._saved_lines = None

    def add(self, entry):
        entry = os.path.normcase(entry)
        # On Windows, os.path.normcase converts the entry to use
        # backslashes.  This is correct for entries that describe absolute
        # paths outside of site-packages, but all the others use forward
        # slashes.
        if WINDOWS and not os.path.splitdrive(entry)[0]:
            entry = entry.replace('\\', '/')
        self.entries.add(entry)

    def remove(self):
        logger.debug('Removing pth entries from %s:', self.file)
        with open(self.file, 'rb') as fh:
            # windows uses '\r\n' with py3k, but uses '\n' with py2.x
            lines = fh.readlines()
            self._saved_lines = lines
        if any(b'\r\n' in line for line in lines):
            endline = '\r\n'
        else:
            endline = '\n'
        for entry in self.entries:
            try:
                logger.debug('Removing entry: %s', entry)
                lines.remove((entry + endline).encode("utf-8"))
            except ValueError:
                pass
        with open(self.file, 'wb') as fh:
            fh.writelines(lines)

    def rollback(self):
        if self._saved_lines is None:
            logger.error(
                'Cannot roll back changes to %s, none were made', self.file
            )
            return False
        logger.debug('Rolling %s back to previous state', self.file)
        with open(self.file, 'wb') as fh:
            fh.writelines(self._saved_lines)
        return True
req_file.py000064400000027226151733105660006724 0ustar00"""
Requirements file parsing
"""

from __future__ import absolute_import

import os
import re
import shlex
import sys
import optparse
import warnings

from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.six.moves import filterfalse

import pip
from pip.download import get_file_content
from pip.req.req_install import InstallRequirement
from pip.exceptions import (RequirementsFileParseError)
from pip.utils.deprecation import RemovedInPip10Warning
from pip import cmdoptions

__all__ = ['parse_requirements']

SCHEME_RE = re.compile(r'^(http|https|file):', re.I)
COMMENT_RE = re.compile(r'(^|\s)+#.*$')

SUPPORTED_OPTIONS = [
    cmdoptions.constraints,
    cmdoptions.editable,
    cmdoptions.requirements,
    cmdoptions.no_index,
    cmdoptions.index_url,
    cmdoptions.find_links,
    cmdoptions.extra_index_url,
    cmdoptions.allow_external,
    cmdoptions.allow_all_external,
    cmdoptions.no_allow_external,
    cmdoptions.allow_unsafe,
    cmdoptions.no_allow_unsafe,
    cmdoptions.use_wheel,
    cmdoptions.no_use_wheel,
    cmdoptions.always_unzip,
    cmdoptions.no_binary,
    cmdoptions.only_binary,
    cmdoptions.pre,
    cmdoptions.process_dependency_links,
    cmdoptions.trusted_host,
    cmdoptions.require_hashes,
]

# options to be passed to requirements
SUPPORTED_OPTIONS_REQ = [
    cmdoptions.install_options,
    cmdoptions.global_options,
    cmdoptions.hash,
]

# the 'dest' string values
SUPPORTED_OPTIONS_REQ_DEST = [o().dest for o in SUPPORTED_OPTIONS_REQ]


def parse_requirements(filename, finder=None, comes_from=None, options=None,
                       session=None, constraint=False, wheel_cache=None):
    """Parse a requirements file and yield InstallRequirement instances.

    :param filename:    Path or url of requirements file.
    :param finder:      Instance of pip.index.PackageFinder.
    :param comes_from:  Origin description of requirements.
    :param options:     cli options.
    :param session:     Instance of pip.download.PipSession.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    :param wheel_cache: Instance of pip.wheel.WheelCache
    """
    if session is None:
        raise TypeError(
            "parse_requirements() missing 1 required keyword argument: "
            "'session'"
        )

    _, content = get_file_content(
        filename, comes_from=comes_from, session=session
    )

    lines_enum = preprocess(content, options)

    for line_number, line in lines_enum:
        req_iter = process_line(line, filename, line_number, finder,
                                comes_from, options, session, wheel_cache,
                                constraint=constraint)
        for req in req_iter:
            yield req


def preprocess(content, options):
    """Split, filter, and join lines, and return a line iterator

    :param content: the content of the requirements file
    :param options: cli options
    """
    lines_enum = enumerate(content.splitlines(), start=1)
    lines_enum = join_lines(lines_enum)
    lines_enum = ignore_comments(lines_enum)
    lines_enum = skip_regex(lines_enum, options)
    return lines_enum


def process_line(line, filename, line_number, finder=None, comes_from=None,
                 options=None, session=None, wheel_cache=None,
                 constraint=False):
    """Process a single requirements line; This can result in creating/yielding
    requirements, or updating the finder.

    For lines that contain requirements, the only options that have an effect
    are from SUPPORTED_OPTIONS_REQ, and they are scoped to the
    requirement. Other options from SUPPORTED_OPTIONS may be present, but are
    ignored.

    For lines that do not contain requirements, the only options that have an
    effect are from SUPPORTED_OPTIONS. Options from SUPPORTED_OPTIONS_REQ may
    be present, but are ignored. These lines may contain multiple options
    (although our docs imply only one is supported), and all our parsed and
    affect the finder.

    :param constraint: If True, parsing a constraints file.
    :param options: OptionParser options that we may update
    """
    parser = build_parser()
    defaults = parser.get_default_values()
    defaults.index_url = None
    if finder:
        # `finder.format_control` will be updated during parsing
        defaults.format_control = finder.format_control
    args_str, options_str = break_args_options(line)
    if sys.version_info < (2, 7, 3):
        # Prior to 2.7.3, shlex cannot deal with unicode entries
        options_str = options_str.encode('utf8')
    opts, _ = parser.parse_args(shlex.split(options_str), defaults)

    # preserve for the nested code path
    line_comes_from = '%s %s (line %s)' % (
        '-c' if constraint else '-r', filename, line_number)

    # yield a line requirement
    if args_str:
        isolated = options.isolated_mode if options else False
        if options:
            cmdoptions.check_install_build_global(options, opts)
        # get the options that apply to requirements
        req_options = {}
        for dest in SUPPORTED_OPTIONS_REQ_DEST:
            if dest in opts.__dict__ and opts.__dict__[dest]:
                req_options[dest] = opts.__dict__[dest]
        yield InstallRequirement.from_line(
            args_str, line_comes_from, constraint=constraint,
            isolated=isolated, options=req_options, wheel_cache=wheel_cache
        )

    # yield an editable requirement
    elif opts.editables:
        isolated = options.isolated_mode if options else False
        default_vcs = options.default_vcs if options else None
        yield InstallRequirement.from_editable(
            opts.editables[0], comes_from=line_comes_from,
            constraint=constraint, default_vcs=default_vcs, isolated=isolated,
            wheel_cache=wheel_cache
        )

    # parse a nested requirements file
    elif opts.requirements or opts.constraints:
        if opts.requirements:
            req_path = opts.requirements[0]
            nested_constraint = False
        else:
            req_path = opts.constraints[0]
            nested_constraint = True
        # original file is over http
        if SCHEME_RE.search(filename):
            # do a url join so relative paths work
            req_path = urllib_parse.urljoin(filename, req_path)
        # original file and nested file are paths
        elif not SCHEME_RE.search(req_path):
            # do a join so relative paths work
            req_path = os.path.join(os.path.dirname(filename), req_path)
        # TODO: Why not use `comes_from='-r {} (line {})'` here as well?
        parser = parse_requirements(
            req_path, finder, comes_from, options, session,
            constraint=nested_constraint, wheel_cache=wheel_cache
        )
        for req in parser:
            yield req

    # percolate hash-checking option upward
    elif opts.require_hashes:
        options.require_hashes = opts.require_hashes

    # set finder options
    elif finder:
        if opts.allow_external:
            warnings.warn(
                "--allow-external has been deprecated and will be removed in "
                "the future. Due to changes in the repository protocol, it no "
                "longer has any effect.",
                RemovedInPip10Warning,
            )

        if opts.allow_all_external:
            warnings.warn(
                "--allow-all-external has been deprecated and will be removed "
                "in the future. Due to changes in the repository protocol, it "
                "no longer has any effect.",
                RemovedInPip10Warning,
            )

        if opts.allow_unverified:
            warnings.warn(
                "--allow-unverified has been deprecated and will be removed "
                "in the future. Due to changes in the repository protocol, it "
                "no longer has any effect.",
                RemovedInPip10Warning,
            )

        if opts.index_url:
            finder.index_urls = [opts.index_url]
        if opts.use_wheel is False:
            finder.use_wheel = False
            pip.index.fmt_ctl_no_use_wheel(finder.format_control)
        if opts.no_index is True:
            finder.index_urls = []
        if opts.extra_index_urls:
            finder.index_urls.extend(opts.extra_index_urls)
        if opts.find_links:
            # FIXME: it would be nice to keep track of the source
            # of the find_links: support a find-links local path
            # relative to a requirements file.
            value = opts.find_links[0]
            req_dir = os.path.dirname(os.path.abspath(filename))
            relative_to_reqs_file = os.path.join(req_dir, value)
            if os.path.exists(relative_to_reqs_file):
                value = relative_to_reqs_file
            finder.find_links.append(value)
        if opts.pre:
            finder.allow_all_prereleases = True
        if opts.process_dependency_links:
            finder.process_dependency_links = True
        if opts.trusted_hosts:
            finder.secure_origins.extend(
                ("*", host, "*") for host in opts.trusted_hosts)


def break_args_options(line):
    """Break up the line into an args and options string.  We only want to shlex
    (and then optparse) the options, not the args.  args can contain markers
    which are corrupted by shlex.
    """
    tokens = line.split(' ')
    args = []
    options = tokens[:]
    for token in tokens:
        if token.startswith('-') or token.startswith('--'):
            break
        else:
            args.append(token)
            options.pop(0)
    return ' '.join(args), ' '.join(options)


def build_parser():
    """
    Return a parser for parsing requirement lines
    """
    parser = optparse.OptionParser(add_help_option=False)

    option_factories = SUPPORTED_OPTIONS + SUPPORTED_OPTIONS_REQ
    for option_factory in option_factories:
        option = option_factory()
        parser.add_option(option)

    # By default optparse sys.exits on parsing errors. We want to wrap
    # that in our own exception.
    def parser_exit(self, msg):
        raise RequirementsFileParseError(msg)
    parser.exit = parser_exit

    return parser


def join_lines(lines_enum):
    """Joins a line ending in '\' with the previous line (except when following
    comments).  The joined line takes on the index of the first line.
    """
    primary_line_number = None
    new_line = []
    for line_number, line in lines_enum:
        if not line.endswith('\\') or COMMENT_RE.match(line):
            if COMMENT_RE.match(line):
                # this ensures comments are always matched later
                line = ' ' + line
            if new_line:
                new_line.append(line)
                yield primary_line_number, ''.join(new_line)
                new_line = []
            else:
                yield line_number, line
        else:
            if not new_line:
                primary_line_number = line_number
            new_line.append(line.strip('\\'))

    # last line contains \
    if new_line:
        yield primary_line_number, ''.join(new_line)

    # TODO: handle space after '\'.


def ignore_comments(lines_enum):
    """
    Strips comments and filter empty lines.
    """
    for line_number, line in lines_enum:
        line = COMMENT_RE.sub('', line)
        line = line.strip()
        if line:
            yield line_number, line


def skip_regex(lines_enum, options):
    """
    Skip lines that match '--skip-requirements-regex' pattern

    Note: the regex pattern is only built once
    """
    skip_regex = options.skip_requirements_regex if options else None
    if skip_regex:
        pattern = re.compile(skip_regex)
        lines_enum = filterfalse(
            lambda e: pattern.search(e[1]),
            lines_enum)
    return lines_enum