{
    "file_diffs": [
        {
            "old_file_content": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"\n\"\"\"\n\nfrom datalad.cmd import Runner\nfrom datalad.dochelpers import exc_str\nimport re\nimport os\nfrom os.path import join as opj, exists\n\ncfg_kv_regex = re.compile(r'(^.*)\\n(.*)$', flags=re.MULTILINE)\ncfg_section_regex = re.compile(r'(.*)\\.[^.]+')\ncfg_sectionoption_regex = re.compile(r'(.*)\\.([^.]+)')\n\n\n_where_reload_doc = \"\"\"\n        where : {'dataset', 'local', 'global'}, optional\n          Indicator which configuration file to modify. 'dataset' indicates the\n          persistent configuration in .datalad/config of a dataset; 'local'\n          the configuration of a dataset's Git repository in .git/config;\n          'global' refers to the general configuration that is not specific to\n          a single repository (usually in $USER/.gitconfig).\n        reload : bool\n          Flag whether to reload the configuration from file(s) after\n          modification. This can be disable to make multiple sequential\n          modifications slightly more efficient.\"\"\".lstrip()\n\n\ndef _where_reload(obj):\n    \"\"\"Helper decorator to simplify providing repetitive docstring\"\"\"\n    obj.__doc__ = obj.__doc__ % _where_reload_doc\n    return obj\n\n\ndef _parse_gitconfig_dump(dump, store, replace):\n    if replace:\n        # if we want to replace existing values in the store\n        # collect into a new dict and `update` the store at the\n        # end. This way we get the desired behavior of multi-value\n        # keys, but only for the current source\n        dct = {}\n    else:\n        # if we don't want to replace value, perform the multi-value\n        # preserving addition on the existing store right away\n        dct = store\n    for line in dump.split('\\0'):\n        if not line:\n            continue\n        k, v = cfg_kv_regex.match(line).groups()\n        present_v = dct.get(k, None)\n        if present_v is None:\n            dct[k] = v\n        else:\n            if isinstance(present_v, tuple):\n                dct[k] = present_v + (v,)\n            else:\n                dct[k] = (present_v, v)\n    if replace:\n        store.update(dct)\n    return store\n\n\ndef _parse_env(store):\n    dct = {}\n    for k in os.environ:\n        if not k.startswith('DATALAD_'):\n            continue\n        dct[k.replace('_', '.').lower()] = os.environ[k]\n    store.update(dct)\n    return store\n\n\ndef anything2bool(val):\n    if hasattr(val, 'lower'):\n        val = val.lower()\n    if val in {\"off\", \"no\", \"false\", \"0\"} or not bool(val):\n        return False\n    elif val in {\"on\", \"yes\", \"true\", True} \\\n            or (hasattr(val, 'isdigit') and val.isdigit() and int(val)) \\\n            or isinstance(val, int) and val:\n        return True\n    else:\n        raise TypeError(\n            \"Got value %s which could not be interpreted as a boolean\"\n            % repr(val))\n\n\nclass ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)\n",
            "new_file_content": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"\n\"\"\"\n\nfrom datalad.cmd import Runner\nfrom datalad.dochelpers import exc_str\nimport re\nimport os\nfrom os.path import join as opj, exists\n\ncfg_kv_regex = re.compile(r'(^.*)\\n(.*)$', flags=re.MULTILINE)\ncfg_section_regex = re.compile(r'(.*)\\.[^.]+')\ncfg_sectionoption_regex = re.compile(r'(.*)\\.([^.]+)')\n\n\n_where_reload_doc = \"\"\"\n        where : {'dataset', 'local', 'global'}, optional\n          Indicator which configuration file to modify. 'dataset' indicates the\n          persistent configuration in .datalad/config of a dataset; 'local'\n          the configuration of a dataset's Git repository in .git/config;\n          'global' refers to the general configuration that is not specific to\n          a single repository (usually in $USER/.gitconfig).\n        reload : bool\n          Flag whether to reload the configuration from file(s) after\n          modification. This can be disable to make multiple sequential\n          modifications slightly more efficient.\"\"\".lstrip()\n\n\ndef _where_reload(obj):\n    \"\"\"Helper decorator to simplify providing repetitive docstring\"\"\"\n    obj.__doc__ = obj.__doc__ % _where_reload_doc\n    return obj\n\n\ndef _parse_gitconfig_dump(dump, store, replace):\n    if replace:\n        # if we want to replace existing values in the store\n        # collect into a new dict and `update` the store at the\n        # end. This way we get the desired behavior of multi-value\n        # keys, but only for the current source\n        dct = {}\n    else:\n        # if we don't want to replace value, perform the multi-value\n        # preserving addition on the existing store right away\n        dct = store\n    for line in dump.split('\\0'):\n        if not line:\n            continue\n        k, v = cfg_kv_regex.match(line).groups()\n        present_v = dct.get(k, None)\n        if present_v is None:\n            dct[k] = v\n        else:\n            if isinstance(present_v, tuple):\n                dct[k] = present_v + (v,)\n            else:\n                dct[k] = (present_v, v)\n    if replace:\n        store.update(dct)\n    return store\n\n\ndef _parse_env(store):\n    dct = {}\n    for k in os.environ:\n        if not k.startswith('DATALAD_'):\n            continue\n        dct[k.replace('_', '.').lower()] = os.environ[k]\n    store.update(dct)\n    return store\n\n\ndef anything2bool(val):\n    if hasattr(val, 'lower'):\n        val = val.lower()\n    if val in {\"off\", \"no\", \"false\", \"0\"} or not bool(val):\n        return False\n    elif val in {\"on\", \"yes\", \"true\", True} \\\n            or (hasattr(val, 'isdigit') and val.isdigit() and int(val)) \\\n            or isinstance(val, int) and val:\n        return True\n    else:\n        raise TypeError(\n            \"Got value %s which could not be interpreted as a boolean\"\n            % repr(val))\n\n\nclass ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Each instance carries a public `overrides` attribute. This dictionary\n    contains variables that override any setting read from a file. The overrides\n    are persistent across reloads, and are not modified by any of the manipulation\n    methods, such as `set` or `unset`.\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files, and even overrides.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    overrides : dict, optional\n      Variable overrides, see general class documentation for details.\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False, overrides=None):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        # public dict to store variables that always override any setting\n        # read from a file\n        self.overrides = {} if overrides is None else overrides\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if self._dataset_only:\n            # superimpose overrides\n            self._store.update(self.overrides)\n            return\n\n        stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n        self._store = _parse_gitconfig_dump(\n            stdout, self._store, replace=True)\n\n        # superimpose overrides\n        self._store.update(self.overrides)\n\n        # override with environment variables\n        self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)\n",
            "header": {
                "file": {
                    "path": "datalad/config.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "150a5cc03",
                "new_commit_hash": "6abfebbab",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/datalad/config.py"
            },
            "plus_file": {
                "path": "b/datalad/config.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 114,
                            "length": 11
                        },
                        "new_range": {
                            "start": 114,
                            "length": 16
                        },
                        "section": "class ConfigManager(object):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    written during normal operation. If such need arises, various solutions are",
                                "type": "context"
                            },
                            {
                                "content": "    possible (via GitPython, or an independent writer).",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    Each instance carries a public `overrides` attribute. This dictionary",
                                "type": "added"
                            },
                            {
                                "content": "    contains variables that override any setting read from a file. The overrides",
                                "type": "added"
                            },
                            {
                                "content": "    are persistent across reloads, and are not modified by any of the manipulation",
                                "type": "added"
                            },
                            {
                                "content": "    methods, such as `set` or `unset`.",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    Any DATALAD_* environment variable is also presented as a configuration",
                                "type": "context"
                            },
                            {
                                "content": "    item. Settings read from environment variables are not stored in any of the",
                                "type": "context"
                            },
                            {
                                "content": "    configuration file, but are read dynamically from the environment at each",
                                "type": "context"
                            },
                            {
                                "content": "    `reload()` call. Their values take precedence over any specification in",
                                "type": "context"
                            },
                            {
                                "content": "    configuration files.",
                                "type": "deleted"
                            },
                            {
                                "content": "    configuration files, and even overrides.",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    Parameters",
                                "type": "context"
                            },
                            {
                                "content": "    ----------",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/config.py",
                            "type": "class",
                            "name": "ConfigManager",
                            "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 95,
                            "end_lineno": 535,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 130,
                            "length": 12
                        },
                        "new_range": {
                            "start": 135,
                            "length": 17
                        },
                        "section": "class ConfigManager(object):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "      If True, configuration items are only read from a datasets persistent",
                                "type": "context"
                            },
                            {
                                "content": "      configuration file, if any present (the one in ``.datalad/config``, not",
                                "type": "context"
                            },
                            {
                                "content": "      ``.git/config``).",
                                "type": "context"
                            },
                            {
                                "content": "    overrides : dict, optional",
                                "type": "added"
                            },
                            {
                                "content": "      Variable overrides, see general class documentation for details.",
                                "type": "added"
                            },
                            {
                                "content": "    \"\"\"",
                                "type": "context"
                            },
                            {
                                "content": "    def __init__(self, dataset=None, dataset_only=False):",
                                "type": "deleted"
                            },
                            {
                                "content": "    def __init__(self, dataset=None, dataset_only=False, overrides=None):",
                                "type": "added"
                            },
                            {
                                "content": "        # store in a simple dict",
                                "type": "context"
                            },
                            {
                                "content": "        # no subclassing, because we want to be largely read-only, and implement",
                                "type": "context"
                            },
                            {
                                "content": "        # config writing separately",
                                "type": "context"
                            },
                            {
                                "content": "        self._store = {}",
                                "type": "context"
                            },
                            {
                                "content": "        # public dict to store variables that always override any setting",
                                "type": "added"
                            },
                            {
                                "content": "        # read from a file",
                                "type": "added"
                            },
                            {
                                "content": "        self.overrides = {} if overrides is None else overrides",
                                "type": "added"
                            },
                            {
                                "content": "        self._dataset_path = dataset.path if dataset else None",
                                "type": "context"
                            },
                            {
                                "content": "        self._dataset_only = dataset_only",
                                "type": "context"
                            },
                            {
                                "content": "        # Since configs could contain sensitive information, to prevent",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/config.py",
                            "type": "class",
                            "name": "ConfigManager",
                            "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 95,
                            "end_lineno": 535,
                            "parent": null
                        },
                        {
                            "file_name": "datalad/config.py",
                            "type": "method",
                            "name": "ConfigManager.__init__",
                            "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 134,
                            "end_lineno": 150,
                            "parent": {
                                "file_name": "datalad/config.py",
                                "type": "class",
                                "name": "ConfigManager",
                                "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 95,
                                "end_lineno": 535,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 169,
                            "length": 13
                        },
                        "new_range": {
                            "start": 179,
                            "length": 20
                        },
                        "section": "class ConfigManager(object):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "                self._store = _parse_gitconfig_dump(",
                                "type": "context"
                            },
                            {
                                "content": "                    stdout, self._store, replace=False)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        if not self._dataset_only:",
                                "type": "deleted"
                            },
                            {
                                "content": "            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)",
                                "type": "deleted"
                            },
                            {
                                "content": "            self._store = _parse_gitconfig_dump(",
                                "type": "deleted"
                            },
                            {
                                "content": "                stdout, self._store, replace=True)",
                                "type": "deleted"
                            },
                            {
                                "content": "        if self._dataset_only:",
                                "type": "added"
                            },
                            {
                                "content": "            # superimpose overrides",
                                "type": "added"
                            },
                            {
                                "content": "            self._store.update(self.overrides)",
                                "type": "added"
                            },
                            {
                                "content": "            return",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        stdout, stderr = self._run(['-z', '-l'], log_stderr=True)",
                                "type": "added"
                            },
                            {
                                "content": "        self._store = _parse_gitconfig_dump(",
                                "type": "added"
                            },
                            {
                                "content": "            stdout, self._store, replace=True)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        # superimpose overrides",
                                "type": "added"
                            },
                            {
                                "content": "        self._store.update(self.overrides)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "            # override with environment variables",
                                "type": "deleted"
                            },
                            {
                                "content": "            self._store = _parse_env(self._store)",
                                "type": "deleted"
                            },
                            {
                                "content": "        # override with environment variables",
                                "type": "added"
                            },
                            {
                                "content": "        self._store = _parse_env(self._store)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    @_where_reload",
                                "type": "context"
                            },
                            {
                                "content": "    def obtain(self, var, default=None, dialog_type=None, valtype=None,",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/config.py",
                            "type": "class",
                            "name": "ConfigManager",
                            "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 95,
                            "end_lineno": 535,
                            "parent": null
                        },
                        {
                            "file_name": "datalad/config.py",
                            "type": "method",
                            "name": "ConfigManager.reload",
                            "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 152,
                            "end_lineno": 178,
                            "parent": {
                                "file_name": "datalad/config.py",
                                "type": "class",
                                "name": "ConfigManager",
                                "content": "class ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 95,
                                "end_lineno": 535,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "# ex: set sts=4 ts=4 sw=4 noet:\n# -*- coding: utf-8 -*-\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"\n\n\"\"\"\n\nimport os\nfrom os.path import exists\nfrom os.path import join as opj\n\nfrom mock import patch\nfrom nose.tools import assert_false, assert_true, assert_equal\nfrom datalad.tests.utils import assert_raises\nfrom datalad.tests.utils import assert_in, assert_not_in\nfrom datalad.tests.utils import ok_file_has_content\nfrom datalad.tests.utils import with_tree\nfrom datalad.tests.utils import with_tempfile\nfrom datalad.utils import swallow_logs\n\nfrom datalad.distribution.dataset import Dataset\nfrom datalad.api import create\nfrom datalad.config import ConfigManager\nfrom datalad.cmd import CommandError\n\nfrom datalad.tests.utils import with_testsui\n\n# XXX tabs are intentional (part of the format)!\n# XXX put back! confuses pep8\n_config_file_content = \"\"\"\\\n[something]\nuser = name=Jane Doe\nuser = email=jd@example.com\nmyint = 3\n\n[onemore \"complicated の beast with.dot\"]\nfindme = 5.0\n\"\"\"\n\n_dataset_config_template = {\n    'ds': {\n    '.datalad': {\n        'config': _config_file_content}}}\n\n\n@with_tree(tree=_dataset_config_template)\n@with_tempfile(mkdir=True)\ndef test_something(path, new_home):\n    # read nothing, has nothing\n    cfg = ConfigManager(dataset_only=True)\n    assert_false(len(cfg))\n    # now read the example config\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_equal(len(cfg), 3)\n    assert_in('something.user', cfg)\n    # multi-value\n    assert_equal(len(cfg['something.user']), 2)\n    assert_equal(cfg['something.user'], ('name=Jane Doe', 'email=jd@example.com'))\n\n    assert_true(cfg.has_section('something'))\n    assert_false(cfg.has_section('somethingelse'))\n    assert_equal(sorted(cfg.sections()), ['onemore.complicated の beast with.dot', 'something'])\n    assert_true(cfg.has_option('something', 'user'))\n    assert_false(cfg.has_option('something', 'us?er'))\n    assert_false(cfg.has_option('some?thing', 'user'))\n    assert_equal(sorted(cfg.options('something')), ['myint', 'user'])\n    assert_equal(cfg.options('onemore.complicated の beast with.dot'), ['findme'])\n\n    assert_equal(\n        sorted(cfg.items()),\n        [('onemore.complicated の beast with.dot.findme', '5.0'),\n         ('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n    assert_equal(\n        sorted(cfg.items('something')),\n        [('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n\n    # always get all values\n    assert_equal(\n        cfg.get('something.user'),\n        ('name=Jane Doe', 'email=jd@example.com'))\n    assert_raises(KeyError, cfg.__getitem__, 'somedthing.user')\n    assert_equal(cfg.getfloat('onemore.complicated の beast with.dot', 'findme'), 5.0)\n    assert_equal(cfg.getint('something', 'myint'), 3)\n    assert_equal(cfg.getbool('something', 'myint'), True)\n    assert_equal(cfg.getbool('doesnot', 'exist', default=True), True)\n    assert_raises(TypeError, cfg.getbool, 'something', 'user')\n\n    # gitpython-style access\n    assert_equal(cfg.get('something.myint'), cfg.get_value('something', 'myint'))\n    assert_equal(cfg.get_value('doesnot', 'exist', default='oohaaa'), 'oohaaa')\n    # weired, but that is how it is\n    assert_raises(KeyError, cfg.get_value, 'doesnot', 'exist', default=None)\n\n    # modification follows\n    cfg.add('something.new', 'の')\n    assert_equal(cfg.get('something.new'), 'の')\n    # sections are added on demand\n    cfg.add('unheard.of', 'fame')\n    assert_true(cfg.has_section('unheard.of'))\n    comp = cfg.items('something')\n    cfg.rename_section('something', 'this')\n    assert_true(cfg.has_section('this'))\n    assert_false(cfg.has_section('something'))\n    # direct comparision would fail, because of section prefix\n    assert_equal(len(cfg.items('this')), len(comp))\n    # fail if no such section\n    with swallow_logs():\n        assert_raises(CommandError, cfg.rename_section, 'nothere', 'irrelevant')\n    assert_true(cfg.has_option('this', 'myint'))\n    cfg.unset('this.myint')\n    assert_false(cfg.has_option('this', 'myint'))\n\n    # batch a changes\n    cfg.add('mike.wants.to', 'know', reload=False)\n    assert_false('mike.wants.to' in cfg)\n    cfg.add('mike.wants.to', 'eat')\n    assert_true('mike.wants.to' in cfg)\n    assert_equal(len(cfg['mike.wants.to']), 2)\n\n    # set a new one:\n    cfg.set('mike.should.have', 'known')\n    assert_in('mike.should.have', cfg)\n    assert_equal(cfg['mike.should.have'], 'known')\n    # set an existing one:\n    cfg.set('mike.should.have', 'known better')\n    assert_equal(cfg['mike.should.have'], 'known better')\n    # set, while there are several matching ones already:\n    cfg.add('mike.should.have', 'a meal')\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # raises with force=False\n    assert_raises(CommandError,\n                  cfg.set, 'mike.should.have', 'a beer', force=False)\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # replaces all matching ones with force=True\n    cfg.set('mike.should.have', 'a beer', force=True)\n    assert_equal(cfg['mike.should.have'], 'a beer')\n\n    # fails unknown location\n    assert_raises(ValueError, cfg.add, 'somesuch', 'shit', where='umpalumpa')\n\n    # very carefully test non-local config\n    # so carefully that even in case of bad weather Yarik doesn't find some\n    # lame datalad unittest sections in his precious ~/.gitconfig\n    with patch.dict('os.environ',\n                    {'HOME': new_home, 'DATALAD_SNEAKY_ADDITION': 'ignore'}):\n        global_gitconfig = opj(new_home, '.gitconfig')\n        assert(not exists(global_gitconfig))\n        globalcfg = ConfigManager(dataset_only=False)\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        assert_in('datalad.sneaky.addition', globalcfg)\n        cfg.add('datalad.unittest.youcan', 'removeme', where='global')\n        assert(exists(global_gitconfig))\n        # it did not go into the dataset's config!\n        assert_not_in('datalad.unittest.youcan', cfg)\n        # does not monitor changes!\n        globalcfg.reload()\n        assert_in('datalad.unittest.youcan', globalcfg)\n        with swallow_logs():\n            assert_raises(\n                CommandError,\n                globalcfg.unset,\n                'datalad.unittest.youcan',\n                where='local')\n        assert(globalcfg.has_section('datalad.unittest'))\n        globalcfg.unset('datalad.unittest.youcan', where='global')\n        # but after we unset the only value -- that section is no longer listed\n        assert (not globalcfg.has_section('datalad.unittest'))\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        # although it does leaves empty section behind in the file\n        ok_file_has_content(global_gitconfig, '[datalad \"unittest\"]', strip=True)\n        # remove_section to clean it up entirely\n        globalcfg.remove_section('datalad.unittest', where='global')\n        ok_file_has_content(global_gitconfig, \"\")\n\n\n@with_tree(tree={\n    'ds': {\n    '.datalad': {\n        'config': \"\"\"\\\n[crazy]\n    fa = !git remote | xargs -r -I REMOTE /bin/bash -c 'echo I: Fetching from REMOTE && git fetch --prune REMOTE && git fetch -t REMOTE' && [ -d .git/svn ] && bash -c 'echo I: Fetching from SVN && git svn fetch' || : && [ -e .gitmodules ] && bash -c 'echo I: Fetching submodules && git submodule foreach git fa' && [ -d .git/sd ] && bash -c 'echo I: Fetching bugs into sd && git-sd pull --all' || :\n    pa = !git paremotes | tr ' ' '\\\\n'  | xargs -r -l1 git push\n    pt = !git testremotes | tr ' ' '\\\\n'  | xargs -r -l1 -I R git push -f R master\n    ptdry = !git testremotes | tr ' ' '\\\\n'  | xargs -r -l1 -I R git push -f --dry-run R master\n    padry = !git paremotes | tr ' ' '\\\\n' | xargs -r -l1 git push --dry-run\n\"\"\"}}})\ndef test_crazy_cfg(path):\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_in('crazy.padry', cfg)\n\n\n@with_tempfile\ndef test_obtain(path):\n    ds = create(path)\n    cfg = ConfigManager(ds)\n    dummy = 'datalad.test.dummy'\n    # we know nothing and we don't know how to ask\n    assert_raises(RuntimeError, cfg.obtain, dummy)\n    # can report known ones\n    cfg.add(dummy, '5.3')\n    assert_equal(cfg.obtain(dummy), '5.3')\n    # better type\n    assert_equal(cfg.obtain(dummy, valtype=float), 5.3)\n    # don't hide type issues, float doesn't become an int magically\n    assert_raises(ValueError, cfg.obtain, dummy, valtype=int)\n    # inject some prior knowledge\n    from datalad.interface.common_cfg import definitions as cfg_defs\n    cfg_defs[dummy] = dict(type=float)\n    # no we don't need to specify a type anymore\n    assert_equal(cfg.obtain(dummy), 5.3)\n    # but if we remove the value from the config, all magic is gone\n    cfg.unset(dummy)\n    # we know nothing and we don't know how to ask\n    assert_raises(RuntimeError, cfg.obtain, dummy)\n\n    #\n    # test actual interaction\n    #\n    @with_testsui()\n    def ask():\n        # fail on unkown dialog type\n        assert_raises(ValueError, cfg.obtain, dummy, dialog_type='Rorschach_test')\n    ask()\n\n    # ask nicely, and get a value of proper type using the preconfiguration\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(\n            cfg.obtain(dummy, dialog_type='question', text='Tell me'), 5.3)\n    ask()\n\n    # preconfigure even more, to get the most compact call\n    cfg_defs[dummy]['ui'] = ('question', dict(text='tell me', title='Gretchen Frage'))\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(cfg.obtain(dummy), 5.3)\n    ask()\n\n    @with_testsui(responses='murks')\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy)\n    ask()\n\n    # fail to store when destination is not specified, will not even ask\n    @with_testsui()\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy, store=True)\n    ask()\n\n    # but we can preconfigure it\n    cfg_defs[dummy]['destination'] = 'broken'\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy, store=True)\n    ask()\n\n    # fixup destination\n    cfg_defs[dummy]['destination'] = 'dataset'\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(cfg.obtain(dummy, store=True), 5.3)\n    ask()\n\n    # now it won't have to ask again\n    @with_testsui()\n    def ask():\n        assert_equal(cfg.obtain(dummy), 5.3)\n    ask()\n\n    # wipe it out again\n    cfg.unset(dummy)\n    assert_not_in(dummy, cfg)\n\n    # XXX cannot figure out how I can simulate a simple <Enter>\n    ## respond with accepting the default\n    #@with_testsui(responses=...)\n    #def ask():\n    #    assert_equal(cfg.obtain(dummy, default=5.3), 5.3)\n    #ask()\n\n\ndef test_from_env():\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.cfg', cfg)\n    os.environ['DATALAD_CRAZY_CFG'] = 'impossibletoguess'\n    cfg.reload()\n    assert_in('datalad.crazy.cfg', cfg)\n    assert_equal(cfg['datalad.crazy.cfg'], 'impossibletoguess')\n    # not in dataset-only mode\n    cfg = ConfigManager(Dataset('nowhere'), dataset_only=True)\n    assert_not_in('datalad.crazy.cfg', cfg)\n",
            "new_file_content": "# ex: set sts=4 ts=4 sw=4 noet:\n# -*- coding: utf-8 -*-\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"\n\n\"\"\"\n\nimport os\nfrom os.path import exists\nfrom os.path import join as opj\n\nfrom mock import patch\nfrom nose.tools import assert_false, assert_true, assert_equal\nfrom datalad.tests.utils import assert_raises\nfrom datalad.tests.utils import assert_in, assert_not_in\nfrom datalad.tests.utils import ok_file_has_content\nfrom datalad.tests.utils import with_tree\nfrom datalad.tests.utils import with_tempfile\nfrom datalad.utils import swallow_logs\n\nfrom datalad.distribution.dataset import Dataset\nfrom datalad.api import create\nfrom datalad.config import ConfigManager\nfrom datalad.cmd import CommandError\n\nfrom datalad.tests.utils import with_testsui\n\n# XXX tabs are intentional (part of the format)!\n# XXX put back! confuses pep8\n_config_file_content = \"\"\"\\\n[something]\nuser = name=Jane Doe\nuser = email=jd@example.com\nmyint = 3\n\n[onemore \"complicated の beast with.dot\"]\nfindme = 5.0\n\"\"\"\n\n_dataset_config_template = {\n    'ds': {\n    '.datalad': {\n        'config': _config_file_content}}}\n\n\n@with_tree(tree=_dataset_config_template)\n@with_tempfile(mkdir=True)\ndef test_something(path, new_home):\n    # read nothing, has nothing\n    cfg = ConfigManager(dataset_only=True)\n    assert_false(len(cfg))\n    # now read the example config\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_equal(len(cfg), 3)\n    assert_in('something.user', cfg)\n    # multi-value\n    assert_equal(len(cfg['something.user']), 2)\n    assert_equal(cfg['something.user'], ('name=Jane Doe', 'email=jd@example.com'))\n\n    assert_true(cfg.has_section('something'))\n    assert_false(cfg.has_section('somethingelse'))\n    assert_equal(sorted(cfg.sections()), ['onemore.complicated の beast with.dot', 'something'])\n    assert_true(cfg.has_option('something', 'user'))\n    assert_false(cfg.has_option('something', 'us?er'))\n    assert_false(cfg.has_option('some?thing', 'user'))\n    assert_equal(sorted(cfg.options('something')), ['myint', 'user'])\n    assert_equal(cfg.options('onemore.complicated の beast with.dot'), ['findme'])\n\n    assert_equal(\n        sorted(cfg.items()),\n        [('onemore.complicated の beast with.dot.findme', '5.0'),\n         ('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n    assert_equal(\n        sorted(cfg.items('something')),\n        [('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n\n    # always get all values\n    assert_equal(\n        cfg.get('something.user'),\n        ('name=Jane Doe', 'email=jd@example.com'))\n    assert_raises(KeyError, cfg.__getitem__, 'somedthing.user')\n    assert_equal(cfg.getfloat('onemore.complicated の beast with.dot', 'findme'), 5.0)\n    assert_equal(cfg.getint('something', 'myint'), 3)\n    assert_equal(cfg.getbool('something', 'myint'), True)\n    assert_equal(cfg.getbool('doesnot', 'exist', default=True), True)\n    assert_raises(TypeError, cfg.getbool, 'something', 'user')\n\n    # gitpython-style access\n    assert_equal(cfg.get('something.myint'), cfg.get_value('something', 'myint'))\n    assert_equal(cfg.get_value('doesnot', 'exist', default='oohaaa'), 'oohaaa')\n    # weired, but that is how it is\n    assert_raises(KeyError, cfg.get_value, 'doesnot', 'exist', default=None)\n\n    # modification follows\n    cfg.add('something.new', 'の')\n    assert_equal(cfg.get('something.new'), 'の')\n    # sections are added on demand\n    cfg.add('unheard.of', 'fame')\n    assert_true(cfg.has_section('unheard.of'))\n    comp = cfg.items('something')\n    cfg.rename_section('something', 'this')\n    assert_true(cfg.has_section('this'))\n    assert_false(cfg.has_section('something'))\n    # direct comparision would fail, because of section prefix\n    assert_equal(len(cfg.items('this')), len(comp))\n    # fail if no such section\n    with swallow_logs():\n        assert_raises(CommandError, cfg.rename_section, 'nothere', 'irrelevant')\n    assert_true(cfg.has_option('this', 'myint'))\n    cfg.unset('this.myint')\n    assert_false(cfg.has_option('this', 'myint'))\n\n    # batch a changes\n    cfg.add('mike.wants.to', 'know', reload=False)\n    assert_false('mike.wants.to' in cfg)\n    cfg.add('mike.wants.to', 'eat')\n    assert_true('mike.wants.to' in cfg)\n    assert_equal(len(cfg['mike.wants.to']), 2)\n\n    # set a new one:\n    cfg.set('mike.should.have', 'known')\n    assert_in('mike.should.have', cfg)\n    assert_equal(cfg['mike.should.have'], 'known')\n    # set an existing one:\n    cfg.set('mike.should.have', 'known better')\n    assert_equal(cfg['mike.should.have'], 'known better')\n    # set, while there are several matching ones already:\n    cfg.add('mike.should.have', 'a meal')\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # raises with force=False\n    assert_raises(CommandError,\n                  cfg.set, 'mike.should.have', 'a beer', force=False)\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # replaces all matching ones with force=True\n    cfg.set('mike.should.have', 'a beer', force=True)\n    assert_equal(cfg['mike.should.have'], 'a beer')\n\n    # fails unknown location\n    assert_raises(ValueError, cfg.add, 'somesuch', 'shit', where='umpalumpa')\n\n    # very carefully test non-local config\n    # so carefully that even in case of bad weather Yarik doesn't find some\n    # lame datalad unittest sections in his precious ~/.gitconfig\n    with patch.dict('os.environ',\n                    {'HOME': new_home, 'DATALAD_SNEAKY_ADDITION': 'ignore'}):\n        global_gitconfig = opj(new_home, '.gitconfig')\n        assert(not exists(global_gitconfig))\n        globalcfg = ConfigManager(dataset_only=False)\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        assert_in('datalad.sneaky.addition', globalcfg)\n        cfg.add('datalad.unittest.youcan', 'removeme', where='global')\n        assert(exists(global_gitconfig))\n        # it did not go into the dataset's config!\n        assert_not_in('datalad.unittest.youcan', cfg)\n        # does not monitor changes!\n        globalcfg.reload()\n        assert_in('datalad.unittest.youcan', globalcfg)\n        with swallow_logs():\n            assert_raises(\n                CommandError,\n                globalcfg.unset,\n                'datalad.unittest.youcan',\n                where='local')\n        assert(globalcfg.has_section('datalad.unittest'))\n        globalcfg.unset('datalad.unittest.youcan', where='global')\n        # but after we unset the only value -- that section is no longer listed\n        assert (not globalcfg.has_section('datalad.unittest'))\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        # although it does leaves empty section behind in the file\n        ok_file_has_content(global_gitconfig, '[datalad \"unittest\"]', strip=True)\n        # remove_section to clean it up entirely\n        globalcfg.remove_section('datalad.unittest', where='global')\n        ok_file_has_content(global_gitconfig, \"\")\n\n    cfg = ConfigManager(\n        Dataset(opj(path, 'ds')),\n        dataset_only=True,\n        overrides={'datalad.godgiven': True})\n    assert_equal(cfg.get('datalad.godgiven'), True)\n    # setter has no effect\n    cfg.set('datalad.godgiven', 'false')\n    assert_equal(cfg.get('datalad.godgiven'), True)\n\n@with_tree(tree={\n    'ds': {\n    '.datalad': {\n        'config': \"\"\"\\\n[crazy]\n    fa = !git remote | xargs -r -I REMOTE /bin/bash -c 'echo I: Fetching from REMOTE && git fetch --prune REMOTE && git fetch -t REMOTE' && [ -d .git/svn ] && bash -c 'echo I: Fetching from SVN && git svn fetch' || : && [ -e .gitmodules ] && bash -c 'echo I: Fetching submodules && git submodule foreach git fa' && [ -d .git/sd ] && bash -c 'echo I: Fetching bugs into sd && git-sd pull --all' || :\n    pa = !git paremotes | tr ' ' '\\\\n'  | xargs -r -l1 git push\n    pt = !git testremotes | tr ' ' '\\\\n'  | xargs -r -l1 -I R git push -f R master\n    ptdry = !git testremotes | tr ' ' '\\\\n'  | xargs -r -l1 -I R git push -f --dry-run R master\n    padry = !git paremotes | tr ' ' '\\\\n' | xargs -r -l1 git push --dry-run\n\"\"\"}}})\ndef test_crazy_cfg(path):\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_in('crazy.padry', cfg)\n\n\n@with_tempfile\ndef test_obtain(path):\n    ds = create(path)\n    cfg = ConfigManager(ds)\n    dummy = 'datalad.test.dummy'\n    # we know nothing and we don't know how to ask\n    assert_raises(RuntimeError, cfg.obtain, dummy)\n    # can report known ones\n    cfg.add(dummy, '5.3')\n    assert_equal(cfg.obtain(dummy), '5.3')\n    # better type\n    assert_equal(cfg.obtain(dummy, valtype=float), 5.3)\n    # don't hide type issues, float doesn't become an int magically\n    assert_raises(ValueError, cfg.obtain, dummy, valtype=int)\n    # inject some prior knowledge\n    from datalad.interface.common_cfg import definitions as cfg_defs\n    cfg_defs[dummy] = dict(type=float)\n    # no we don't need to specify a type anymore\n    assert_equal(cfg.obtain(dummy), 5.3)\n    # but if we remove the value from the config, all magic is gone\n    cfg.unset(dummy)\n    # we know nothing and we don't know how to ask\n    assert_raises(RuntimeError, cfg.obtain, dummy)\n\n    #\n    # test actual interaction\n    #\n    @with_testsui()\n    def ask():\n        # fail on unkown dialog type\n        assert_raises(ValueError, cfg.obtain, dummy, dialog_type='Rorschach_test')\n    ask()\n\n    # ask nicely, and get a value of proper type using the preconfiguration\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(\n            cfg.obtain(dummy, dialog_type='question', text='Tell me'), 5.3)\n    ask()\n\n    # preconfigure even more, to get the most compact call\n    cfg_defs[dummy]['ui'] = ('question', dict(text='tell me', title='Gretchen Frage'))\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(cfg.obtain(dummy), 5.3)\n    ask()\n\n    @with_testsui(responses='murks')\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy)\n    ask()\n\n    # fail to store when destination is not specified, will not even ask\n    @with_testsui()\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy, store=True)\n    ask()\n\n    # but we can preconfigure it\n    cfg_defs[dummy]['destination'] = 'broken'\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy, store=True)\n    ask()\n\n    # fixup destination\n    cfg_defs[dummy]['destination'] = 'dataset'\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(cfg.obtain(dummy, store=True), 5.3)\n    ask()\n\n    # now it won't have to ask again\n    @with_testsui()\n    def ask():\n        assert_equal(cfg.obtain(dummy), 5.3)\n    ask()\n\n    # wipe it out again\n    cfg.unset(dummy)\n    assert_not_in(dummy, cfg)\n\n    # XXX cannot figure out how I can simulate a simple <Enter>\n    ## respond with accepting the default\n    #@with_testsui(responses=...)\n    #def ask():\n    #    assert_equal(cfg.obtain(dummy, default=5.3), 5.3)\n    #ask()\n\n\ndef test_from_env():\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.cfg', cfg)\n    os.environ['DATALAD_CRAZY_CFG'] = 'impossibletoguess'\n    cfg.reload()\n    assert_in('datalad.crazy.cfg', cfg)\n    assert_equal(cfg['datalad.crazy.cfg'], 'impossibletoguess')\n    # not in dataset-only mode\n    cfg = ConfigManager(Dataset('nowhere'), dataset_only=True)\n    assert_not_in('datalad.crazy.cfg', cfg)\n    # check env trumps override\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.override', cfg)\n    cfg.overrides['datalad.crazy.override'] = 'fromoverride'\n    cfg.reload()\n    assert_equal(cfg['datalad.crazy.override'], 'fromoverride')\n    os.environ['DATALAD_CRAZY_OVERRIDE'] = 'fromenv'\n    cfg.reload()\n    assert_equal(cfg['datalad.crazy.override'], 'fromenv')\n",
            "header": {
                "file": {
                    "path": "datalad/tests/test_config.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "4d64dfeaa",
                "new_commit_hash": "6841eb241",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/datalad/tests/test_config.py"
            },
            "plus_file": {
                "path": "b/datalad/tests/test_config.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 179,
                            "length": 6
                        },
                        "new_range": {
                            "start": 179,
                            "length": 14
                        },
                        "section": "def test_something(path, new_home):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        globalcfg.remove_section('datalad.unittest', where='global')",
                                "type": "context"
                            },
                            {
                                "content": "        ok_file_has_content(global_gitconfig, \"\")",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    cfg = ConfigManager(",
                                "type": "added"
                            },
                            {
                                "content": "        Dataset(opj(path, 'ds')),",
                                "type": "added"
                            },
                            {
                                "content": "        dataset_only=True,",
                                "type": "added"
                            },
                            {
                                "content": "        overrides={'datalad.godgiven': True})",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(cfg.get('datalad.godgiven'), True)",
                                "type": "added"
                            },
                            {
                                "content": "    # setter has no effect",
                                "type": "added"
                            },
                            {
                                "content": "    cfg.set('datalad.godgiven', 'false')",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(cfg.get('datalad.godgiven'), True)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "@with_tree(tree={",
                                "type": "context"
                            },
                            {
                                "content": "    'ds': {",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/tests/test_config.py",
                            "type": "function",
                            "name": "test_something",
                            "content": "def test_something(path, new_home):\n    # read nothing, has nothing\n    cfg = ConfigManager(dataset_only=True)\n    assert_false(len(cfg))\n    # now read the example config\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_equal(len(cfg), 3)\n    assert_in('something.user', cfg)\n    # multi-value\n    assert_equal(len(cfg['something.user']), 2)\n    assert_equal(cfg['something.user'], ('name=Jane Doe', 'email=jd@example.com'))\n\n    assert_true(cfg.has_section('something'))\n    assert_false(cfg.has_section('somethingelse'))\n    assert_equal(sorted(cfg.sections()), ['onemore.complicated の beast with.dot', 'something'])\n    assert_true(cfg.has_option('something', 'user'))\n    assert_false(cfg.has_option('something', 'us?er'))\n    assert_false(cfg.has_option('some?thing', 'user'))\n    assert_equal(sorted(cfg.options('something')), ['myint', 'user'])\n    assert_equal(cfg.options('onemore.complicated の beast with.dot'), ['findme'])\n\n    assert_equal(\n        sorted(cfg.items()),\n        [('onemore.complicated の beast with.dot.findme', '5.0'),\n         ('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n    assert_equal(\n        sorted(cfg.items('something')),\n        [('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n\n    # always get all values\n    assert_equal(\n        cfg.get('something.user'),\n        ('name=Jane Doe', 'email=jd@example.com'))\n    assert_raises(KeyError, cfg.__getitem__, 'somedthing.user')\n    assert_equal(cfg.getfloat('onemore.complicated の beast with.dot', 'findme'), 5.0)\n    assert_equal(cfg.getint('something', 'myint'), 3)\n    assert_equal(cfg.getbool('something', 'myint'), True)\n    assert_equal(cfg.getbool('doesnot', 'exist', default=True), True)\n    assert_raises(TypeError, cfg.getbool, 'something', 'user')\n\n    # gitpython-style access\n    assert_equal(cfg.get('something.myint'), cfg.get_value('something', 'myint'))\n    assert_equal(cfg.get_value('doesnot', 'exist', default='oohaaa'), 'oohaaa')\n    # weired, but that is how it is\n    assert_raises(KeyError, cfg.get_value, 'doesnot', 'exist', default=None)\n\n    # modification follows\n    cfg.add('something.new', 'の')\n    assert_equal(cfg.get('something.new'), 'の')\n    # sections are added on demand\n    cfg.add('unheard.of', 'fame')\n    assert_true(cfg.has_section('unheard.of'))\n    comp = cfg.items('something')\n    cfg.rename_section('something', 'this')\n    assert_true(cfg.has_section('this'))\n    assert_false(cfg.has_section('something'))\n    # direct comparision would fail, because of section prefix\n    assert_equal(len(cfg.items('this')), len(comp))\n    # fail if no such section\n    with swallow_logs():\n        assert_raises(CommandError, cfg.rename_section, 'nothere', 'irrelevant')\n    assert_true(cfg.has_option('this', 'myint'))\n    cfg.unset('this.myint')\n    assert_false(cfg.has_option('this', 'myint'))\n\n    # batch a changes\n    cfg.add('mike.wants.to', 'know', reload=False)\n    assert_false('mike.wants.to' in cfg)\n    cfg.add('mike.wants.to', 'eat')\n    assert_true('mike.wants.to' in cfg)\n    assert_equal(len(cfg['mike.wants.to']), 2)\n\n    # set a new one:\n    cfg.set('mike.should.have', 'known')\n    assert_in('mike.should.have', cfg)\n    assert_equal(cfg['mike.should.have'], 'known')\n    # set an existing one:\n    cfg.set('mike.should.have', 'known better')\n    assert_equal(cfg['mike.should.have'], 'known better')\n    # set, while there are several matching ones already:\n    cfg.add('mike.should.have', 'a meal')\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # raises with force=False\n    assert_raises(CommandError,\n                  cfg.set, 'mike.should.have', 'a beer', force=False)\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # replaces all matching ones with force=True\n    cfg.set('mike.should.have', 'a beer', force=True)\n    assert_equal(cfg['mike.should.have'], 'a beer')\n\n    # fails unknown location\n    assert_raises(ValueError, cfg.add, 'somesuch', 'shit', where='umpalumpa')\n\n    # very carefully test non-local config\n    # so carefully that even in case of bad weather Yarik doesn't find some\n    # lame datalad unittest sections in his precious ~/.gitconfig\n    with patch.dict('os.environ',\n                    {'HOME': new_home, 'DATALAD_SNEAKY_ADDITION': 'ignore'}):\n        global_gitconfig = opj(new_home, '.gitconfig')\n        assert(not exists(global_gitconfig))\n        globalcfg = ConfigManager(dataset_only=False)\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        assert_in('datalad.sneaky.addition', globalcfg)\n        cfg.add('datalad.unittest.youcan', 'removeme', where='global')\n        assert(exists(global_gitconfig))\n        # it did not go into the dataset's config!\n        assert_not_in('datalad.unittest.youcan', cfg)\n        # does not monitor changes!\n        globalcfg.reload()\n        assert_in('datalad.unittest.youcan', globalcfg)\n        with swallow_logs():\n            assert_raises(\n                CommandError,\n                globalcfg.unset,\n                'datalad.unittest.youcan',\n                where='local')\n        assert(globalcfg.has_section('datalad.unittest'))\n        globalcfg.unset('datalad.unittest.youcan', where='global')\n        # but after we unset the only value -- that section is no longer listed\n        assert (not globalcfg.has_section('datalad.unittest'))\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        # although it does leaves empty section behind in the file\n        ok_file_has_content(global_gitconfig, '[datalad \"unittest\"]', strip=True)\n        # remove_section to clean it up entirely\n        globalcfg.remove_section('datalad.unittest', where='global')\n        ok_file_has_content(global_gitconfig, \"\")\n\n    cfg = ConfigManager(\n        Dataset(opj(path, 'ds')),\n        dataset_only=True,\n        overrides={'datalad.godgiven': True})\n    assert_equal(cfg.get('datalad.godgiven'), True)\n    # setter has no effect\n    cfg.set('datalad.godgiven', 'false')\n    assert_equal(cfg.get('datalad.godgiven'), True)",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 53,
                            "end_lineno": 189,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 299,
                            "length": 3
                        },
                        "new_range": {
                            "start": 307,
                            "length": 12
                        },
                        "section": "def test_from_env():"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    # not in dataset-only mode",
                                "type": "context"
                            },
                            {
                                "content": "    cfg = ConfigManager(Dataset('nowhere'), dataset_only=True)",
                                "type": "context"
                            },
                            {
                                "content": "    assert_not_in('datalad.crazy.cfg', cfg)",
                                "type": "context"
                            },
                            {
                                "content": "    # check env trumps override",
                                "type": "added"
                            },
                            {
                                "content": "    cfg = ConfigManager()",
                                "type": "added"
                            },
                            {
                                "content": "    assert_not_in('datalad.crazy.override', cfg)",
                                "type": "added"
                            },
                            {
                                "content": "    cfg.overrides['datalad.crazy.override'] = 'fromoverride'",
                                "type": "added"
                            },
                            {
                                "content": "    cfg.reload()",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(cfg['datalad.crazy.override'], 'fromoverride')",
                                "type": "added"
                            },
                            {
                                "content": "    os.environ['DATALAD_CRAZY_OVERRIDE'] = 'fromenv'",
                                "type": "added"
                            },
                            {
                                "content": "    cfg.reload()",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(cfg['datalad.crazy.override'], 'fromenv')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/tests/test_config.py",
                            "type": "function",
                            "name": "test_from_env",
                            "content": "def test_from_env():\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.cfg', cfg)\n    os.environ['DATALAD_CRAZY_CFG'] = 'impossibletoguess'\n    cfg.reload()\n    assert_in('datalad.crazy.cfg', cfg)\n    assert_equal(cfg['datalad.crazy.cfg'], 'impossibletoguess')\n    # not in dataset-only mode\n    cfg = ConfigManager(Dataset('nowhere'), dataset_only=True)\n    assert_not_in('datalad.crazy.cfg', cfg)\n    # check env trumps override\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.override', cfg)\n    cfg.overrides['datalad.crazy.override'] = 'fromoverride'\n    cfg.reload()\n    assert_equal(cfg['datalad.crazy.override'], 'fromoverride')\n    os.environ['DATALAD_CRAZY_OVERRIDE'] = 'fromenv'\n    cfg.reload()\n    assert_equal(cfg['datalad.crazy.override'], 'fromenv')",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 300,
                            "end_lineno": 318,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "9670bc78ef2601fc3f4dda507c9591f90232efd1^",
    "new_commit_hash": "9670bc78ef2601fc3f4dda507c9591f90232efd1",
    "commit_message": "NF: General `overrides` mechanism for ConfigManager()\n\nSee docstring diff for details.",
    "commit_date": "2017-03-01T10:25:46+01:00",
    "metadata": {}
}
{
    "repo_name": "datalad",
    "new_commit_hash": "9670bc78ef2601fc3f4dda507c9591f90232efd1",
    "test_file_codes": [
        "# ex: set sts=4 ts=4 sw=4 noet:\n# -*- coding: utf-8 -*-\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"\n\n\"\"\"\n\nimport os\nfrom os.path import exists\nfrom os.path import join as opj\n\nfrom mock import patch\nfrom nose.tools import assert_false, assert_true, assert_equal\nfrom datalad.tests.utils import assert_raises\nfrom datalad.tests.utils import assert_in, assert_not_in\nfrom datalad.tests.utils import ok_file_has_content\nfrom datalad.tests.utils import with_tree\nfrom datalad.tests.utils import with_tempfile\nfrom datalad.utils import swallow_logs\n\nfrom datalad.distribution.dataset import Dataset\nfrom datalad.api import create\nfrom datalad.config import ConfigManager\nfrom datalad.cmd import CommandError\n\nfrom datalad.tests.utils import with_testsui\n\n# XXX tabs are intentional (part of the format)!\n# XXX put back! confuses pep8\n_config_file_content = \"\"\"\\\n[something]\nuser = name=Jane Doe\nuser = email=jd@example.com\nmyint = 3\n\n[onemore \"complicated の beast with.dot\"]\nfindme = 5.0\n\"\"\"\n\n_dataset_config_template = {\n    'ds': {\n    '.datalad': {\n        'config': _config_file_content}}}\n\n\n@with_tree(tree=_dataset_config_template)\n@with_tempfile(mkdir=True)\ndef test_something(path, new_home):\n    # read nothing, has nothing\n    cfg = ConfigManager(dataset_only=True)\n    assert_false(len(cfg))\n    # now read the example config\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_equal(len(cfg), 3)\n    assert_in('something.user', cfg)\n    # multi-value\n    assert_equal(len(cfg['something.user']), 2)\n    assert_equal(cfg['something.user'], ('name=Jane Doe', 'email=jd@example.com'))\n\n    assert_true(cfg.has_section('something'))\n    assert_false(cfg.has_section('somethingelse'))\n    assert_equal(sorted(cfg.sections()), ['onemore.complicated の beast with.dot', 'something'])\n    assert_true(cfg.has_option('something', 'user'))\n    assert_false(cfg.has_option('something', 'us?er'))\n    assert_false(cfg.has_option('some?thing', 'user'))\n    assert_equal(sorted(cfg.options('something')), ['myint', 'user'])\n    assert_equal(cfg.options('onemore.complicated の beast with.dot'), ['findme'])\n\n    assert_equal(\n        sorted(cfg.items()),\n        [('onemore.complicated の beast with.dot.findme', '5.0'),\n         ('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n    assert_equal(\n        sorted(cfg.items('something')),\n        [('something.myint', '3'),\n         ('something.user', ('name=Jane Doe', 'email=jd@example.com'))])\n\n    # always get all values\n    assert_equal(\n        cfg.get('something.user'),\n        ('name=Jane Doe', 'email=jd@example.com'))\n    assert_raises(KeyError, cfg.__getitem__, 'somedthing.user')\n    assert_equal(cfg.getfloat('onemore.complicated の beast with.dot', 'findme'), 5.0)\n    assert_equal(cfg.getint('something', 'myint'), 3)\n    assert_equal(cfg.getbool('something', 'myint'), True)\n    assert_equal(cfg.getbool('doesnot', 'exist', default=True), True)\n    assert_raises(TypeError, cfg.getbool, 'something', 'user')\n\n    # gitpython-style access\n    assert_equal(cfg.get('something.myint'), cfg.get_value('something', 'myint'))\n    assert_equal(cfg.get_value('doesnot', 'exist', default='oohaaa'), 'oohaaa')\n    # weired, but that is how it is\n    assert_raises(KeyError, cfg.get_value, 'doesnot', 'exist', default=None)\n\n    # modification follows\n    cfg.add('something.new', 'の')\n    assert_equal(cfg.get('something.new'), 'の')\n    # sections are added on demand\n    cfg.add('unheard.of', 'fame')\n    assert_true(cfg.has_section('unheard.of'))\n    comp = cfg.items('something')\n    cfg.rename_section('something', 'this')\n    assert_true(cfg.has_section('this'))\n    assert_false(cfg.has_section('something'))\n    # direct comparision would fail, because of section prefix\n    assert_equal(len(cfg.items('this')), len(comp))\n    # fail if no such section\n    with swallow_logs():\n        assert_raises(CommandError, cfg.rename_section, 'nothere', 'irrelevant')\n    assert_true(cfg.has_option('this', 'myint'))\n    cfg.unset('this.myint')\n    assert_false(cfg.has_option('this', 'myint'))\n\n    # batch a changes\n    cfg.add('mike.wants.to', 'know', reload=False)\n    assert_false('mike.wants.to' in cfg)\n    cfg.add('mike.wants.to', 'eat')\n    assert_true('mike.wants.to' in cfg)\n    assert_equal(len(cfg['mike.wants.to']), 2)\n\n    # set a new one:\n    cfg.set('mike.should.have', 'known')\n    assert_in('mike.should.have', cfg)\n    assert_equal(cfg['mike.should.have'], 'known')\n    # set an existing one:\n    cfg.set('mike.should.have', 'known better')\n    assert_equal(cfg['mike.should.have'], 'known better')\n    # set, while there are several matching ones already:\n    cfg.add('mike.should.have', 'a meal')\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # raises with force=False\n    assert_raises(CommandError,\n                  cfg.set, 'mike.should.have', 'a beer', force=False)\n    assert_equal(len(cfg['mike.should.have']), 2)\n    # replaces all matching ones with force=True\n    cfg.set('mike.should.have', 'a beer', force=True)\n    assert_equal(cfg['mike.should.have'], 'a beer')\n\n    # fails unknown location\n    assert_raises(ValueError, cfg.add, 'somesuch', 'shit', where='umpalumpa')\n\n    # very carefully test non-local config\n    # so carefully that even in case of bad weather Yarik doesn't find some\n    # lame datalad unittest sections in his precious ~/.gitconfig\n    with patch.dict('os.environ',\n                    {'HOME': new_home, 'DATALAD_SNEAKY_ADDITION': 'ignore'}):\n        global_gitconfig = opj(new_home, '.gitconfig')\n        assert(not exists(global_gitconfig))\n        globalcfg = ConfigManager(dataset_only=False)\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        assert_in('datalad.sneaky.addition', globalcfg)\n        cfg.add('datalad.unittest.youcan', 'removeme', where='global')\n        assert(exists(global_gitconfig))\n        # it did not go into the dataset's config!\n        assert_not_in('datalad.unittest.youcan', cfg)\n        # does not monitor changes!\n        globalcfg.reload()\n        assert_in('datalad.unittest.youcan', globalcfg)\n        with swallow_logs():\n            assert_raises(\n                CommandError,\n                globalcfg.unset,\n                'datalad.unittest.youcan',\n                where='local')\n        assert(globalcfg.has_section('datalad.unittest'))\n        globalcfg.unset('datalad.unittest.youcan', where='global')\n        # but after we unset the only value -- that section is no longer listed\n        assert (not globalcfg.has_section('datalad.unittest'))\n        assert_not_in('datalad.unittest.youcan', globalcfg)\n        # although it does leaves empty section behind in the file\n        ok_file_has_content(global_gitconfig, '[datalad \"unittest\"]', strip=True)\n        # remove_section to clean it up entirely\n        globalcfg.remove_section('datalad.unittest', where='global')\n        ok_file_has_content(global_gitconfig, \"\")\n\n    cfg = ConfigManager(\n        Dataset(opj(path, 'ds')),\n        dataset_only=True,\n        overrides={'datalad.godgiven': True})\n    assert_equal(cfg.get('datalad.godgiven'), True)\n    # setter has no effect\n    cfg.set('datalad.godgiven', 'false')\n    assert_equal(cfg.get('datalad.godgiven'), True)\n\n@with_tree(tree={\n    'ds': {\n    '.datalad': {\n        'config': \"\"\"\\\n[crazy]\n    fa = !git remote | xargs -r -I REMOTE /bin/bash -c 'echo I: Fetching from REMOTE && git fetch --prune REMOTE && git fetch -t REMOTE' && [ -d .git/svn ] && bash -c 'echo I: Fetching from SVN && git svn fetch' || : && [ -e .gitmodules ] && bash -c 'echo I: Fetching submodules && git submodule foreach git fa' && [ -d .git/sd ] && bash -c 'echo I: Fetching bugs into sd && git-sd pull --all' || :\n    pa = !git paremotes | tr ' ' '\\\\n'  | xargs -r -l1 git push\n    pt = !git testremotes | tr ' ' '\\\\n'  | xargs -r -l1 -I R git push -f R master\n    ptdry = !git testremotes | tr ' ' '\\\\n'  | xargs -r -l1 -I R git push -f --dry-run R master\n    padry = !git paremotes | tr ' ' '\\\\n' | xargs -r -l1 git push --dry-run\n\"\"\"}}})\ndef test_crazy_cfg(path):\n    cfg = ConfigManager(Dataset(opj(path, 'ds')), dataset_only=True)\n    assert_in('crazy.padry', cfg)\n\n\n@with_tempfile\ndef test_obtain(path):\n    ds = create(path)\n    cfg = ConfigManager(ds)\n    dummy = 'datalad.test.dummy'\n    # we know nothing and we don't know how to ask\n    assert_raises(RuntimeError, cfg.obtain, dummy)\n    # can report known ones\n    cfg.add(dummy, '5.3')\n    assert_equal(cfg.obtain(dummy), '5.3')\n    # better type\n    assert_equal(cfg.obtain(dummy, valtype=float), 5.3)\n    # don't hide type issues, float doesn't become an int magically\n    assert_raises(ValueError, cfg.obtain, dummy, valtype=int)\n    # inject some prior knowledge\n    from datalad.interface.common_cfg import definitions as cfg_defs\n    cfg_defs[dummy] = dict(type=float)\n    # no we don't need to specify a type anymore\n    assert_equal(cfg.obtain(dummy), 5.3)\n    # but if we remove the value from the config, all magic is gone\n    cfg.unset(dummy)\n    # we know nothing and we don't know how to ask\n    assert_raises(RuntimeError, cfg.obtain, dummy)\n\n    #\n    # test actual interaction\n    #\n    @with_testsui()\n    def ask():\n        # fail on unkown dialog type\n        assert_raises(ValueError, cfg.obtain, dummy, dialog_type='Rorschach_test')\n    ask()\n\n    # ask nicely, and get a value of proper type using the preconfiguration\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(\n            cfg.obtain(dummy, dialog_type='question', text='Tell me'), 5.3)\n    ask()\n\n    # preconfigure even more, to get the most compact call\n    cfg_defs[dummy]['ui'] = ('question', dict(text='tell me', title='Gretchen Frage'))\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(cfg.obtain(dummy), 5.3)\n    ask()\n\n    @with_testsui(responses='murks')\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy)\n    ask()\n\n    # fail to store when destination is not specified, will not even ask\n    @with_testsui()\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy, store=True)\n    ask()\n\n    # but we can preconfigure it\n    cfg_defs[dummy]['destination'] = 'broken'\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_raises(ValueError, cfg.obtain, dummy, store=True)\n    ask()\n\n    # fixup destination\n    cfg_defs[dummy]['destination'] = 'dataset'\n\n    @with_testsui(responses='5.3')\n    def ask():\n        assert_equal(cfg.obtain(dummy, store=True), 5.3)\n    ask()\n\n    # now it won't have to ask again\n    @with_testsui()\n    def ask():\n        assert_equal(cfg.obtain(dummy), 5.3)\n    ask()\n\n    # wipe it out again\n    cfg.unset(dummy)\n    assert_not_in(dummy, cfg)\n\n    # XXX cannot figure out how I can simulate a simple <Enter>\n    ## respond with accepting the default\n    #@with_testsui(responses=...)\n    #def ask():\n    #    assert_equal(cfg.obtain(dummy, default=5.3), 5.3)\n    #ask()\n\n\ndef test_from_env():\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.cfg', cfg)\n    os.environ['DATALAD_CRAZY_CFG'] = 'impossibletoguess'\n    cfg.reload()\n    assert_in('datalad.crazy.cfg', cfg)\n    assert_equal(cfg['datalad.crazy.cfg'], 'impossibletoguess')\n    # not in dataset-only mode\n    cfg = ConfigManager(Dataset('nowhere'), dataset_only=True)\n    assert_not_in('datalad.crazy.cfg', cfg)\n    # check env trumps override\n    cfg = ConfigManager()\n    assert_not_in('datalad.crazy.override', cfg)\n    cfg.overrides['datalad.crazy.override'] = 'fromoverride'\n    cfg.reload()\n    assert_equal(cfg['datalad.crazy.override'], 'fromoverride')\n    os.environ['DATALAD_CRAZY_OVERRIDE'] = 'fromenv'\n    cfg.reload()\n    assert_equal(cfg['datalad.crazy.override'], 'fromenv')\n",
        "import pytest\nimport tempfile\nimport os\n\n\n@pytest.fixture\ndef path():\n    with tempfile.TemporaryDirectory() as tmpdir:\n        yield tmpdir\n\n\n@pytest.fixture(autouse=True)\ndef setup_git_config():\n    with tempfile.TemporaryDirectory() as home:\n        old_home = os.environ.get(\"HOME\")\n        os.environ[\"HOME\"] = home\n        os.system('git config --global user.name \"DataLad Tester\"')\n        os.system('git config --global user.email \"test@example.com\"')\n        yield\n        if old_home:\n            os.environ[\"HOME\"] = old_home\n"
    ],
    "test_file_names": [
        "test_1.py",
        "conftest.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Datalad installation attempts...\nVerifying installation...\n❌ Verification failed\nPython 3.9 installation failed, trying Python 3.7...\nVerifying installation...\nDatalad version: 0.4.1.dev573\n✅ Installation successful!\nSuccessfully installed Datalad using Python 3.7\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 25 packages in 44ms\nInstalled 25 packages in 5.80s\n + coverage==7.6.10\n + docopt==0.6.2\n + exceptiongroup==1.2.2\n + grabbit==0.2.6\n + importlib-resources==6.4.5\n + iniconfig==2.0.0\n + nibabel==5.3.2\n + num2words==0.5.14\n + numpy==2.0.2\n + packaging==24.2\n + pandas==2.2.3\n + patsy==1.0.1\n + pluggy==1.5.0\n + pybids==0.6.5\n + pytest==8.3.4\n + pytest-cov==6.0.0\n + python-dateutil==2.9.0.post0\n + pytz==2024.2\n + scipy==1.13.1\n + setuptools==75.6.0\n + six==1.17.0\n + tomli==2.2.1\n + typing-extensions==4.12.2\n + tzdata==2024.2\n + zipp==3.21.0\nerror: The build backend returned an error\n  Caused by: Call to `setuptools.build_meta:__legacy__.build_editable` failed (exit status: 1)\n\n[stderr]\nTraceback (most recent call last):\n  File \"<string>\", line 14, in <module>\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpEUZ7bF/lib/python3.9/site-packages/setuptools/build_meta.py\", line 483, in get_requires_for_build_editable\n    return self.get_requires_for_build_wheel(config_settings)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpEUZ7bF/lib/python3.9/site-packages/setuptools/build_meta.py\", line 334, in get_requires_for_build_wheel\n    return self._get_build_requires(config_settings, requirements=[])\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpEUZ7bF/lib/python3.9/site-packages/setuptools/build_meta.py\", line 304, in _get_build_requires\n    self.run_setup()\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpEUZ7bF/lib/python3.9/site-packages/setuptools/build_meta.py\", line 522, in run_setup\n    super().run_setup(setup_script=setup_script)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpEUZ7bF/lib/python3.9/site-packages/setuptools/build_meta.py\", line 320, in run_setup\n    exec(code, locals())\n  File \"<string>\", line 50, in <module>\nAttributeError: module 'platform' has no attribute 'dist'\n\nhint: This usually indicates a problem with the package or the build environment.\nerror: The build backend returned an error\n  Caused by: Call to `setuptools.build_meta:__legacy__.build_editable` failed (exit status: 1)\n\n[stderr]\nTraceback (most recent call last):\n  File \"<string>\", line 14, in <module>\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpkT3sSq/lib/python3.9/site-packages/setuptools/build_meta.py\", line 483, in get_requires_for_build_editable\n    return self.get_requires_for_build_wheel(config_settings)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpkT3sSq/lib/python3.9/site-packages/setuptools/build_meta.py\", line 334, in get_requires_for_build_wheel\n    return self._get_build_requires(config_settings, requirements=[])\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpkT3sSq/lib/python3.9/site-packages/setuptools/build_meta.py\", line 304, in _get_build_requires\n    self.run_setup()\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpkT3sSq/lib/python3.9/site-packages/setuptools/build_meta.py\", line 522, in run_setup\n    super().run_setup(setup_script=setup_script)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpkT3sSq/lib/python3.9/site-packages/setuptools/build_meta.py\", line 320, in run_setup\n    exec(code, locals())\n  File \"<string>\", line 50, in <module>\nAttributeError: module 'platform' has no attribute 'dist'\n\nhint: This usually indicates a problem with the package or the build environment.\nTraceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/datalad/__init__.py\", line 30, in <module>\n    ssh_manager = SSHManager()\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/datalad/support/sshconnector.py\", line 314, in __init__\n    for p in listdir(self.socket_dir)\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/datalad/support/sshconnector.py\", line 323, in socket_dir\n    self._socket_dir = opj(cfg.obtain('datalad.locations.cache'),\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/datalad/config.py\", line 233, in obtain\n    from datalad.interface.common_cfg import definitions as cfg_defs\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/datalad/interface/common_cfg.py\", line 15, in <module>\n    from appdirs import AppDirs\nModuleNotFoundError: No module named 'appdirs'\nUsing CPython 3.7.9\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 26 packages in 225ms\nInstalled 26 packages in 1.28s\n + bids==0.0\n + coverage==7.2.7\n + docopt==0.6.2\n + exceptiongroup==1.2.2\n + fasteners==0.19\n + grabbit==0.2.6\n + importlib-metadata==6.7.0\n + iniconfig==2.0.0\n + nibabel==4.0.2\n + num2words==0.5.14\n + numpy==1.21.6\n + packaging==24.0\n + pandas==1.3.5\n + patsy==1.0.1\n + pluggy==1.2.0\n + pybids==0.6.5\n + pytest==7.4.4\n + pytest-cov==4.1.0\n + python-dateutil==2.9.0.post0\n + pytz==2024.2\n + scipy==1.7.3\n + setuptools==68.0.0\n + six==1.17.0\n + tomli==2.0.1\n + typing-extensions==4.7.1\n + zipp==3.15.0\nResolved 77 packages in 1.16s\nPrepared 1 package in 827ms\nInstalled 71 packages in 20ms\n + appdirs==1.4.4\n + attrs==24.2.0\n + automat==22.10.0\n + beautifulsoup4==4.12.3\n + boto==2.49.0\n + cachetools==5.5.0\n + certifi==2024.12.14\n + cffi==1.15.1\n + charset-normalizer==3.4.1\n + constantly==15.1.0\n + cryptography==44.0.0\n + cssselect==1.2.0\n + datalad==0.4.1.dev1 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1)\n + deprecated==1.2.15\n + filelock==3.12.2\n + frozendict==2.4.6\n + gitdb==4.0.12\n + gitpython==3.1.44\n + httpretty==1.1.4\n + humanize==4.6.0\n + hyperlink==21.0.0\n + idna==3.10\n + importlib-resources==5.12.0\n + incremental==22.10.0\n + iso8601==2.1.0\n + itemadapter==0.8.0\n + itemloaders==1.1.0\n + jaraco-classes==3.2.3\n + jeepney==0.8.0\n + jmespath==1.0.1\n + jsmin==3.0.1\n + keyring==24.1.1\n + keyrings-alt==4.2.0\n + lxml==5.3.0\n + mock==5.1.0\n + more-itertools==9.1.0\n + msgpack-python==0.5.6\n + multidict==6.0.5\n + nose==1.3.7\n + parsel==1.8.1\n + patool==1.12\n + protego==0.3.0\n + pyasn1==0.5.1\n + pyasn1-modules==0.3.0\n + pycparser==2.21\n + pydispatcher==2.0.7\n + pygithub==2.3.0\n + pyjwt==2.8.0\n + pyld==2.0.4\n + pynacl==1.5.0\n + pyopenssl==24.3.0\n + pyyaml==6.0.1\n + queuelib==1.6.2\n + requests==2.31.0\n + requests-file==2.1.0\n + requests-ftp==0.3.1\n + scrapy==2.9.0\n + secretstorage==3.3.3\n + service-identity==21.1.0\n + simplejson==3.19.3\n + smmap==5.0.2\n + soupsieve==2.4.1\n + tldextract==4.0.0\n + tqdm==4.67.1\n + twisted==23.8.0\n + urllib3==2.0.7\n + vcrpy==4.3.0\n + w3lib==2.1.2\n + wrapt==1.16.0\n + yarl==1.9.4\n + zope-interface==6.4.post2\nResolved 100 packages in 209ms\nInstalled 20 packages in 74ms\n + alabaster==0.7.13\n + babel==2.14.0\n + docutils==0.19\n + imagesize==1.4.1\n + jinja2==3.1.5\n + line-profiler==4.1.3\n + markupsafe==2.1.5\n + nose-timer==1.0.1\n + pygments==2.17.2\n + pypandoc==1.14\n + snowballstemmer==2.2.0\n + sphinx==5.3.0\n + sphinx-rtd-theme==2.0.0\n + sphinxcontrib-applehelp==1.0.2\n + sphinxcontrib-devhelp==1.0.2\n + sphinxcontrib-htmlhelp==2.0.0\n + sphinxcontrib-jquery==4.1\n + sphinxcontrib-jsmath==1.0.1\n + sphinxcontrib-qthelp==1.0.3\n + sphinxcontrib-serializinghtml==1.1.5\n",
    "new_commit_res_code": 1,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1\nplugins: cov-4.1.0\ncollected 4 items\n\nr2e_tests/test_1.py EFF.                                                 [100%]\n\n==================================== ERRORS ====================================\n_______________________ ERROR at setup of test_something _______________________\nfile /home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/r2e_tests/test_1.py, line 51\n  @with_tree(tree=_dataset_config_template)\n  @with_tempfile(mkdir=True)\n  def test_something(path, new_home):\nE       fixture 'new_home' not found\n>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest_namespace, monkeypatch, no_cover, path, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, setup_git_config, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory\n>       use 'pytest --fixtures [testpath]' for help on them.\n\n/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/r2e_tests/test_1.py:51\n=================================== FAILURES ===================================\n________________________________ test_crazy_cfg ________________________________\n\narg = (), kw = {'path': '/tmp/tmp-page2annexx2wu7klj'}\ntkwargs_ = {'prefix': 'datalad_temp_tree_test_crazy_cfg'}\nd = '/tmp/datalad_temp_tree_test_crazy_cfg3dmwsrvb'\n\n    @wraps(t)\n    def newfunc(*arg, **kw):\n        tkwargs_ = get_tempfile_kwargs(tkwargs, prefix=\"tree\", wrapped=t)\n        d = tempfile.mkdtemp(**tkwargs_)\n        create_tree(d, tree, archives_leading_dir=archives_leading_dir)\n        try:\n>           return t(*(arg + (d,)), **kw)\nE           TypeError: test_crazy_cfg() got multiple values for argument 'path'\n\ndatalad/tests/utils.py:429: TypeError\n_________________________________ test_obtain __________________________________\n\narg = (), kw = {'path': '/tmp/tmp-page2annex08heog_r'}\nfilename = '/tmp/datalad_temp_test_obtainw9oecvdn'\n\n    @wraps(t)\n    def newfunc(*arg, **kw):\n        with make_tempfile(wrapped=t, **tkwargs) as filename:\n>           return t(*(arg + (filename,)), **kw)\nE           TypeError: test_obtain() got multiple values for argument 'path'\n\ndatalad/tests/utils.py:564: TypeError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_from_env\nERROR r2e_tests/test_1.py::test_something\nFAILED r2e_tests/test_1.py::test_crazy_cfg - TypeError: test_crazy_cfg() got ...\nFAILED r2e_tests/test_1.py::test_obtain - TypeError: test_obtain() got multip...\n===================== 2 failed, 1 passed, 1 error in 0.91s =====================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1\nplugins: cov-4.1.0\ncollected 4 items\n\nr2e_tests/test_1.py EFFF                                                 [100%]\n\n==================================== ERRORS ====================================\n_______________________ ERROR at setup of test_something _______________________\nfile /home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/r2e_tests/test_1.py, line 51\n  @with_tree(tree=_dataset_config_template)\n  @with_tempfile(mkdir=True)\n  def test_something(path, new_home):\nE       fixture 'new_home' not found\n>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest_namespace, monkeypatch, no_cover, path, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, setup_git_config, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory\n>       use 'pytest --fixtures [testpath]' for help on them.\n\n/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_9670bc78ef2601fc3f4dda507c9591f90232efd1/r2e_tests/test_1.py:51\n=================================== FAILURES ===================================\n________________________________ test_crazy_cfg ________________________________\n\narg = (), kw = {'path': '/tmp/tmp-page2annexvi6ajypv'}\ntkwargs_ = {'prefix': 'datalad_temp_tree_test_crazy_cfg'}\nd = '/tmp/datalad_temp_tree_test_crazy_cfgrrrqlf7s'\n\n    @wraps(t)\n    def newfunc(*arg, **kw):\n        tkwargs_ = get_tempfile_kwargs(tkwargs, prefix=\"tree\", wrapped=t)\n        d = tempfile.mkdtemp(**tkwargs_)\n        create_tree(d, tree, archives_leading_dir=archives_leading_dir)\n        try:\n>           return t(*(arg + (d,)), **kw)\nE           TypeError: test_crazy_cfg() got multiple values for argument 'path'\n\ndatalad/tests/utils.py:429: TypeError\n_________________________________ test_obtain __________________________________\n\narg = (), kw = {'path': '/tmp/tmp-page2annexjaciudvp'}\nfilename = '/tmp/datalad_temp_test_obtainf85dsmxb'\n\n    @wraps(t)\n    def newfunc(*arg, **kw):\n        with make_tempfile(wrapped=t, **tkwargs) as filename:\n>           return t(*(arg + (filename,)), **kw)\nE           TypeError: test_obtain() got multiple values for argument 'path'\n\ndatalad/tests/utils.py:564: TypeError\n________________________________ test_from_env _________________________________\n\n    def test_from_env():\n        cfg = ConfigManager()\n        assert_not_in('datalad.crazy.cfg', cfg)\n        os.environ['DATALAD_CRAZY_CFG'] = 'impossibletoguess'\n        cfg.reload()\n        assert_in('datalad.crazy.cfg', cfg)\n        assert_equal(cfg['datalad.crazy.cfg'], 'impossibletoguess')\n        # not in dataset-only mode\n        cfg = ConfigManager(Dataset('nowhere'), dataset_only=True)\n        assert_not_in('datalad.crazy.cfg', cfg)\n        # check env trumps override\n        cfg = ConfigManager()\n        assert_not_in('datalad.crazy.override', cfg)\n>       cfg.overrides['datalad.crazy.override'] = 'fromoverride'\nE       AttributeError: 'ConfigManager' object has no attribute 'overrides'\n\nr2e_tests/test_1.py:313: AttributeError\n=========================== short test summary info ============================\nERROR r2e_tests/test_1.py::test_something\nFAILED r2e_tests/test_1.py::test_crazy_cfg - TypeError: test_crazy_cfg() got ...\nFAILED r2e_tests/test_1.py::test_obtain - TypeError: test_obtain() got multip...\nFAILED r2e_tests/test_1.py::test_from_env - AttributeError: 'ConfigManager' o...\n========================== 3 failed, 1 error in 0.50s ==========================\n",
    "old_commit_res_stderr": ""
}
datalad/config.py datalad/tests/test_config.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** ConfigManager Missing `overrides` Attribute Causes AttributeError

**Description:**
When using the `ConfigManager` without providing an `overrides` parameter, attempting to access the `overrides` attribute results in an `AttributeError`. This prevents users from setting override configurations as intended.

**Example Code:**
```python
cfg = ConfigManager()
cfg.overrides['datalad.crazy.override'] = 'fromoverride'
```

**Expected Behavior:**
The `overrides` attribute should be available as a dictionary, allowing users to set and manage override configurations without errors.

**Actual Behavior:**
An `AttributeError` is raised:
```
AttributeError: 'ConfigManager' object has no attribute 'overrides'
```
This error occurs because the `overrides` attribute is not initialized, making it impossible to set override values.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### datalad/config.py
# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
# ex: set sts=4 ts=4 sw=4 noet:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the datalad package for the
#   copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""
"""

from datalad.cmd import Runner
from datalad.dochelpers import exc_str
import re
import os
from os.path import join as opj, exists

cfg_kv_regex = re.compile(r'(^.*)\n(.*)$', flags=re.MULTILINE)
cfg_section_regex = re.compile(r'(.*)\.[^.]+')
cfg_sectionoption_regex = re.compile(r'(.*)\.([^.]+)')


_where_reload_doc = """
        where : {'dataset', 'local', 'global'}, optional
          Indicator which configuration file to modify. 'dataset' indicates the
          persistent configuration in .datalad/config of a dataset; 'local'
          the configuration of a dataset's Git repository in .git/config;
          'global' refers to the general configuration that is not specific to
          a single repository (usually in $USER/.gitconfig).
        reload : bool
          Flag whether to reload the configuration from file(s) after
          modification. This can be disable to make multiple sequential
          modifications slightly more efficient.""".lstrip()


def _where_reload(obj):
    """Helper decorator to simplify providing repetitive docstring"""
    obj.__doc__ = obj.__doc__ % _where_reload_doc
    return obj


def _parse_gitconfig_dump(dump, store, replace):
    if replace:
        # if we want to replace existing values in the store
        # collect into a new dict and `update` the store at the
        # end. This way we get the desired behavior of multi-value
        # keys, but only for the current source
        dct = {}
    else:
        # if we don't want to replace value, perform the multi-value
        # preserving addition on the existing store right away
        dct = store
    for line in dump.split('\0'):
        if not line:
            continue
        k, v = cfg_kv_regex.match(line).groups()
        present_v = dct.get(k, None)
        if present_v is None:
            dct[k] = v
        else:
            if isinstance(present_v, tuple):
                dct[k] = present_v + (v,)
            else:
                dct[k] = (present_v, v)
    if replace:
        store.update(dct)
    return store


def _parse_env(store):
    dct = {}
    for k in os.environ:
        if not k.startswith('DATALAD_'):
            continue
        dct[k.replace('_', '.').lower()] = os.environ[k]
    store.update(dct)
    return store


def anything2bool(val):
    if hasattr(val, 'lower'):
        val = val.lower()
    if val in {"off", "no", "false", "0"} or not bool(val):
        return False
    elif val in {"on", "yes", "true", True} \
            or (hasattr(val, 'isdigit') and val.isdigit() and int(val)) \
            or isinstance(val, int) and val:
        return True
    else:
        raise TypeError(
            "Got value %s which could not be interpreted as a boolean"
            % repr(val))


class ConfigManager(object):
    """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. If such need arises, various solutions are
    possible (via GitPython, or an independent writer).

    Any DATALAD_* environment variable is also presented as a configuration
    item. Settings read from environment variables are not stored in any of the
    configuration file, but are read dynamically from the environment at each
    `reload()` call. Their values take precedence over any specification in
    configuration files.

    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)
    dataset_only : bool
      If True, configuration items are only read from a datasets persistent
      configuration file, if any present (the one in ``.datalad/config``, not
      ``.git/config``).
    """
    def __init__(self, dataset=None, dataset_only=False):
        # store in a simple dict
        # no subclassing, because we want to be largely read-only, and implement
        # config writing separately
        self._store = {}
        self._dataset_path = dataset.path if dataset else None
        self._dataset_only = dataset_only
        # Since configs could contain sensitive information, to prevent
        # any "facilitated" leakage -- just disable logging of outputs for
        # this runner
        run_kwargs = dict(log_outputs=False)
        if dataset is not None:
            # make sure we run the git config calls in the dataset
            # to pick up the right config files
            run_kwargs['cwd'] = dataset.path
        self._runner = Runner(**run_kwargs)
        self.reload()

    def reload(self):
        """Reload all configuration items from the configured sources"""
        self._store = {}
        # 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
        if self._dataset_path:
            # now any dataset config
            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')
            if exists(dscfg_fname):
                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],
                                           log_stderr=True)
                # overwrite existing value, do not amend to get multi-line
                # values
                self._store = _parse_gitconfig_dump(
                    stdout, self._store, replace=False)

        if not self._dataset_only:
            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)
            self._store = _parse_gitconfig_dump(
                stdout, self._store, replace=True)

            # override with environment variables
            self._store = _parse_env(self._store)

    @_where_reload
    def obtain(self, var, default=None, dialog_type=None, valtype=None,
               store=False, where=None, reload=True, **kwargs):
        """
        Convenience method to obtain settings interactively, if needed

        A UI will be used to ask for user input in interactive sessions.
        Questions to ask, and additional explanations can be passed directly
        as arguments, or retrieved from a list of pre-configured items.

        Additionally, this method allows for type conversion and storage
        of obtained settings. Both aspects can also be pre-configured.

        Parameters
        ----------
        var : str
          Variable name including any section like `git config` expects them,
          e.g. 'core.editor'
        default : any type
          In interactive sessions and if `store` is True, this default value
          will be presented to the user for confirmation (or modification).
          In all other cases, this value will be silently assigned unless
          there is an existing configuration setting.
        dialog_type : {'question', 'yesno', None}
          Which dialog type to use in interactive sessions. If `None`,
          pre-configured UI options are used.
        store : bool
          Whether to store the obtained value (or default)
        %s
        `**kwargs`
          Additional arguments for the UI function call, such as a question
          `text`.
        """
        # do local import, as this module is import prominently and the
        # could theroetically import all kind of weired things for type
        # conversion
        from datalad.interface.common_cfg import definitions as cfg_defs
        # fetch what we know about this variable
        cdef = cfg_defs.get(var, {})
        # type conversion setup
        if valtype is None and 'type' in cdef:
            valtype = cdef['type']
        if valtype is None:
            valtype = lambda x: x

        # any default?
        if default is None and 'default' in cdef:
            default = cdef['default']

        _value = None
        if var in self:
            # nothing needs to be obtained, it is all here already
            _value = self[var]
        elif store is False and default is not None:
            # nothing will be stored, and we have a default -> no user confirmation
            # we cannot use logging, because we want to use the config to confiugre
            # the logging
            #lgr.debug('using default {} for config setting {}'.format(default, var))
            _value = default

        if _value is not None:
            # we got everything we need and can exit early
            try:
                return valtype(_value)
            except Exception as e:
                raise ValueError(
                    "value '{}' of existing configuration for '{}' cannot be "
                    "converted to the desired type '{}' ({})".format(
                        _value, var, valtype, exc_str(e)))

        # now we need to try to obtain something from the user
        from datalad.ui import ui

        # configure UI
        dialog_opts = kwargs
        if dialog_type is None:  # no override
            # check for common knowledge on how to obtain a value
            if 'ui' in cdef:
                dialog_type = cdef['ui'][0]
                # pull standard dialog settings
                dialog_opts = cdef['ui'][1]
                # update with input
                dialog_opts.update(kwargs)

        if (not ui.is_interactive or dialog_type is None) and default is None:
            raise RuntimeError(
                "cannot obtain value for configuration item '{}', "
                "not preconfigured, no default, no UI available".format(var))

        if not hasattr(ui, dialog_type):
            raise ValueError("UI '{}' does not support dialog type '{}'".format(
                ui, dialog_type))

        # configure storage destination, if needed
        if store:
            if where is None and 'destination' in cdef:
                where = cdef['destination']
            if where is None:
                raise ValueError(
                    "request to store configuration item '{}', but no "
                    "storage destination specified".format(var))

        # obtain via UI
        dialog = getattr(ui, dialog_type)
        _value = dialog(default=default, **dialog_opts)

        if _value is None:
            # we got nothing
            if default is None:
                raise RuntimeError(
                    "could not obtain value for configuration item '{}', "
                    "not preconfigured, no default".format(var))
            # XXX maybe we should return default here, even it was returned
            # from the UI -- if that is even possible

        # execute type conversion before storing to check that we got
        # something that looks like what we want
        try:
            value = valtype(_value)
        except Exception as e:
            raise ValueError(
                "cannot convert user input `{}` to desired type ({})".format(
                    _value, exc_str(e)))
            # XXX we could consider "looping" until we have a value of proper
            # type in case of a user typo...

        if store:
            # store value as it was before any conversion, needs to be str
            # anyway
            # needs string conversion nevertheless, because default could come
            # in as something else
            self.add(var, '{}'.format(_value), where=where, reload=reload)
        return value

    #
    # Compatibility with dict API
    #
    def __len__(self):
        return len(self._store)

    def __getitem__(self, key):
        return self._store.__getitem__(key)

    def __contains__(self, key):
        return self._store.__contains__(key)

    def keys(self):
        """Returns list of configuration item names"""
        return self._store.keys()

    def get(self, key, default=None):
        """D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None."""
        return self._store.get(key, default)

    #
    # Compatibility with ConfigParser API
    #
    def sections(self):
        """Returns a list of the sections available"""
        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))

    def options(self, section):
        """Returns a list of options available in the specified section."""
        opts = []
        for k in self._store:
            sec, opt = cfg_sectionoption_regex.match(k).groups()
            if sec == section:
                opts.append(opt)
        return opts

    def has_section(self, section):
        """Indicates whether a section is present in the configuration"""
        for k in self._store:
            if k.startswith(section):
                return True
        return False

    def has_option(self, section, option):
        """If the given section exists, and contains the given option"""
        for k in self._store:
            sec, opt = cfg_sectionoption_regex.match(k).groups()
            if sec == section and opt == option:
                return True
        return False

    def getint(self, section, option):
        """A convenience method which coerces the option value to an integer"""
        return int(self.get_value(section, option))

    def getbool(self, section, option, default=None):
        """A convenience method which coerces the option value to a bool

        Values "on", "yes", "true" and any int!=0 are considered True
        Values which evaluate to bool False, "off", "no", "false" are considered
        False
        TypeError is raised for other values.
        """
        val = self.get_value(section, option, default=default)
        return anything2bool(val)

    def getfloat(self, section, option):
        """A convenience method which coerces the option value to a float"""
        return float(self.get_value(section, option))

    # this is a hybrid of ConfigParser and dict API
    def items(self, section=None):
        """Return a list of (name, value) pairs for each option

        Optionally limited to a given section.
        """
        if section is None:
            return self._store.items()
        return [(k, v) for k, v in self._store.items()
                if cfg_section_regex.match(k).group(1) == section]

    #
    # Compatibility with GitPython's ConfigParser
    #
    def get_value(self, section, option, default=None):
        """Like `get()`, but with an optional default value

        If the default is not None, the given default value will be returned in
        case the option did not exist. This behavior immitates GitPython's
        config parser.
        """
        try:
            return self['.'.join((section, option))]
        except KeyError as e:
            # this strange dance is needed because gitpython does it this way
            if default is not None:
                return default
            else:
                raise e

    #
    # Modify configuration (proxy respective git-config call)
    #
    @_where_reload
    def _run(self, args, where=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 where:
            args = self._get_location_args(where) + args
        out = self._runner.run(['git', 'config'] + args, **kwargs)
        if reload:
            self.reload()
        return out

    def _get_location_args(self, where, args=None):
        if args is None:
            args = []
        cfg_labels = ('dataset', 'local', 'global')
        if where not in cfg_labels:
            raise ValueError(
                "unknown configuration label '{}' (not in {})".format(
                    where, cfg_labels))
        if where == 'dataset':
            if not self._dataset_path:
                raise ValueError(
                    'ConfigManager cannot store to configuration to dataset, none specified')
            # create an empty config file if none exists, `git config` will
            # fail otherwise
            dscfg_dirname = opj(self._dataset_path, '.datalad')
            dscfg_fname = opj(dscfg_dirname, 'config')
            if not exists(dscfg_dirname):
                os.makedirs(dscfg_dirname)
            if not exists(dscfg_fname):
                open(dscfg_fname, 'w').close()
            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])
        elif where == 'global':
            args.append('--global')
        elif where == 'local':
            args.append('--local')
        return args

    @_where_reload
    def add(self, var, value, where='dataset', reload=True):
        """Add a configuration variable and value

        Parameters
        ----------
        var : str
          Variable name including any section like `git config` expects them, e.g.
          'core.editor'
        value : str
          Variable value
        %s"""
        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)

    @_where_reload
    def set(self, var, value, where='dataset', reload=True, force=False):
        """Set a variable to a value.

        In opposition to `add`, this replaces the value of `var` if there is
        one already.

        Parameters
        ----------
        var : str
          Variable name including any section like `git config` expects them, e.g.
          'core.editor'
        value : str
          Variable value
        force: bool
          if set, replaces all occurrences of `var` by a single one with the
          given `value`. Otherwise raise if multiple entries for `var` exist
          already
        %s"""
        from datalad.support.gitrepo import to_options

        self._run(to_options(replace_all=force) + [var, value],
                  where=where, reload=reload, log_stderr=True)

    @_where_reload
    def rename_section(self, old, new, where='dataset', reload=True):
        """Rename a configuration section

        Parameters
        ----------
        old : str
          Name of the section to rename.
        new : str
          Name of the section to rename to.
        %s"""
        self._run(['--rename-section', old, new], where=where, reload=reload)

    @_where_reload
    def remove_section(self, sec, where='dataset', reload=True):
        """Rename a configuration section

        Parameters
        ----------
        sec : str
          Name of the section to remove.
        %s"""
        self._run(['--remove-section', sec], where=where, reload=reload)

    @_where_reload
    def unset(self, var, where='dataset', reload=True):
        """Remove all occurrences of a variable

        Parameters
        ----------
        var : str
          Name of the variable to remove
        %s"""
        # use unset all as it is simpler for now
        self._run(['--unset-all', var], where=where, reload=reload)

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** ConfigManager Missing `overrides` Attribute Causes AttributeError

**Description:**
When using the `ConfigManager` without providing an `overrides` parameter, attempting to access the `overrides` attribute results in an `AttributeError`. This prevents users from setting override configurations as intended.

**Example Code:**
```python
cfg = ConfigManager()
cfg.overrides['datalad.crazy.override'] = 'fromoverride'
```

**Expected Behavior:**
The `overrides` attribute should be available as a dictionary, allowing users to set and manage override configurations without errors.

**Actual Behavior:**
An `AttributeError` is raised:
```
AttributeError: 'ConfigManager' object has no attribute 'overrides'
```
This error occurs because the `overrides` attribute is not initialized, making it impossible to set override values.

[/ISSUE]
{
    "test_from_env": "PASSED",
    "test_something": "ERROR",
    "test_crazy_cfg": "FAILED",
    "test_obtain": "FAILED"
}
diff --git a/datalad/config.py b/datalad/config.py
index 150a5cc03..6abfebbab 100644
--- a/datalad/config.py
+++ b/datalad/config.py
@@ -114,11 +114,16 @@ class ConfigManager(object):
     written during normal operation. If such need arises, various solutions are
     possible (via GitPython, or an independent writer).
 
+    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, and are not modified by any of the manipulation
+    methods, such as `set` or `unset`.
+
     Any DATALAD_* environment variable is also presented as a configuration
     item. Settings read from environment variables are not stored in any of the
     configuration file, but are read dynamically from the environment at each
     `reload()` call. Their values take precedence over any specification in
-    configuration files.
+    configuration files, and even overrides.
 
     Parameters
     ----------
@@ -130,12 +135,17 @@ class ConfigManager(object):
       If True, configuration items are only read from a datasets persistent
       configuration file, if any present (the one in ``.datalad/config``, not
       ``.git/config``).
+    overrides : dict, optional
+      Variable overrides, see general class documentation for details.
     """
-    def __init__(self, dataset=None, dataset_only=False):
+    def __init__(self, dataset=None, dataset_only=False, overrides=None):
         # store in a simple dict
         # no subclassing, because we want to be largely read-only, and implement
         # config writing separately
         self._store = {}
+        # public dict to store variables that always override any setting
+        # read from a file
+        self.overrides = {} if overrides is None else overrides
         self._dataset_path = dataset.path if dataset else None
         self._dataset_only = dataset_only
         # Since configs could contain sensitive information, to prevent
@@ -169,13 +179,20 @@ class ConfigManager(object):
                 self._store = _parse_gitconfig_dump(
                     stdout, self._store, replace=False)
 
-        if not self._dataset_only:
-            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)
-            self._store = _parse_gitconfig_dump(
-                stdout, self._store, replace=True)
+        if self._dataset_only:
+            # superimpose overrides
+            self._store.update(self.overrides)
+            return
+
+        stdout, stderr = self._run(['-z', '-l'], log_stderr=True)
+        self._store = _parse_gitconfig_dump(
+            stdout, self._store, replace=True)
+
+        # superimpose overrides
+        self._store.update(self.overrides)
 
-            # override with environment variables
-            self._store = _parse_env(self._store)
+        # override with environment variables
+        self._store = _parse_env(self._store)
 
     @_where_reload
     def obtain(self, var, default=None, dialog_type=None, valtype=None,

{"datalad/config.py": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"\n\"\"\"\n\nfrom datalad.cmd import Runner\nfrom datalad.dochelpers import exc_str\nimport re\nimport os\nfrom os.path import join as opj, exists\n\ncfg_kv_regex = re.compile(r'(^.*)\\n(.*)$', flags=re.MULTILINE)\ncfg_section_regex = re.compile(r'(.*)\\.[^.]+')\ncfg_sectionoption_regex = re.compile(r'(.*)\\.([^.]+)')\n\n\n_where_reload_doc = \"\"\"\n        where : {'dataset', 'local', 'global'}, optional\n          Indicator which configuration file to modify. 'dataset' indicates the\n          persistent configuration in .datalad/config of a dataset; 'local'\n          the configuration of a dataset's Git repository in .git/config;\n          'global' refers to the general configuration that is not specific to\n          a single repository (usually in $USER/.gitconfig).\n        reload : bool\n          Flag whether to reload the configuration from file(s) after\n          modification. This can be disable to make multiple sequential\n          modifications slightly more efficient.\"\"\".lstrip()\n\n\ndef _where_reload(obj):\n    \"\"\"Helper decorator to simplify providing repetitive docstring\"\"\"\n    obj.__doc__ = obj.__doc__ % _where_reload_doc\n    return obj\n\n\ndef _parse_gitconfig_dump(dump, store, replace):\n    if replace:\n        # if we want to replace existing values in the store\n        # collect into a new dict and `update` the store at the\n        # end. This way we get the desired behavior of multi-value\n        # keys, but only for the current source\n        dct = {}\n    else:\n        # if we don't want to replace value, perform the multi-value\n        # preserving addition on the existing store right away\n        dct = store\n    for line in dump.split('\\0'):\n        if not line:\n            continue\n        k, v = cfg_kv_regex.match(line).groups()\n        present_v = dct.get(k, None)\n        if present_v is None:\n            dct[k] = v\n        else:\n            if isinstance(present_v, tuple):\n                dct[k] = present_v + (v,)\n            else:\n                dct[k] = (present_v, v)\n    if replace:\n        store.update(dct)\n    return store\n\n\ndef _parse_env(store):\n    dct = {}\n    for k in os.environ:\n        if not k.startswith('DATALAD_'):\n            continue\n        dct[k.replace('_', '.').lower()] = os.environ[k]\n    store.update(dct)\n    return store\n\n\ndef anything2bool(val):\n    if hasattr(val, 'lower'):\n        val = val.lower()\n    if val in {\"off\", \"no\", \"false\", \"0\"} or not bool(val):\n        return False\n    elif val in {\"on\", \"yes\", \"true\", True} \\\n            or (hasattr(val, 'isdigit') and val.isdigit() and int(val)) \\\n            or isinstance(val, int) and val:\n        return True\n    else:\n        raise TypeError(\n            \"Got value %s which could not be interpreted as a boolean\"\n            % repr(val))\n\n\nclass ConfigManager(object):\n    \"\"\"Thin wrapper around `git-config` with support for a dataset configuration.\n\n    The general idea is to have an object that is primarily used to read/query\n    configuration option.  Upon creation, current configuration is read via one\n    (or max two, in the case of the presence of dataset-specific configuration)\n    calls to `git config`.  If this class is initialized with a Dataset\n    instance, it supports reading and writing configuration from\n    ``.datalad/config`` inside a dataset too. This file is committed to Git and\n    hence useful to ship certain configuration items with a dataset.\n\n    The API aims to provide the most significant read-access API of a\n    dictionary, the Python ConfigParser, and GitPython's config parser\n    implementations.\n\n    This class is presently not capable of efficiently writing multiple\n    configurations items at once.  Instead, each modification results in a\n    dedicated call to `git config`. This author thinks this is OK, as he\n    cannot think of a situation where a large number of items need to be\n    written during normal operation. If such need arises, various solutions are\n    possible (via GitPython, or an independent writer).\n\n    Any DATALAD_* environment variable is also presented as a configuration\n    item. Settings read from environment variables are not stored in any of the\n    configuration file, but are read dynamically from the environment at each\n    `reload()` call. Their values take precedence over any specification in\n    configuration files.\n\n    Parameters\n    ----------\n    dataset : Dataset, optional\n      If provided, all `git config` calls are executed in this dataset's\n      directory. Moreover, any modifications are, by default, directed to\n      this dataset's configuration file (which will be created on demand)\n    dataset_only : bool\n      If True, configuration items are only read from a datasets persistent\n      configuration file, if any present (the one in ``.datalad/config``, not\n      ``.git/config``).\n    \"\"\"\n    def __init__(self, dataset=None, dataset_only=False):\n        # store in a simple dict\n        # no subclassing, because we want to be largely read-only, and implement\n        # config writing separately\n        self._store = {}\n        self._dataset_path = dataset.path if dataset else None\n        self._dataset_only = dataset_only\n        # Since configs could contain sensitive information, to prevent\n        # any \"facilitated\" leakage -- just disable logging of outputs for\n        # this runner\n        run_kwargs = dict(log_outputs=False)\n        if dataset is not None:\n            # make sure we run the git config calls in the dataset\n            # to pick up the right config files\n            run_kwargs['cwd'] = dataset.path\n        self._runner = Runner(**run_kwargs)\n        self.reload()\n\n    def reload(self):\n        \"\"\"Reload all configuration items from the configured sources\"\"\"\n        self._store = {}\n        # 2-step strategy:\n        #   - load datalad dataset config from dataset\n        #   - load git config from all supported by git sources\n        # in doing so we always stay compatible with where Git gets its\n        # config from, but also allow to override persistent information\n        # from dataset locally or globally\n        if self._dataset_path:\n            # now any dataset config\n            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')\n            if exists(dscfg_fname):\n                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],\n                                           log_stderr=True)\n                # overwrite existing value, do not amend to get multi-line\n                # values\n                self._store = _parse_gitconfig_dump(\n                    stdout, self._store, replace=False)\n\n        if not self._dataset_only:\n            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)\n            self._store = _parse_gitconfig_dump(\n                stdout, self._store, replace=True)\n\n            # override with environment variables\n            self._store = _parse_env(self._store)\n\n    @_where_reload\n    def obtain(self, var, default=None, dialog_type=None, valtype=None,\n               store=False, where=None, reload=True, **kwargs):\n        \"\"\"\n        Convenience method to obtain settings interactively, if needed\n\n        A UI will be used to ask for user input in interactive sessions.\n        Questions to ask, and additional explanations can be passed directly\n        as arguments, or retrieved from a list of pre-configured items.\n\n        Additionally, this method allows for type conversion and storage\n        of obtained settings. Both aspects can also be pre-configured.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them,\n          e.g. 'core.editor'\n        default : any type\n          In interactive sessions and if `store` is True, this default value\n          will be presented to the user for confirmation (or modification).\n          In all other cases, this value will be silently assigned unless\n          there is an existing configuration setting.\n        dialog_type : {'question', 'yesno', None}\n          Which dialog type to use in interactive sessions. If `None`,\n          pre-configured UI options are used.\n        store : bool\n          Whether to store the obtained value (or default)\n        %s\n        `**kwargs`\n          Additional arguments for the UI function call, such as a question\n          `text`.\n        \"\"\"\n        # do local import, as this module is import prominently and the\n        # could theroetically import all kind of weired things for type\n        # conversion\n        from datalad.interface.common_cfg import definitions as cfg_defs\n        # fetch what we know about this variable\n        cdef = cfg_defs.get(var, {})\n        # type conversion setup\n        if valtype is None and 'type' in cdef:\n            valtype = cdef['type']\n        if valtype is None:\n            valtype = lambda x: x\n\n        # any default?\n        if default is None and 'default' in cdef:\n            default = cdef['default']\n\n        _value = None\n        if var in self:\n            # nothing needs to be obtained, it is all here already\n            _value = self[var]\n        elif store is False and default is not None:\n            # nothing will be stored, and we have a default -> no user confirmation\n            # we cannot use logging, because we want to use the config to confiugre\n            # the logging\n            #lgr.debug('using default {} for config setting {}'.format(default, var))\n            _value = default\n\n        if _value is not None:\n            # we got everything we need and can exit early\n            try:\n                return valtype(_value)\n            except Exception as e:\n                raise ValueError(\n                    \"value '{}' of existing configuration for '{}' cannot be \"\n                    \"converted to the desired type '{}' ({})\".format(\n                        _value, var, valtype, exc_str(e)))\n\n        # now we need to try to obtain something from the user\n        from datalad.ui import ui\n\n        # configure UI\n        dialog_opts = kwargs\n        if dialog_type is None:  # no override\n            # check for common knowledge on how to obtain a value\n            if 'ui' in cdef:\n                dialog_type = cdef['ui'][0]\n                # pull standard dialog settings\n                dialog_opts = cdef['ui'][1]\n                # update with input\n                dialog_opts.update(kwargs)\n\n        if (not ui.is_interactive or dialog_type is None) and default is None:\n            raise RuntimeError(\n                \"cannot obtain value for configuration item '{}', \"\n                \"not preconfigured, no default, no UI available\".format(var))\n\n        if not hasattr(ui, dialog_type):\n            raise ValueError(\"UI '{}' does not support dialog type '{}'\".format(\n                ui, dialog_type))\n\n        # configure storage destination, if needed\n        if store:\n            if where is None and 'destination' in cdef:\n                where = cdef['destination']\n            if where is None:\n                raise ValueError(\n                    \"request to store configuration item '{}', but no \"\n                    \"storage destination specified\".format(var))\n\n        # obtain via UI\n        dialog = getattr(ui, dialog_type)\n        _value = dialog(default=default, **dialog_opts)\n\n        if _value is None:\n            # we got nothing\n            if default is None:\n                raise RuntimeError(\n                    \"could not obtain value for configuration item '{}', \"\n                    \"not preconfigured, no default\".format(var))\n            # XXX maybe we should return default here, even it was returned\n            # from the UI -- if that is even possible\n\n        # execute type conversion before storing to check that we got\n        # something that looks like what we want\n        try:\n            value = valtype(_value)\n        except Exception as e:\n            raise ValueError(\n                \"cannot convert user input `{}` to desired type ({})\".format(\n                    _value, exc_str(e)))\n            # XXX we could consider \"looping\" until we have a value of proper\n            # type in case of a user typo...\n\n        if store:\n            # store value as it was before any conversion, needs to be str\n            # anyway\n            # needs string conversion nevertheless, because default could come\n            # in as something else\n            self.add(var, '{}'.format(_value), where=where, reload=reload)\n        return value\n\n    #\n    # Compatibility with dict API\n    #\n    def __len__(self):\n        return len(self._store)\n\n    def __getitem__(self, key):\n        return self._store.__getitem__(key)\n\n    def __contains__(self, key):\n        return self._store.__contains__(key)\n\n    def keys(self):\n        \"\"\"Returns list of configuration item names\"\"\"\n        return self._store.keys()\n\n    def get(self, key, default=None):\n        \"\"\"D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.\"\"\"\n        return self._store.get(key, default)\n\n    #\n    # Compatibility with ConfigParser API\n    #\n    def sections(self):\n        \"\"\"Returns a list of the sections available\"\"\"\n        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))\n\n    def options(self, section):\n        \"\"\"Returns a list of options available in the specified section.\"\"\"\n        opts = []\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section:\n                opts.append(opt)\n        return opts\n\n    def has_section(self, section):\n        \"\"\"Indicates whether a section is present in the configuration\"\"\"\n        for k in self._store:\n            if k.startswith(section):\n                return True\n        return False\n\n    def has_option(self, section, option):\n        \"\"\"If the given section exists, and contains the given option\"\"\"\n        for k in self._store:\n            sec, opt = cfg_sectionoption_regex.match(k).groups()\n            if sec == section and opt == option:\n                return True\n        return False\n\n    def getint(self, section, option):\n        \"\"\"A convenience method which coerces the option value to an integer\"\"\"\n        return int(self.get_value(section, option))\n\n    def getbool(self, section, option, default=None):\n        \"\"\"A convenience method which coerces the option value to a bool\n\n        Values \"on\", \"yes\", \"true\" and any int!=0 are considered True\n        Values which evaluate to bool False, \"off\", \"no\", \"false\" are considered\n        False\n        TypeError is raised for other values.\n        \"\"\"\n        val = self.get_value(section, option, default=default)\n        return anything2bool(val)\n\n    def getfloat(self, section, option):\n        \"\"\"A convenience method which coerces the option value to a float\"\"\"\n        return float(self.get_value(section, option))\n\n    # this is a hybrid of ConfigParser and dict API\n    def items(self, section=None):\n        \"\"\"Return a list of (name, value) pairs for each option\n\n        Optionally limited to a given section.\n        \"\"\"\n        if section is None:\n            return self._store.items()\n        return [(k, v) for k, v in self._store.items()\n                if cfg_section_regex.match(k).group(1) == section]\n\n    #\n    # Compatibility with GitPython's ConfigParser\n    #\n    def get_value(self, section, option, default=None):\n        \"\"\"Like `get()`, but with an optional default value\n\n        If the default is not None, the given default value will be returned in\n        case the option did not exist. This behavior immitates GitPython's\n        config parser.\n        \"\"\"\n        try:\n            return self['.'.join((section, option))]\n        except KeyError as e:\n            # this strange dance is needed because gitpython does it this way\n            if default is not None:\n                return default\n            else:\n                raise e\n\n    #\n    # Modify configuration (proxy respective git-config call)\n    #\n    @_where_reload\n    def _run(self, args, where=None, reload=False, **kwargs):\n        \"\"\"Centralized helper to run \"git config\" calls\n\n        Parameters\n        ----------\n        args : list\n          Arguments to pass for git config\n        %s\n        **kwargs\n          Keywords arguments for Runner's call\n        \"\"\"\n        if where:\n            args = self._get_location_args(where) + args\n        out = self._runner.run(['git', 'config'] + args, **kwargs)\n        if reload:\n            self.reload()\n        return out\n\n    def _get_location_args(self, where, args=None):\n        if args is None:\n            args = []\n        cfg_labels = ('dataset', 'local', 'global')\n        if where not in cfg_labels:\n            raise ValueError(\n                \"unknown configuration label '{}' (not in {})\".format(\n                    where, cfg_labels))\n        if where == 'dataset':\n            if not self._dataset_path:\n                raise ValueError(\n                    'ConfigManager cannot store to configuration to dataset, none specified')\n            # create an empty config file if none exists, `git config` will\n            # fail otherwise\n            dscfg_dirname = opj(self._dataset_path, '.datalad')\n            dscfg_fname = opj(dscfg_dirname, 'config')\n            if not exists(dscfg_dirname):\n                os.makedirs(dscfg_dirname)\n            if not exists(dscfg_fname):\n                open(dscfg_fname, 'w').close()\n            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])\n        elif where == 'global':\n            args.append('--global')\n        elif where == 'local':\n            args.append('--local')\n        return args\n\n    @_where_reload\n    def add(self, var, value, where='dataset', reload=True):\n        \"\"\"Add a configuration variable and value\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        %s\"\"\"\n        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def set(self, var, value, where='dataset', reload=True, force=False):\n        \"\"\"Set a variable to a value.\n\n        In opposition to `add`, this replaces the value of `var` if there is\n        one already.\n\n        Parameters\n        ----------\n        var : str\n          Variable name including any section like `git config` expects them, e.g.\n          'core.editor'\n        value : str\n          Variable value\n        force: bool\n          if set, replaces all occurrences of `var` by a single one with the\n          given `value`. Otherwise raise if multiple entries for `var` exist\n          already\n        %s\"\"\"\n        from datalad.support.gitrepo import to_options\n\n        self._run(to_options(replace_all=force) + [var, value],\n                  where=where, reload=reload, log_stderr=True)\n\n    @_where_reload\n    def rename_section(self, old, new, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        old : str\n          Name of the section to rename.\n        new : str\n          Name of the section to rename to.\n        %s\"\"\"\n        self._run(['--rename-section', old, new], where=where, reload=reload)\n\n    @_where_reload\n    def remove_section(self, sec, where='dataset', reload=True):\n        \"\"\"Rename a configuration section\n\n        Parameters\n        ----------\n        sec : str\n          Name of the section to remove.\n        %s\"\"\"\n        self._run(['--remove-section', sec], where=where, reload=reload)\n\n    @_where_reload\n    def unset(self, var, where='dataset', reload=True):\n        \"\"\"Remove all occurrences of a variable\n\n        Parameters\n        ----------\n        var : str\n          Name of the variable to remove\n        %s\"\"\"\n        # use unset all as it is simpler for now\n        self._run(['--unset-all', var], where=where, reload=reload)\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** ConfigManager Missing `overrides` Attribute Causes AttributeError

**Description:**
When using the `ConfigManager` without providing an `overrides` parameter, attempting to access the `overrides` attribute results in an `AttributeError`. This prevents users from setting override configurations as intended.

**Example Code:**
```python
cfg = ConfigManager()
cfg.overrides['datalad.crazy.override'] = 'fromoverride'
```

**Expected Behavior:**
The `overrides` attribute should be available as a dictionary, allowing users to set and manage override configurations without errors.

**Actual Behavior:**
An `AttributeError` is raised:
```
AttributeError: 'ConfigManager' object has no attribute 'overrides'
```
This error occurs because the `overrides` attribute is not initialized, making it impossible to set override values.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### datalad/config.py
# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
# ex: set sts=4 ts=4 sw=4 noet:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the datalad package for the
#   copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""
"""

from datalad.cmd import Runner
from datalad.dochelpers import exc_str
import re
import os
from os.path import join as opj, exists

cfg_kv_regex = re.compile(r'(^.*)\n(.*)$', flags=re.MULTILINE)
cfg_section_regex = re.compile(r'(.*)\.[^.]+')
cfg_sectionoption_regex = re.compile(r'(.*)\.([^.]+)')


_where_reload_doc = """
        where : {'dataset', 'local', 'global'}, optional
          Indicator which configuration file to modify. 'dataset' indicates the
          persistent configuration in .datalad/config of a dataset; 'local'
          the configuration of a dataset's Git repository in .git/config;
          'global' refers to the general configuration that is not specific to
          a single repository (usually in $USER/.gitconfig).
        reload : bool
          Flag whether to reload the configuration from file(s) after
          modification. This can be disable to make multiple sequential
          modifications slightly more efficient.""".lstrip()


def _where_reload(obj):
    """Helper decorator to simplify providing repetitive docstring"""
    obj.__doc__ = obj.__doc__ % _where_reload_doc
    return obj


def _parse_gitconfig_dump(dump, store, replace):
    if replace:
        # if we want to replace existing values in the store
        # collect into a new dict and `update` the store at the
        # end. This way we get the desired behavior of multi-value
        # keys, but only for the current source
        dct = {}
    else:
        # if we don't want to replace value, perform the multi-value
        # preserving addition on the existing store right away
        dct = store
    for line in dump.split('\0'):
        if not line:
            continue
        k, v = cfg_kv_regex.match(line).groups()
        present_v = dct.get(k, None)
        if present_v is None:
            dct[k] = v
        else:
            if isinstance(present_v, tuple):
                dct[k] = present_v + (v,)
            else:
                dct[k] = (present_v, v)
    if replace:
        store.update(dct)
    return store


def _parse_env(store):
    dct = {}
    for k in os.environ:
        if not k.startswith('DATALAD_'):
            continue
        dct[k.replace('_', '.').lower()] = os.environ[k]
    store.update(dct)
    return store


def anything2bool(val):
    if hasattr(val, 'lower'):
        val = val.lower()
    if val in {"off", "no", "false", "0"} or not bool(val):
        return False
    elif val in {"on", "yes", "true", True} \
            or (hasattr(val, 'isdigit') and val.isdigit() and int(val)) \
            or isinstance(val, int) and val:
        return True
    else:
        raise TypeError(
            "Got value %s which could not be interpreted as a boolean"
            % repr(val))


class ConfigManager(object):
    """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. If such need arises, various solutions are
    possible (via GitPython, or an independent writer).

    Any DATALAD_* environment variable is also presented as a configuration
    item. Settings read from environment variables are not stored in any of the
    configuration file, but are read dynamically from the environment at each
    `reload()` call. Their values take precedence over any specification in
    configuration files.

    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)
    dataset_only : bool
      If True, configuration items are only read from a datasets persistent
      configuration file, if any present (the one in ``.datalad/config``, not
      ``.git/config``).
    """
    def __init__(self, dataset=None, dataset_only=False):
        # store in a simple dict
        # no subclassing, because we want to be largely read-only, and implement
        # config writing separately
        self._store = {}
        self._dataset_path = dataset.path if dataset else None
        self._dataset_only = dataset_only
        # Since configs could contain sensitive information, to prevent
        # any "facilitated" leakage -- just disable logging of outputs for
        # this runner
        run_kwargs = dict(log_outputs=False)
        if dataset is not None:
            # make sure we run the git config calls in the dataset
            # to pick up the right config files
            run_kwargs['cwd'] = dataset.path
        self._runner = Runner(**run_kwargs)
        self.reload()

    def reload(self):
        """Reload all configuration items from the configured sources"""
        self._store = {}
        # 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
        if self._dataset_path:
            # now any dataset config
            dscfg_fname = opj(self._dataset_path, '.datalad', 'config')
            if exists(dscfg_fname):
                stdout, stderr = self._run(['-z', '-l', '--file', dscfg_fname],
                                           log_stderr=True)
                # overwrite existing value, do not amend to get multi-line
                # values
                self._store = _parse_gitconfig_dump(
                    stdout, self._store, replace=False)

        if not self._dataset_only:
            stdout, stderr = self._run(['-z', '-l'], log_stderr=True)
            self._store = _parse_gitconfig_dump(
                stdout, self._store, replace=True)

            # override with environment variables
            self._store = _parse_env(self._store)

    @_where_reload
    def obtain(self, var, default=None, dialog_type=None, valtype=None,
               store=False, where=None, reload=True, **kwargs):
        """
        Convenience method to obtain settings interactively, if needed

        A UI will be used to ask for user input in interactive sessions.
        Questions to ask, and additional explanations can be passed directly
        as arguments, or retrieved from a list of pre-configured items.

        Additionally, this method allows for type conversion and storage
        of obtained settings. Both aspects can also be pre-configured.

        Parameters
        ----------
        var : str
          Variable name including any section like `git config` expects them,
          e.g. 'core.editor'
        default : any type
          In interactive sessions and if `store` is True, this default value
          will be presented to the user for confirmation (or modification).
          In all other cases, this value will be silently assigned unless
          there is an existing configuration setting.
        dialog_type : {'question', 'yesno', None}
          Which dialog type to use in interactive sessions. If `None`,
          pre-configured UI options are used.
        store : bool
          Whether to store the obtained value (or default)
        %s
        `**kwargs`
          Additional arguments for the UI function call, such as a question
          `text`.
        """
        # do local import, as this module is import prominently and the
        # could theroetically import all kind of weired things for type
        # conversion
        from datalad.interface.common_cfg import definitions as cfg_defs
        # fetch what we know about this variable
        cdef = cfg_defs.get(var, {})
        # type conversion setup
        if valtype is None and 'type' in cdef:
            valtype = cdef['type']
        if valtype is None:
            valtype = lambda x: x

        # any default?
        if default is None and 'default' in cdef:
            default = cdef['default']

        _value = None
        if var in self:
            # nothing needs to be obtained, it is all here already
            _value = self[var]
        elif store is False and default is not None:
            # nothing will be stored, and we have a default -> no user confirmation
            # we cannot use logging, because we want to use the config to confiugre
            # the logging
            #lgr.debug('using default {} for config setting {}'.format(default, var))
            _value = default

        if _value is not None:
            # we got everything we need and can exit early
            try:
                return valtype(_value)
            except Exception as e:
                raise ValueError(
                    "value '{}' of existing configuration for '{}' cannot be "
                    "converted to the desired type '{}' ({})".format(
                        _value, var, valtype, exc_str(e)))

        # now we need to try to obtain something from the user
        from datalad.ui import ui

        # configure UI
        dialog_opts = kwargs
        if dialog_type is None:  # no override
            # check for common knowledge on how to obtain a value
            if 'ui' in cdef:
                dialog_type = cdef['ui'][0]
                # pull standard dialog settings
                dialog_opts = cdef['ui'][1]
                # update with input
                dialog_opts.update(kwargs)

        if (not ui.is_interactive or dialog_type is None) and default is None:
            raise RuntimeError(
                "cannot obtain value for configuration item '{}', "
                "not preconfigured, no default, no UI available".format(var))

        if not hasattr(ui, dialog_type):
            raise ValueError("UI '{}' does not support dialog type '{}'".format(
                ui, dialog_type))

        # configure storage destination, if needed
        if store:
            if where is None and 'destination' in cdef:
                where = cdef['destination']
            if where is None:
                raise ValueError(
                    "request to store configuration item '{}', but no "
                    "storage destination specified".format(var))

        # obtain via UI
        dialog = getattr(ui, dialog_type)
        _value = dialog(default=default, **dialog_opts)

        if _value is None:
            # we got nothing
            if default is None:
                raise RuntimeError(
                    "could not obtain value for configuration item '{}', "
                    "not preconfigured, no default".format(var))
            # XXX maybe we should return default here, even it was returned
            # from the UI -- if that is even possible

        # execute type conversion before storing to check that we got
        # something that looks like what we want
        try:
            value = valtype(_value)
        except Exception as e:
            raise ValueError(
                "cannot convert user input `{}` to desired type ({})".format(
                    _value, exc_str(e)))
            # XXX we could consider "looping" until we have a value of proper
            # type in case of a user typo...

        if store:
            # store value as it was before any conversion, needs to be str
            # anyway
            # needs string conversion nevertheless, because default could come
            # in as something else
            self.add(var, '{}'.format(_value), where=where, reload=reload)
        return value

    #
    # Compatibility with dict API
    #
    def __len__(self):
        return len(self._store)

    def __getitem__(self, key):
        return self._store.__getitem__(key)

    def __contains__(self, key):
        return self._store.__contains__(key)

    def keys(self):
        """Returns list of configuration item names"""
        return self._store.keys()

    def get(self, key, default=None):
        """D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None."""
        return self._store.get(key, default)

    #
    # Compatibility with ConfigParser API
    #
    def sections(self):
        """Returns a list of the sections available"""
        return list(set([cfg_section_regex.match(k).group(1) for k in self._store]))

    def options(self, section):
        """Returns a list of options available in the specified section."""
        opts = []
        for k in self._store:
            sec, opt = cfg_sectionoption_regex.match(k).groups()
            if sec == section:
                opts.append(opt)
        return opts

    def has_section(self, section):
        """Indicates whether a section is present in the configuration"""
        for k in self._store:
            if k.startswith(section):
                return True
        return False

    def has_option(self, section, option):
        """If the given section exists, and contains the given option"""
        for k in self._store:
            sec, opt = cfg_sectionoption_regex.match(k).groups()
            if sec == section and opt == option:
                return True
        return False

    def getint(self, section, option):
        """A convenience method which coerces the option value to an integer"""
        return int(self.get_value(section, option))

    def getbool(self, section, option, default=None):
        """A convenience method which coerces the option value to a bool

        Values "on", "yes", "true" and any int!=0 are considered True
        Values which evaluate to bool False, "off", "no", "false" are considered
        False
        TypeError is raised for other values.
        """
        val = self.get_value(section, option, default=default)
        return anything2bool(val)

    def getfloat(self, section, option):
        """A convenience method which coerces the option value to a float"""
        return float(self.get_value(section, option))

    # this is a hybrid of ConfigParser and dict API
    def items(self, section=None):
        """Return a list of (name, value) pairs for each option

        Optionally limited to a given section.
        """
        if section is None:
            return self._store.items()
        return [(k, v) for k, v in self._store.items()
                if cfg_section_regex.match(k).group(1) == section]

    #
    # Compatibility with GitPython's ConfigParser
    #
    def get_value(self, section, option, default=None):
        """Like `get()`, but with an optional default value

        If the default is not None, the given default value will be returned in
        case the option did not exist. This behavior immitates GitPython's
        config parser.
        """
        try:
            return self['.'.join((section, option))]
        except KeyError as e:
            # this strange dance is needed because gitpython does it this way
            if default is not None:
                return default
            else:
                raise e

    #
    # Modify configuration (proxy respective git-config call)
    #
    @_where_reload
    def _run(self, args, where=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 where:
            args = self._get_location_args(where) + args
        out = self._runner.run(['git', 'config'] + args, **kwargs)
        if reload:
            self.reload()
        return out

    def _get_location_args(self, where, args=None):
        if args is None:
            args = []
        cfg_labels = ('dataset', 'local', 'global')
        if where not in cfg_labels:
            raise ValueError(
                "unknown configuration label '{}' (not in {})".format(
                    where, cfg_labels))
        if where == 'dataset':
            if not self._dataset_path:
                raise ValueError(
                    'ConfigManager cannot store to configuration to dataset, none specified')
            # create an empty config file if none exists, `git config` will
            # fail otherwise
            dscfg_dirname = opj(self._dataset_path, '.datalad')
            dscfg_fname = opj(dscfg_dirname, 'config')
            if not exists(dscfg_dirname):
                os.makedirs(dscfg_dirname)
            if not exists(dscfg_fname):
                open(dscfg_fname, 'w').close()
            args.extend(['--file', opj(self._dataset_path, '.datalad', 'config')])
        elif where == 'global':
            args.append('--global')
        elif where == 'local':
            args.append('--local')
        return args

    @_where_reload
    def add(self, var, value, where='dataset', reload=True):
        """Add a configuration variable and value

        Parameters
        ----------
        var : str
          Variable name including any section like `git config` expects them, e.g.
          'core.editor'
        value : str
          Variable value
        %s"""
        self._run(['--add', var, value], where=where, reload=reload, log_stderr=True)

    @_where_reload
    def set(self, var, value, where='dataset', reload=True, force=False):
        """Set a variable to a value.

        In opposition to `add`, this replaces the value of `var` if there is
        one already.

        Parameters
        ----------
        var : str
          Variable name including any section like `git config` expects them, e.g.
          'core.editor'
        value : str
          Variable value
        force: bool
          if set, replaces all occurrences of `var` by a single one with the
          given `value`. Otherwise raise if multiple entries for `var` exist
          already
        %s"""
        from datalad.support.gitrepo import to_options

        self._run(to_options(replace_all=force) + [var, value],
                  where=where, reload=reload, log_stderr=True)

    @_where_reload
    def rename_section(self, old, new, where='dataset', reload=True):
        """Rename a configuration section

        Parameters
        ----------
        old : str
          Name of the section to rename.
        new : str
          Name of the section to rename to.
        %s"""
        self._run(['--rename-section', old, new], where=where, reload=reload)

    @_where_reload
    def remove_section(self, sec, where='dataset', reload=True):
        """Rename a configuration section

        Parameters
        ----------
        sec : str
          Name of the section to remove.
        %s"""
        self._run(['--remove-section', sec], where=where, reload=reload)

    @_where_reload
    def unset(self, var, where='dataset', reload=True):
        """Remove all occurrences of a variable

        Parameters
        ----------
        var : str
          Name of the variable to remove
        %s"""
        # use unset all as it is simpler for now
        self._run(['--unset-all', var], where=where, reload=reload)

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user