Skip to content

[Merged by Bors] - feat(Tactic/Linter/Header): access library root without cwd - #45061

Closed
thorimur wants to merge 8 commits into
leanprover-community:masterfrom
thorimur:header-linter-root-path
Closed

thorimur wants to merge 8 commits into
leanprover-community:masterfrom
thorimur:header-linter-root-path

Conversation

@thorimur

@thorimur thorimur commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

This PR modifies the way the header linter finds the library root from the current module. Instead of assuming that the current working directory contains the root, we peel off components from the current filename and match them against the current module name until we reach the root.

We also adjust the directory dependency linter to take in a srcDir when locating Mathlib.Init and scripts/forbiddenDirs.json, which we provide as the parent of this filepath.

This is both more principled and enables us to apply header linter suggestions from skimmer, which is started from scripts/. It also has the effect of (correctly) running these linters when building mathlib as an upstream dependency, just as we run mathlib's other linters in the same circumstance. Note that the scripts/ folder is distributed along with the source files, so we are still able to locate scripts/forbiddenDirs.json successfully. (This was tested locally with a minimal downstream project.)

This was used in conjunction with #44507 to create #45071.

(This PR also adjusts the style of some nearby but unrelated MessageData handling.)


@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

PR summary e315cf4660

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ modPathToRootPath

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit e315cf4).

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


No changes to strong technical debt.
No changes to weak technical debt.

Current commit e315cf4660
Reference commit d4acc3be57

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-linter Linter label Oct 20, 2026
@thorimur

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Oct 20, 2026 •

Copy link
Copy Markdown

Benchmark results for 9e2d44c against d4acc3b are in. No significant results found. @thorimur

  • 🟥 build//instructions: +2.0G (+0.00%)

Small changes (7✅, 3🟥)

  • ✅ build/module/Aesop.Frontend.Basic//instructions: -2.3M (-0.33%)
  • ✅ build/module/Batteries.Lean.Syntax//instructions: -805.4k (-0.14%)
  • ✅ build/module/Mathlib.Algebra.Group.Nat.Units//instructions: -18.2M (-1.15%)
  • ✅ build/module/Mathlib.Algebra.GroupWithZero.Submonoid.Instances//instructions: -21.6M (-0.59%)
  • 🟥 build/module/Mathlib.Algebra.Notation.Defs//instructions: +21.5M (+0.58%)
  • ✅ build/module/Mathlib.Algebra.Order.GroupWithZero.Unbundled.OrderIso//instructions: -2.0M (-0.14%)
  • 🟥 build/module/Mathlib.Data.Int.LeastGreatest//instructions: +4.3M (+0.29%)
  • 🟥 build/module/Mathlib.Tactic.Linter.Header//instructions: +107.8M (+2.64%) (reduced significance based on *//lines)
  • ✅ build/module/Mathlib.Tactic.Replace//instructions: -7.7M (-0.52%)
  • ✅ build/module/Mathlib.Util.CodeActions//instructions: -452.5k (-0.06%)

@thorimur
thorimur marked this pull request as ready for review October 20, 2026 05:44

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

A few small comments.

Comment thread Mathlib/Tactic/Linter/Header.lean Resolved
@grunweg

grunweg commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Would applying the same logic allow running mk_all from any directory also? (If so, can I ask you to make that change in a follow-up PR? This has been occasionally annoying me for a long time.)

@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 20, 2026
@grunweg

grunweg commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Aside from these minor comments, LGTM!

mathlib-bors Bot pushed a commit that referenced this pull request Oct 20, 2026
This PR reformats imports to be in line with the style convention in preparation for #44507.

This was created with `scripts/runSkimmer.sh` after temporarily incorporating #45061 into #44507.
@grunweg

grunweg commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

With the adjustments above made, this LGTM!
bors d+

@mathlib-bors mathlib-bors Bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Oct 20, 2026
@mathlib-bors

mathlib-bors Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

✌️ thorimur can now approve this pull request until 2026-11-03 16:25 UTC (in 2 weeks). To approve and merge, reply with bors r+. More detailed instructions are available here.

⚠️ This delegation only covers changes within Archive/**, Counterexamples/**, docs/**, DownstreamTest/**, Mathlib/**, MathlibTest/**, Wanted/**, widget/**, Archive.lean, Counterexamples.lean, docs.lean, Mathlib.lean, Wanted.lean; an author commit touching anything else will revoke it. Bors also revokes it if a later push changes too many files for it to check the full list — even if it stays within scope.

@mathlib-triage mathlib-triage Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 20, 2026
@thorimur

thorimur commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@grunweg I also just wanted to mention this aspect of the PR, which I had forgotten to put in the PR description originally:

[This PR] also has the effect of (correctly) running these linters when building Mathlib as an upstream dependency, just as we run mathlib's other linters in the same circumstance. Note that the scripts/ folder is distributed along with the source files, so we are still able to locate scripts/forbiddenDirs.json successfully. (This was tested locally with a minimal downstream project.)

I'll merge in a few hours or earlier if you happen to see this. :)

@grunweg

grunweg commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Looks good to me, thanks!

@thorimur

Copy link
Copy Markdown
Contributor Author

bors r+

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Oct 21, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Oct 21, 2026
This PR modifies the way the header linter finds the library root from the current module. Instead of assuming that the current working directory contains the root, we peel off components from the current filename and match them against the current module name until we reach the root.

We also adjust the directory dependency linter to take in a `srcDir` when locating `Mathlib.Init` and `scripts/forbiddenDirs.json`, which we provide as the parent of this filepath.

This is both more principled and enables us to apply header linter suggestions from skimmer, which is started from `scripts/`. It also has the effect of (correctly) running these linters when building mathlib as an upstream dependency, just as we run mathlib's other linters in the same circumstance. Note that the `scripts/` folder is distributed along with the source files, so we are still able to locate `scripts/forbiddenDirs.json` successfully. (This was tested locally with a minimal downstream project.)

This was used in conjunction with #44507 to create #45071.

(This PR also adjusts the style of some nearby but unrelated `MessageData` handling.)
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Oct 21, 2026
@mathlib-bors

mathlib-bors Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title feat(Tactic/Linter/Header): access library root without cwd [Merged by Bors] - feat(Tactic/Linter/Header): access library root without cwd Oct 21, 2026
@mathlib-bors mathlib-bors Bot closed this Oct 21, 2026
@mathlib-bors mathlib-bors Bot removed the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. ready-to-merge This PR has been sent to bors. t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants