Skip to content

Docs: A raft of cleanup & style changes #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 26, 2025
Merged

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Jun 25, 2025

This PR represents a set of tweaks to the project documentation, mostly focused around usability and presentation of information. A lot of it is obviously subjective, and while I personally thing each change is an improvement, I'm not married to any of it and am more than willing to take feedback / remove anything that's not wanted. It's all in very granular commits specifically so that it can easily be adjusted.

What's here

(Formatted as a checklist, so we can mark off anything to be removed/changed)

  • Turned all of the 3.0.0 "Deprecated" messages into real .. deprecated:: markup
  • Added .. versionchanged:: and .. versionadded:: markup for most of the items in the "what's new in 3.1.0 / 3.2.0" documents (some items don't easily translate into API documentation)
  • Added custom CSS to style the change messages for visibility. It makes use of the relatively-new CSS :has() selector to push the .. deprecated:: styling up to the containing class/function/method/etc. level, so that anything marked deprecated has a red border line running all the way down its left side for maximum visibility. You'll see in screenshots.
    (After some deliberation, I decided not to do the same with added/changed notes, because those won't be "recent" forever and as they age they deserve less prominence. Deprecated features warrant greater prominence, if anything, as time passes until they're eventually removed.)
  • Eliminated the unnecessary docs/modules.rst document, and made docs/pyparsing.rst the top-level index for its own documentation (by putting a hidden .. toctree:: at the bottom containing only self).
  • Moved the documentation from a couple of classes' __init__s to the class itself, and removed the __init__ signatures from the docs entirely, since the construction signatures are shown on the class itself and the __init__s become totally redundant, with the documentation moved.
  • Removed the .. sectnum::s from the documentation pages, because Sphinx says not to use them, and with good reason -- they're totally broken. Every document gets numbered "1" in the TOC. There are apparently ways to make the sections properly numbered, but sectnum isn't it. (I personally don't think it's necessary.)

Sphinx configuration changes

  • Leave class/module parents out of the TOC, for readability and to keep them from overflowing into the body text
  • Break longer call signatures (over 100 characters, as currently configured) at each argument for "better" readability; it's still not great but better than one long, sometimes-four-or-five-wrapped-lines continuous signature string.
  • Leave resolvable type names unexpanded in the signatures, which affects some signatures in small ways. (For example, the default max_matches argument for ParserElement.scan_string() is now listed as _MAX_INT instead of 9223372036854775807.)

autodoc configuration changes

  • I changed the .. automodule:: in pyparsing.rst like so:
Before
.. automodule:: pyparsing
    :members:
    :special-members:
    :show-inheritance:
After
.. automodule:: pyparsing
    :members:
    :undoc-members:
    :special-members: __add__,__sub__,__div__,__mul__,__and__,__or__,__xor__,__call__,__weakref__,__str__
    :exclude-members: __init__,__repl__,parseImpl,parseImpl_regex,parseImplAsGroupList,parseImplAsMatch,postParse,preParse
    :show-inheritance:

Which, obviously, greatly affects the contents of the documentation. But I felt there were a number of undocumented members that were worth showing signatures for, and many special members that weren't, so explictly selecting the ones we actually want seemed more productive.

It is a lot of configuration, though, and isn't maintenance-free. (For example, after I added a .. versionchanged:: to the __str__ method for ParseBaseException, I had to go back and add __str__ to the :special-members: list to get it to show up in the docs.)

So, even more than everything else, explicitly up for debate / open to revision.

I'll follow up with comment(s) showing some side-by-side screenshots, this opening message has gotten long enough.

ferdnyc added 10 commits June 14, 2025 05:04
Eliminate any docstrings on `__init__` methods, either adding the
contents to the class docstring (`pyparsing.core.Regex`), or making
it the previously-nonexistent class docstring instead
(`pyparsing.core.DelimitedList`).

This allows `__init__` methods to be excluded from the API docs,
as they're redundant with the class-level documentation (which
includes the `__init__` signature).
And remove the toctree caption (ugly)
- Hide module names in TOC, docs
- Line-wrap long signatures for better readability
- More compact types in signature docs
- Push constructor docs up to class level, remove __init__ docs
- Document some special members
- Exclude some internal members
- Show signatures of undocumented members
- deprecated objects get a red border down the left side of their
  entire documentation, and a bold "Deprecated since" message
  underlined in red
- added and changed items get a "New in" / "Changed in" message
  with a blue or orange border (respectively) to its left.
