Zulip Chat Archive
Stream: PR reviews
Topic: Rewriting Python style linters in Lean
Michael Rothgang (May 31 2024 at 15:28):
#13339 is one of the first steps towards rewriting all style linters in Python, blocking further progress. Can I interest somebody in reviewing it? It's almost all code motion (from a file in scripts
to a new file in Mathlib/Utils
), plus one easy refactoring.
CC @Damiano Testa who originally wrote the code
Kim Morrison (Jun 01 2024 at 12:26):
Looks good. Perhaps we can add a note in the lakefile warning about the hardcoding?
Michael Rothgang (Jun 01 2024 at 12:42):
Done. While at this, I realised one possible defect in the code: getLeanLibs
on mathlib also yields the the lean_lib
docs
; should this be excluded as well?
Matthew Ballard (Jun 01 2024 at 15:14):
http://speed.lean-fro.org/mathlib4/run-detail/c08c756c-9478-422c-8729-73459c2ca228
Michael Rothgang (Jun 01 2024 at 20:47):
Oh, that seems unexpected. This PR was purely moving code...
Can you help me interpret these numbers - what does "linting" mean? Is this simply measuring "there's a new file in mathlib" (and the time was spent just on the script before) - I guess not, but I have very little idea what this means. Help welcome.
Matthew Ballard (Jun 12 2024 at 16:17):
This seems to not be a hiccup, instructions for linting jumped 14.2% and the linting wall clock jumped 17.3% (~90 seconds) and the instructions haven't come down.
I am bit stumped by this atm. Perhaps I am being dense.
Matthew Ballard (Jun 12 2024 at 17:12):
We will see if it is real soon #13779
Matthew Ballard (Jun 12 2024 at 17:52):
Not fake
Matthew Ballard (Jun 12 2024 at 18:10):
I can't believe it is taking 90s to lint that single file but what is another explanation?
Matthew Ballard (Jun 13 2024 at 19:25):
Can confirm that just adding Mathlib.Util.GetAllModules
alone is enough for the regression.
Mario Carneiro (Jun 13 2024 at 23:54):
By the way, the thread title is somewhat ambiguous, I wasn't sure if it meant rewriting style linters to use Python (instead of lean / something else?)
Michael Rothgang (Jun 14 2024 at 08:03):
Can an admin rename this to "Rewriting Python style linters in Lean", please? I just tried, but cannot any more?
Johan Commelin (Jun 14 2024 at 08:04):
Done
Matthew Ballard (Jun 14 2024 at 12:23):
It was the Lake
import
Matthew Ballard (Jun 14 2024 at 12:24):
Do we need getLeanLibs
in Mathlib
proper for whatever is coming next?
Michael Rothgang (Jun 14 2024 at 12:47):
I just approved your PR - short answer: no, I'm not aware of any reason we do.
Michael Rothgang (Jun 14 2024 at 12:55):
Filed #13836 to lint on importing Lake
in Mathlib, with a clear warning explaining the reason.
Michael Rothgang (Jun 14 2024 at 13:01):
By the way: I'd love to rewrite this all in Lean. In Python, I have to choose between adding a second error variant or trying to thread extra data through it - Lean's inductive types are just much nicer. If you'd like to see this happen, you'd love to hear your opinion here.
Michael Rothgang (Jun 19 2024 at 12:25):
Status update: this is bottle-necked on a review of #13620, for providing the equivalent infrastructure in Lean. Subsequent linters can be reviewed in parallel.
Michael Rothgang (Jun 20 2024 at 13:52):
Michael Rothgang said:
Status update: this is bottle-necked on a review of #13620, for providing the equivalent infrastructure in Lean. Subsequent linters can be reviewed in parallel.
Thanks for the feedback! I responded.
Kim Morrison (Jun 20 2024 at 23:04):
Okay, I'm happy with just an explanation in the comments of the difficulty with error handling there.
Michael Rothgang (Jun 21 2024 at 09:16):
Thanks for the review! The next step could be to land #14012 - making lake exe lint_style
produce human-readable output by default. (This also paves the way towards granular updates of file length exceptions, which @Patrick Massot (and others before) asked for the other day.)
Michael Rothgang (Jun 21 2024 at 11:14):
I just realised that #13620 breaks update-style-exceptions.py
on master: the style exception entries will be in the wrong format. Sorry for this! #14012 fixes this as well; I had not realised this changes was already required...
Michael Rothgang (Jun 21 2024 at 11:42):
Less urgent: #13240 rewrites the copyright header check in Lean; I just rebased this on master.
Michael Rothgang (Jun 23 2024 at 19:11):
Thanks for the reviews! #14058 rewrites the "adaptation note" linter in Lean; #14059 (depending on that, but is reviewable already) does the "broad imports" (e.g. Mathlib.Tactic) one.
Michael Rothgang (Jun 24 2024 at 14:56):
#14093 rewrite the line length check in Lean (and fixes some small oversights from the "broad imports" linter, which were inconsequential).
Michael Rothgang (Jul 12 2024 at 21:42):
#14676 contains some easy refactoring of lint_style
, split out for ease of reviewing
Michael Rothgang (Jul 13 2024 at 03:18):
#14697, building on this, rewrites update-style-exceptions
in Lean.
In particular, if you encounter e.g. a "file to large error", you can just run lake exe lint_style --update
and it will update the style exceptions accordingly. It does a minimal update: obsolete entries are removed, but where possible, existing entries are kept.
Michael Rothgang (Jul 15 2024 at 12:34):
Michael Rothgang said:
#14697, building on this, rewrites
update-style-exceptions
in Lean.
In particular, if you encounter e.g. a "file to large error", you can just runlake exe lint_style --update
and it will update the style exceptions accordingly. It does a minimal update: obsolete entries are removed, but where possible, existing entries are kept.
The blocking PR has landed and I have rebased and fixed up this PR: it's now ready for review.
Michael Rothgang (Aug 02 2024 at 09:43):
#14757 is ready for review: minor style tweaks and renaming the executable to lint-style
. Should be an easy diff.
Michael Rothgang (Aug 02 2024 at 11:04):
#15438 is a one-line fix for an error message, and should be very easy to review
Michael Rothgang (Aug 15 2024 at 15:32):
#15051 removes lint-style.sh
. The executable bit check is moved to the build.yml files, and the calling of lint-style.py
is moved to the existing print-style-errors.sh
script.
(That script can be removed once all Python style linters have been rewritten in Lean, which will hopefully happen soon.)
Michael Rothgang (Sep 02 2024 at 15:02):
#16332 ports the linter for windows line endings to Lean
It also lays the groundwork for a fair chunk of the remaining linters, by porting the functionality of auto-fixing linters. Review appreciated (best reviewed as a whole).
Michael Rothgang (Sep 02 2024 at 15:02):
Building on that, #16334 rewrites the trailing whitespace check in Lean
Johan Commelin (Sep 03 2024 at 08:46):
cc @Damiano Testa @Jon Eugster
Michael Rothgang (Sep 03 2024 at 10:11):
Responded to Damiano's comment on the trailing whitespace linter.
Kim Morrison (Sep 04 2024 at 06:03):
@Michael Rothgang :writing: on #16332.
Michael Rothgang (Nov 21 2024 at 15:56):
Periodic reminder that #16334 and #16532 are awaiting review. Each rewrites a text-based style linter from Python in Lean.
The former PR has been up for review for over two months now, with no activity at all in the past 6 weeks; it's a +-20 lines PR. (The latter PR depends on the former, and is comparatively simple.)
Michael Rothgang (Nov 21 2024 at 15:57):
CC @Kim Morrison on the above
Kim Morrison (Nov 22 2024 at 01:48):
Kim Morrison (Nov 22 2024 at 01:50):
:peace_sign: #16532. I'm slightly surprised that we're linting for this, but given it's just a change in implementation, not behaviour, I guess I can't complain. :-)
Kevin Buzzard (Nov 23 2024 at 12:03):
Kim is also testing emojibot here :-)
Michael Rothgang (Mar 09 2025 at 09:23):
#22727 rewrites three more Python style linters in Lean
Michael Rothgang (Mar 09 2025 at 09:24):
It depends on two rounds of fixes, namely #22726 and #22728.
Michael Rothgang (Mar 10 2025 at 17:27):
#22728 has run into a style bikeshed: I will start a zulip thread about this, but possibly not very soon
Michael Rothgang (Mar 25 2025 at 21:31):
#22727 is ready for review again: all dependencies have been merged. (I can split out the ~30 lines of style fixes if preferred; as they don't seem controversial to me, I don't have to.)
Last updated: May 02 2025 at 03:31 UTC