SERVER-107464 Remove pylinters (#38447)

Co-authored-by: Steve McClure <steve.mcclure@mongodb.com>
GitOrigin-RevId: 64e98fb129fa337cf53359cc32625903032b517b
This commit is contained in:
Zack Winter 2025-07-14 06:56:09 -07:00 committed by MongoDB Bot
parent af07ed86d3
commit feb50b5356
4 changed files with 12 additions and 137 deletions

View File

@ -1,95 +0,0 @@
#!/usr/bin/env python3
"""Extensible script to run one or more Python Linters across a subset of files in parallel."""
import argparse
import logging
import os
import sys
import structlog
mongo_dir = os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__))))
# Get relative imports to work when the package is not installed on the PYTHONPATH.
if __name__ == "__main__" and __package__ is None:
sys.path.append(mongo_dir)
from buildscripts.linter import ruffchecker, ruffformatter, runner
# List of supported linters
_LINTERS = [
ruffchecker.RuffChecker(),
ruffformatter.RuffFormatter(),
]
def lint(file_names: list[str]):
"""Lint files command entry point."""
lint_runner = runner.LintRunner()
linter_instances = runner.find_linters(_LINTERS, {})
any_failed = False
for linter in linter_instances:
lint_success = lint_runner.run_lint(linter, file_names, mongo_dir)
any_failed |= not lint_success
if any_failed:
print("ERROR: Code Style does not match coding style")
print("To fix formatting errors, run `buildscripts/pylinters.py fix`.")
sys.exit(1)
def fix_func(file_names: list[str]):
"""Fix a list of files with linters if possible."""
lint_runner = runner.LintRunner()
linter_instances = runner.find_linters(_LINTERS, {})
any_failed = False
for linter in linter_instances:
lint_success = lint_runner.run_fix(linter, file_names, mongo_dir)
any_failed |= not lint_success
if any_failed:
print("ERROR: Code Style does not match coding style")
print("Code could not be automatically fixed.")
sys.exit(1)
def main():
# type: () -> None
"""Execute Main entry point."""
parser = argparse.ArgumentParser(
description="PyLinter frontend; see more details at https://wiki.corp.mongodb.com/x/1vP5BQ"
)
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose logging")
sub = parser.add_subparsers(title="Linter subcommands", help="sub-command help")
parser_lint = sub.add_parser(
"lint", help="Lint files and exit with nonzero status if any violations are found"
)
parser_lint.add_argument("file_names", nargs="*", help="Globs of files to check")
parser_lint.set_defaults(func=lint)
parser_fix = sub.add_parser("fix", help="Fix files if possible")
parser_fix.add_argument("file_names", nargs="*", help="Globs of files to check")
parser_fix.set_defaults(func=fix_func)
# No args given? Fall back to usage screen:
if len(sys.argv) == 1:
parser.print_help()
return
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
structlog.configure(logger_factory=structlog.stdlib.LoggerFactory())
args.func(args.file_names)
if __name__ == "__main__":
main()

View File

@ -383,13 +383,13 @@ def run_smoke_tests(
log_file="clang_format.log",
),
runner.command(
name="python format",
name="misc. lint",
args=[
MONGO_PYTHON_INTERPRETER,
ROOT.joinpath("buildscripts", "pylinters.py"),
"fix",
BAZEL,
"run",
"//:lint",
],
log_file="python_format.log",
log_file="misc_lint.log",
),
runner.command(
# catch-all for other bazel-driven formatters

View File

@ -63,12 +63,12 @@ Ex: `bash buildscripts/yamllinters.sh`
## Python Linters
The `buildscripts/pylinters.py` wrapper script runs the Python linters. You can
see the usage message for the wrapper by running the following command:
`buildscripts/pylinters.py --help`.
The `bazel run lint` command runs all Python linters as well as several other linters in our code base. You can
run auto-remediations via:
`bazel run lint --fix`.
Ex: `buildscripts/pylinters.py lint`
Ex: `bazel run lint`
| Linter | Configuration File(s) | Help Command | Documentation |
| ------ | --------------------- | ------------- | ------------------------------------------------------------ |
| `ruff` | `pyproject.toml` | `ruff --help` | [https://docs.astral.sh/ruff/](https://docs.astral.sh/ruff/) |
| Linter | Configuration File(s) | Help Command | Documentation |
| ------ | --------------------- | ------------ | ------------------------------------------------------------ |
| `ruff` | `pyproject.toml` | | [https://docs.astral.sh/ruff/](https://docs.astral.sh/ruff/) |

View File

@ -912,36 +912,6 @@ tasks:
- "lint-sbom"
- "buildscripts/sbom_linter.py"
- name: lint_pylinters
tags:
[
"assigned_to_jira_team_devprod_build",
"development_critical_single_variant",
"lint",
]
commands:
- command: timeout.update
params:
# 20 mins
exec_timeout_secs: 1200
- func: "f_expansions_write"
- command: manifest.load
- func: "git get project and add git tag"
- func: "f_expansions_write"
- func: "kill processes"
- func: "cleanup environment"
- func: "set up venv"
- func: "upload pip requirements"
- command: subprocess.exec
type: test
params:
binary: bash
args:
- "./src/evergreen/run_python_script_with_report.sh"
- "lint-pylinters"
- "buildscripts/pylinters.py"
- "lint"
- name: lint_pyright
tags:
[