class_docstr: Responsible for parsing configuration from files and CLI.
  
  There are 2 types of configurations: Run configurations and Check
  configurations.
  
  Run Configurations:
  ------------------
  Responsible for deciding things that are related to the user interface and
  configuration discovery, e.g. verbosity, debug options, etc.
  All run configurations default to `False` or `None` and are decided only
  by CLI.
  
  Check Configurations:
  --------------------
  Configurations that are related to which files and errors will be checked.
  These are configurable in 2 ways: using the CLI, and using configuration
  files.
  
  Configuration files are nested within the file system, meaning that the
  closer a configuration file is to a checked file, the more relevant it will
  be. For instance, imagine this directory structure:
  
  A
  +-- tox.ini: sets `select=D100`
  +-- B
      +-- foo.py
      +-- tox.ini: sets `add-ignore=D100`
  
  Then `foo.py` will not be checked for `D100`.
  The configuration build algorithm is described in `self._get_config`.
  
  Note: If any of `BASE_ERROR_SELECTION_OPTIONS` was selected in the CLI, all
  configuration files will be ignored and each file will be checked for
  the error codes supplied in the CLI.
class_docstr_tok: ["Responsible","for","parsing","configuration","from","files","and","CLI",".","There","are","2","types","of","configurations",":","Run","configurations","and","Check","configurations",".","Run","Configurations",":","--","--","--","--","--","--","--","--","--","Responsible","for","deciding","things","that","are","related","to","the","user","interface","and","configuration","discovery",",","e.g",".","verbosity",",","debug","options",",","etc",".","All","run","configurations","default","to","`","False","`","or","`","None","`","and","are","decided","only","by","CLI",".","Check","Configurations",":","--","--","--","--","--","--","--","--","--","--","Configurations","that","are","related","to","which","files","and","errors","will","be","checked",".","These","are","configurable","in","2","ways",":","using","the","CLI",",","and","using","configuration","files",".","Configuration","files","are","nested","within","the","file","system",",","meaning","that","the","closer","a","configuration","file","is","to","a","checked","file",",","the","more","relevant","it","will","be",".","For","instance",",","imagine","this","directory","structure",":","A","+","--","tox.ini",":","sets","`","select=D100","`","+","--","B","+","--","foo.py","+","--","tox.ini",":","sets","`","add-ignore=D100","`","Then","`","foo.py","`","will","not","be","checked","for","`","D100","`",".","The","configuration","build","algorithm","is","described","in","`","self._get_config","`",".","Note",":","If","any","of","`","BASE_ERROR_SELECTION_OPTIONS","`","was","selected","in","the","CLI",",","all","configuration","files","will","be","ignored","and","each","file","will","be","checked","for","the","error","codes","supplied","in","the","CLI","."]
docstr: Get a configuration for checking `node` by config discovery.
  
  Config discovery happens when no explicit config file is specified. The
  file system is searched for config files starting from the directory
  containing the file being checked, and up until the root directory of
  the project.
  
  See `_get_config` for further details.
docstr_tok: ["Get","a","configuration","for","checking","`","node","`","by","config","discovery",".","Config","discovery","happens","when","no","explicit","config","file","is","specified",".","The","file","system","is","searched","for","config","files","starting","from","the","directory","containing","the","file","being","checked",",","and","up","until","the","root","directory","of","the","project",".","See","`","_get_config","`","for","further","details","."]
code: def _get_config_by_discovery(self, node):
      """Get a configuration for checking `node` by config discovery.
  
      Config discovery happens when no explicit config file is specified. The
      file system is searched for config files starting from the directory
      containing the file being checked, and up until the root directory of
      the project.
  
      See `_get_config` for further details.
  
      """
      path = self._get_node_dir(node)
  
      if path in self._cache:
          return self._cache[path]
  
      config_file = self._get_config_file_in_folder(path)
  
      if config_file is None:
          parent_dir, tail = os.path.split(path)
          if tail:
              # No configuration file, simply take the parent's.
              config = self._get_config(parent_dir)
          else:
              # There's no configuration file and no parent directory.
              # Use the default configuration or the one given in the CLI.
              config = self._create_check_config(self._options)
      else:
          # There's a config file! Read it and merge if necessary.
          options, inherit = self._read_configuration_file(config_file)
  
          parent_dir, tail = os.path.split(path)
          if tail and inherit:
              # There is a parent dir and we should try to merge.
              parent_config = self._get_config(parent_dir)
              config = self._merge_configuration(parent_config, options)
          else:
              # No need to merge or parent dir does not exist.
              config = self._create_check_config(options)
  
      return config
  
imports: import copy
  import itertools
  import operator
  import os
  import sys
  from collections import namedtuple
  from collections.abc import Set
  from configparser import NoOptionError, NoSectionError, RawConfigParser
  from functools import reduce
  from re import compile
  from ._version import __version__
  from .utils import log
  from .violations import ErrorRegistry, conventions
label_desc: Use image node_id 6 for calling the ConfigurationParser obj's underlying member method code with example usage: obj._get_config_by_discovery(node) and returns: config, self