Skip to content

Move Python formatting to a supported formatter #158384

Open

Description

@cbracken

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:

brew install [email protected]

Related

Activity

  1. added
    c: contributor-productivityTeam-specific productivity, code health, technical debt.
    engineflutter/engine related. See also e: labels.
    P2Important issues not at the top of the work list
    c: tech-debtTechnical debt, code quality, testing, etc.
    on Nov 8, 2024
  2. zanderso commented on Nov 11, 2024

    @zanderso
    Member

    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.

  3. matanlurey commented on Nov 12, 2024

    @matanlurey
    Contributor

    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).

  4. cbracken commented on Nov 13, 2024

    @cbracken
    MemberAuthor

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

  5. self-assigned this
    on Nov 13, 2024
  6. matanlurey commented on Nov 13, 2024

    @matanlurey
    Contributor

    That would amazing, thanks Chris!

  7. jmagman commented on Nov 13, 2024

    @jmagman
    Member
    cipd ls -r | grep black
    

    There are some existing black cipd pacakges.

  8. gaaclarke commented on Nov 18, 2024

    @gaaclarke
    Member

    If we move to black what are we going to do about its dependencies? It's using pyproject.toml to 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?

  9. removed their assignment
    on Feb 26, 2025
  10. added a commit that references this issue on Apr 4, 2025
  11. cbracken commented on Jun 20, 2025

    @cbracken
    MemberAuthor

    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.

  12. jtmcdole commented on Jan 8, 2026

    @jtmcdole
    Member

    Its 2026. We're still using yapf. The best way to work around this for now (in my opinion) is pyenv:

    pyenv install 3.12.12
    cd engine/src
    pyenv local 3.12.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: contributor-productivityTeam-specific productivity, code health, technical debt.c: tech-debtTechnical debt, code quality, testing, etc.engineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions