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: Reload all configuration items from the configured sources
  
  If `force` is False, all files configuration was previously read from
  are checked for differences in the modification times. If no difference
  is found for any file no reload is performed. This mechanism will not
  detect newly created global configuration files, use `force` in this case.
docstr_tok: ["Reload","all","configuration","items","from","the","configured","sources","If","`","force","`","is","False",",","all","files","configuration","was","previously","read","from","are","checked","for","differences","in","the","modification","times",".","If","no","difference","is","found","for","any","file","no","reload","is","performed",".","This","mechanism","will","not","detect","newly","created","global","configuration","files",",","use","`","force","`","in","this","case","."]
code: def reload(self, force=False):
      """Reload all configuration items from the configured sources
  
      If `force` is False, all files configuration was previously read from
      are checked for differences in the modification times. If no difference
      is found for any file no reload is performed. This mechanism will not
      detect newly created global configuration files, use `force` in this case.
      """
      run_args = ["-z", "-l", "--show-origin"]
  
      # update from desired config sources only
      # 2-step strategy:
      #   - load datalad dataset config from dataset
      #   - load git config from all supported by git sources
      # in doing so we always stay compatible with where Git gets its
      # config from, but also allow to override persistent information
      # from dataset locally or globally
  
      # figure out what needs to be reloaded at all
      to_run = {}
      # committed branch config
      # well, actually not necessarily committed
  
      if self._src_mode != "local" and self._repo_pathobj:
          # we have to read the branch config from this existing repo
          if self._repo_dot_git == self._repo_pathobj:
              # this is a bare repo, we go with the default HEAD,
              # if it has a config
              try:
                  # will blow if absent
                  self._runner.run(
                      ["git", "cat-file", "-e", "HEAD:.datalad/config"],
                      protocol=KillOutput,
                  )
                  to_run["branch"] = run_args + [
                      "--blob",
                      "HEAD:.datalad/config",
                  ]
              except CommandError:
                  # all good, just no branch config
                  pass
          else:
              # non-bare repo
              # we could use the same strategy as for bare repos, and rely
              # on the committed config, however, for now we must pay off
              # the sins of the past and work with the file at hand
              dataset_cfgfile = self._repo_pathobj / DATASET_CONFIG_FILE
              if dataset_cfgfile.exists() and (
                  force or self._need_reload(self._stores["branch"])
              ):
                  # we have the file and are forced or encourages to (re)load
                  to_run["branch"] = run_args + [
                      "--file",
                      str(dataset_cfgfile),
                  ]
  
      if self._src_mode != "branch" and (
          force or self._need_reload(self._stores["git"])
      ):
          to_run["git"] = (
              run_args + ["--local"]
              if self._src_mode == "branch-local"
              else run_args
          )
  
      # reload everything that was found todo
      while to_run:
          store_id, runargs = to_run.popitem()
          self._stores[store_id] = self._reload(runargs)
  
      # always update the merged representation, even if we did not reload
      # anything from a file. ENV or overrides could change independently
      # start with the commit dataset config
      merged = self._stores["branch"]["cfg"].copy()
      # local config always takes precedence
      merged.update(self._stores["git"]["cfg"])
      # superimpose overrides
      merged.update(self.overrides)
      # override with environment variables, unless we only want to read the
      # dataset's commit config
      if self._src_mode != "branch":
          _update_from_env(merged)
      self._merged_store = merged
  
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 2 for calling the ConfigManager obj's underlying member method code with example usage: obj.reload(force) without return types