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

build: fix quality CI checks #402

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 3 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04]
toxenv: [py38-django42, py311-django42, py312-django42, py38-quality, py311-quality, py312-quality, translations]
python-version: [3.8, 3.11, 3.12]
toxenv: [django42, quality, translations]

steps:
- name: checkout repo
uses: actions/checkout@v3
with:
submodules: recursive

- name: Extract the Python version from tox environment
run: |
if [[ "${{ matrix.toxenv }}" =~ py[0-9]+ ]]; then
PYTHON_VERSION=$(echo "${{ matrix.toxenv }}" | sed -E 's/py([0-9])([0-9]+).*/\1.\2/')
else
# Default version
PYTHON_VERSION=3.8
fi
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV

- name: setup python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ matrix.python-version }}

- name: Install translations dependencies
if: ${{ startsWith(matrix.toxenv, 'translations') }}
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Drag and Drop XBlock changelog
Unreleased
---------------------------

* Adjust code styling for newer pylint versions.

Version 4.0.2 (2024-04-24)
--------------------------

Expand Down
1 change: 1 addition & 0 deletions drag_and_drop_v2/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ def get_grading_ignore_decoys_waffle_flag():
# Ref: https://github.com/openedx/public-engineering/issues/28
return CourseWaffleFlag(WAFFLE_NAMESPACE, GRADING_IGNORE_DECOYS, __name__)
except ValueError:
# pylint: disable=toggle-missing-annotation
return CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.{GRADING_IGNORE_DECOYS}', __name__)
24 changes: 11 additions & 13 deletions drag_and_drop_v2/drag_and_drop_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import json
import logging

import six.moves.urllib.error # pylint: disable=import-error
import six.moves.urllib.parse # pylint: disable=import-error
import six.moves.urllib.request # pylint: disable=import-error
import six.moves.urllib.error
import six.moves.urllib.parse
import six.moves.urllib.request
import six
import webob

Expand Down Expand Up @@ -45,7 +45,6 @@
# Classes ###########################################################


# pylint: disable=bad-continuation
@XBlock.wants('settings')
@XBlock.wants('replace_urls')
@XBlock.wants('user') # Using `needs` breaks the Course Outline page in Maple.
Expand Down Expand Up @@ -257,7 +256,7 @@ def score(self):
"""
return Score(self.raw_earned, self.raw_possible)

def max_score(self): # pylint: disable=no-self-use
def max_score(self):
"""
Return the problem's max score, which for DnDv2 always equals 1.
Required by the grading system in the LMS.
Expand Down Expand Up @@ -515,7 +514,7 @@ def _get_block_id(self):
- In the workbench, use the usage_id.
"""
if hasattr(self, 'location'):
return self.location.html_id() # pylint: disable=no-member
return self.location.html_id()
else:
return six.text_type(self.scope_ids.usage_id)

Expand Down Expand Up @@ -581,7 +580,6 @@ def do_attempt(self, data, suffix=''):
self._validate_do_attempt()

self.attempts += 1
# pylint: disable=fixme
# TODO: Refactor this method to "freeze" item_state and pass it to methods that need access to it.
# These implicit dependencies between methods exist because most of them use `item_state` or other
# fields, either as an "input" (i.e. read value) or as output (i.e. set value) or both. As a result,
Expand Down Expand Up @@ -712,7 +710,7 @@ def has_submission_deadline_passed(self):
functionality.
"""
if hasattr(self, "has_deadline_passed"):
return self.has_deadline_passed() # pylint: disable=no-member
return self.has_deadline_passed()
else:
return False

Expand Down Expand Up @@ -949,7 +947,6 @@ def _mark_complete_and_publish_grade(self):
"""
Helper method to update `self.completed` and submit grade event if appropriate conditions met.
"""
# pylint: disable=fixme
# TODO: (arguable) split this method into "clean" functions (with no side effects and implicit state)
# This method implicitly depends on self.item_state (via is_correct and _learner_raw_score)
# and also updates self.raw_earned if some conditions are met. As a result this method implies some order of
Expand Down Expand Up @@ -1052,8 +1049,9 @@ def _expand_static_url(self, url):
# edX Studio uses a different runtime for 'studio_view' than 'student_view',
# and the 'studio_view' runtime doesn't provide the replace_urls API.
try:
from common.djangoapps.static_replace import replace_static_urls # pylint: disable=import-error
url = replace_static_urls(u'"{}"'.format(url), None, course_id=self.runtime.course_id)[1:-1]
# pylint: disable=import-outside-toplevel
from common.djangoapps.static_replace import replace_static_urls
url = replace_static_urls('"{}"'.format(url), None, course_id=self.runtime.course_id)[1:-1]
except ImportError:
pass
return url
Expand Down Expand Up @@ -1108,7 +1106,7 @@ def _get_preferred_zone(zone_count, zones):
return preferred_zone

# Set states of all items dropped in correct zones
for item_id in self.item_state:
for item_id in self.item_state: # pylint: disable=consider-using-dict-items
if self.item_state[item_id]['correct']:
state[item_id] = self.item_state[item_id]
correct_items.add(item_id)
Expand Down Expand Up @@ -1319,7 +1317,7 @@ def index_dictionary(self):
# values may be numeric / string or dict
# default implementation is an empty dict

xblock_body = super(DragAndDropBlock, self).index_dictionary()
xblock_body = super().index_dictionary()

zones_display_names = {
"zone_{}_display_name".format(zone_i):
Expand Down
19 changes: 10 additions & 9 deletions drag_and_drop_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ def sanitize_html(raw_body: str) -> str:
"""
Remove not allowed HTML tags to mitigate XSS vulnerabilities.
"""
bleach_options = dict(
tags=ALLOWED_TAGS,
protocols=bleach.ALLOWED_PROTOCOLS,
strip=True,
attributes=ALLOWED_ATTRIBUTES,
)
bleach_options['css_sanitizer'] = CSSSanitizer()
bleach_options = {
"tags": ALLOWED_TAGS,
"protocols": bleach.ALLOWED_PROTOCOLS,
"strip": True,
"attributes": ALLOWED_ATTRIBUTES,
"css_sanitizer": CSSSanitizer()
}

return bleach.clean(raw_body, **bleach_options)


Expand Down Expand Up @@ -165,8 +166,8 @@ def not_placed(number, ngettext=ngettext_fallback):
).format(missing_count=number)


FeedbackMessage = namedtuple("FeedbackMessage", ["message", "message_class"]) # pylint: disable=invalid-name
ItemStats = namedtuple( # pylint: disable=invalid-name
FeedbackMessage = namedtuple("FeedbackMessage", ["message", "message_class"])
ItemStats = namedtuple(
'ItemStats',
["required", "placed", "correctly_placed", "decoy", "decoy_in_bank"]
)
Expand Down
Loading
Loading