From f8d7389da7ef5c6ff715b9a8015a8113db022e95 Mon Sep 17 00:00:00 2001 From: Zhuoyuan <75076820+ZLI-afk@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:19:16 +0800 Subject: [PATCH 1/3] feat: add `post_func_skip_list` to control execution of post functions --- dpdata/system.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dpdata/system.py b/dpdata/system.py index 3be86ef4..25798923 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -229,7 +229,12 @@ def from_fmt_obj(self, fmtobj, file_name, **kwargs): self.data = {**self.data, **data} self.check_data() if hasattr(fmtobj.from_system, "post_func"): + post_func_skip_list = kwargs.get("post_func_skip_list", []) + if not isinstance(post_func_skip_list, list): + post_func_skip_list = [post_func_skip_list] for post_f in fmtobj.from_system.post_func: + if post_f in post_func_skip_list: + continue self.post_funcs.get_plugin(post_f)(self) return self From b29790676db5a2d0f788f67390cd6a008ed60226 Mon Sep 17 00:00:00 2001 From: Zhuoyuan <75076820+ZLI-afk@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:43:59 +0800 Subject: [PATCH 2/3] change: change `post_func_skip_list` argument explicitly --- dpdata/system.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index 25798923..876ce3f3 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -93,6 +93,7 @@ def __init__( step=1, data=None, convergence_check=True, + post_func_skip_list=None, **kwargs, ): """Constructor. @@ -163,6 +164,8 @@ def __init__( The raw data of System class. convergence_check : boolean Whether to request a convergence check. + post_func_skip_list : list of str + The list of post function names to skip. **kwargs : dict other parameters """ @@ -180,6 +183,7 @@ def __init__( return if file_name is None: return + self.post_func_skip_list = post_func_skip_list if post_func_skip_list is not None else [] self.from_fmt( file_name, fmt, @@ -193,6 +197,7 @@ def __init__( if type_map is not None: self.apply_type_map(type_map) + def check_data(self): """Check if data is correct. @@ -229,11 +234,10 @@ def from_fmt_obj(self, fmtobj, file_name, **kwargs): self.data = {**self.data, **data} self.check_data() if hasattr(fmtobj.from_system, "post_func"): - post_func_skip_list = kwargs.get("post_func_skip_list", []) - if not isinstance(post_func_skip_list, list): - post_func_skip_list = [post_func_skip_list] + assert isinstance(self.post_func_skip_list, list), \ + "post_func_skip_list should be a list of string" for post_f in fmtobj.from_system.post_func: - if post_f in post_func_skip_list: + if post_f in self.post_func_skip_list: continue self.post_funcs.get_plugin(post_f)(self) return self From 01b43cbfc4d110b2aa33c7edc4ea39debe023cfe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:48:55 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/system.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index 876ce3f3..43526f33 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -183,7 +183,9 @@ def __init__( return if file_name is None: return - self.post_func_skip_list = post_func_skip_list if post_func_skip_list is not None else [] + self.post_func_skip_list = ( + post_func_skip_list if post_func_skip_list is not None else [] + ) self.from_fmt( file_name, fmt, @@ -197,7 +199,6 @@ def __init__( if type_map is not None: self.apply_type_map(type_map) - def check_data(self): """Check if data is correct. @@ -234,8 +235,9 @@ def from_fmt_obj(self, fmtobj, file_name, **kwargs): self.data = {**self.data, **data} self.check_data() if hasattr(fmtobj.from_system, "post_func"): - assert isinstance(self.post_func_skip_list, list), \ - "post_func_skip_list should be a list of string" + assert isinstance( + self.post_func_skip_list, list + ), "post_func_skip_list should be a list of string" for post_f in fmtobj.from_system.post_func: if post_f in self.post_func_skip_list: continue