From 04046a5ce47d394521d8de88b047095d6af779ee Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Wed, 25 Mar 2026 15:03:09 -0500 Subject: [PATCH 1/3] Instantiate class to read instance-level OPTS and ALIAS in load_opts_alias() Previously the class was used directly with getattr(), which only finds class-level attributes. Now the class is instantiated first so that self.OPTS and self.ALIAS set in __init__ are accessible. Co-Authored-By: Claude Sonnet 4.6 --- src/rda_python_miscs/pg_rst.py | 40 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/rda_python_miscs/pg_rst.py b/src/rda_python_miscs/pg_rst.py index 4ac759a..eeabce3 100755 --- a/src/rda_python_miscs/pg_rst.py +++ b/src/rda_python_miscs/pg_rst.py @@ -1119,9 +1119,10 @@ def load_opts_alias(self, docname): Resolution order for OPTS / ALIAS: - 1. Module-level ``OPTS`` / ``ALIAS`` attributes. - 2. The first class *defined in that module* that carries both ``OPTS`` - and ``ALIAS`` as class-level attributes. + 1. The first class *defined in that module* that carries ``OPTS`` + as a class-level attribute. + 2. Module-level ``OPTS`` / ``ALIAS`` attributes (fallback when no + qualifying class is found). ``ALIAS`` is optional; an empty dict is returned when not found. @@ -1155,25 +1156,26 @@ def load_opts_alias(self, docname): # Derive ORIGIN from the module's own file path. origin = op.dirname(op.abspath(mod.__file__)) - # 1. Try module-level attributes first. - opts = getattr(mod, 'OPTS', None) - alias = getattr(mod, 'ALIAS', None) - - # 2. Fall back to the first class in the module that owns both. - if opts is None or alias is None: - for _, obj in inspect.getmembers(mod, inspect.isclass): - if obj.__module__ == modname: - cls_opts = getattr(obj, 'OPTS', None) - cls_alias = getattr(obj, 'ALIAS', None) - if cls_opts is not None: - if opts is None: opts = cls_opts - if alias is None: alias = cls_alias - break + # 1. Find the first class defined in this module and read OPTS / ALIAS from it. + cls = next( + (obj for _, obj in inspect.getmembers(mod, inspect.isclass) + if obj.__module__ == modname), + None, + ) + + if cls is not None: + obj = cls() + opts = getattr(obj, 'OPTS', None) + alias = getattr(obj, 'ALIAS', None) + else: + # 2. Fall back to module-level attributes when no class is found. + opts = getattr(mod, 'OPTS', None) + alias = getattr(mod, 'ALIAS', None) if opts is None: self.pglog( - "Module '{}' does not define OPTS (checked module level and " - "all classes defined in the module)".format(modname), + "Module '{}' does not define OPTS (checked class and " + "module level)".format(modname), self.LGWNEX, ) From 1c8ec8a8205d320a990fd91b9f262773ee38d586 Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Wed, 25 Mar 2026 15:18:18 -0500 Subject: [PATCH 2/3] save for testing --- .claude/worktrees/sad-shockley | 1 + MANIFEST.in | 1 + pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 160000 .claude/worktrees/sad-shockley diff --git a/.claude/worktrees/sad-shockley b/.claude/worktrees/sad-shockley new file mode 160000 index 0000000..093dc70 --- /dev/null +++ b/.claude/worktrees/sad-shockley @@ -0,0 +1 @@ +Subproject commit 093dc703c2b5060d38afaa79f4417a05b0e505b3 diff --git a/MANIFEST.in b/MANIFEST.in index 816f50a..6fd403c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include src/rda_python_miscs/*.usg +include src/rda_python_miscs/rst_templetes/*.temp diff --git a/pyproject.toml b/pyproject.toml index c7ba334..5da10ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "rda_python_miscs" -version = "2.0.3" +version = "2.0.4" authors = [ { name="Zaihua Ji", email="zji@ucar.edu" }, ] From 10bfbdaa22f48ffa1a281af4f79fa17b6c049b2b Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Wed, 25 Mar 2026 18:08:42 -0500 Subject: [PATCH 3/3] rst_templates --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 6fd403c..b77c568 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include src/rda_python_miscs/*.usg -include src/rda_python_miscs/rst_templetes/*.temp +include src/rda_python_miscs/rst_templates/*.temp