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

fix: unpin pylint pycodestyle #10

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/api/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def initialize_course(cls, course):
update_key.course_key,
update_key.block_type,
block_id=update_key.block_id,
fields=dict(data="<ol><li><h2>Date</h2>Hello world!</li></ol>"),
fields={"data": "<ol><li><h2>Date</h2>Hello world!</li></ol>"},
)

section = BlockFactory.create(
Expand Down
94 changes: 46 additions & 48 deletions cms/djangoapps/contentstore/api/views/course_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,24 @@ def _execute_method_and_log_time(log_time, func, *args):
# Added for EDUCATOR-3660
course_key_harvard = str(course_key) == 'course-v1:HarvardX+SW12.1x+2016'

response = dict(
is_self_paced=course.self_paced,
)
response = {"is_self_paced": course.self_paced}
if get_bool_param(request, 'sections', all_requested):
response.update(
sections=_execute_method_and_log_time(course_key_harvard, self._sections_quality, course)
{"sections": _execute_method_and_log_time(course_key_harvard, self._sections_quality, course)}
)
if get_bool_param(request, 'subsections', all_requested):
response.update(
subsections=_execute_method_and_log_time(
{"subsections": _execute_method_and_log_time(
course_key_harvard, self._subsections_quality, course, request
)
)}
)
if get_bool_param(request, 'units', all_requested):
response.update(
units=_execute_method_and_log_time(course_key_harvard, self._units_quality, course, request)
{"units": _execute_method_and_log_time(course_key_harvard, self._units_quality, course, request)}
)
if get_bool_param(request, 'videos', all_requested):
response.update(
videos=_execute_method_and_log_time(course_key_harvard, self._videos_quality, course)
{"videos": _execute_method_and_log_time(course_key_harvard, self._videos_quality, course)}
)

return Response(response)
Expand All @@ -142,13 +140,13 @@ def _required_course_depth(self, request, all_requested): # lint-amnesty, pylin
def _sections_quality(self, course):
sections, visible_sections = self._get_sections(course)
sections_with_highlights = [section for section in visible_sections if section.highlights]
return dict(
total_number=len(sections),
total_visible=len(visible_sections),
number_with_highlights=len(sections_with_highlights),
highlights_active_for_course=course.highlights_enabled_for_messaging,
highlights_enabled=True, # used to be controlled by a waffle switch, now just always enabled
)
return {
"total_number": len(sections),
"total_visible": len(visible_sections),
"number_with_highlights": len(sections_with_highlights),
"highlights_active_for_course": course.highlights_enabled_for_messaging,
"highlights_enabled": True, # used to be controlled by a waffle switch, now just always enabled
}

def _subsections_quality(self, course, request): # lint-amnesty, pylint: disable=missing-function-docstring
subsection_unit_dict = self._get_subsections_and_units(course, request)
Expand All @@ -160,11 +158,11 @@ def _subsections_quality(self, course, request): # lint-amnesty, pylint: disabl
)
num_block_types_per_subsection_dict[subsection_key] = len(set().union(*leaf_block_types_in_subsection))

return dict(
total_visible=len(num_block_types_per_subsection_dict),
num_with_one_block_type=list(num_block_types_per_subsection_dict.values()).count(1),
num_block_types=self._stats_dict(list(num_block_types_per_subsection_dict.values())),
)
return {
"total_visible": len(num_block_types_per_subsection_dict),
"num_with_one_block_type": list(num_block_types_per_subsection_dict.values()).count(1),
"num_block_types": self._stats_dict(list(num_block_types_per_subsection_dict.values())),
}

def _units_quality(self, course, request): # lint-amnesty, pylint: disable=missing-function-docstring
subsection_unit_dict = self._get_subsections_and_units(course, request)
Expand All @@ -173,23 +171,23 @@ def _units_quality(self, course, request): # lint-amnesty, pylint: disable=miss
for unit_dict in subsection_unit_dict.values()
for unit_info in unit_dict.values()
]
return dict(
total_visible=len(num_leaf_blocks_per_unit),
num_blocks=self._stats_dict(num_leaf_blocks_per_unit),
)
return {
"total_visible": len(num_leaf_blocks_per_unit),
"num_blocks": self._stats_dict(num_leaf_blocks_per_unit),
}

def _videos_quality(self, course): # lint-amnesty, pylint: disable=missing-function-docstring
video_blocks_in_course = modulestore().get_items(course.id, qualifiers={'category': 'video'})
videos, __ = get_videos_for_course(course.id)
videos_in_val = list(videos)
video_durations = [video['duration'] for video in videos_in_val]

return dict(
total_number=len(video_blocks_in_course),
num_mobile_encoded=len(videos_in_val),
num_with_val_id=len([v for v in video_blocks_in_course if v.edx_video_id]),
durations=self._stats_dict(video_durations),
)
return {
"total_number": len(video_blocks_in_course),
"num_mobile_encoded": len(videos_in_val),
"num_with_val_id": len([v for v in video_blocks_in_course if v.edx_video_id]),
"durations": self._stats_dict(video_durations),
}

