def test_should_override_bool_value_with_env_var(self, tmp_path: Path, env_vars_mock: dict): env_vars_mock['SCIENCEBEAM_PARSER__KEY1'] = 'false' config_path = tmp_path / 'config.yml' config_path.write_text(yaml.dump({'key1': True})) config = AppConfig.load_yaml(str(config_path)) config = config.apply_environment_variables() assert config.props['key1'] is False
def test_should_override_nested_value_with_env_var(self, tmp_path: Path, env_vars_mock: dict): env_vars_mock['SCIENCEBEAM_PARSER__PARENT1__KEY1'] = 'updated value1' config_path = tmp_path / 'config.yml' config_path.write_text( yaml.dump({'parent1': { 'key1': 'original value1' }})) original_config = AppConfig.load_yaml(str(config_path)) config = original_config.apply_environment_variables() assert config.props['parent1']['key1'] == 'updated value1' assert original_config.props['parent1']['key1'] == 'original value1'
def run(args: argparse.Namespace): LOGGER.info('args: %r', args) output_path = args.output_path config = AppConfig.load_yaml(DEFAULT_CONFIG_FILE) sciencebeam_parser = ScienceBeamParser.from_config(config) LOGGER.info('output_path: %r', output_path) os.makedirs(output_path, exist_ok=True) for source_filename in glob(args.source_path): generate_training_data_for_source_filename( source_filename, output_path=output_path, sciencebeam_parser=sciencebeam_parser, use_model=args.use_model, use_directory_structure=args.use_directory_structure)
def main(argv=None): args = parse_args(argv) config = AppConfig.load_yaml( DEFAULT_CONFIG_FILE).apply_environment_variables() logging_config = config.get('logging') if logging_config: for handler_config in logging_config.get('handlers', {}).values(): filename = handler_config.get('filename') if not filename: continue dirname = os.path.dirname(filename) if dirname: os.makedirs(dirname, exist_ok=True) try: dictConfig(logging_config) except ValueError: LOGGER.info('logging_config: %r', logging_config) raise LOGGER.info('app config: %s', config) app = create_app_for_config(config) app.run(port=args.port, host=args.host, threaded=True)
def _app_config() -> AppConfig: return AppConfig.load_yaml(DEFAULT_CONFIG_FILE)
def test_should_load_yaml(self, tmp_path: Path): config_path = tmp_path / 'config.yml' config_path.write_text(yaml.dump({'key1': 'value1'})) config = AppConfig.load_yaml(str(config_path)) assert config.props['key1'] == 'value1'