          """
          import pexpect  # pylint:disable=import-outside-toplevel,import-error
          logger.info("Installing %s", package)
  
          proc = pexpect.spawn(" ".join(command),
                               encoding=self._env.encoding,
                               codec_errors="replace",
                               timeout=None)
          last_line_cr = False
          while True:
              try:
                  idx = proc.expect(["\r\n", "\r"])
                  line = proc.before.rstrip()
                  if line and idx == 0:
                      if last_line_cr:
                          last_line_cr = False
                          # Output last line of progress bar and go to next line
                          if not self._is_gui:
                              print(line)
                      logger.verbose(line)  # type:ignore
                  elif line and idx == 1:
                      last_line_cr = True
 
</s> remove         import pexpect  # pylint:disable=import-outside-toplevel,import-error
        logger.info("Installing %s", package)
 </s> add         try:
            import pexpect  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            logger.debug("argv: %s", command)

            proc = pexpect.spawn(" ".join(command),
                                 encoding=self._env.encoding,
                                 codec_errors="replace",
                                 timeout=None)
            last_line_cr = False
            while True:
                try:
                    idx = proc.expect(["\r\n", "\r"])
                    line = proc.before.rstrip()
                    if line and idx == 0:
                        if last_line_cr:
                            last_line_cr = False
                            # Output last line of progress bar and go to next line
                            if not self._is_gui:
                                print(line)
                        logger.verbose(line)  # type:ignore
                    elif line and idx == 1:
                        last_line_cr = True
                        logger.debug(line)
                        if not self._is_gui:
                            print(line, end="\r")
                except pexpect.EOF:
                    break
            proc.close()
            returncode = proc.exitstatus
            logger.debug("Package: %s, returncode: %s", package, returncode)
            return returncode
        except Exception as err:  # pylint:disable=broad-except
            logger.debug("Failed to install with pexpect. Falling back to subprocess. Error: %s",
                         str(err))
            return self._subproc_installer(command, package) </s> remove                             print(line)
                    logger.verbose(line)  # type:ignore
                elif line and idx == 1:
                    last_line_cr = True
                    logger.debug(line)
                    if not self._is_gui:
                        print(line, end="\r")
            except pexpect.EOF:
                break
        proc.close()
        returncode = proc.exitstatus
        logger.debug("Package: %s, returncode: %s", package, returncode)
        return returncode
 </s> add                             print(line, end="\r")
                lines = []
                if eof:
                    returncode = proc.get_exitstatus()
                    break

            del proc
            logger.debug("Package: %s, returncode: %s", package, returncode)
            return returncode
        except Exception as err:  # pylint:disable=broad-except
            logger.debug("Failed to install with pexpect. Falling back to subprocess. Error: %s",
                         str(err))
            return self._subproc_installer(command, package) </s> remove                 if line == "" and proc.poll is not None:
 </s> add                 returncode = proc.poll()
                if line == "" and returncode is not None: </s> remove             returncode = proc.wait()
 </s> add 
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
          """
          import pexpect  # pylint:disable=import-outside-toplevel,import-error
          logger.info("Installing %s", package)
  
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
    def _pywinpty_installer(self, command: List[str], package: str) -> int:
        """ Run an install command using pywinpty and log output.

        pywinpty is used so we can get unbuffered output to display updates

        Parameters
        ----------
        command: list
            The command to run
        package: str
            The package name that is being installed

        Returns
        -------
        int
            The return code from the subprocess
        """
        try:
            import winpty  # pylint:disable=import-outside-toplevel,import-error
            logger.info("Installing %s", package)
            cmd = which(command[0], path=os.environ.get('PATH', os.defpath))
            # For some reason with WinPTY we need to pass in the full command. Probably a bug
            cmdline = list2cmdline(command)
            logger.debug("argv: %s, cmd: '%s', cmdline: '%s'", command, cmd, cmdline)

            proc = winpty.PTY(
                100,
                24,
                backend=winpty.enums.Backend.WinPTY,  # ConPTY hangs and has lots of Ansi Escapes
                agent_config=winpty.enums.AgentConfig.WINPTY_FLAG_PLAIN_OUTPUT)  # Strip all Ansi

            if not proc.spawn(cmd, cmdline=cmdline):
                del proc
                raise RuntimeError("Failed to spawn winpty")

            pbar = re.compile(r"(?:eta\s[\d\W]+)|(?:\s+\|\s+\d+%)\Z")
            lines = []
            out = ""
            eof = False
            last_line_cr = False
            num_bytes = 1024
            while True:
                try:
                    from_pty = proc.read(num_bytes)
                except winpty.WinptyError as err:
                    if any(val in str(err) for val in ["EOF", "pipe has been ended"]):
                        # Get remaining bytes. On a comms error, the buffer remains unread so keep
                        # halving buffer amount until down to 1 when we know we have everything
                        if num_bytes == 1:
                            eof = True
                        from_pty = ""
                        num_bytes //= 2
                    else:
                        raise
                out += from_pty
                if "\n" in out:
                    lines.extend(out.split("\n"))
                    if out.endswith("\n") or eof:  # Ends on newline or is EOF
                        out = ""
                    else:  # roll over semi-consumed line to next read
                        out = lines[-1]
                        lines = lines[:-1]

                for line in lines:  # Dump the output to log
                    line = line.rstrip()
                    is_cr = bool(pbar.search(line))
                    if line and not is_cr:
                        if last_line_cr:
                            last_line_cr = False
                            if not self._is_gui:  # Go to next line
                                print("")
                        logger.verbose(line)  # type:ignore
                    elif line:
                        last_line_cr = True
                        logger.debug(line)
                          if not self._is_gui:
                              print(line)
                      logger.verbose(line)  # type:ignore
                  elif line and idx == 1:
                      last_line_cr = True
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Update setup.py
  - Realtime output for Windows
  - color logging for compatible Windows versions 
setup.py