From e0e4338f542470ca2b7f2a2affe21f37b90621a3 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Tue, 3 Mar 2026 12:07:47 -0500 Subject: [PATCH 1/8] feat: add ruff and configure it to match current pycodestyle rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds ruff to testing requirements and configures it in pyproject.toml to enforce the same E/W rules that pycodestyle 2.8.x was enforcing. Two additional rules (E714, E721) that pycodestyle 2.8.x did not enforce are explicitly ignored for now and can be cleaned up in a follow-up. Part of the migration from pycodestyle → ruff. Co-Authored-By: Claude Sonnet 4.6 --- pyproject.toml | 31 +++++++++++++++++++++++++++++++ requirements/edx/testing.in | 1 + 2 files changed, 32 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 60a8d20b235e..ab21ec27b5dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -205,6 +205,37 @@ norecursedirs = ". .* *.egg build conf dist node_modules test_root cms/envs lms/ python_classes = [] python_files = ["tests.py", "test_*.py", "tests_*.py", "*_tests.py", "__init__.py"] +[tool.ruff] +line-length = 120 +exclude = [ + "migrations", + ".git", + ".pycharm_helpers", + ".tox", + "test_root/staticfiles", + "node_modules", +] + +[tool.ruff.lint] +select = ["E", "W"] +ignore = [ + "E203", # whitespace before ':' (black compat) + "E265", # block comment should start with '# ' + "E266", # too many leading '#' for block comment + "E305", # expected 2 blank lines after class or function definition + "E402", # module level import not at top of file + "E501", # line too long (pylint enforces this at 120 chars) + "E722", # do not use bare 'except' + "E731", # do not assign a lambda expression + "E741", # ambiguous variable name + "E743", # ambiguous function name + # The rules below were added in pycodestyle 2.9.x but we were pinned to 2.8.x, + # so they represent new findings. Keeping them ignored here to make this an + # equivalent swap; they can be cleaned up in a follow-up. + "E714", # use `is not` instead of `not ... is` + "E721", # use `isinstance()` for type comparisons +] + [tool.isort] indent = " " line_length = 120 diff --git a/requirements/edx/testing.in b/requirements/edx/testing.in index 14a0c781da82..34870f7b7a57 100644 --- a/requirements/edx/testing.in +++ b/requirements/edx/testing.in @@ -30,6 +30,7 @@ import-linter # Tool for making assertions about which modules can i isort # For checking and fixing the order of imports mock # Deprecated alias to standard library `unittest.mock` pycodestyle # Checker for compliance with the Python style guide (PEP 8) +ruff # Fast Python linter and formatter (replacing pycodestyle) polib # Library for manipulating gettext translation files, used to test paver i18n commands pyquery # jQuery-like API for retrieving fragments of HTML and XML files in tests pytest # Testing framework From 109f6324fe0d1fe19b245eb2098160e5eaa8182d Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Tue, 3 Mar 2026 12:09:22 -0500 Subject: [PATCH 2/8] feat: add ruff Makefile target Co-Authored-By: Claude Sonnet 4.6 --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 2ca7fbc5848e..315ca97ed17e 100644 --- a/Makefile +++ b/Makefile @@ -174,6 +174,9 @@ xsslint: ## check xss for quality issuest pycodestyle: ## check python files for quality issues pycodestyle . +ruff: ## check python files with ruff + ruff check . + ## Re-enable --lint flag when this issue https://github.com/openedx/edx-platform/issues/35775 is resolved pii_check: ## check django models for pii annotations DJANGO_SETTINGS_MODULE=cms.envs.test \ From c9d56badc585fd4430320d362fc0675b6311d40c Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Tue, 3 Mar 2026 12:09:57 -0500 Subject: [PATCH 3/8] feat: add ruff to quality CI workflow alongside pycodestyle Runs ruff alongside pycodestyle so we can validate parity before removing pycodestyle in the next commit. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/quality-checks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/quality-checks.yml b/.github/workflows/quality-checks.yml index 3fd680b2375f..2db30b652d23 100644 --- a/.github/workflows/quality-checks.yml +++ b/.github/workflows/quality-checks.yml @@ -78,6 +78,7 @@ jobs: PIP_SRC: ${{ runner.temp }} TARGET_BRANCH: ${{ github.base_ref }} run: | + make ruff make pycodestyle make xsslint make pii_check From 7d03a282d06624ea3d188a428a8f7a7d0ac44ad1 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Tue, 3 Mar 2026 12:18:18 -0500 Subject: [PATCH 4/8] feat: remove pycodestyle, replaced by ruff - Remove pycodestyle from requirements - Remove pycodestyle version constraint (pinned to <2.9.0 due to a false positive E275 bug that is no longer relevant) - Remove [pycodestyle] config from setup.cfg (config now lives in pyproject.toml under [tool.ruff]) - Remove pycodestyle Makefile target - Remove make pycodestyle from quality CI workflow Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/quality-checks.yml | 1 - Makefile | 3 --- requirements/constraints.txt | 5 ----- requirements/edx/testing.in | 3 +-- setup.cfg | 22 ---------------------- 5 files changed, 1 insertion(+), 33 deletions(-) diff --git a/.github/workflows/quality-checks.yml b/.github/workflows/quality-checks.yml index 2db30b652d23..3e8e9c75e7e3 100644 --- a/.github/workflows/quality-checks.yml +++ b/.github/workflows/quality-checks.yml @@ -79,7 +79,6 @@ jobs: TARGET_BRANCH: ${{ github.base_ref }} run: | make ruff - make pycodestyle make xsslint make pii_check make check_keywords diff --git a/Makefile b/Makefile index 315ca97ed17e..bd70a15cd76f 100644 --- a/Makefile +++ b/Makefile @@ -171,9 +171,6 @@ xsslint: ## check xss for quality issuest --config=scripts.xsslint_config \ --thresholds=scripts/xsslint_thresholds.json -pycodestyle: ## check python files for quality issues - pycodestyle . - ruff: ## check python files with ruff ruff check . diff --git a/requirements/constraints.txt b/requirements/constraints.txt index ee608faee3c5..7678425d510c 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -78,11 +78,6 @@ openai<=0.28.1 # Issue for unpinning: https://github.com/openedx/edx-platform/issues/35267 path<16.12.0 -# Date: 2022-08-03 -# pycodestyle==2.9.0 generates false positive error E275. -# Constraint can be removed once the issue https://github.com/PyCQA/pycodestyle/issues/1090 is fixed. -pycodestyle<2.9.0 - # Date: 2021-08-25 # At the time of writing this comment, we do not know whether py2neo>=2022 # will support our currently-deployed Neo4j version (3.5). diff --git a/requirements/edx/testing.in b/requirements/edx/testing.in index 34870f7b7a57..275460512f97 100644 --- a/requirements/edx/testing.in +++ b/requirements/edx/testing.in @@ -29,8 +29,7 @@ httpretty # Library for mocking HTTP requests, used in many test import-linter # Tool for making assertions about which modules can import which others isort # For checking and fixing the order of imports mock # Deprecated alias to standard library `unittest.mock` -pycodestyle # Checker for compliance with the Python style guide (PEP 8) -ruff # Fast Python linter and formatter (replacing pycodestyle) +ruff # Fast Python linter and formatter polib # Library for manipulating gettext translation files, used to test paver i18n commands pyquery # jQuery-like API for retrieving fragments of HTML and XML files in tests pytest # Testing framework diff --git a/setup.cfg b/setup.cfg index 7e1ab370a043..e69de29bb2d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,22 +0,0 @@ -[pycodestyle] -# error codes: https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes -# E501: line too long -# E265: block comment should start with '# ' -# We ignore this because pep8 used to erroneously lump E266 into it also. -# We should probably fix these now. -# E266: too many leading '#' for block comment -# We have lots of comments that look like "##### HEADING #####" which violate -# this rule, because they don't have a space after the first #. However, -# they're still perfectly reasonable comments, so we disable this rule. -# W602: deprecated form of raising exception -# We do this in a few places to modify the exception message while preserving -# the traceback. See this blog post for more info: -# http://nedbatchelder.com/blog/200711/rethrowing_exceptions_in_python.html -# It's a little unusual, but we have good reasons for doing so, so we disable -# this rule. -# E203: whitespace before ':' -# We ignore this because of black formatter defaults -# E305,E402,E722,E731,E741,E743,W503,W504: errors and warnings added since pep8/pycodestyle -# 1.5.7 that we haven't cleaned up yet -ignore=E203,E265,E266,E305,E402,E501,E722,E731,E741,E743,W503,W504,W602 -exclude=migrations,.git,.pycharm_helpers,.tox,test_root/staticfiles,node_modules From 38e502bd01473fa9f458534c049bf6b8a1f64fd8 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Tue, 3 Mar 2026 15:24:23 -0500 Subject: [PATCH 5/8] style: Apply suggestions from code review Remove unnecessary ignores. Co-authored-by: Braden MacDonald --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ab21ec27b5dd..aaaa79c8d613 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -224,10 +224,10 @@ ignore = [ "E266", # too many leading '#' for block comment "E305", # expected 2 blank lines after class or function definition "E402", # module level import not at top of file - "E501", # line too long (pylint enforces this at 120 chars) + "E501", # line too long (pylint enforces this at 120 chars while ignoring trailing comments) "E722", # do not use bare 'except' "E731", # do not assign a lambda expression - "E741", # ambiguous variable name + "E741", # ambiguous variable name. TODO: fix the ~9 issues and re-enable this. "E743", # ambiguous function name # The rules below were added in pycodestyle 2.9.x but we were pinned to 2.8.x, # so they represent new findings. Keeping them ignored here to make this an From 5f037165bb8292e645b0e1d11b3243a516b2f417 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Tue, 3 Mar 2026 15:32:13 -0500 Subject: [PATCH 6/8] style: Fix a style isusue and remove ignores. Most of these ignores are unnecessary as we're passing them now and we want to check them in the future. E714 only had one fixable violation so we just fixed it. --- cms/djangoapps/contentstore/views/tests/test_block.py | 2 +- pyproject.toml | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index 846c62d2436a..31f5244e2f55 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -3506,7 +3506,7 @@ def validate_xblock_info_consistency( self.validate_xblock_info_consistency( child_response, has_child_info=( - not child_response.get("child_info", None) is None + child_response.get("child_info", None) is not None ), course_outline=course_outline, ) diff --git a/pyproject.toml b/pyproject.toml index aaaa79c8d613..1c0208e04c39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -219,20 +219,14 @@ exclude = [ [tool.ruff.lint] select = ["E", "W"] ignore = [ - "E203", # whitespace before ':' (black compat) - "E265", # block comment should start with '# ' - "E266", # too many leading '#' for block comment - "E305", # expected 2 blank lines after class or function definition "E402", # module level import not at top of file "E501", # line too long (pylint enforces this at 120 chars while ignoring trailing comments) "E722", # do not use bare 'except' "E731", # do not assign a lambda expression "E741", # ambiguous variable name. TODO: fix the ~9 issues and re-enable this. - "E743", # ambiguous function name # The rules below were added in pycodestyle 2.9.x but we were pinned to 2.8.x, # so they represent new findings. Keeping them ignored here to make this an # equivalent swap; they can be cleaned up in a follow-up. - "E714", # use `is not` instead of `not ... is` "E721", # use `isinstance()` for type comparisons ] From 8c6d523d2405665eddffa301fd52a71819dbcf51 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 4 Mar 2026 10:25:52 -0500 Subject: [PATCH 7/8] style: Update ruff config and workflows * Update the call to `ruff` so that it outputs in a github friendly manner. * Remove ruff exclusions that are already covered by .gitignore which ruff respects. --- .github/workflows/quality-checks.yml | 2 +- pyproject.toml | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/quality-checks.yml b/.github/workflows/quality-checks.yml index 3e8e9c75e7e3..77f094ba3d8d 100644 --- a/.github/workflows/quality-checks.yml +++ b/.github/workflows/quality-checks.yml @@ -78,7 +78,7 @@ jobs: PIP_SRC: ${{ runner.temp }} TARGET_BRANCH: ${{ github.base_ref }} run: | - make ruff + ruff check --output-format=github . make xsslint make pii_check make check_keywords diff --git a/pyproject.toml b/pyproject.toml index 1c0208e04c39..8dc968170c22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,11 +209,7 @@ python_files = ["tests.py", "test_*.py", "tests_*.py", "*_tests.py", "__init__.p line-length = 120 exclude = [ "migrations", - ".git", - ".pycharm_helpers", - ".tox", "test_root/staticfiles", - "node_modules", ] [tool.ruff.lint] From 84956c3e67e0b67eba09ed69077973217f9b0b52 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 4 Mar 2026 10:37:48 -0500 Subject: [PATCH 8/8] chore: Recompile requirements. Update the requirements to drop pycodestyle and add ruff. --- requirements/edx/development.txt | 6 ++---- requirements/edx/testing.txt | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 8d9e2a1f64ab..bc6dc67a57de 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -1570,10 +1570,6 @@ pycasbin==2.8.0 # -r requirements/edx/testing.txt # casbin-django-orm-adapter # openedx-authz -pycodestyle==2.8.0 - # via - # -c requirements/constraints.txt - # -r requirements/edx/testing.txt pycountry==26.2.16 # via # -r requirements/edx/doc.txt @@ -1899,6 +1895,8 @@ rsa==4.9.1 # -r requirements/edx/doc.txt # -r requirements/edx/testing.txt # google-auth +ruff==0.15.4 + # via -r requirements/edx/testing.txt rules==3.5 # via # -r requirements/edx/doc.txt diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 8467a577e888..8f848de526d4 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -1199,10 +1199,6 @@ pycasbin==2.8.0 # -r requirements/edx/base.txt # casbin-django-orm-adapter # openedx-authz -pycodestyle==2.8.0 - # via - # -c requirements/constraints.txt - # -r requirements/edx/testing.in pycountry==26.2.16 # via -r requirements/edx/base.txt pycparser==3.0 @@ -1452,6 +1448,8 @@ rsa==4.9.1 # via # -r requirements/edx/base.txt # google-auth +ruff==0.15.4 + # via -r requirements/edx/testing.in rules==3.5 # via # -r requirements/edx/base.txt