diff --git a/.github/workflows/quality-checks.yml b/.github/workflows/quality-checks.yml index 3fd680b2375f..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 pycodestyle + ruff check --output-format=github . make xsslint make pii_check make check_keywords diff --git a/Makefile b/Makefile index 2ca7fbc5848e..bd70a15cd76f 100644 --- a/Makefile +++ b/Makefile @@ -171,8 +171,8 @@ 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 . ## 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 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 60a8d20b235e..8dc968170c22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -205,6 +205,27 @@ 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", + "test_root/staticfiles", +] + +[tool.ruff.lint] +select = ["E", "W"] +ignore = [ + "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. + # 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. + "E721", # use `isinstance()` for type comparisons +] + [tool.isort] indent = " " line_length = 120 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/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.in b/requirements/edx/testing.in index 14a0c781da82..275460512f97 100644 --- a/requirements/edx/testing.in +++ b/requirements/edx/testing.in @@ -29,7 +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 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/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 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