From de1ee0e575d0170c87d131c69760401222110d8f Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Wed, 21 Aug 2024 18:21:27 -0400 Subject: [PATCH 1/4] Use private func instead of lambda for pattern match --- src/diffpy/srfit/fitbase/recipeorganizer.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/diffpy/srfit/fitbase/recipeorganizer.py b/src/diffpy/srfit/fitbase/recipeorganizer.py index d484c7ae..28342ee7 100644 --- a/src/diffpy/srfit/fitbase/recipeorganizer.py +++ b/src/diffpy/srfit/fitbase/recipeorganizer.py @@ -933,6 +933,9 @@ def _formatRestraints(self): rlines.sort(key=numstr) return rlines + def _get_pmatch(self, s): + return len(s.split(None, 1)) < 2 or self._regexp.search(s.split(None, 1)[0]) + def show(self, pattern="", textwidth=78): """Show the configuration hierarchy on the screen. @@ -947,14 +950,14 @@ def show(self, pattern="", textwidth=78): Trim formatted lines at this text width to avoid folding at the screen width. Do not trim when negative or 0. """ - regexp = re.compile(pattern) - pmatch = lambda s: (len(s.split(None, 1)) < 2 or regexp.search(s.split(None, 1)[0])) + self._regexp = re.compile(pattern) + # Show sub objects and their parameters lines = [] tlines = self._formatManaged() if tlines: lines.extend(["Parameters", _DASHEDLINE]) - linesok = filter(pmatch, tlines) + linesok = filter(self._get_pmatch, tlines) lastnotblank = False # squeeze repeated blank lines for lastnotblank, g in groupby(linesok, bool): @@ -965,7 +968,7 @@ def show(self, pattern="", textwidth=78): # FIXME - parameter names in equations not particularly informative # Show constraints - cmatch = regexp.search + cmatch = self._regexp.search tlines = self._formatConstraints() if tlines: if lines: @@ -980,7 +983,7 @@ def show(self, pattern="", textwidth=78): if lines: lines.append("") lines.extend(["Restraints", _DASHEDLINE]) - lines.extend(filter(pmatch, tlines)) + lines.extend(filter(self._get_pmatch, tlines)) # Determine effective text width tw. tw = textwidth if (textwidth is not None and textwidth > 0) else None From 99bab099adfcb6e466335fc808bc0477616709d1 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Wed, 21 Aug 2024 18:22:27 -0400 Subject: [PATCH 2/4] Rename pmatch to matchPattern --- src/diffpy/srfit/fitbase/recipeorganizer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffpy/srfit/fitbase/recipeorganizer.py b/src/diffpy/srfit/fitbase/recipeorganizer.py index 28342ee7..d6484251 100644 --- a/src/diffpy/srfit/fitbase/recipeorganizer.py +++ b/src/diffpy/srfit/fitbase/recipeorganizer.py @@ -933,7 +933,7 @@ def _formatRestraints(self): rlines.sort(key=numstr) return rlines - def _get_pmatch(self, s): + def _matchPattern(self, s): return len(s.split(None, 1)) < 2 or self._regexp.search(s.split(None, 1)[0]) def show(self, pattern="", textwidth=78): @@ -957,7 +957,7 @@ def show(self, pattern="", textwidth=78): tlines = self._formatManaged() if tlines: lines.extend(["Parameters", _DASHEDLINE]) - linesok = filter(self._get_pmatch, tlines) + linesok = filter(self._matchPattern, tlines) lastnotblank = False # squeeze repeated blank lines for lastnotblank, g in groupby(linesok, bool): @@ -983,7 +983,7 @@ def show(self, pattern="", textwidth=78): if lines: lines.append("") lines.extend(["Restraints", _DASHEDLINE]) - lines.extend(filter(self._get_pmatch, tlines)) + lines.extend(filter(self._matchPattern, tlines)) # Determine effective text width tw. tw = textwidth if (textwidth is not None and textwidth > 0) else None From 7bdf344e9bd10ca7f10005eac770b458e1b2100a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:25:21 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/srfit/fitbase/recipeorganizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/srfit/fitbase/recipeorganizer.py b/src/diffpy/srfit/fitbase/recipeorganizer.py index d6484251..f8c11071 100644 --- a/src/diffpy/srfit/fitbase/recipeorganizer.py +++ b/src/diffpy/srfit/fitbase/recipeorganizer.py @@ -935,7 +935,7 @@ def _formatRestraints(self): def _matchPattern(self, s): return len(s.split(None, 1)) < 2 or self._regexp.search(s.split(None, 1)[0]) - + def show(self, pattern="", textwidth=78): """Show the configuration hierarchy on the screen. From e5637bf6abcbe05cd829f65674a23253044e309a Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Sat, 24 Aug 2024 15:57:36 -0400 Subject: [PATCH 4/4] Chnage name from matchPattern to is_single_or_matches_pattern --- src/diffpy/srfit/fitbase/recipeorganizer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffpy/srfit/fitbase/recipeorganizer.py b/src/diffpy/srfit/fitbase/recipeorganizer.py index d6484251..78e90724 100644 --- a/src/diffpy/srfit/fitbase/recipeorganizer.py +++ b/src/diffpy/srfit/fitbase/recipeorganizer.py @@ -933,7 +933,7 @@ def _formatRestraints(self): rlines.sort(key=numstr) return rlines - def _matchPattern(self, s): + def _is_single_or_matches_pattern(self, s): return len(s.split(None, 1)) < 2 or self._regexp.search(s.split(None, 1)[0]) def show(self, pattern="", textwidth=78): @@ -957,7 +957,7 @@ def show(self, pattern="", textwidth=78): tlines = self._formatManaged() if tlines: lines.extend(["Parameters", _DASHEDLINE]) - linesok = filter(self._matchPattern, tlines) + linesok = filter(self._is_single_or_matches_pattern, tlines) lastnotblank = False # squeeze repeated blank lines for lastnotblank, g in groupby(linesok, bool): @@ -983,7 +983,7 @@ def show(self, pattern="", textwidth=78): if lines: lines.append("") lines.extend(["Restraints", _DASHEDLINE]) - lines.extend(filter(self._matchPattern, tlines)) + lines.extend(filter(self._is_single_or_matches_pattern, tlines)) # Determine effective text width tw. tw = textwidth if (textwidth is not None and textwidth > 0) else None