Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff linter #34820

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,8 @@ migrate: migrate-lms migrate-cms
# Part of https://github.com/openedx/wg-developer-experience/issues/136
ubuntu-requirements: ## Install ubuntu 22.04 system packages needed for `pip install` to work on ubuntu.
sudo apt install libmysqlclient-dev libxmlsec1-dev
ruff: ## Run ruff
ruff check lms/djangoapps/ lms/envs/ lms/lib/ lms/tests.py \
openedx/core/djangoapps/ openedx/core/djangolib/ openedx/core/lib/ openedx/core/tests/ \
openedx/core/tests/ openedx/core/types/ openedx/features/ openedx/testing/ openedx/tests/ \
cms common xmodule --preview
2 changes: 1 addition & 1 deletion common/djangoapps/student/models/course_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ def refund_window(self, refund_window):

class BulkUnenrollConfiguration(ConfigurationModel): # lint-amnesty, pylint: disable=empty-docstring
"""

config model for the bulk_unenroll_csv command
"""
csv_file = models.FileField(
validators=[FileExtensionValidator(allowed_extensions=['csv'])],
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,9 @@ def handle_exceptions(request, course_key, course, exception):
Handle exceptions raised when rendering a view.
"""
if isinstance(exception, Redirect) or isinstance(exception, Http404): # lint-amnesty, pylint: disable=consider-merging-isinstance
raise # lint-amnesty, pylint: disable=misplaced-bare-raise
raise # lint-amnesty, pylint: disable=misplaced-bare-raise # noqa: PLE0704
if settings.DEBUG:
raise # lint-amnesty, pylint: disable=misplaced-bare-raise
raise # lint-amnesty, pylint: disable=misplaced-bare-raise # noqa: PLE0704
user = request.user
log.exception(
"Error in %s: user=%s, effective_user=%s, course=%s",
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/lib/api/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def handle_exception(self, exc):
elif isinstance(exc, ValidationError):
return self._make_validation_error_response(exc)
else:
raise # lint-amnesty, pylint: disable=misplaced-bare-raise
raise # lint-amnesty, pylint: disable=misplaced-bare-raise # noqa: PLE0704


class ExpandableFieldViewMixin:
Expand Down
3 changes: 2 additions & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,8 @@ zipp==3.18.1
# -r requirements/edx/testing.txt
# importlib-metadata
# importlib-resources

ruff==0.1.3
# via -r requirements/edx/testing.in
# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
1 change: 1 addition & 0 deletions requirements/edx/testing.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pytest-json-report # Output json formatted warnings after running pytest
pytest-metadata==1.8.0 # To prevent 'make upgrade' failure, dependency of pytest-json-report
pytest-randomly # pytest plugin to randomly order tests
pytest-xdist[psutil] # Parallel execution of tests on multiple CPU cores or hosts
ruff # rust based linter
singledispatch # Backport of functools.singledispatch from Python 3.4+, used in tests of XBlock rendering
testfixtures # Provides a LogCapture utility used by several tests
tox # virtualenv management for tests
Expand Down
3 changes: 2 additions & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ zipp==3.18.1
# -r requirements/edx/base.txt
# importlib-metadata
# importlib-resources

ruff==0.1.3
# via -r requirements/edx/testing.in
# The following packages are considered to be unsafe in a requirements file:
# setuptools
131 changes: 131 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
select = [
"A001", # redefined-builtin
"ARG001", # unused-argument
"B002", # nonexistent-operator
"B006", # dangerous-default-value
"B012", # lost-exception
"B014", # duplicate-except
"B018", # expression-not-assigned
"B018", # pointless-statement
"B023", # cell-var-from-loop
"D419", # empty-docstring
"E401", # multiple-imports
"E501", # line-too-long
"E702", # multiple-statements
"E703", # unnecessary-semicolon
"E712", # singleton-comparison
"E721", # unidiomatic-typecheck
"E722", # bare-except
"E999", # syntax-error
"F401", # unused-import
"F403", # wildcard-import
"F404", # misplaced-future
"F501", # truncated-format-string
"F502", # format-needs-mapping
"F504", # unused-format-string-key
"F507", # unused-format-string-argument
"F522", # too-many-format-args
"F524", # missing-format-argument-key
"F524", # missing-format-string-key
"F524", # too-few-format-args
"F525", # format-combined-specification
"F601", # duplicate-key
"F631", # assert-on-tuple
"F702", # not-in-loop
"F704", # yield-outside-function
"F706", # return-outside-function
"F811", # function-redefined
"F811", # reimported
"F821", # undefined-variable
"F822", # undefined-all-variable
"F841", # unused-variable
"FIX004", # fixme
"G", # logging-format-interpolation
"G", # logging-fstring-interpolation
"G", # logging-not-lazy
"I001", # ungrouped-imports
"I001", # wrong-import-order
"N804", # bad-classmethod-argument
"N805", # no-method-argument
"N805", # no-self-argument
"N815", # invalid-name
"PGH001", # eval-used
"PIE790", # unnecessary-pass
"PLE0101", # return-in-init
"PLE0116", # continue-in-finally
"PLE0241", # duplicate-bases
"PLE0302", # unexpected-special-method-signature
"PLE0604", # invalid-all-object
"PLE0704", # misplaced-bare-raise
"PLE1205", # logging-too-many-args
"PLE1206", # logging-too-few-args
"PLE1310", # bad-str-strip-call
"PLR0904", # too-many-public-methods
"PLR0911", # too-many-return-statements
"PLR0912", # too-many-branches
"PLR0913", # too-many-arguments
"PLR0915", # too-many-statements
"PLR0916", # too-many-boolean-expressions
"PLW0120", # useless-else-on-loop
"PLW0406", # import-self
"PLW0602", # global-variable-not-assigned
"PLW0603", # global-statement
"PLW0711", # binary-op-exception
"PLW1514", # unspecified-encoding
"RET502", # inconsistent-return-statements
"RET505", # no-else-return
"RET507", # no-else-continue
"RET508", # no-else-break
"S102", # exec-used
"SIM118", # consider-iterating-dictionary
"SIM208", # unneeded-not
"UP004", # useless-object-inheritance
"W292", # missing-final-newline
"W605", # anomalous-backslash-in-string
]

ignore = [
"ARG001", # unused-argument
"F841", # unused-variable
"FIX004", # fixme
"G", # logging-format-interpolation
"G", # logging-fstring-interpolation
"I001", # ungrouped-imports
"I001", # wrong-import-order
"N815", # invalid-name
"PLR0904", # too-many-public-methods
"PLR0911", # too-many-return-statements
"PLR0912", # too-many-branches
"PLR0913", # too-many-arguments
"PLW0603", # global-statement
"PLW1514", # unspecified-encoding
"RET502", # inconsistent-return-statements
"RET505", # no-else-return
"RET507", # no-else-continue
"RET508", # no-else-break
"UP004", # useless-object-inheritance

# enabled in pylint but failing in ruff because of too many inline suppressions
"A001", # redefined-builtin
"B006", # dangerous-default-value
"B018", # expression-not-assigned
"B018", # pointless-statement
"B023", # cell-var-from-loop
"E501", # line-too-long
"E712", # singleton-comparison
"E721", # unidiomatic-typecheck
"E722", # bare-except
"F401", # unused-import
"F403", # wildcard-import
"F811", # function-redefined
"F811", # reimported
"F821", # undefined-variable
"N804", # bad-classmethod-argument
"N805", # no-method-argument
"N805", # no-self-argument
"PGH001", # eval-used
"PIE790", # unnecessary-pass
"PLR0915", # too-many-statements
"PLW0602", # global-variable-not-assigned
"SIM118", # consider-iterating-dictionary
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: would it make sense to move these configs to pyproject.toml -> [tool.ruff], to start using a common place for such configurations?

51 changes: 37 additions & 14 deletions scripts/generic-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,43 @@ case "$TEST_SUITE" in

mkdir -p reports

echo "Finding fixme's and storing report..."
run_paver_quality find_fixme || { EXIT=1; }
echo "Finding pycodestyle violations and storing report..."
run_paver_quality run_pep8 || { EXIT=1; }
echo "Finding ESLint violations and storing report..."
run_paver_quality run_eslint -l "$ESLINT_THRESHOLD" || { EXIT=1; }
echo "Finding Stylelint violations and storing report..."
run_paver_quality run_stylelint || { EXIT=1; }
echo "Running xss linter report."
run_paver_quality run_xsslint -t "$XSSLINT_THRESHOLDS" || { EXIT=1; }
echo "Running PII checker on all Django models..."
run_paver_quality run_pii_check || { EXIT=1; }
echo "Running reserved keyword checker on all Django models..."
run_paver_quality check_keywords || { EXIT=1; }
case "$SHARD" in
1)
echo "Finding pylint violations and storing in report..."
run_paver_quality run_pylint --system=common || { EXIT=1; }
;;

2)
echo "Finding pylint violations and storing in report..."
run_paver_quality run_pylint --system=lms || { EXIT=1; }
;;

3)
echo "Finding pylint violations and storing in report..."
run_paver_quality run_pylint --system="cms,openedx,pavelib" || { EXIT=1; }
;;

4)
echo "Finding fixme's and storing report..."
run_paver_quality find_fixme || { EXIT=1; }
echo "Finding pycodestyle violations and storing report..."
run_paver_quality run_pep8 || { EXIT=1; }
echo "Finding ESLint violations and storing report..."
run_paver_quality run_eslint -l "$ESLINT_THRESHOLD" || { EXIT=1; }
echo "Finding Stylelint violations and storing report..."
run_paver_quality run_stylelint || { EXIT=1; }
echo "Running xss linter report."
run_paver_quality run_xsslint -t "$XSSLINT_THRESHOLDS" || { EXIT=1; }
echo "Running PII checker on all Django models..."
run_paver_quality run_pii_check || { EXIT=1; }
echo "Running reserved keyword checker on all Django models..."
run_paver_quality check_keywords || { EXIT=1; }
echo "Running ruff linter..."
make ruff || { EXIT=1; }
echo "Running ruff linter..."
make ruff || { EXIT=1; }

esac

# Need to create an empty test result so the post-build
# action doesn't fail the build.
Expand Down
2 changes: 1 addition & 1 deletion xmodule/modulestore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _get_bulk_ops_record(self, course_key, ignore_case=False):
# Shortcut: check basic equivalence for cases where org/course/run might be None.
key_library = get_library_or_course_attribute(key)
course_library = get_library_or_course_attribute(course_key)
if (key == course_key) or ( # lint-amnesty, pylint: disable=too-many-boolean-expressions
if (key == course_key) or ( # lint-amnesty, pylint: disable=too-many-boolean-expressions # noqa: PLR0916
(key.org and key.org.lower() == course_key.org.lower()) and
(key_library and key_library.lower() == course_library.lower()) and
(key.run and key.run.lower() == course_key.run.lower())
Expand Down
Loading