Skip to content

Commit 467495c

Browse files
feanilclaudebradenmacdonald
authored
feanil/pycodestyle to ruff (#38076)
* feat: add ruff and configure it to match current pycodestyle rules 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 <[email protected]> * feat: add ruff Makefile target Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * style: Apply suggestions from code review Remove unnecessary ignores. Co-authored-by: Braden MacDonald <[email protected]> * 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. * 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. * chore: Recompile requirements. Update the requirements to drop pycodestyle and add ruff. --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]> Co-authored-by: Braden MacDonald <[email protected]>
1 parent b5a9fff commit 467495c

9 files changed

Lines changed: 30 additions & 40 deletions

File tree

.github/workflows/quality-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
PIP_SRC: ${{ runner.temp }}
7979
TARGET_BRANCH: ${{ github.base_ref }}
8080
run: |
81-
make pycodestyle
81+
ruff check --output-format=github .
8282
make xsslint
8383
make pii_check
8484
make check_keywords

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ xsslint: ## check xss for quality issuest
171171
--config=scripts.xsslint_config \
172172
--thresholds=scripts/xsslint_thresholds.json
173173

174-
pycodestyle: ## check python files for quality issues
175-
pycodestyle .
174+
ruff: ## check python files with ruff
175+
ruff check .
176176

177177
## Re-enable --lint flag when this issue https://github.com/openedx/edx-platform/issues/35775 is resolved
178178
pii_check: ## check django models for pii annotations

cms/djangoapps/contentstore/views/tests/test_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,7 @@ def validate_xblock_info_consistency(
35063506
self.validate_xblock_info_consistency(
35073507
child_response,
35083508
has_child_info=(
3509-
not child_response.get("child_info", None) is None
3509+
child_response.get("child_info", None) is not None
35103510
),
35113511
course_outline=course_outline,
35123512
)

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ norecursedirs = ". .* *.egg build conf dist node_modules test_root cms/envs lms/
205205
python_classes = []
206206
python_files = ["tests.py", "test_*.py", "tests_*.py", "*_tests.py", "__init__.py"]
207207

208+
[tool.ruff]
209+
line-length = 120
210+
exclude = [
211+
"migrations",
212+
"test_root/staticfiles",
213+
]
214+
215+
[tool.ruff.lint]
216+
select = ["E", "W"]
217+
ignore = [
218+
"E402", # module level import not at top of file
219+
"E501", # line too long (pylint enforces this at 120 chars while ignoring trailing comments)
220+
"E722", # do not use bare 'except'
221+
"E731", # do not assign a lambda expression
222+
"E741", # ambiguous variable name. TODO: fix the ~9 issues and re-enable this.
223+
# The rules below were added in pycodestyle 2.9.x but we were pinned to 2.8.x,
224+
# so they represent new findings. Keeping them ignored here to make this an
225+
# equivalent swap; they can be cleaned up in a follow-up.
226+
"E721", # use `isinstance()` for type comparisons
227+
]
228+
208229
[tool.isort]
209230
indent = " "
210231
line_length = 120

requirements/constraints.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ openai<=0.28.1
7878
# Issue for unpinning: https://github.com/openedx/edx-platform/issues/35267
7979
path<16.12.0
8080

81-
# Date: 2022-08-03
82-
# pycodestyle==2.9.0 generates false positive error E275.
83-
# Constraint can be removed once the issue https://github.com/PyCQA/pycodestyle/issues/1090 is fixed.
84-
pycodestyle<2.9.0
85-
8681
# Date: 2021-08-25
8782
# At the time of writing this comment, we do not know whether py2neo>=2022
8883
# will support our currently-deployed Neo4j version (3.5).

requirements/edx/development.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,10 +1570,6 @@ pycasbin==2.8.0
15701570
# -r requirements/edx/testing.txt
15711571
# casbin-django-orm-adapter
15721572
# openedx-authz
1573-
pycodestyle==2.8.0
1574-
# via
1575-
# -c requirements/constraints.txt
1576-
# -r requirements/edx/testing.txt
15771573
pycountry==26.2.16
15781574
# via
15791575
# -r requirements/edx/doc.txt
@@ -1899,6 +1895,8 @@ rsa==4.9.1
18991895
# -r requirements/edx/doc.txt
19001896
# -r requirements/edx/testing.txt
19011897
# google-auth
1898+
ruff==0.15.4
1899+
# via -r requirements/edx/testing.txt
19021900
rules==3.5
19031901
# via
19041902
# -r requirements/edx/doc.txt

requirements/edx/testing.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ httpretty # Library for mocking HTTP requests, used in many test
2929
import-linter # Tool for making assertions about which modules can import which others
3030
isort # For checking and fixing the order of imports
3131
mock # Deprecated alias to standard library `unittest.mock`
32-
pycodestyle # Checker for compliance with the Python style guide (PEP 8)
32+
ruff # Fast Python linter and formatter
3333
polib # Library for manipulating gettext translation files, used to test paver i18n commands
3434
pyquery # jQuery-like API for retrieving fragments of HTML and XML files in tests
3535
pytest # Testing framework

requirements/edx/testing.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,6 @@ pycasbin==2.8.0
11991199
# -r requirements/edx/base.txt
12001200
# casbin-django-orm-adapter
12011201
# openedx-authz
1202-
pycodestyle==2.8.0
1203-
# via
1204-
# -c requirements/constraints.txt
1205-
# -r requirements/edx/testing.in
12061202
pycountry==26.2.16
12071203
# via -r requirements/edx/base.txt
12081204
pycparser==3.0
@@ -1452,6 +1448,8 @@ rsa==4.9.1
14521448
# via
14531449
# -r requirements/edx/base.txt
14541450
# google-auth
1451+
ruff==0.15.4
1452+
# via -r requirements/edx/testing.in
14551453
rules==3.5
14561454
# via
14571455
# -r requirements/edx/base.txt

setup.cfg

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
[pycodestyle]
2-
# error codes: https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
3-
# E501: line too long
4-
# E265: block comment should start with '# '
5-
# We ignore this because pep8 used to erroneously lump E266 into it also.
6-
# We should probably fix these now.
7-
# E266: too many leading '#' for block comment
8-
# We have lots of comments that look like "##### HEADING #####" which violate
9-
# this rule, because they don't have a space after the first #. However,
10-
# they're still perfectly reasonable comments, so we disable this rule.
11-
# W602: deprecated form of raising exception
12-
# We do this in a few places to modify the exception message while preserving
13-
# the traceback. See this blog post for more info:
14-
# http://nedbatchelder.com/blog/200711/rethrowing_exceptions_in_python.html
15-
# It's a little unusual, but we have good reasons for doing so, so we disable
16-
# this rule.
17-
# E203: whitespace before ':'
18-
# We ignore this because of black formatter defaults
19-
# E305,E402,E722,E731,E741,E743,W503,W504: errors and warnings added since pep8/pycodestyle
20-
# 1.5.7 that we haven't cleaned up yet
21-
ignore=E203,E265,E266,E305,E402,E501,E722,E731,E741,E743,W503,W504,W602
22-
exclude=migrations,.git,.pycharm_helpers,.tox,test_root/staticfiles,node_modules

0 commit comments

Comments
 (0)