Skip to content

Commit

Permalink
fix: remove pylint<2.16.0 constraint, update dependencies, and fix py…
Browse files Browse the repository at this point in the history
…lint issues
  • Loading branch information
mfarhan943 committed Oct 23, 2024
1 parent d25e651 commit b041d43
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,5 @@ def handle(self, *args, **options):

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 += ''.join([f' - {error_key}\n' for error_key in error_keys])
logger.info(msg)
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ 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}"')
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def handle(self, *args, **options):
self.change_enrollments(csv_file)

else:
CommandError('No file is provided. File is required')
CommandError('No file is provided. File is required') # pylint: disable=pointless-exception-statement

def change_enrollments(self, csv_file):
""" change the enrollments of the learners. """
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ def check_user_reset_password_threshold(cls, user):
return record.failure_count >= max_failures_allowed / 2, record.failure_count

@classmethod
def clear_lockout_counter(cls, user):
def clear_lockout_counter(cls, user): # pylint: disable=useless-return
"""
Removes the lockout counters (normally called after a successful login)
"""
Expand Down
5 changes: 2 additions & 3 deletions common/djangoapps/track/views/segmentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
raise EventValidationError(ERROR_USER_NOT_EXIST) # lint-amnesty, pylint: disable=raise-missing-from
except ValueError:
raise EventValidationError(ERROR_INVALID_USER_ID) # lint-amnesty, pylint: disable=raise-missing-from
else:
context['user_id'] = user.id
context['username'] = user.username
context['user_id'] = user.id
context['username'] = user.username