@classmethod
@request_cached()
Expand All @@ -212,10 +210,10 @@ def _get_subsections_and_units(cls, course, request):

for unit in visible_units:
leaf_blocks = cls._get_leaf_blocks(unit)
unit_dict[unit.location] = dict(
num_leaf_blocks=len(leaf_blocks),
leaf_block_types={block.location.block_type for block in leaf_blocks},
)
unit_dict[unit.location] = {
"num_leaf_blocks": len(leaf_blocks),
"leaf_block_types": {block.location.block_type for block in leaf_blocks},
}

subsection_dict[subsection.location] = unit_dict
return subsection_dict
Expand Down Expand Up @@ -259,18 +257,18 @@ def leaf_filter(block):

def _stats_dict(self, data): # lint-amnesty, pylint: disable=missing-function-docstring
if not data:
return dict(
min=None,
max=None,
mean=None,
median=None,
mode=None,
)
return {
"min": None,
"max": None,
"mean": None,
"median": None,
"mode": None,
}
else:
return dict(
min=min(data),
max=max(data),
mean=np.around(np.mean(data)),
median=np.around(np.median(data)),
mode=stats.mode(data, axis=None)[0],
)
return {
"min": min(data),
"max": max(data),
"mean": np.around(np.mean(data)),
"median": np.around(np.median(data)),
"mode": stats.mode(data, axis=None)[0],
}
98 changes: 42 additions & 56 deletions cms/djangoapps/contentstore/api/views/course_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,23 @@ def get(self, request, course_key):

store = modulestore()
with store.bulk_operations(course_key):
course = store.get_course(course_key, depth=self._required_course_depth(request, all_requested))

response = dict(
is_self_paced=course.self_paced,
course = store.get_course(
course_key, depth=self._required_course_depth(request, all_requested)
)
if get_bool_param(request, 'dates', all_requested):
response.update(
dates=self._dates_validation(course)
)
if get_bool_param(request, 'assignments', all_requested):
response.update(
assignments=self._assignments_validation(course, request)
)
if get_bool_param(request, 'grades', all_requested):
response.update(
grades=self._grades_validation(course)
)
if get_bool_param(request, 'certificates', all_requested):
response.update(
certificates=self._certificates_validation(course)
)
if get_bool_param(request, 'updates', all_requested):
response.update(
updates=self._updates_validation(course, request)
)
if get_bool_param(request, 'proctoring', all_requested):
response.update(
proctoring=self._proctoring_validation(course)
)

response = {"is_self_paced": course.self_paced}
if get_bool_param(request, "dates", all_requested):
response.update({"dates": self._dates_validation(course)})
if get_bool_param(request, "assignments", all_requested):
response.update({"assignments": self._assignments_validation(course, request)})
if get_bool_param(request, "grades", all_requested):
response.update({"grades": self._grades_validation(course)})
if get_bool_param(request, "certificates", all_requested):
response.update({"certificates": self._certificates_validation(course)})
if get_bool_param(request, "updates", all_requested):
response.update({"updates": self._updates_validation(course, request)})
if get_bool_param(request, "proctoring", all_requested):
response.update({"proctoring": self._proctoring_validation(course)})

return Response(response)

Expand All @@ -113,10 +101,10 @@ def _required_course_depth(self, request, all_requested):
return 0

def _dates_validation(self, course):
return dict(
has_start_date=self._has_start_date(course),
has_end_date=course.end is not None,
)
return {
"has_start_date": self._has_start_date(course),
"has_end_date": course.end is not None,
}

def _assignments_validation(self, course, request): # lint-amnesty, pylint: disable=missing-function-docstring
assignments, visible_assignments = self._get_assignments(course)
Expand Down Expand Up @@ -193,38 +181,36 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis
'display_name': parent_assignment.display_name
})

return dict(
total_number=len(assignments),
total_visible=len(visible_assignments),
assignments_with_dates_before_start=assignments_with_dates_before_start,
assignments_with_dates_after_end=assignments_with_dates_after_end,
assignments_with_ora_dates_before_start=assignments_with_ora_dates_before_start,
assignments_with_ora_dates_after_end=assignments_with_ora_dates_after_end,
)
return {
"total_number": len(assignments),
"total_visible": len(visible_assignments),
"assignments_with_dates_before_start": assignments_with_dates_before_start,
"assignments_with_dates_after_end": assignments_with_dates_after_end,
"assignments_with_ora_dates_before_start": assignments_with_ora_dates_before_start,
"assignments_with_ora_dates_after_end": assignments_with_ora_dates_after_end,
}

def _grades_validation(self, course):
has_grading_policy = self._has_grading_policy(course)
sum_of_weights = course.grader.sum_of_weights
return dict(
has_grading_policy=has_grading_policy,
sum_of_weights=sum_of_weights,
)
return {
"has_grading_policy": has_grading_policy,
"sum_of_weights": sum_of_weights,
}

