code: def _configure_remote(
      ds,
      repo,
      name,
      known_remotes,
      url,
      pushurl,
      fetch,
      description,
      as_common_datasrc,
      publish_depends,
      publish_by_default,
      annex_wanted,
      annex_required,
      annex_group,
      annex_groupwanted,
      inherit,
      res_kwargs,
      **unused_kwargs,
  ):
      result_props = dict(
          action="configure-sibling",
          path=ds.path,
          type="sibling",
          name=name,
          **res_kwargs,
      )
      if name is None:
          result_props["status"] = "error"
          result_props[
              "message"
          ] = "need sibling `name` for configuration"
          yield result_props
          return
  
      if name != "here":
          # do all configure steps that are not meaningful for the 'here' sibling
          # AKA the local repo
          if name not in known_remotes and url:
              # this remote is fresh: make it known
              # just minimalistic name and URL, the rest is coming from `configure`
              repo.add_remote(name, url)
              known_remotes.append(name)
          elif url:
              # not new, override URl if given
              repo.set_remote_url(name, url)
  
          # make sure we have a configured fetch expression at this point
          fetchvar = "remote.{}.fetch".format(name)
          if fetchvar not in repo.config:
              # place default fetch refspec in config
              # same as `git remote add` would have added
              repo.config.add(
                  fetchvar,
                  "+refs/heads/*:refs/remotes/{}/*".format(name),
                  scope="local",
              )
  
          if pushurl:
              repo.set_remote_url(name, pushurl, push=True)
  
          if publish_depends:
              # Check if all `deps` remotes are known to the `repo`
              unknown_deps = set(
                  ensure_list(publish_depends)
              ).difference(known_remotes)
              if unknown_deps:
                  result_props["status"] = "error"
                  result_props["message"] = (
                      "unknown sibling(s) specified as publication dependency: %s",
                      unknown_deps,
                  )
                  yield result_props
                  return
  
          # define config var name for potential publication dependencies
          depvar = "remote.{}.datalad-publish-depends".format(name)
          # and default pushes
          dfltvar = "remote.{}.push".format(name)
  
          if fetch:
              # fetch the remote so we are up to date
              for r in Update.__call__(
                  dataset=ds.path,
                  sibling=name,
                  merge=False,
                  recursive=False,
                  on_failure="ignore",
                  return_type="generator",
                  result_xfm=None,
              ):
                  # fixup refds
                  r.update(res_kwargs)
                  yield r
  
          delayed_super = _DelayedSuper(repo)
          if inherit and delayed_super.super is not None:
              # Adjust variables which we should inherit
              publish_depends = _inherit_config_var(
                  delayed_super, depvar, publish_depends
              )
              publish_by_default = _inherit_config_var(
                  delayed_super, dfltvar, publish_by_default
              )
              # Copy relevant annex settings for the sibling
              # makes sense only if current AND super are annexes, so it is
              # kinda a boomer, since then forbids having a super a pure git
              if (
                  isinstance(repo, AnnexRepo)
                  and isinstance(delayed_super.repo, AnnexRepo)
                  and name in delayed_super.repo.get_remotes()
              ):
                  if annex_wanted is None:
                      annex_wanted = _inherit_annex_var(
                          delayed_super, name, "wanted"
                      )
                  if annex_required is None:
                      annex_required = _inherit_annex_var(
                          delayed_super, name, "required"
                      )
                  if annex_group is None:
                      # I think it might be worth inheriting group regardless what
                      # value is
                      # if annex_wanted in {'groupwanted', 'standard'}:
                      annex_group = _inherit_annex_var(
                          delayed_super, name, "group"
                      )
                  if (
                      annex_wanted == "groupwanted"
                      and annex_groupwanted is None
                  ):
                      # we better have a value for the expression for that group
                      annex_groupwanted = _inherit_annex_var(
                          delayed_super, name, "groupwanted"
                      )
  
          if publish_depends:
              if depvar in ds.config:
                  # config vars are incremental, so make sure we start from
                  # scratch
                  ds.config.unset(depvar, scope="local", reload=False)
              for d in ensure_list(publish_depends):
                  lgr.info(
                      'Configure additional publication dependency on "%s"',
                      d,
                  )
                  ds.config.add(depvar, d, scope="local", reload=False)
              ds.config.reload()
  
          if publish_by_default:
              if dfltvar in ds.config:
                  ds.config.unset(dfltvar, scope="local", reload=False)
              for refspec in ensure_list(publish_by_default):
                  lgr.info(
                      'Configure additional default publication refspec "%s"',
                      refspec,
                  )
                  ds.config.add(dfltvar, refspec, "local")
              ds.config.reload()
  
          assert isinstance(repo, GitRepo)  # just against silly code
          if isinstance(repo, AnnexRepo):
              # we need to check if added sibling an annex, and try to enable it
              # another part of the fix for #463 and #432
              try:
                  exc = None
                  if not ds.config.obtain(
                      "remote.{}.annex-ignore".format(name),
                      default=False,
                      valtype=EnsureBool(),
                      store=False,
                  ):
                      repo.enable_remote(name)
              except (CommandError, DownloadError) as exc:
                  # Note: CommandError happens with git-annex
                  # 6.20180416+gitg86b18966f-1~ndall+1 (prior 6.20180510, from
                  # which starts to fail with AccessFailedError) if URL is bogus,
                  # so enableremote fails. E.g. as "tested" in test_siblings
                  # TODO yield
                  ce = CapturedException(exc)
                  repo.config.reload()
                  if repo.is_remote_annex_ignored(name):
                      # Only inform user about the failure, if it's actually
                      # consequential, because annex decided to set
                      # annex-ignore=true.
                      lgr.info(
                          "Could not annex-enable %s: %s",
                          name,
                          exc.stderr,
                      )
  
              if as_common_datasrc:
                  # we need a fully configured remote here
                  # do not reuse `url`, but ask for the remote config
                  # that git-annex will use too
                  remote_url = repo.config.get(f"remote.{name}.url")
                  ri = RI(remote_url)
                  if isinstance(ri, URL) and ri.scheme in (
                      "http",
                      "https",
                  ):
                      # XXX what if there is already a special remote
                      # of this name? Above check for remotes ignores special
                      # remotes. we need to `git annex dead REMOTE` on reconfigure
                      # before we can init a new one
                      # XXX except it is not enough
  
                      # make special remote of type=git (see #335)
                      repo.call_annex(
                          [
                              "initremote",
                              as_common_datasrc,
                              "type=git",
                              "location={}".format(remote_url),
                              "autoenable=true",
                          ]
                      )
                  else:
                      yield dict(
                          status="impossible",
                          message="cannot configure as a common data source, "
                          "URL protocol is not http or https",
                          **result_props,
                      )
      #
      # place configure steps that also work for 'here' below
      #
      if isinstance(repo, AnnexRepo):
          for prop, var in (
              ("wanted", annex_wanted),
              ("required", annex_required),
              ("group", annex_group),
          ):
              if var is not None:
                  repo.set_preferred_content(
                      prop, var, "." if name == "here" else name
                  )
          if annex_groupwanted:
              repo.set_groupwanted(annex_group, annex_groupwanted)
  
      if description:
          if not isinstance(repo, AnnexRepo):
              result_props["status"] = "impossible"
              result_props[
                  "message"
              ] = "cannot set description of a plain Git repository"
              yield result_props
              return
          repo.call_annex(["describe", name, description])
  
      # report all we know at once
      info = list(
          _query_remotes(ds, repo, name, known_remotes, **unused_kwargs)
      )[0]
      info.update(dict(status="ok", **result_props))
      yield info
  