- Don't mention "module" since pyparsing is multiple modules in a
  package
- Remove the weird dash after the "Getting started" heading
@ferdnyc
Copy link
Contributor Author

ferdnyc commented Jun 25, 2025

Side-by-side screenshots, live docs on the left, this branch on the right. Expand for readability.

The new main TOC

The removal of the modules.rst does mean that the pyparsing top-level elements all end up in the list; I'm sure that can be corrected if it's a problem
image

The API-docs TOC

(Actually readable!)
image

DelimitedList is new in 3.1.0

You can really see the value of the signature-wrapping, too.
image

Changes to ParseBaseException in 3.2.0

image

(Also, deprecations!)
image

Lots of deprecations

They can sometimes get a bit overwhelming, when there's a LOT of them, but that's rare.
image

@ptmcg
Copy link
Member

ptmcg commented Jun 25, 2025

This is totally awesome, and I love it!!! Thanks a ton! I'll give this a more thorough look this evening, but your before/afters are very impressive. +1000

@ferdnyc
Copy link
Contributor Author

ferdnyc commented Jun 25, 2025

This one deserves special mention:

image

I had a HELL of a time with asList and asDict, and almost lost all of my changes trying to debug what was going on, because every time I built the docs they came out with the documentation from as_list and as_dict, instead of their deprecation messages. I couldn't figure out what config I'd screwed up to make that happen.

Turns out, it wasn't any config. I was originally building the docs with the latest Sphinx 8.2.3, and in that version, it's as I said. The custom messages for those methods get lost, even in the master branch docs. Downgrading to Sphinx 8.1.3, which is the default on Fedora 42 and the version the online docs are built with, restored the custom messages.

So, just a heads up that Sphinx 8.2.3 will screw up the docs for these aliased methods. Not sure what changed or why, or if 8.2.3 can be configured to the old behavior, but it's definitely caused by that version.

@ferdnyc
Copy link
Contributor Author

ferdnyc commented Jun 25, 2025

Aw, hell. WTF, Github? I just tried clicking on those images to expand them, and I'm getting 404s instead of the full-size images. That blows.

(EDIT: The one on my previous comment works, but none of the ones in the long comment. I have no idea why. I'll try to fix it when I get a chance... or you can just build the docs and see for yourself, I guess. 😀 )

Comment on lines +4 to +9
dl.py:where(.class,.exception,.method,.function):has(> dd > div.deprecated)
{
margin-inline-start: -0.6rem;
border-inline-start: 0.4rem solid #f00;
padding: 0 0.6rem 0 0.2rem;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This, BTW, is very modern CSS, but https://caniuse.com/?search=%3Awhere and https://caniuse.com/?search=%3Ahas say that it should be supported in recent releases of all major browsers, all of the ones anyone has any business being on the internet with, anyway.

Plus, the nice thing about CSS is that it degrades so gracefully. I keep a copy of PaleMoon around, the Firefox 62 or 57 or whatever fork that definitely does NOT support :where and :has, and this is how it renders these docs:

Screenshot From 2025-06-25 10-41-22

So, that's just about ideal.

@ptmcg
Copy link
Member

ptmcg commented Jun 26, 2025

Have reviewed your changes a bit, though CSS is a vast mystery to me tbh. I'm accepting these changes in toto, you've put in a lot of effort here, and I think the results are fantastic!

@ptmcg ptmcg merged commit 1a7a97f into pyparsing:master Jun 26, 2025
8 checks passed
@ferdnyc ferdnyc deleted the docs-cleanup branch June 26, 2025 13:56
@ferdnyc
Copy link
Contributor Author

ferdnyc commented Jun 26, 2025

@ptmcg

Wow, thanks very much!

We probably should iterate a bit on my selections of :special-members: and :excluded-members: for the autodocs, though.

Like, for example, I included __weakrefs__ in the visible :special-members: purely because it was one of the symbols that the existing documentation showed, and I was making that decision at a point where I'd already changed so much, that I felt the need to be really conservative and minimize the changes that resulted from those decisions.

But I really don't think there's any value in __weakrefs__ (which always has the default, Python-standard-library docstring, so nothing of value) showing up in the docs. I'd always sort of planned to fold like a house of cards the moment someone questioned its inclusion. Except that never happened! 😆

But I'm planning to open a follow-up issue about documentation anyway (in fact, I came here to do that right now), so that conversation can happen over there.

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