parameters: (args, parser)
return_statement: return parser
docstring: Read both user configuration and local configuration.
docstring_summary: Read both user configuration and local configuration.
docstring_tokens: Read both user configuration and local configuration .
function: def read_config(args, parser):
      """Read both user configuration and local configuration."""
      try:
          from configparser import ConfigParser as SafeConfigParser
          from configparser import Error
      except ImportError:
          from ConfigParser import SafeConfigParser
          from ConfigParser import Error
  
      config = SafeConfigParser()
  
      try:
          config.read(args.global_config)
  
          if not args.ignore_local_config:
              parent = tail = args.files and os.path.abspath(
                  os.path.commonprefix(args.files))
              while tail:
                  if config.read([os.path.join(parent, fn)
                                  for fn in PROJECT_CONFIG]):
                      break
                  (parent, tail) = os.path.split(parent)
  
          defaults = dict()
          option_list = dict([(o.dest, o.type or type(o.default))
                              for o in parser._actions])
  
          for section in ['pep8', 'pycodestyle']:
              if not config.has_section(section):
                  continue
              for k, v in config.items(section):
                  norm_opt = k.lstrip('-').replace('-', '_')
                  opt_type = option_list[norm_opt]
                  if opt_type is int:
                      value = config.getint(section, k)
                  elif opt_type is bool:
                      value = config.getboolean(section, k)
                  else:
                      value = config.get(section, k)
                  defaults[norm_opt] = value
  
          parser.set_defaults(**defaults)
      except Error:
          # Ignore for now.
          pass
  
      return parser
function_tokens: def read_config ( args , parser ) : try : from configparser import ConfigParser as SafeConfigParser from configparser import Error except ImportError : from ConfigParser import SafeConfigParser from ConfigParser import Error config = SafeConfigParser ( ) try : config . read ( args . global_config ) if not args . ignore_local_config : parent = tail = args . files and os . path . abspath ( os . path . commonprefix ( args . files ) ) while tail : if config . read ( [ os . path . join ( parent , fn ) for fn in PROJECT_CONFIG ] ) : break ( parent , tail ) = os . path . split ( parent ) defaults = dict ( ) option_list = dict ( [ ( o . dest , o . type or type ( o . default ) ) for o in parser . _actions ] ) for section in [ 'pep8' , 'pycodestyle' ] : if not config . has_section ( section ) : continue for k , v in config . items ( section ) : norm_opt = k . lstrip ( '-' ) . replace ( '-' , '_' ) opt_type = option_list [ norm_opt ] if opt_type is int : value = config . getint ( section , k ) elif opt_type is bool : value = config . getboolean ( section , k ) else : value = config . get ( section , k ) defaults [ norm_opt ] = value parser . set_defaults ( * * defaults ) except Error : # Ignore for now. pass return parser