Skip to content

Generalize export-functions hook: scan entire package directory, include all functions, add --strict#1628

Closed
Copilot wants to merge 7 commits intomainfrom
copilot/update-generalized-hooks-logic
Closed

Generalize export-functions hook: scan entire package directory, include all functions, add --strict#1628
Copilot wants to merge 7 commits intomainfrom
copilot/update-generalized-hooks-logic

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

hooks/export-functions.py was tightly coupled to the usethis project — first via hard-coded section headings, then via a hard-coded list of specific modules to scan. The hook is now fully general and can be applied to any Python package without modification.

Changes

  • hooks/export-functions.py: Completely rewritten to be project-agnostic:

    • Removed the _Entry dataclass and all hard-coded module lists
    • Added --source-root CLI argument (accepts the root package directory, mirroring export-module-tree's interface) — the hook recursively scans all .py files under it
    • Includes all functions — public and private (no filtering on leading _)
    • Derives module names automatically from file paths relative to the source root's parent
    • Added --strict CLI flag: fails the hook when any function is missing a docstring
    • Output is a flat bullet list in source-file order — no section headings, no project-specific logic
  • .pre-commit-config.yaml: Updated export-functions args to ["--source-root=src/usethis", "--output-file=docs/functions.txt"]

  • docs/functions.txt: Regenerated — expanded from 26 lines to 576 lines covering every function in the package

  • AGENTS.md: Updated <!-- sync:docs/functions.txt --> block to match

  • Two source docstrings fixed to avoid prettier-incompatible markdown syntax (__eq__ reworded, double RST backticks changed to single markdown backticks) so check-doc-sync passes cleanly after prettier runs


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 29, 2026 21:36
…unctions.txt)

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor logic for generalized hook agents Generalize export-functions hook: remove hard-coded section headers Mar 29, 2026
Copilot AI requested a review from nathanjmcdougall March 29, 2026 21:40
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review March 29, 2026 21:49
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!


# The modules to scan for public functions with docstrings.
# Add entries here to include additional modules in the reference.
MODULES: list[_Entry] = [
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.

@copilot don't hard code modules. Scan all modules in the relevant package directory (accept this as an option to the CLI call for this hook, similar to the export-module-tree hook).

We should aim to keep this hook module totally general - not have usethis specifics.

Similarly, include a "--strict" CLI arg to fail the hook if there are functions without docstrings.

Please make sure you include ALL functions.,including ones with leading underscores.

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.

Done in ac06c66. The hook now:

  • Accepts --source-root (the root package directory) and scans all .py files recursively — no hardcoded module list
  • Includes ALL functions, including private ones with leading _
  • Derives module names from file paths relative to the source root's parent (same pattern as export-module-tree)
  • Adds --strict to fail when any function is missing a docstring

The .pre-commit-config.yaml invocation now passes --source-root=src/usethis --output-file=docs/functions.txt. docs/functions.txt expanded from 26 to 576 lines covering every function in the package.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 29, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/update-generalized-hooks-logic (c718fa7) with main (ebb0ef2)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (ced41b3) during the generation of this report, so ebb0ef2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

… include all functions, add --strict

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/6b62b5f0-931f-451c-b79f-b08e4845040f

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title Generalize export-functions hook: remove hard-coded section headers Generalize export-functions hook: scan entire package directory, include all functions, add --strict Mar 29, 2026
Copilot AI requested a review from nathanjmcdougall March 29, 2026 21:58
@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

Feels like this was a bit confused based on the order I triggered the PRs. Still could try and improve the skills here but I can't be bothered.

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.

Config agents that hooks should be generalized

2 participants