docs: def _install_requirement(
      python_bin: str, package: str, version: str = None, index_url: str = None, clean: bool = True
  ) -> None:
      """Install requirements specified using suggested pip binary."""
      previous_version = _pipdeptree(python_bin, package)
  
      try:
          cmd = "{} -m pip install --force-reinstall --no-cache-dir --no-deps {}".format(python_bin, quote(package))
          if version:
              cmd += "=={}".format(quote(version))
          if index_url:
              cmd += ' --index-url "{}" '.format(quote(index_url))
              # Supply trusted host by default so we do not get errors - it safe to
              # do it here as package indexes are managed by Thoth.
              trusted_host = urlparse(index_url).netloc
              cmd += " --trusted-host {}".format(trusted_host)
  
          _LOGGER.debug("Installing requirement %r in version %r", package, version)
          run_command(cmd)
          yield
      finally:
          if clean:
              _LOGGER.debug("Removing installed package %r", package)
              cmd = "{} -m pip uninstall --yes {}".format(python_bin, quote(package))
              result = run_command(cmd, raise_on_error=False)
  
              if result.return_code != 0:
                  _LOGGER.warning(
                      "Failed to restore previous environment by removing package %r (installed version %r), "
                      "the error is not fatal but can affect future actions: %s",
                      package,
                      version,
                      result.stderr,
                  )
  
              _LOGGER.debug(
                  "Restoring previous environment setup after installation of %r (%s)", package, previous_version
              )
              if previous_version:
                  cmd = "{} -m pip install --force-reinstall --no-cache-dir --no-deps {}=={}".format(
                      python_bin, quote(package), quote(previous_version["package"]["installed_version"])
                  )
                  result = run_command(cmd, raise_on_error=False)
  
                  if result.return_code != 0:
                      _LOGGER.warning(
                          "Failed to restore previous environment for package %r (installed version %r), "
                          ", the error is not fatal but can affect future actions (previous version: %r): %s",
                          package,
                          version,
                          previous_version,
                          result.stderr,
                      )