imports: import logging
  import os
  import os.path
  from urllib.parse import urlparse
  import datalad.support.ansi_colors
  from datalad.distribution.dataset import Dataset, require_dataset
  from datalad.distribution.update import Update
  from datalad.downloaders.credentials import UserPassword
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.common_opts import annex_group_opt, annex_groupwanted_opt, annex_required_opt, annex_wanted_opt, as_common_datasrc, inherit_opt, location_description, publish_by_default, publish_depends, recursion_flag, recursion_limit
  from datalad.interface.results import get_status_dict
  from datalad.interface.utils import generic_result_renderer
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.constraints import EnsureBool, EnsureChoice, EnsureNone, EnsureStr
  from datalad.support.exceptions import AccessDeniedError, AccessFailedError, CapturedException, CommandError, DownloadError, InsufficientArgumentsError, RemoteNotAvailableError
  from datalad.support.gitrepo import GitRepo
  from datalad.support.network import RI, URL, PathRI
  from datalad.support.param import Parameter
  from datalad.utils import Path, ensure_list, slash_join
  from .dataset import EnsureDataset, datasetmethod
label_desc: Use image node_id 3 for calling a global function with example usage: _configure_remote(ds, repo, name, known_remotes, url, pushurl, fetch, description, as_common_datasrc, publish_depends, publish_by_default, annex_wanted, annex_required, annex_group, annex_groupwanted, inherit, res_kwargs) without return types