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..b77c568 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include src/rda_python_miscs/*.usg +include src/rda_python_miscs/rst_templates/*.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" }, ] 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, )