You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move Python formatting to a supported formatter #158384
We currently format all Python code using yapf. This is done via the tools/yapf.sh and tools/yapf.bat wrapper scripts.
Unfortunately, yapf is abandoned and only works with Python versions up to and including Python 3.10. As OS and local Python installations are upgraded, this will become more and more problematic. On some Linux distributions side-by-side python installations are unsupported, for example.
Workarounds
Those on macOS can work around this by installing homebrew then:
yapf was only chosen because it was already used for LUCI recipes, and we already had a mirror set up for it. One thing to investigate would be whether pylint has options to also enforce formatting, which we might currently have disabled so that yapf and pylint don't fight with eachother.
Working on Linux is frustrating since the latest Ubuntu/Debian LTS releases no longer offer the option to install older python3 versions compatible with our version check.
Not to kick the can further down the road, but I was able to successfully run the check using python3.13 with the 2to3 package installed separately. It seems like we might be able to widen the version check further if we needed to, but this isn't sustainable long-term.
@matanlurey I can do a trial run later this week sometime to see how black looks locally on my machine. If it looks like it'd be a reasonable fit, I can report back then and look at wiring up the mirroring unless anyone has any objection.
There have been a few patches to get us as far as Python 3.12, which still ships with the python 2to3 library that yapf relies on. 2to3 no longer ships with Python 3.13 so we need to get on this now.
Activity
yapf: Add more detailed error message and TODO (#56458)
zanderso commentedon Nov 11, 2024
yapfwas only chosen because it was already used for LUCI recipes, and we already had a mirror set up for it. One thing to investigate would be whetherpylinthas options to also enforce formatting, which we might currently have disabled so thatyapfandpylintdon't fight with eachother.matanlurey commentedon Nov 12, 2024
It looks like the Python Software Foundation currently supports
black: The uncompromising Python code formatter.We would need to (a) import it via a mirror, (b) change our internal tooling to support it, and (c) potentially reformat the repo.
If this is something we want to do, I can look into getting started with (a).
cbracken commentedon Nov 13, 2024
I think we should do something about this.
Working on Linux is frustrating since the latest Ubuntu/Debian LTS releases no longer offer the option to install older python3 versions compatible with our version check.
Not to kick the can further down the road, but I was able to successfully run the check using python3.13 with the 2to3 package installed separately. It seems like we might be able to widen the version check further if we needed to, but this isn't sustainable long-term.
@matanlurey I can do a trial run later this week sometime to see how
blacklooks locally on my machine. If it looks like it'd be a reasonable fit, I can report back then and look at wiring up the mirroring unless anyone has any objection.matanlurey commentedon Nov 13, 2024
That would amazing, thanks Chris!
jmagman commentedon Nov 13, 2024
There are some existing
blackcipd pacakges.gaaclarke commentedon Nov 18, 2024
If we move to
blackwhat are we going to do about its dependencies? It's usingpyproject.tomlto specify them. Are they baked into the cipd packages?edit: for example,
hatchling. This seems to be a build dependency, so maybe it doesn't matter?yapf: Add more detailed error message and TODO (flutter-team-archive/…
yapf: Allow python 3.13 in yapf
Verify old version of Python has the `lib2to3` import available (#170187
cbracken commentedon Jun 20, 2025
There have been a few patches to get us as far as Python 3.12, which still ships with the python 2to3 library that yapf relies on. 2to3 no longer ships with Python 3.13 so we need to get on this now.
jtmcdole commentedon Jan 8, 2026
Its 2026. We're still using
yapf. The best way to work around this for now (in my opinion) ispyenv:Migrate Python formatter from yapf to black (flutter#158384)
Verify old version of Python has the `lib2to3` import available (#170…