Esempio n. 1
0
    def _setup_logging(self):
        """
        Setup pip's logger. Ensure pip is verbose same as pip-tools and sync
        pip's log stream with LogContext.stream.
        """
        # Default pip's logger is noisy, so decrease it's verbosity
        setup_logging(
            verbosity=log.verbosity - 1,
            no_color=self.options.no_color,
            user_log_file=self.options.log,
        )

        # Sync pip's console handler stream with LogContext.stream
        logger = logging.getLogger()
        for handler in logger.handlers:
            if handler.name == "console":  # pragma: no branch
                handler.stream = log.stream
                break
        else:  # pragma: no cover
            # There is always a console handler. This warning would be a signal that
            # this block should be removed/revisited, because of pip possibly
            # refactored-out logging config.
            log.warning("Couldn't find a 'console' logging handler")

        # Sync pip's progress bars stream with LogContext.stream
        for bar_cls in itertools.chain(*BAR_TYPES.values()):
            bar_cls.file = log.stream
Esempio n. 2
0
    def _setup_logging(self) -> None:
        """
        Setup pip's logger. Ensure pip is verbose same as pip-tools and sync
        pip's log stream with LogContext.stream. This is only necessary for
        pip<22.0.
        """
        # Default pip's logger is noisy, so decrease it's verbosity
        setup_logging(
            verbosity=log.verbosity - 1,
            no_color=self.options.no_color,
            user_log_file=self.options.log,
        )

        # Sync pip's console handler stream with LogContext.stream
        logger = logging.getLogger()
        for handler in logger.handlers:
            if handler.name == "console":  # pragma: no branch
                assert isinstance(handler, logging.StreamHandler)
                handler.stream = log.stream
                break
        else:  # pragma: no cover
            # There is always a console handler. This warning would be a signal that
            # this block should be removed/revisited, because of pip possibly
            # refactored-out logging config.
            log.warning("Couldn't find a 'console' logging handler")

        # This import will fail with pip 22.1, but here we're pip<22.0
        from pip._internal.cli.progress_bars import BAR_TYPES

        # Sync pip's progress bars stream with LogContext.stream
        for bar_cls in itertools.chain(*BAR_TYPES.values()):
            bar_cls.file = log.stream