Skip to content

Hua work miscs#14

Merged
zaihuaji merged 7 commits into
mainfrom
hua-work-miscs
Mar 25, 2026
Merged

Hua work miscs#14
zaihuaji merged 7 commits into
mainfrom
hua-work-miscs

Conversation

@zaihuaji

Copy link
Copy Markdown
Collaborator

No description provided.

zaihuaji and others added 7 commits March 24, 2026 16:23
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 &lt/&gt back to </> before returning,
  so <UPPERCASE> tokens escaped during parse_docs appear correctly in
  RST output instead of as raw &ltNAME&gt strings
- replace_option_link: remove dead &#33; HTML entity escape for <!>;
  opts list is pre-computed before the loop so re-matching cannot occur,
  and &#33; rendered as literal text in RST anyway
- parse_docs docstring: clarify the escape/unescape cycle and correct
  the token format (&ltNAME&gt, not &lt;NAME&gt;)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_alias into PgRST.load_opts_alias() and update main() 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

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
``PgRST.DOCS['ORIGIN']`` so that :meth:`PgRST.parse_docs` looks for the
``self.DOCS['ORIGIN']`` so that :meth:`PgRST.parse_docs` looks for the

Copilot uses AI. Check for mistakes.
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

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
SystemExit: via :func:`PgLOG.pglog` (``LGWNEX``) if the module
SystemExit: via :meth:`PgRST.pglog` (``self.LGWNEX``) if the module

Copilot uses AI. Check for mistakes.
@zaihuaji zaihuaji merged commit 03fc4db into main Mar 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants