diff --git a/Changelog.md b/Changelog.md index 24ac75a..ea1f815 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,10 @@ +# 0.1.1 + +## bug修复 + ++ 解决自定义解析的配置文件不受``控制的问题 ++ 解决打印出奇怪字符的问题 + # 0.1.0 ## 新特性 diff --git a/schema_entry/entrypoint.py b/schema_entry/entrypoint.py index 994a57f..b3980da 100644 --- a/schema_entry/entrypoint.py +++ b/schema_entry/entrypoint.py @@ -225,28 +225,32 @@ def parse_env_args(self) -> Dict[str, Any]: else: return {} - def parse_json_configfile_args(self, p: Path) -> Dict[str, Any]: - with open(p, "r", encoding="utf-8") as f: - result = json.load(f) + def file_config_filter(self, file_param: Dict[str, Any]) -> Dict[str, Any]: + """根据条件筛选从文件中获得的参数. + + Args: + file_param (Dict[str, Any]): 文件中获得的全量参数 + + Returns: + Dict[str, Any]: 筛选过后的参数 + """ if self.config_file_only_get_need and self.schema is not None and self.schema.get("properties") is not None: needs = list(self.schema.get("properties").keys()) res = {} for key in needs: - if result.get(key) is not None: - res[key] = result.get(key) + if file_param.get(key) is not None: + res[key] = file_param.get(key) return res + return file_param + + def parse_json_configfile_args(self, p: Path) -> Dict[str, Any]: + with open(p, "r", encoding="utf-8") as f: + result = json.load(f) return result def parse_yaml_configfile_args(self, p: Path) -> Dict[str, Any]: with open(p, "r", encoding="utf-8") as f: result = yaml_load(f) - if self.config_file_only_get_need and self.schema is not None and self.schema.get("properties") is not None: - needs = list(self.schema.get("properties").keys()) - res = {} - for key in needs: - if result.get(key) is not None: - res[key] = result.get(key) - return res return result def regist_config_file_parser(self, file_name: str) -> Callable[[Callable[[Path], Dict[str, Any]]], Callable[[Path], Dict[str, Any]]]: @@ -267,12 +271,11 @@ def parse_configfile_args(self) -> Dict[str, Any]: if p.is_file(): parfunc = self._config_file_parser_map.get(p.name) if parfunc: - print("&&&&&&") - return parfunc(p) + return self.file_config_filter(parfunc(p)) if p.suffix == ".json": - return self.parse_json_configfile_args(p) + return self.file_config_filter(self.parse_json_configfile_args(p)) elif p.suffix == ".yml": - return self.parse_yaml_configfile_args(p) + return self.file_config_filter(self.parse_yaml_configfile_args(p)) else: warnings.warn(f"跳过不支持的配置格式的文件{str(p)}") else: @@ -285,12 +288,12 @@ def parse_configfile_args(self) -> Dict[str, Any]: if p.is_file(): parfunc = self._config_file_parser_map.get(p.name) if parfunc: - result.update(parfunc(p)) + result.update(self.file_config_filter(parfunc(p))) else: if p.suffix == ".json": - result.update(self.parse_json_configfile_args(p)) + result.update(self.file_config_filter(self.parse_json_configfile_args(p))) elif p.suffix == ".yml": - result.update(self.parse_yaml_configfile_args(p)) + result.update(self.file_config_filter(self.parse_yaml_configfile_args(p))) else: warnings.warn(f"跳过不支持的配置格式的文件{str(p)}") return result diff --git a/setup.cfg b/setup.cfg index bc91707..06f6dc1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = schema_entry -version = 0.1.0 +version = 0.1.1 url = https://github.com/Python-Tools/schema_entry author = hsz author_email = hsz1273327@gmail.com