def _certificates_validation(self, course):
is_activated, certificates = CertificateManager.is_activated(course)
certificates_enabled = certificates is not None
return dict(
is_activated=is_activated,
has_certificate=certificates_enabled and len(certificates) > 0,
is_enabled=certificates_enabled,
)
return {
"is_activated": is_activated,
"has_certificate": certificates_enabled and len(certificates) > 0,
"is_enabled": certificates_enabled,
}

def _updates_validation(self, course, request):
updates_usage_key = course.id.make_usage_key('course_info', 'updates')
updates = get_course_updates(updates_usage_key, provided_id=None, user_id=request.user.id)
return dict(
has_update=len(updates) > 0,
)
return {"has_update": len(updates) > 0}

def _get_assignments(self, course): # lint-amnesty, pylint: disable=missing-function-docstring
store = modulestore()
Expand Down Expand Up @@ -336,7 +322,7 @@ def _has_grading_policy(self, course): # lint-amnesty, pylint: disable=missing-

def _proctoring_validation(self, course):
# A proctoring escalation email is currently only required for courses using Proctortrack
return dict(
needs_proctoring_escalation_email=course.proctoring_provider == 'proctortrack',
has_proctoring_escalation_email=bool(course.proctoring_escalation_email)
)
return {
"needs_proctoring_escalation_email": course.proctoring_provider == 'proctortrack',
"has_proctoring_escalation_email": bool(course.proctoring_escalation_email)
}
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def _get_location_info(cls, normalized_structure_key):
@classmethod
def _id_modifier(cls, usage_id):
""" Modifies usage_id to submit to index """
return usage_id.replace(library_key=(usage_id.library_key.replace(version_guid=None, branch=None)))
return usage_id.replace(library_key=usage_id.library_key.replace(version_guid=None, branch=None))

@classmethod
def do_library_reindex(cls, modulestore, library_key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def handle(self, *args, **options):
error_keys.append(course_key)

if error_keys:
msg = 'The following courses encountered errors and were not updated:\n'
for error_key in error_keys:
msg += f' - {error_key}\n'
msg = (
"The following courses encountered errors and were not updated:\n"
+ "\n".join(f" - {error_key}" for error_key in error_keys)
)
logger.info(msg)
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ def handle(self, *args, **options):
tarball = tasks.create_export_tarball(library, library_key, {}, None)
except Exception as e:
raise CommandError(f'Failed to export "{library_key}" with "{e}"') # lint-amnesty, pylint: disable=raise-missing-from
else:
with tarball:
# Save generated archive with keyed filename
prefix, suffix, n = str(library_key).replace(':', '+'), '.tar.gz', 0
while os.path.exists(prefix + suffix):
n += 1
prefix = '{}_{}'.format(prefix.rsplit('_', 1)[0], n) if n > 1 else f'{prefix}_1'
filename = prefix + suffix
target = os.path.join(dest_path, filename)
tarball.file.seek(0)
with open(target, 'wb') as f:
shutil.copyfileobj(tarball.file, f)
print(f'Library "{library.location.library_key}" exported to "{target}"')

with tarball:
# Save generated archive with keyed filename
prefix, suffix, n = str(library_key).replace(':', '+'), '.tar.gz', 0
while os.path.exists(prefix + suffix):
n += 1
prefix = '{}_{}'.format(prefix.rsplit('_', 1)[0], n) if n > 1 else f'{prefix}_1'
filename = prefix + suffix
target = os.path.join(dest_path, filename)
tarball.file.seek(0)
with open(target, 'wb') as f:
shutil.copyfileobj(tarball.file, f)
print(f'Library "{library.location.library_key}" exported to "{target}"')
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def test_toggle_invalid_tab_visibility(self, invalid_tab_locator):
self.check_invalid_response(resp)

@ddt.data(
dict(is_hidden=None),
dict(is_hidden="abc"),
{"is_hidden": None},
{"is_hidden": "abc"},
{},
)
def test_toggle_tab_invalid_visibility(self, invalid_visibility):
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def update_search_index(course_id, triggered_time_isoformat):
)
return

CoursewareSearchIndexer.index(modulestore(), course_key, triggered_at=(_parse_time(triggered_time_isoformat)))
CoursewareSearchIndexer.index(modulestore(), course_key, triggered_at=_parse_time(triggered_time_isoformat))

except SearchIndexingError as exc:
error_list = exc.error_list
Expand All @@ -237,7 +237,7 @@ def update_library_index(library_id, triggered_time_isoformat):
""" Updates course search index. """
try:
library_key = CourseKey.from_string(library_id)
LibrarySearchIndexer.index(modulestore(), library_key, triggered_at=(_parse_time(triggered_time_isoformat)))
LibrarySearchIndexer.index(modulestore(), library_key, triggered_at=_parse_time(triggered_time_isoformat))

except SearchIndexingError as exc:
LOGGER.error('Search indexing error for library %s - %s', library_id, str(exc))
Expand Down
Loading
Loading