示例#1
0
文件: wheel.py 项目: nipunn1313/pip
def req_error_context(req_description: str) -> Iterator[None]:
    try:
        yield
    except InstallationError as e:
        message = "For req: {}. {}".format(req_description, e.args[0])
        reraise(InstallationError, InstallationError(message),
                sys.exc_info()[2])
示例#2
0
 def get(self, wrap_exception=False):
     """
     Return the return value of this Attempt instance or raise an Exception.
     If wrap_exception is true, this Attempt is wrapped inside of a
     RetryError before being raised.
     """
     if self.has_exception:
         if wrap_exception:
             raise RetryError(self)
         else:
             six.reraise(self.value[0], self.value[1], self.value[2])
     else:
         return self.value
 def get(self, wrap_exception=False):
     """
     Return the return value of this Attempt instance or raise an Exception.
     If wrap_exception is true, this Attempt is wrapped inside of a
     RetryError before being raised.
     """
     if self.has_exception:
         if wrap_exception:
             raise RetryError(self)
         else:
             six.reraise(self.value[0], self.value[1], self.value[2])
     else:
         return self.value
示例#4
0
文件: _not.py 项目: uranusjr/petpeeve
def from_pip_import(path, attr=None, prepath=None):
    """This encapsulate pip imports between the introduction of pip._internal.
    """
    try:
        module = importlib.import_module('pip._internal.' + path)
    except ImportError:
        exc_info = sys.exc_info()
        try:
            module = importlib.import_module('pip.' + (prepath or path))
        except ImportError:
            six.reraise(*exc_info)  # The pip 10 exception is better.
    if not attr:
        return module
    try:
        return getattr(module, attr)
    except AttributeError:
        raise ImportError('cannot import name {!r}'.format(attr))
示例#5
0
    def install(
            self,
            install_options,  # type: List[str]
            global_options=None,  # type: Optional[Sequence[str]]
            root=None,  # type: Optional[str]
            home=None,  # type: Optional[str]
            prefix=None,  # type: Optional[str]
            warn_script_location=True,  # type: bool
            use_user_site=False,  # type: bool
            pycompile=True  # type: bool
    ):
        # type: (...) -> None
        scheme = get_scheme(
            self.name,
            user=use_user_site,
            home=home,
            root=root,
            isolated=self.isolated,
            prefix=prefix,
        )

        global_options = global_options if global_options is not None else []
        if self.editable:
            install_editable_legacy(
                install_options,
                global_options,
                prefix=prefix,
                home=home,
                use_user_site=use_user_site,
                name=self.name,
                setup_py_path=self.setup_py_path,
                isolated=self.isolated,
                build_env=self.build_env,
                unpacked_source_directory=self.unpacked_source_directory,
            )
            self.install_succeeded = True
            return

        if self.is_wheel:
            assert self.local_file_path
            direct_url = None
            if self.original_link:
                direct_url = direct_url_from_link(
                    self.original_link,
                    self.source_dir,
                    self.original_link_is_in_wheel_cache,
                )
            install_wheel(
                self.name,
                self.local_file_path,
                scheme=scheme,
                req_description=str(self.req),
                pycompile=pycompile,
                warn_script_location=warn_script_location,
                direct_url=direct_url,
            )
            self.install_succeeded = True
            return

        # TODO: Why don't we do this for editable installs?

        # 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 = list(global_options) + self.global_options
        install_options = list(install_options) + self.install_options

        try:
            success = install_legacy(
                install_options=install_options,
                global_options=global_options,
                root=root,
                home=home,
                prefix=prefix,
                use_user_site=use_user_site,
                pycompile=pycompile,
                scheme=scheme,
                setup_py_path=self.setup_py_path,
                isolated=self.isolated,
                req_name=self.name,
                build_env=self.build_env,
                unpacked_source_directory=self.unpacked_source_directory,
                req_description=str(self.req),
            )
        except LegacyInstallFailure as exc:
            self.install_succeeded = False
            six.reraise(*exc.parent)
        except Exception:
            self.install_succeeded = True
            raise

        self.install_succeeded = success
    def install(
        self,
        install_options,  # type: List[str]
        global_options=None,  # type: Optional[Sequence[str]]
        root=None,  # type: Optional[str]
        home=None,  # type: Optional[str]
        prefix=None,  # type: Optional[str]
        warn_script_location=True,  # type: bool
        use_user_site=False,  # type: bool
        pycompile=True  # type: bool
    ):
        # type: (...) -> None
        scheme = get_scheme(
            name,
            user=use_user_site,
            home=home,
            root=root,
            isolated=isolated,
            prefix=prefix,
        )

        global_options = global_options if global_options is not None else []
        if editable:
            install_editable_legacy(
                install_options,
                global_options,
                prefix=prefix,
                home=home,
                use_user_site=use_user_site,
                name=name,
                setup_py_path=setup_py_path,
                isolated=isolated,
                build_env=build_env,
                unpacked_source_directory=unpacked_source_directory,
            )
            install_succeeded = True
            return

        if is_wheel:
            assert local_file_path
            direct_url = None
            if original_link:
                direct_url = direct_url_from_link(
                    original_link,
                    source_dir,
                    original_link_is_in_wheel_cache,
                )
            install_wheel(
                name,
                local_file_path,
                scheme=scheme,
                req_description=str(req),
                pycompile=pycompile,
                warn_script_location=warn_script_location,
                direct_url=direct_url,
                requested=user_supplied,
            )
            install_succeeded = True
            return

        # TODO: Why don't we do this for editable installs?

        # 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 = list(global_options) + global_options
        install_options = list(install_options) + install_options

        try:
            success = install_legacy(
                install_options=install_options,
                global_options=global_options,
                root=root,
                home=home,
                prefix=prefix,
                use_user_site=use_user_site,
                pycompile=pycompile,
                scheme=scheme,
                setup_py_path=setup_py_path,
                isolated=isolated,
                req_name=name,
                build_env=build_env,
                unpacked_source_directory=unpacked_source_directory,
                req_description=str(req),
            )
        except LegacyInstallFailure as exc:
            install_succeeded = False
            six.reraise(*exc.parent)
        except Exception:
            install_succeeded = True
            raise

        install_succeeded = success

        if success and legacy_install_reason == 8368:
            deprecated(
                reason=(
                    "{} was installed using the legacy 'setup.py install' "
                    "method, because a wheel could not be built for it.".
                    format(name)
                ),
                replacement="to fix the wheel build issue reported above",
                gone_in="21.0",
                issue=8368,
            )
示例#7
0
__all__ = ['SimpleWheelCache']

import sys

from pip._vendor import six

from ._not import from_pip_import

try:
    SimpleWheelCache = from_pip_import('cache', 'SimpleWheelCache')
except ImportError:  # Even older versions.
    exc_info = sys.exc_info()
    try:
        from pip.wheel import WheelCache, _cache_for_link
    except ImportError:
        six.reraise(*exc_info)

    class SimpleWheelCache(WheelCache):  # noqa
        def get_path_for_link(self, link):
            return _cache_for_link(self._cache_dir, link)