From 718b6651fec7607e016fb106f1e671d39f0164fb Mon Sep 17 00:00:00 2001 From: Bascht74 <66269310+Bascht74@users.noreply.github.com> Date: Tue, 6 Oct 2026 04:20:28 +0200 Subject: [PATCH] [ci] Run pylint when its version, dependencies or configuration change (#20202) --- script/determine-jobs.py | 28 ++++++++++++++++++++-------- tests/script/test_determine_jobs.py | 4 ++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/script/determine-jobs.py b/script/determine-jobs.py index 9c8f3cd3b4..9d146c94a0 100755 --- a/script/determine-jobs.py +++ b/script/determine-jobs.py @@ -31,7 +31,7 @@ The CI workflow uses this information to: - Skip or run integration tests - Skip or run clang-tidy (and whether to do a full scan) - Skip or run clang-format -- Skip or run Python linters (ruff, flake8, pylint, pyupgrade) +- Skip or run pylint - Skip or run downstream esphome/device-builder tests against the PR's Python code - Determine which components to test individually - Decide how to split component tests (if there are many) @@ -403,21 +403,33 @@ def should_run_clang_format(branch: str | None = None) -> bool: return _any_changed_file_endswith(branch, CPP_FILE_EXTENSIONS) +# Linter pins, dependencies and linter config can change findings without a .py change. +PYTHON_LINTERS_TRIGGER_FILES = frozenset( + { + "requirements.txt", + "requirements_test.txt", + "pyproject.toml", + } +) + + def should_run_python_linters(branch: str | None = None) -> bool: - """Determine if Python linters (ruff, flake8, pylint, pyupgrade) should run based on changed files. + """Determine if the pylint job should run based on changed files. - This function is used by the CI workflow to skip Python linting checks when no Python files - have changed, saving CI time and resources. - - Python linters will run when any Python source files have changed. + The CI workflow skips pylint unless a Python file or a file in + PYTHON_LINTERS_TRIGGER_FILES has changed. ruff, flake8 and pyupgrade run in + lint-format, which this flag does not gate. Args: branch: Branch to compare against. If None, uses default. Returns: - True if Python linters should run, False otherwise. + True if pylint should run, False otherwise. """ - return _any_changed_file_endswith(branch, PYTHON_FILE_EXTENSIONS) + return any( + file.endswith(PYTHON_FILE_EXTENSIONS) or file in PYTHON_LINTERS_TRIGGER_FILES + for file in changed_files(branch) + ) # Files outside esphome/**/*.py whose changes can affect `import esphome.__main__` diff --git a/tests/script/test_determine_jobs.py b/tests/script/test_determine_jobs.py index da688703fc..7e9b09b2b9 100644 --- a/tests/script/test_determine_jobs.py +++ b/tests/script/test_determine_jobs.py @@ -907,6 +907,10 @@ def test_should_run_clang_tidy_with_branch() -> None: (["esphome/core.py"], True), (["script/test.py"], True), (["esphome/test.pyi"], True), # .pyi files should trigger + (["requirements_test.txt"], True), + (["requirements.txt"], True), + (["pyproject.toml"], True), + (["requirements_dev.txt"], False), (["README.md"], False), ([], False), ],