def _load_config(self, configfile): config = Config() if not configfile: return config configpath = Path(configfile) try: if not configpath.expanduser().resolve().exists(): logger.debug('Ignoring non existing config file %s', configfile) return config except FileNotFoundError: # we are on python 3.5 and Path.resolve raised a FileNotFoundError logger.debug('Ignoring non existing config file %s', configfile) return config try: config.load(configpath, def_section=self._name) logger.debug('Loaded config %s', configfile) except Exception as e: # pylint: disable=broad-except raise RuntimeError( 'Error while parsing config file {config}. Error was ' '{message}'.format(config=configfile, message=e)) return config
def _load_config(self, configfile: str) -> Config: config = Config() if not configfile: return config configpath = Path(configfile) if not configpath.expanduser().resolve().exists(): logger.debug('Ignoring non existing config file %s', configfile) return config try: config.load(configpath, def_section=self._name) logger.debug('Loaded config %s', configfile) except Exception as e: # pylint: disable=broad-except raise RuntimeError( 'Error while parsing config file {config}. Error was ' '{message}'.format(config=configfile, message=e)) from None return config
def _load_config(self, configfile: str) -> Config: config = Config() configpath = Path(configfile or DEFAULT_CONFIG_PATH) if not configpath.expanduser().resolve().exists(): if configfile: # user has passed an config file # print error and exit self.parser.error(f'Config file {configpath} does not exist') else: logger.debug('Ignoring non existing config file %s', configfile) return config try: config.load(configpath, def_section=self._name) logger.debug('Loaded config %s', configfile) except Exception as e: # pylint: disable=broad-except raise RuntimeError( f'Error while parsing config file {configfile}. Error was {e}' ) from None return config