Skip to content

docs(create_rstfiles): order the notebook galleries by when a notebook was added - #2792

Merged
jdhughes-dev merged 2 commits into
modflowpy:developfrom
jdhughes-dev:docs-notebook-order
Aug 5, 2026
Merged

docs(create_rstfiles): order the notebook galleries by when a notebook was added#2792
jdhughes-dev merged 2 commits into
modflowpy:developfrom
jdhughes-dev:docs-notebook-order

Conversation

@jdhughes-dev

Copy link
Copy Markdown
Contributor
  • The notebook galleries were built from an alphabetical list, so a new notebook landed wherever its name fell rather than at the end
  • Notebooks are now ordered by the commit that added them, and one that is not in the history yet sorts last
  • Notebooks added in the same commit keep their alphabetical order, so most of the galleries are unchanged
  • The order falls back to alphabetical when the history is not available, as in a shallow clone, rather than failing the documentation build

…k was added

The galleries were built from an alphabetical list, so a new notebook landed
wherever its name happened to fall and the reader had no way to tell what had
just been added. Notebooks are now ordered by the commit that added them, and
a notebook that is not in the history yet, as when it is added in the same
pull request, sorts last.

Notebooks added in the same commit keep their alphabetical order, so the
majority of the galleries are unchanged. The order falls back to alphabetical
when the history is not available, as in a shallow clone, rather than failing
the documentation build.
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.8%. Comparing base (556c088) to head (c2be913).
⚠️ Report is 187 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2792      +/-   ##
===========================================
+ Coverage     55.5%    72.8%   +17.2%     
===========================================
  Files          644      662      +18     
  Lines       124135   133001    +8866     
===========================================
+ Hits         68947    96828   +27881     
+ Misses       55188    36173   -19015     

see 583 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the docs gallery generation script to order tutorial/example notebook listings by the commit timestamp when each notebook was first added (with graceful fallback to alphabetical ordering when Git history is unavailable).

Changes:

  • Introduces an added_order() sort key that queries git log --diff-filter=A for each notebook’s “added” timestamp.
  • Uses that sort key when building tutorials.rst and examples.rst notebook lists, instead of purely alphabetical ordering.
  • Preserves alphabetical ordering as a tie-breaker and provides a fallback when history cannot be queried.
Suppressed comments (1)

.docs/create_rstfiles.py:104

  • This sorts all notebook files and only then filters by name, which does extra added_order() work (and extra git log calls) for notebooks that will be discarded. Filtering first and then sorting only the relevant subset avoids that overhead.
    filenames = [
        path.name
        for path in sorted(nbs_path.rglob("*.py"), key=added_order)
        if "example" in path.name
    ]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .docs/create_rstfiles.py Outdated
Comment on lines +1 to +25
import subprocess
from pathlib import Path

project_root_path = Path(__file__).parent.parent


def added_order(path):
"""Sort key that puts notebooks in the order they were added

Notebooks added in the same commit keep their alphabetical order, and one
that is not in the history yet sorts last. The order falls back to
alphabetical when the history is not available, as in a shallow clone.
"""
try:
added = subprocess.run(
["git", "log", "--diff-filter=A", "--format=%at", "-1", "--", str(path)],
capture_output=True,
text=True,
cwd=project_root_path,
timeout=10,
check=False,
).stdout.strip()
except (OSError, subprocess.SubprocessError):
added = ""
return (int(added) if added else 2**31, path.name)

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.

All three fixed in c2be913.

The pathspec is now relative to the repository, so git log gets what it expects rather than an absolute path. The sentinel is float("inf") instead of 2**31, which was going to stop sorting an unreleased notebook last in 2038. The key is cached with lru_cache, which matters because the tutorials and the examples each sort the same notebooks.

Comment thread .docs/create_rstfiles.py
Comment on lines +58 to +62
filenames = [
path.name
for path in sorted(nbs_path.rglob("*.py"), key=added_order)
if "tutorial" in path.name
]

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.

Fixed in c2be913, in both places. The notebooks are filtered by name before they are sorted.

Together with caching the key that is 84 calls to git log rather than 174, and the whole of create_rstfiles.py runs in about a second.

…rtable

The sort key ran git log on an absolute path, which is not a pathspec git
accepts everywhere and would have silently fallen back to alphabetical order.
It also used a sentinel that stops sorting an unreleased notebook last in
2038, sorted every notebook before filtering by name, and ran once for the
tutorials and again for the examples.

The pathspec is now relative to the repository, the sentinel is infinity, the
notebooks are filtered before they are sorted, and the key is cached. That is
84 calls to git log rather than 174.
@jdhughes-dev
jdhughes-dev merged commit d165731 into modflowpy:develop Aug 5, 2026
20 checks passed
@jdhughes-dev
jdhughes-dev deleted the docs-notebook-order branch August 5, 2026 19:42
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