Skip to content

DOP-5816: Avoid parsing txt files in reserved directories#669

Merged
rayangler merged 3 commits into
mainfrom
DOP-5816-code-examples
Jul 15, 2025
Merged

DOP-5816: Avoid parsing txt files in reserved directories#669
rayangler merged 3 commits into
mainfrom
DOP-5816-code-examples

Conversation

@rayangler

@rayangler rayangler commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Ticket

DOP-5816

Notes

Currently, the parser assumes that any txt file should be parsed as reStructuredText and be counted as a page. This PR makes it so that the code-examples directory is treated as a special directory name reserved for code examples, and not pages.

I created a staging link that did not result in any orphan page errors:

This is the following behavior:

  • Do not parse any txt file nested in any code-examples subdirectory as reStructuredText.
    • I checked if this affects any existing files using find . -type f \( -name "*.txt" \) -print0 | grep -z "code-examples" | xargs -0 -I {} realpath {} across the subdirectories I had locally, and it shouldn't (unless my content repos were severely out-of-date).
    • I also confirmed with Dachary that we should apply this change to any txt file in any code-examples subdirectory, regardless of nesting level.
  • Parse any rst file nested in any code-examples subdirectory as reStructuredText.
    • This is to provide backwards compatibility with any docs sites that currently use code-examples with rst files, such as server manual.
  • Parse any txt file that is called code-examples.txt (unless it’s nested in some code-examples subdirectory).

README updates

    • This PR introduces changes that should be reflected in the README.md and/or HACKING.md, and I have made those updates.
    • This PR does not introduce changes that should be reflected in the README.md and/or HACKING.md

@rayangler
rayangler requested review from dacharyc and seungpark July 14, 2025 20:37

@seungpark seungpark 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.

LGTM 👍 thanks for the insightful test!

@dacharyc

Copy link
Copy Markdown
Contributor

Awesome - looks like this captures the behavior we want. Thank you for investigating the related cases! LGTM 🚢

@rayangler
rayangler merged commit c8c70b0 into main Jul 15, 2025
5 checks passed
@rayangler
rayangler deleted the DOP-5816-code-examples branch July 15, 2025 17:07
Comment thread snooty/util.py
PAT_URI = re.compile(r"^(?P<schema>[a-z]+)://")
SOURCE_FILE_EXTENSIONS = {".txt", ".rst", ".yaml"}
RST_EXTENSIONS = {".txt", ".rst"}
RESERVED_DIRS = {"code-examples"}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not a huge deal because eventually the parser will be going away, but I would have loved for this to have been defined by the user (let's say in snooty.toml). Things like this can make the platform more "brittle"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. I made this a set to begin with to allow for that flexibility if needed. The reason why it wasn't implemented here was for convenience and consistency since this seems like desired behavior across all docs sites. If this assumption is or becomes false, I'd recommend creating a follow-up to this accordingly.

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.

4 participants