Skip to content

Use pipeweld to insert pre-commit hooks#1595

Open
Copilot wants to merge 7 commits intomainfrom
copilot/better-respect-pre-commit-repos
Open

Use pipeweld to insert pre-commit hooks#1595
Copilot wants to merge 7 commits intomainfrom
copilot/better-respect-pre-commit-repos

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

Hook insertion in add_repo() used hand-rolled precedent/successor logic against a static _HOOK_ORDER list. This replaces it with pipeweld's Adder, which models the same ordering constraints as a series-parallel graph — laying groundwork for repo-aware insertion and prek priority support.

Changes

  • func.pyAdder: Added force_linear setting that post-processes the solution to flatten any Parallel nodes into a deterministic linear Series. Added _extract_ordered_steps() and _linearize_component() helpers internal to the pipeweld layer.
  • hooks.pyadd_repo(): Build a Series pipeline from existing hook IDs, derive prerequisites/postrequisites sets from _HOOK_ORDER, and delegate insertion positioning to Adder.add() with force_linear=True. The predecessor is read directly from the flat solution.
  • test_func.py: Unit tests for _extract_ordered_steps, _linearize_component, and Adder with force_linear=True (16 new tests)
  • test_hooks.py: Integration tests exercising pipeweld-based insertion (prerequisite present, postrequisite only, mixed non-dependent/postrequisite)

Before/After

# Before: manual list slicing
precedents = _HOOK_ORDER[:hook_idx]
successors = _HOOK_ORDER[hook_idx + 1:]
existing_precedents = [h for h in existing_hooks if h in precedents]
# ... 15 lines of if/elif/else to find last_precedent

# After: pipeweld solver
adder = Adder(
    pipeline=series(*existing_hooks),
    step=hook_config.id,
    prerequisites=set(_HOOK_ORDER[:hook_idx]),
    postrequisites=set(_HOOK_ORDER[hook_idx + 1:]),
    force_linear=True,
)
result = adder.add()
# Solution is a flat Series of strings — read predecessor directly
flat = result.solution.root
idx = flat.index(hook_config.id)
predecessor = flat[idx - 1] if idx > 0 else None

All existing tests pass unchanged — behavioral compatibility is preserved for current hook orderings.


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI and others added 2 commits March 27, 2026 10:26
Replace manual precedent/successor ordering logic in add_repo() with
pipeweld's Adder algorithm. This uses the Series-Parallel graph model
to determine the correct insertion position based on prerequisites and
postrequisites derived from _HOOK_ORDER.

Add _get_predecessor_from_solution() and _linearize() helper functions
to extract a linear hook ordering from pipeweld's solution pipeline.
Within parallel groups, existing hooks maintain their original order
and the new hook is placed after them.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/babc26ed-68ad-44e8-8a8c-00c72d32ddba

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/babc26ed-68ad-44e8-8a8c-00c72d32ddba

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix handling of pre-commit repos using pipeweld Use pipeweld to insert pre-commit hooks Mar 27, 2026
Copilot AI requested a review from nathanjmcdougall March 27, 2026 10:32
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 95.83333% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_pipeweld/func.py 94.11% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 27, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/better-respect-pre-commit-repos (12fdf66) 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.

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot static checks are failing

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/a1927db8-7b00-4ea4-b7a8-23c4626ad979

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 28, 2026

@copilot static checks are failing

Fixed in cb3d129 — moved DepGroup import into the TYPE_CHECKING block to resolve the TC001 ruff error. It's only used in type annotations (not in any isinstance() check), so it doesn't need a runtime import.

@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review March 28, 2026 23:51
Copilot AI and others added 2 commits March 29, 2026 21:43
…linear setting

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/17dc4709-1485-40c9-916d-b68f146ec22f

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
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.

Better respect pre-commit repos by using pipeweld to insert pre-commit hooks

2 participants