Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz1273327 committed Feb 3, 2021
1 parent 795f6c1 commit 953158c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.1.1

## bug修复

+ 解决自定义解析的配置文件不受``控制的问题
+ 解决打印出奇怪字符的问题

# 0.1.0

## 新特性
Expand Down
41 changes: 22 additions & 19 deletions schema_entry/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]:
Expand All @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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 = [email protected]
Expand Down

0 comments on commit 953158c

Please sign in to comment.