Skip to content

process(python): Explore the possibility of using a single linter #1373

@parthea

Description

@parthea

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang: pythonIssues specific to Python.type: processA process-related concern. May include testing, release, or the like.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions