Skip to content
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

fix(sage-monorepo): format on save Python files with black #2262

Merged
merged 5 commits into from
Oct 24, 2023

Conversation

tschaffter
Copy link
Member

@tschaffter tschaffter commented Oct 20, 2023

Closes #2261

Description

Configure Format On Save for Python files.

Changelog

  • Prevent flake8 from running when saving Python files
  • Add VS Code extension ms-python.black-formatter to the dev container
  • Configure Format On Save with Black for Python files

Notes

Also, the Black extension for VS Code says:

The bundled black is only used if there is no installed version of black found in the selected python environment.

Your Python project must still have black as a dev dependencies in your project poetry file. The above feature of the Black extension means that the output of formatting with black programmatically (e.g. in the CI workflow) and in VS Code (Format On Save) should be the same.

Here is the version of Black bundle with the extension used when a Python project does not provide black itself.

2023-10-20 21:42:05.244 [info] SUPPORTED black>=22.3.0
FOUND black==23.3.0

After preparing the Python environment for schematic-api and activating it in VS Code, we can see that Format On Save use the version of Black specified by the schematic-api project. It is this version that will be executed by the CI workflow.

In pyproject.toml:

[tool.poetry.group.dev.dependencies]
black = "23.7.0"
2023-10-20 21:57:26.170 [info] SUPPORTED black>=22.3.0
FOUND black==23.7.0

Preview

Format On Save

Recording 2023-10-20 at 14 36 12

@tschaffter tschaffter self-assigned this Oct 20, 2023
@tschaffter tschaffter marked this pull request as ready for review October 20, 2023 22:10
@tschaffter tschaffter changed the title fix(sage-monorepo): format file on save with black fix(sage-monorepo): format on save Python files with black Oct 20, 2023
@andrewelamb
Copy link
Contributor

@tschaffter We're already using black in the schamtic API of the Monorepo. How will that interact with this change?

@tschaffter
Copy link
Member Author

@andrewelamb I believe that you are running Black CLI to format Python files. This PR enables to format files when saving them in VS Code, which will save you time and improve DX.

@andrewelamb
Copy link
Contributor

@tschaffter I don't think I'm understanding the distinction, I scheduled a meeting tomorrow to discuss amongst a few other issues.

@tschaffter tschaffter merged commit 132e3ab into Sage-Bionetworks:main Oct 24, 2023
9 checks passed
@tschaffter tschaffter deleted the disable-flake8 branch October 24, 2023 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Saving Python files trigger flake8 which is not installed
2 participants