-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: rewrite update-style-exceptions.sh
as a Lean executable
#13245
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
629199e
chore: refactor and move functionality for getting all modules out of…
grunweg 9c6183f
feat: rewrite update_style_exceptions as a Lean executable
grunweg 00109e5
Change the update-nolints workflow accordingly.
grunweg a23f34f
Merge branch 'master' into MR-rewrite-update-style-exceptions
grunweg b3faf17
Small touch-ups; match the naming convention.
grunweg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/- | ||
Copyright (c) 2024 Michael Rothgang. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Michael Rothgang | ||
-/ | ||
|
||
import Mathlib.Util.GetAllModules | ||
|
||
/-! | ||
# Style exception file generator | ||
|
||
This script completely regenerates the `scripts/style-exceptions.txt` file. | ||
Typically this should only be run by automation. Human contributors shouldn't need to run this | ||
unless they are making changes to the linting script. | ||
-/ | ||
|
||
/-- The entry point to the `lake exe update_style_exceptions` command. | ||
Regenerate the `scripts/style-exceptions.txt` file. -/ | ||
def main : IO UInt32 := do | ||
-- Find all files in the mathlib, archive and counterexamples directories. | ||
let mut allFiles ← getAllFiles false "Mathlib" | ||
let archive ← getAllFiles false "Archive" | ||
let cex ← getAllFiles false "Counterexamples" | ||
allFiles := (allFiles.append archive).append cex | ||
-- Run the linter on all of them; gather the resulting exceptions and sort them. | ||
-- Call xargs, to avoid spawning a new python process for each file. | ||
-- `IO.Process.output` passes empty standard input, so this actually works. | ||
-- `-s` specifies the maximum size of the command line (including the initial argument): | ||
-- since we pass all input files as initial arguments to xargs, this small hack is necessary. | ||
-- As of May 2024, the limit 200 000 suffices; therefore, we pass 300 000 to be future-proof. | ||
let args := #["-s", "300000", "./scripts/lint-style.py"].append | ||
(allFiles.map System.FilePath.toString) | ||
let out ← IO.Process.output { cmd := "xargs", args := args } | ||
if out.exitCode != 0 then | ||
println! "error {out.exitCode} on updating style exceptions : {out.stderr}" | ||
return out.exitCode | ||
let lines := out.stdout.splitOn "\n" | ||
let final := "\n".intercalate (lines.toArray.qsort (· < ·)).toList | ||
IO.FS.writeFile (System.mkFilePath ["scripts", "style-exceptions.txt"]) final | ||
return 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too happy about the list->array->list conversion: this is because
splitOn
returns aList String
qsort
requires anArray
to sortintercalate
requires aList String
againSuggestions for avoiding this as welcome. It seems this difference isn't important for speed; this is purely an aesthetic thing.