# course_id is expected to be provided in the context when applicable
course_id = context.get('course_id')
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/discussion/rest_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ def get_thread_list(
if view in ["unread", "unanswered", "unresponded"]:
query_params[view] = "true"
else:
ValidationError({
ValidationError({ # pylint: disable=pointless-exception-statement
"view": [f"Invalid value. '{view}' must be 'unread' or 'unanswered'"]
})

Expand Down
2 changes: 0 additions & 2 deletions lms/djangoapps/discussion/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ def send_ace_message(context): # lint-amnesty, pylint: disable=missing-function
log.info('Sending forum comment notification with context %s', message_context)
ace.send(message, limit_to_channels=[ChannelType.PUSH])
_track_notification_sent(message, context)
else:
return


@shared_task(base=LoggedTask)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/experiments/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def get_bucket(self, course_key=None, track=True):
if (
track and hasattr(request, 'session') and
session_key not in request.session and
not masquerading_as_specific_student and not anonymous
not masquerading_as_specific_student and not anonymous # pylint: disable=used-before-assignment
):
segment.track(
user_id=user.id,
Expand Down
3 changes: 1 addition & 2 deletions lms/djangoapps/static_template_view/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def render_press_release(request, slug):
resp = render_to_response('static_templates/press_releases/' + template, {})
except TemplateDoesNotExist:
raise Http404 # lint-amnesty, pylint: disable=raise-missing-from
else:
return resp
return resp


@fix_crum_request
Expand Down
6 changes: 5 additions & 1 deletion lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@
FACEBOOK_API_VERSION = "v2.8"

######### custom courses #########
INSTALLED_APPS += ['lms.djangoapps.ccx', 'openedx.core.djangoapps.ccxcon.apps.CCXConnectorConfig']
INSTALLED_APPS += [
'lms.djangoapps.ccx',
'openedx.core.djangoapps.ccxcon.apps.CCXConnectorConfig',
'openedx.core.djangoapps.content_staging',
]
FEATURES['CUSTOM_COURSES_EDX'] = True

# Set dummy values for profile image settings.
Expand Down
1 change: 0 additions & 1 deletion openedx/core/djangoapps/credit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ def remove_requirement_status(cls, username, requirement):
)
)
log.error(log_msg)
return

@classmethod
def retire_user(cls, retirement):
Expand Down
3 changes: 1 addition & 2 deletions openedx/core/djangoapps/credit/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def update_credit_course_requirements(course_id):
except (InvalidKeyError, ItemNotFoundError, InvalidCreditRequirements) as exc:
LOGGER.error('Error on adding the requirements for course %s - %s', course_id, str(exc))
raise update_credit_course_requirements.retry(args=[course_id], exc=exc)
else:
LOGGER.info('Requirements added for course %s', course_id)
LOGGER.info('Requirements added for course %s', course_id)


def _get_course_credit_requirements(course_key):
Expand Down
3 changes: 1 addition & 2 deletions openedx/core/djangoapps/enrollments/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ def get_course_enrollment_info(course_id, include_expired=False):
msg = f"Requested enrollment information for unknown course {course_id}"
log.warning(msg)
raise CourseNotFoundError(msg) # lint-amnesty, pylint: disable=raise-missing-from
else:
return CourseSerializer(course, include_expired=include_expired).data
return CourseSerializer(course, include_expired=include_expired).data


def get_user_roles(username):
Expand Down
15 changes: 7 additions & 8 deletions openedx/core/djangoapps/safe_sessions/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,13 @@ def parse(cls, safe_cookie_string):
raise SafeCookieError( # lint-amnesty, pylint: disable=raise-missing-from
f"SafeCookieData BWC parse error: {safe_cookie_string!r}."
)
else:
if safe_cookie_data.version != cls.CURRENT_VERSION:
raise SafeCookieError(
"SafeCookieData version {!r} is not supported. Current version is {}.".format(
safe_cookie_data.version,
cls.CURRENT_VERSION,
))
return safe_cookie_data
if safe_cookie_data.version != cls.CURRENT_VERSION:
raise SafeCookieError(
"SafeCookieData version {!r} is not supported. Current version is {}.".format(
safe_cookie_data.version,
cls.CURRENT_VERSION,
))
return safe_cookie_data

def __str__(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ def handle(self, *args, **options):
optout_rows[end_idx][0], optout_rows[end_idx][1],
str(err))
raise
else:
cursor.execute('COMMIT;')
log.info("Committed opt-out for rows (%s, %s) through (%s, %s).",
optout_rows[start_idx][0], optout_rows[start_idx][1],
optout_rows[end_idx][0], optout_rows[end_idx][1])
cursor.execute('COMMIT;')
log.info("Committed opt-out for rows (%s, %s) through (%s, %s).",
optout_rows[start_idx][0], optout_rows[start_idx][1],
optout_rows[end_idx][0], optout_rows[end_idx][1])
log.info("Sleeping %s seconds...", sleep_between)
time.sleep(sleep_between)
curr_row_idx += chunk_size
3 changes: 1 addition & 2 deletions openedx/core/lib/api/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ def __len__(self):

def __iter__(self):
# Yield all the known data first
for item in self._data:
yield item
yield from self._data

# Capture and yield data from the underlying iterator
# until it is exhausted
Expand Down
5 changes: 2 additions & 3 deletions openedx/core/lib/celery/task_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ def emulate_http_request(site=None, user=None, middleware_classes=None):
for middleware in reversed(middleware_instances):
_run_method_if_implemented(middleware, 'process_exception', request, exc)
raise
else:
for middleware in reversed(middleware_instances):
_run_method_if_implemented(middleware, 'process_response', request, response)
for middleware in reversed(middleware_instances):
_run_method_if_implemented(middleware, 'process_response', request, response)


def _run_method_if_implemented(instance, method_name, *args, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions pavelib/paver_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,3 @@ def unexpected_fail_on_npm_install(*args, **kwargs): # pylint: disable=unused-a
"""
if ["npm", "install", "--verbose"] == args[0]: # lint-amnesty, pylint: disable=no-else-raise
raise BuildFailure('Subprocess return code: 50')
else:
return
9 changes: 7 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
# SERIOUSLY.
#
# ------------------------------
# Generated by edx-lint version: 5.3.7
# Generated by edx-lint version: 5.4.0
# ------------------------------
[MASTER]
ignore = ,.git,.tox,migrations,node_modules,.pycharm_helpers
Expand Down Expand Up @@ -314,6 +314,10 @@ disable =
c-extension-no-member,
no-name-in-module,
unnecessary-lambda-assignment,
too-many-positional-arguments,
use-dict-literal,
possibly-used-before-assignment,
superfluous-parens,

[REPORTS]
output-format = text
Expand Down Expand Up @@ -409,5 +413,6 @@ int-import-graph =

[EXCEPTIONS]
overgeneral-exceptions = builtins.Exception
overgeneral-exceptions = builtins.Exception

# e624ea03d8124aa9cf2e577f830632344a0a07d9
# 2e978edfd219a1e769192ec8de3d37667862cdb8
4 changes: 4 additions & 0 deletions pylintrc_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ disable+ =
c-extension-no-member,
no-name-in-module,
unnecessary-lambda-assignment,
too-many-positional-arguments,
use-dict-literal,
possibly-used-before-assignment,
superfluous-parens

[BASIC]
attr-rgx = [a-z_][a-z0-9_]{2,40}$
Expand Down
4 changes: 0 additions & 4 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ path<16.12.0
# Constraint can be removed once the issue https://github.com/PyCQA/pycodestyle/issues/1090 is fixed.
pycodestyle<2.9.0

# Date: 2021-07-12
# Issue for unpinning: https://github.com/openedx/edx-platform/issues/33560
pylint<2.16.0 # greater version failing quality test. Fix them in seperate ticket.

# 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).
Expand Down
10 changes: 5 additions & 5 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ bleach[css]==6.1.0
# xblock-poll
boto==2.49.0
# via -r requirements/edx/kernel.in
boto3==1.35.45
boto3==1.35.46
# via
# -r requirements/edx/kernel.in
# django-ses
# fs-s3fs
# ora2
botocore==1.35.45
botocore==1.35.46
# via
# -r requirements/edx/kernel.in
# boto3
Expand Down Expand Up @@ -427,7 +427,7 @@ edx-celeryutils==1.3.0
# -r requirements/edx/kernel.in
# edx-name-affirmation
# super-csv
edx-codejail==3.4.1
edx-codejail==3.5.1
# via -r requirements/edx/kernel.in
edx-completion==4.7.3
# via -r requirements/edx/kernel.in
Expand Down Expand Up @@ -564,7 +564,7 @@ filelock==3.16.1
# via snowflake-connector-python
firebase-admin==6.5.0
# via edx-ace
frozenlist==1.4.1
frozenlist==1.5.0
# via
# aiohttp
# aiosignal
Expand Down Expand Up @@ -885,7 +885,7 @@ proto-plus==1.24.0
# via
# google-api-core
# google-cloud-firestore
protobuf==5.28.2
protobuf==5.28.3
# via
# google-api-core
# google-cloud-firestore
Expand Down
Loading

0 comments on commit b041d43

Please sign in to comment.