In the templated nox_file.py for python, there is a lint nox session which runs both black and flake8 linters.
|
def lint(session): |
|
"""Run linters. |
|
|
|
Returns a failure if the linters find linting errors or sufficiently |
|
serious code quality issues. |
|
""" |
|
session.install("flake8", BLACK_VERSION) |
|
session.run( |
|
"black", |
|
"--check", |
|
*BLACK_PATHS, |
|
) |
|
session.run("flake8", "google", "tests") |
googleapis/python-aiplatform#1087, there is a conflict between the 2 lint tools that we use where a formatting change made by black causes the flake8 check to fail.
In the current configuration, black and flake8 check for different things. black tests/applies formatting while flake checks for syntax.
To check this, create an empty file test_lint.py with a single import statement and no new line at the end of the file. As an example, I used import google.api in an empty file without a blank line at the end.
If you run black --check test_lint.py which tests the file without changing it.
black --check test_lint.py
would reformat test_lint.py
All done! 💥 💔 💥
1 file would be reformatted.
Then run black test_lint.py, which adds an empty line at the end of the file.
black test_lint.py
reformatted test_lint.py
All done! ✨ 🍰✨
1 file reformatted.
On the same file run flake8 test_lint.py which tests for syntax.
flake8 test_lint.py
test_lint.py:1:1: F401 'google.api' imported but unused
I've opened this issue to understand the impact of removing black, and confirm that flake8 can fill the gap.
In the templated
nox_file.pyfor python, there is alintnoxsession which runs bothblackandflake8linters.synthtool/synthtool/gcp/templates/python_library/noxfile.py.j2
Lines 52 to 64 in 02193e4
googleapis/python-aiplatform#1087, there is a conflict between the 2 lint tools that we use where a formatting change made by
blackcauses theflake8check to fail.In the current configuration,
blackandflake8check for different things.blacktests/applies formatting whileflakechecks for syntax.To check this, create an empty file
test_lint.pywith a single import statement and no new line at the end of the file. As an example, I usedimport google.apiin an empty file without a blank line at the end.If you run
black --check test_lint.pywhich tests the file without changing it.Then run
black test_lint.py, which adds an empty line at the end of the file.On the same file run
flake8 test_lint.pywhich tests for syntax.I've opened this issue to understand the impact of removing
black, and confirm thatflake8can fill the gap.