Skip to content

Commit 953158c

Browse files
committed
update
1 parent 795f6c1 commit 953158c

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.1.1
2+
3+
## bug修复
4+
5+
+ 解决自定义解析的配置文件不受``控制的问题
6+
+ 解决打印出奇怪字符的问题
7+
18
# 0.1.0
29

310
## 新特性

schema_entry/entrypoint.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,28 +225,32 @@ def parse_env_args(self) -> Dict[str, Any]:
225225
else:
226226
return {}
227227

228-
def parse_json_configfile_args(self, p: Path) -> Dict[str, Any]:
229-
with open(p, "r", encoding="utf-8") as f:
230-
result = json.load(f)
228+
def file_config_filter(self, file_param: Dict[str, Any]) -> Dict[str, Any]:
229+
"""根据条件筛选从文件中获得的参数.
230+
231+
Args:
232+
file_param (Dict[str, Any]): 文件中获得的全量参数
233+
234+
Returns:
235+
Dict[str, Any]: 筛选过后的参数
236+
"""
231237
if self.config_file_only_get_need and self.schema is not None and self.schema.get("properties") is not None:
232238
needs = list(self.schema.get("properties").keys())
233239
res = {}
234240
for key in needs:
235-
if result.get(key) is not None:
236-
res[key] = result.get(key)
241+
if file_param.get(key) is not None:
242+
res[key] = file_param.get(key)
237243
return res
244+
return file_param
245+
246+
def parse_json_configfile_args(self, p: Path) -> Dict[str, Any]:
247+
with open(p, "r", encoding="utf-8") as f:
248+
result = json.load(f)
238249
return result
239250

240251
def parse_yaml_configfile_args(self, p: Path) -> Dict[str, Any]:
241252
with open(p, "r", encoding="utf-8") as f:
242253
result = yaml_load(f)
243-
if self.config_file_only_get_need and self.schema is not None and self.schema.get("properties") is not None:
244-
needs = list(self.schema.get("properties").keys())
245-
res = {}
246-
for key in needs:
247-
if result.get(key) is not None:
248-
res[key] = result.get(key)
249-
return res
250254
return result
251255

252256
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]:
267271
if p.is_file():
268272
parfunc = self._config_file_parser_map.get(p.name)
269273
if parfunc:
270-
print("&&&&&&")
271-
return parfunc(p)
274+
return self.file_config_filter(parfunc(p))
272275
if p.suffix == ".json":
273-
return self.parse_json_configfile_args(p)
276+
return self.file_config_filter(self.parse_json_configfile_args(p))
274277
elif p.suffix == ".yml":
275-
return self.parse_yaml_configfile_args(p)
278+
return self.file_config_filter(self.parse_yaml_configfile_args(p))
276279
else:
277280
warnings.warn(f"跳过不支持的配置格式的文件{str(p)}")
278281
else:
@@ -285,12 +288,12 @@ def parse_configfile_args(self) -> Dict[str, Any]:
285288
if p.is_file():
286289
parfunc = self._config_file_parser_map.get(p.name)
287290
if parfunc:
288-
result.update(parfunc(p))
291+
result.update(self.file_config_filter(parfunc(p)))
289292
else:
290293
if p.suffix == ".json":
291-
result.update(self.parse_json_configfile_args(p))
294+
result.update(self.file_config_filter(self.parse_json_configfile_args(p)))
292295
elif p.suffix == ".yml":
293-
result.update(self.parse_yaml_configfile_args(p))
296+
result.update(self.file_config_filter(self.parse_yaml_configfile_args(p)))
294297
else:
295298
warnings.warn(f"跳过不支持的配置格式的文件{str(p)}")
296299
return result

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = schema_entry
3-
version = 0.1.0
3+
version = 0.1.1
44
url = https://github.com/Python-Tools/schema_entry
55
author = hsz
66
author_email = hsz1273327@gmail.com

0 commit comments

Comments
 (0)