class_docstr: Thin wrapper around `git-config` with support for a dataset configuration.
  
  The general idea is to have an object that is primarily used to read/query
  configuration option.  Upon creation, current configuration is read via one
  (or max two, in the case of the presence of dataset-specific configuration)
  calls to `git config`.  If this class is initialized with a Dataset
  instance, it supports reading and writing configuration from
  ``.datalad/config`` inside a dataset too. This file is committed to Git and
  hence useful to ship certain configuration items with a dataset.
  
  The API aims to provide the most significant read-access API of a
  dictionary, the Python ConfigParser, and GitPython's config parser
  implementations.
  
  This class is presently not capable of efficiently writing multiple
  configurations items at once.  Instead, each modification results in a
  dedicated call to `git config`. This author thinks this is OK, as he
  cannot think of a situation where a large number of items need to be
  written during normal operation.
  
  Each instance carries a public `overrides` attribute. This dictionary
  contains variables that override any setting read from a file. The overrides
  are persistent across reloads.
  
  Any DATALAD_* environment variable is also presented as a configuration
  item. Settings read from environment variables are not stored in any of the
  configuration files, but are read dynamically from the environment at each
  `reload()` call. Their values take precedence over any specification in
  configuration files, and even overrides.
  
  Parameters
  ----------
  dataset : Dataset, optional
    If provided, all `git config` calls are executed in this dataset's
    directory. Moreover, any modifications are, by default, directed to
    this dataset's configuration file (which will be created on demand)
  overrides : dict, optional
    Variable overrides, see general class documentation for details.
  source : {'any', 'local', 'branch', 'branch-local'}, optional
    Which sources of configuration setting to consider. If 'branch',
    configuration items are only read from a dataset's persistent
    configuration file in current branch, if any is present
    (the one in ``.datalad/config``, not
    ``.git/config``); if 'local', any non-committed source is considered
    (local and global configuration in Git config's terminology);
    if 'branch-local', persistent configuration in current dataset branch
    and local, but not global or system configuration are considered; if 'any'
    all possible sources of configuration are considered.
    Note: 'dataset' and 'dataset-local' are deprecated in favor of 'branch'
    and 'branch-local'.
class_docstr_tok: ["Thin","wrapper","around","`","git-config","`","with","support","for","a","dataset","configuration",".","The","general","idea","is","to","have","an","object","that","is","primarily","used","to","read\/query","configuration","option",".","Upon","creation",",","current","configuration","is","read","via","one","(","or","max","two",",","in","the","case","of","the","presence","of","dataset-specific","configuration",")","calls","to","`","git","config","`",".","If","this","class","is","initialized","with","a","Dataset","instance",",","it","supports","reading","and","writing","configuration","from","``",".datalad\/config","``","inside","a","dataset","too",".","This","file","is","committed","to","Git","and","hence","useful","to","ship","certain","configuration","items","with","a","dataset",".","The","API","aims","to","provide","the","most","significant","read-access","API","of","a","dictionary",",","the","Python","ConfigParser",",","and","GitPython","'s","config","parser","implementations",".","This","class","is","presently","not","capable","of","efficiently","writing","multiple","configurations","items","at","once",".","Instead",",","each","modification","results","in","a","dedicated","call","to","`","git","config","`",".","This","author","thinks","this","is","OK",",","as","he","can","not","think","of","a","situation","where","a","large","number","of","items","need","to","be","written","during","normal","operation",".","Each","instance","carries","a","public","`","overrides","`","attribute",".","This","dictionary","contains","variables","that","override","any","setting","read","from","a","file",".","The","overrides","are","persistent","across","reloads",".","Any","DATALAD_","*","environment","variable","is","also","presented","as","a","configuration","item",".","Settings","read","from","environment","variables","are","not","stored","in","any","of","the","configuration","files",",","but","are","read","dynamically","from","the","environment","at","each","`","reload","(",")","`","call",".","Their","values","take","precedence","over","any","specification","in","configuration","files",",","and","even","overrides",".","Parameters","--","--","--","--","--","dataset",":","Dataset",",","optional","If","provided",",","all","`","git","config","`","calls","are","executed","in","this","dataset's","directory",".","Moreover",",","any","modifications","are",",","by","default",",","directed","to","this","dataset","'s","configuration","file","(","which","will","be","created","on","demand",")","overrides",":","dict",",","optional","Variable","overrides",",","see","general","class","documentation","for","details",".","source",":","{","'any","'",",","'local","'",",","'branch","'",",","'branch-local","'","}",",","optional","Which","sources","of","configuration","setting","to","consider",".","If","'branch","'",",","configuration","items","are","only","read","from","a","dataset","'s","persistent","configuration","file","in","current","branch",",","if","any","is","present","(","the","one","in","``",".datalad\/config","``",",","not","``",".git\/config","``",")",";","if","'local","'",",","any","non-committed","source","is","considered","(","local","and","global","configuration","in","Git","config","'s","terminology",")",";","if","'branch-local","'",",","persistent","configuration","in","current","dataset","branch","and","local",",","but","not","global","or","system","configuration","are","considered",";","if","'any'","all","possible","sources","of","configuration","are","considered",".","Note",":","'dataset","'","and","'dataset-local","'","are","deprecated","in","favor","of","'branch'","and","'branch-local","'","."]
docstr: Centralized helper to run "git config" calls
  
  Parameters
  ----------
  args : list
    Arguments to pass for git config
  %s
  **kwargs
    Keywords arguments for Runner's call
docstr_tok: ["Centralized","helper","to","run","``","git","config","''","calls","Parameters","--","--","--","--","--","args",":","list","Arguments","to","pass","for","git","config","%","s","*","*","kwargs","Keywords","arguments","for","Runner","'s","call"]
code: def _run(self, args, scope=None, reload=False, **kwargs):
      """Centralized helper to run "git config" calls
  
      Parameters
      ----------
      args : list
        Arguments to pass for git config
      %s
      **kwargs
        Keywords arguments for Runner's call
      """
      if scope:
          args = self._get_location_args(scope) + args
      if "-l" in args:
          # we are just reading, no need to reload, no need to lock
          out = self._runner.run(self._config_cmd + args, **kwargs)
          return out["stdout"], out["stderr"]
  
      # all other calls are modifications
      if "--file" in args:
          # all paths we are passing are absolute
          custom_file = Path(args[args.index("--file") + 1])
          custom_file.parent.mkdir(exist_ok=True)
      lockfile = None
      if self._repo_dot_git and ("--local" in args or "--file" in args):
          # modification of config in a dataset
          lockfile = self._repo_dot_git / "config.dataladlock"
      else:
          # follow pattern in downloaders for lockfile location
          lockfile = (
              Path(self.obtain("datalad.locations.locks"))
              / "gitconfig.lck"
          )
  
      with ConfigManager._run_lock, InterProcessLock(
          lockfile, logger=lgr
      ):
          out = self._runner.run(self._config_cmd + args, **kwargs)
  
      if reload:
          self.reload()
          # this function is only used to modify config. If any manager
          # has modified the global scope, and is not itself the global
          # manager, we reload that one too in order to avoid stale
          # configuration reports
          if scope == "global" and self is not datalad.cfg:
              datalad.cfg.reload()
      return out["stdout"], out["stderr"]
  
imports: import json
  import logging
  import os
  import re
  import threading
  import warnings
  from collections import namedtuple
  from fasteners import InterProcessLock
  from functools import lru_cache, wraps
  from pathlib import Path
  import datalad
  from datalad.consts import DATASET_CONFIG_FILE
  from datalad.runner import CommandError, GitRunner, KillOutput, StdOutErrCapture
  from datalad.utils import getpwd, on_windows
label_desc: Use image node_id 25 for calling the ConfigManager obj's underlying member method code with example usage: obj._run(args, scope, reload) and returns: out,  out, out,  out