# Path: venv_update.py
# def colorize(cmd):
#     from os import isatty
# 
#     if isatty(1):
#         template = '\033[36m>\033[m \033[32m{0}\033[m'
#     else:
#         template = '> {0}'
# 
#     return template.format(shellescape(cmd))
# 
# Path: venv_update.py
# def raise_on_failure(mainfunc, ignore_return=False):
#     """raise if and only if mainfunc fails"""
#     try:
#         errors = mainfunc()
#         if not ignore_return and errors:
#             exit(errors)
#     except CalledProcessError as error:
#         exit(error.returncode)
#     except SystemExit as error:
#         if error.code:
#             raise
#     except KeyboardInterrupt:  # I don't plan to test-cover this.  :pragma:nocover:
#         exit(1)
# 
# Path: venv_update.py
# def timid_relpath(arg):
#     """convert an argument to a relative path, carefully"""
#     # TODO-TEST: unit tests
#     from os.path import isabs, relpath, sep
#     if isabs(arg):
#         result = relpath(arg)
#         if result.count(sep) + 1 < arg.count(sep):
#             return result
# 
#     return arg
# 
# Path: venv_update.py
# def user_cache_dir():
#     # stolen from pip.utils.appdirs.user_cache_dir
#     from os import getenv
#     from os.path import expanduser
#     return getenv('XDG_CACHE_HOME', expanduser('~/.cache'))


import errno
import glob
import os
import random
import re
import shutil
import sys
import pip as pipmodule
    import pkg_resources
from contextlib import contextmanager
from pip._internal import logger
from pip._internal.commands.install import InstallCommand
from pip._internal.exceptions import DistributionNotFound
from pip._internal.exceptions import InstallationError
from pip._internal.index import BestVersionAlreadyInstalled
from pip._internal.index import HTMLPage
from pip._internal.index import Link
from pip._internal.index import PackageFinder
from pip._internal.req import InstallRequirement
from pip._internal.wheel import Wheel
from venv_update import colorize
from venv_update import raise_on_failure
from venv_update import timid_relpath
from venv_update import user_cache_dir
    from pip._vendor import pkg_resources
    from pip._internal.req.constructors import install_req_from_line
    from sys import stdout
        from pip._internal.operations.freeze import FrozenRequirement
        from pip import FrozenRequirement
    from pip._internal.utils.misc import dist_is_local
    from copy import copy
    from collections import deque
        from pip._internal.cli import base_command
        from pip._internal import basecommand as base_command
    from pip._internal import download


def pipfaster_install_prune_option():
    return patched(pipmodule._internal.commands.commands_dict, {FasterInstallCommand.name: FasterInstallCommand})


def pipfaster_packagefinder():
    """Provide a short-circuited search when the requirement is pinned and appears on disk.

    Suggested upstream at: https://github.com/pypa/pip/pull/2114
    """
    # A poor man's dependency injection: monkeypatch :(
    try:  # :pragma:nocover: pip>=18.1
    except ImportError:  # :pragma:nocover: pip<18.1
    return patched(vars(base_command), {'PackageFinder': FasterPackageFinder})


def pipfaster_download_cacher(index_urls):
    """vanilla pip stores a cache of the http session in its cache and not the
    wheel files.  We intercept the download and save those files into our
    cache
    """
    orig = download._download_http_url
    patched_fn = get_patched_download_http_url(orig, index_urls)
    return patched(vars(download), {'_download_http_url': patched_fn})


def main():
    with pipfaster_install_prune_option():
        with pipfaster_packagefinder():

# Path: venv_update.py
# def colorize(cmd):
#     from os import isatty
# 
#     if isatty(1):
#         template = '\033[36m>\033[m \033[32m{0}\033[m'
#     else:
#         template = '> {0}'
# 
#     return template.format(shellescape(cmd))
# 
# Path: venv_update.py
# def raise_on_failure(mainfunc, ignore_return=False):
#     """raise if and only if mainfunc fails"""
#     try:
#         errors = mainfunc()
#         if not ignore_return and errors:
#             exit(errors)
#     except CalledProcessError as error:
#         exit(error.returncode)
#     except SystemExit as error:
#         if error.code:
#             raise
#     except KeyboardInterrupt:  # I don't plan to test-cover this.  :pragma:nocover:
#         exit(1)
# 
# Path: venv_update.py
# def timid_relpath(arg):
#     """convert an argument to a relative path, carefully"""
#     # TODO-TEST: unit tests
#     from os.path import isabs, relpath, sep
#     if isabs(arg):
#         result = relpath(arg)
#         if result.count(sep) + 1 < arg.count(sep):
#             return result
# 
#     return arg
# 
# Path: venv_update.py
# def user_cache_dir():
#     # stolen from pip.utils.appdirs.user_cache_dir
#     from os import getenv
#     from os.path import expanduser
#     return getenv('XDG_CACHE_HOME', expanduser('~/.cache'))


# Path: pip_faster.py
import errno
import glob
import os
import random
import re
import shutil
import sys
import pip as pipmodule
    import pkg_resources
from contextlib import contextmanager
from pip._internal import logger
from pip._internal.commands.install import InstallCommand
from pip._internal.exceptions import DistributionNotFound
from pip._internal.exceptions import InstallationError
from pip._internal.index import BestVersionAlreadyInstalled
from pip._internal.index import HTMLPage
from pip._internal.index import Link
from pip._internal.index import PackageFinder
from pip._internal.req import InstallRequirement
from pip._internal.wheel import Wheel
from venv_update import colorize
from venv_update import raise_on_failure
from venv_update import timid_relpath
from venv_update import user_cache_dir
    from pip._vendor import pkg_resources
    from pip._internal.req.constructors import install_req_from_line
    from sys import stdout
        from pip._internal.operations.freeze import FrozenRequirement
        from pip import FrozenRequirement
    from pip._internal.utils.misc import dist_is_local
    from copy import copy
    from collections import deque
        from pip._internal.cli import base_command
        from pip._internal import basecommand as base_command
    from pip._internal import download



def pipfaster_install_prune_option():
    return patched(pipmodule._internal.commands.commands_dict, {FasterInstallCommand.name: FasterInstallCommand})


def pipfaster_packagefinder():
    """Provide a short-circuited search when the requirement is pinned and appears on disk.

    Suggested upstream at: https://github.com/pypa/pip/pull/2114
    """
    # A poor man's dependency injection: monkeypatch :(
    try:  # :pragma:nocover: pip>=18.1
    except ImportError:  # :pragma:nocover: pip<18.1
    return patched(vars(base_command), {'PackageFinder': FasterPackageFinder})


def pipfaster_download_cacher(index_urls):
    """vanilla pip stores a cache of the http session in its cache and not the
    wheel files.  We intercept the download and save those files into our
    cache
    """
    orig = download._download_http_url
    patched_fn = get_patched_download_http_url(orig, index_urls)
    return patched(vars(download), {'_download_http_url': patched_fn})


def main():
    with pipfaster_install_prune_option():
        with pipfaster_packagefinder():

            raise_on_failure(pipmodule._internal.main)