From 19caff4277600006a95f13013afbf36fc08eedc3 Mon Sep 17 00:00:00 2001 From: aadalal <57609353+AaDalal@users.noreply.github.com> Date: Wed, 25 Oct 2023 23:23:09 -0400 Subject: [PATCH] lint --- Pipfile | 11 +++++++++++ backend/review/import_utils/parse_sql.py | 4 ++-- backend/review/management/commands/iscimport.py | 12 ++++++++---- backend/tests/review/test_import.py | 4 +--- 4 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 Pipfile diff --git a/Pipfile b/Pipfile new file mode 100644 index 000000000..c398b0d5a --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.10" diff --git a/backend/review/import_utils/parse_sql.py b/backend/review/import_utils/parse_sql.py index f74583d35..af9371e20 100644 --- a/backend/review/import_utils/parse_sql.py +++ b/backend/review/import_utils/parse_sql.py @@ -1,11 +1,12 @@ import gc import re from datetime import datetime -from courses.util import translate_semester_inv, semester_suffix_map_inv from lark import Lark, Transformer from tqdm import tqdm +from courses.util import semester_suffix_map_inv, translate_semester_inv + """ This file contains functionality for parsing the SQL dump files that we get from ISC. @@ -82,7 +83,6 @@ def row(self, items): row_dict["TERM"] = translate_semester_inv(stripped_term) return row_dict - def TOKEN(self, items): """ A token simply represents itself. diff --git a/backend/review/management/commands/iscimport.py b/backend/review/management/commands/iscimport.py index 1fe93a0b8..f81f88b2f 100644 --- a/backend/review/management/commands/iscimport.py +++ b/backend/review/management/commands/iscimport.py @@ -36,6 +36,7 @@ def assert_semesters_not_current(semesters): f"Did you forget to update the SEMESTER option in the Django admin console?" ) + class Command(BaseCommand): help = """ Import course review data from the zip of mysqldump files that we get from ISC every semester. @@ -159,7 +160,7 @@ def handle(self, *args, **kwargs): import_all = kwargs["import_all"] s3_bucket = kwargs["s3_bucket"] is_zip_file = kwargs["zip"] or s3_bucket is not None - summary_file = kwargs["summary_file"] # either summary table or summary hist table + summary_file = kwargs["summary_file"] # either summary table or summary hist table import_details = kwargs["import_details"] import_descriptions = kwargs["import_descriptions"] show_progress_bar = kwargs["show_progress_bar"] @@ -220,7 +221,7 @@ def handle(self, *args, **kwargs): for semester in semesters: print(f"Loading {semester}...") - with transaction.atomic(): # Only commit changes if all imports for the semester succeed + with transaction.atomic(): # Commit changes if all imports for the semester succeed to_delete = Review.objects.filter(section__course__semester=semester) delete_count = to_delete.count() if delete_count > 0: @@ -234,12 +235,15 @@ def handle(self, *args, **kwargs): return 0 print( - f"Deleting {delete_count} existing reviews for {semester} from the database..." + f"Deleting {delete_count} existing reviews for {semester} " + "from the database..." ) to_delete.delete() print(f"Importing reviews for semester {semester}") - stats = import_summary_rows((r for r in summary_rows if r["TERM"] == semester), show_progress_bar) + stats = import_summary_rows( + (r for r in summary_rows if r["TERM"] == semester), show_progress_bar + ) print(stats) gc.collect() diff --git a/backend/tests/review/test_import.py b/backend/tests/review/test_import.py index 16918c07b..6918cc8bb 100644 --- a/backend/tests/review/test_import.py +++ b/backend/tests/review/test_import.py @@ -122,9 +122,7 @@ def test_semester_transformation(self): (TERM) Values ('202230'); """ parse = parse_row(query) - expected = { - "TERM": "2022C" - } + expected = {"TERM": "2022C"} self.assertDictEqual(parse, expected)