Hua work miscs#14
Conversation
…iscs.git into hua-work-miscs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parse_docs, template_to_rst: use `with` for file I/O (safe close on exception)
- replace_option_link: remove dead `if opts is None` guard (re.findall never returns None)
- replace_option_link: remove stale comment referencing list.insert()
- init_section: replace re.split dot-count with secid.count('.') + 1; init level directly in dict
- init_example: return dict literal directly, drop redundant temp variable
- create_description: use str.split instead of re.split for newline splitting
- get_short_option: fix off-by-one indent on inner if (13 -> 12 spaces)
- main: remove duplicate `import argparse` (already imported at module level)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- replace_option_link: unescape </> back to </> before returning, so <UPPERCASE> tokens escaped during parse_docs appear correctly in RST output instead of as raw <NAME> strings - replace_option_link: remove dead ! HTML entity escape for <!>; opts list is pre-computed before the loop so re-matching cannot occur, and ! rendered as literal text in RST anyway - parse_docs docstring: clarify the escape/unescape cycle and correct the token format (<NAME>, not <NAME>) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors pg_rst.py to modernize file handling, streamline a few helpers, and move OPTS/ALIAS loading into the PgRST class for consistent logging and origin resolution.
Changes:
- Replace manual file open/close with context managers and fix template processing loop to advance input lines.
- Compute section nesting level directly from the section id and simplify
init_example. - Move
_load_opts_aliasintoPgRST.load_opts_alias()and updatemain()to use it; add unescaping of temporarily-escaped<UPPERCASE>tokens during link replacement.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| The ``origin`` value is the absolute path of the directory that contains | ||
| ``<docname>.py`` (i.e. ``rda_python_<docname>/``), derived from | ||
| ``mod.__file__``. It is intended to be assigned to | ||
| ``PgRST.DOCS['ORIGIN']`` so that :meth:`PgRST.parse_docs` looks for the |
There was a problem hiding this comment.
The docstring refers to assigning the returned origin to PgRST.DOCS['ORIGIN'], but DOCS is an instance attribute initialized in __init__. To avoid confusing consumers, update this to self.DOCS['ORIGIN'] (or describe it as an instance field).
| ``PgRST.DOCS['ORIGIN']`` so that :meth:`PgRST.parse_docs` looks for the | |
| ``self.DOCS['ORIGIN']`` so that :meth:`PgRST.parse_docs` looks for the |
| tuple[dict, dict, str]: ``(OPTS, ALIAS, origin)`` where *origin* is | ||
| the absolute directory path of the imported module file. | ||
| Raises: | ||
| SystemExit: via :func:`PgLOG.pglog` (``LGWNEX``) if the module |
There was a problem hiding this comment.
load_opts_alias now reports errors via self.pglog(...), but the docstring still says the SystemExit is raised via PgLOG.pglog. Please update the docstring to match the current behavior (and the instance log level constant used).
| SystemExit: via :func:`PgLOG.pglog` (``LGWNEX``) if the module | |
| SystemExit: via :meth:`PgRST.pglog` (``self.LGWNEX``) if the module |
No description provided.