From 5b4a357069030530c1ef15f623861ff5bf9349f2 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 9 Nov 2023 08:47:59 -0700 Subject: [PATCH] Linting --- .../commands/load_transition_domain.py | 2 +- .../commands/master_domain_migrations.py | 2 +- .../transfer_transition_domains_to_domains.py | 34 ++++++++++++------- .../commands/utility/epp_data_containers.py | 2 +- .../utility/extra_transition_domain_helper.py | 21 +++++++----- .../commands/utility/terminal_helper.py | 10 +++--- .../utility/transition_domain_arguments.py | 4 +-- .../test_transition_domain_migrations.py | 8 +++-- 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/registrar/management/commands/load_transition_domain.py b/src/registrar/management/commands/load_transition_domain.py index bb6f59ad9..20c0c34e1 100644 --- a/src/registrar/management/commands/load_transition_domain.py +++ b/src/registrar/management/commands/load_transition_domain.py @@ -66,7 +66,7 @@ class Command(BaseCommand): parser.add_argument( "--infer_filenames", action=argparse.BooleanOptionalAction, - help="Determines if we should infer filenames or not." + help="Determines if we should infer filenames or not." "Recommended to be enabled only in a development or testing setting.", ) diff --git a/src/registrar/management/commands/master_domain_migrations.py b/src/registrar/management/commands/master_domain_migrations.py index 95349ef45..6656458d7 100644 --- a/src/registrar/management/commands/master_domain_migrations.py +++ b/src/registrar/management/commands/master_domain_migrations.py @@ -88,7 +88,7 @@ class Command(BaseCommand): # The following file arguments have default values for running in the sandbox - # TODO: make this a mandatory argument + # TODO: make this a mandatory argument # (if/when we strip out defaults, it will be mandatory) # TODO: use the migration directory arg or force user to type FULL filepath? parser.add_argument( diff --git a/src/registrar/management/commands/transfer_transition_domains_to_domains.py b/src/registrar/management/commands/transfer_transition_domains_to_domains.py index af7976c30..4e7eea852 100644 --- a/src/registrar/management/commands/transfer_transition_domains_to_domains.py +++ b/src/registrar/management/commands/transfer_transition_domains_to_domains.py @@ -114,7 +114,7 @@ class Command(BaseCommand): Created {total_domain_invitation_entries} domain invitation entries (NOTE: no invitations are SENT in this script) {TerminalColors.ENDC} - """ # noqa + """ # noqa ) if len(skipped_domain_entries) > 0: logger.info( @@ -192,16 +192,15 @@ class Command(BaseCommand): # ---- UPDATE THE DOMAIN # update the status - self.update_domain_status( - transition_domain, target_domain, debug_on - ) - # TODO: not all domains need to be updated (the information is the same). + self.update_domain_status(transition_domain, target_domain, debug_on) + # TODO: not all domains need to be updated + # (the information is the same). # Need to bubble this up to the final report. # update dates (creation and expiration) if transition_domain_creation_date is not None: - # TODO: added this because I ran into a situation where - # the created_at date was null (violated a key constraint). + # TODO: added this because I ran into a situation where + # the created_at date was null (violated a key constraint). # How do we want to handle this case? target_domain.created_at = transition_domain_creation_date @@ -493,7 +492,9 @@ class Command(BaseCommand): self.update_domain_information( target_domain_information, template_domain_information, debug_on ) - # TODO: not all domains need to be updated (the information is the same). Need to bubble this up to the final report. + # TODO: not all domains need to be updated + # (the information is the same). + # Need to bubble this up to the final report. return (target_domain_information, domain, False) except DomainInformation.MultipleObjectsReturned: @@ -594,8 +595,11 @@ class Command(BaseCommand): debug_on, f"{TerminalColors.OKCYAN}" "Processing Transition Domain: " - f"{transition_domain_name}, {transition_domain_status}, {transition_domain_email}" - f", {transition_domain_creation_date}, {transition_domain_expiration_date}" + f"{transition_domain_name}," + f" {transition_domain_status}," + f" {transition_domain_email}" + f", {transition_domain_creation_date}, " + f"{transition_domain_expiration_date}" f"{TerminalColors.ENDC}", # noqa ) @@ -680,7 +684,8 @@ class Command(BaseCommand): else: # Raise an err for now raise Exception( - f"Domain {existing_domain} wants to be added but doesn't exist in the DB" + f"Domain {existing_domain} wants to be added" + "but doesn't exist in the DB" ) invitation.save() @@ -740,7 +745,9 @@ class Command(BaseCommand): ), None, ) - # TODO: this is redundant. Currently debugging....running into unique key constraint error.... + # TODO: this is redundant. + # Currently debugging.... + # running into unique key constraint error.... existing_domain_info = DomainInformation.objects.filter( domain__name=target_domain_information.domain.name ).exists() @@ -765,7 +772,8 @@ class Command(BaseCommand): f"updated domain information: {target_domain_information}" ) else: - debug_string = f"domain information already exists and matches incoming data (NO CHANGES MADE): {target_domain_information}" + debug_string = "domain information already exists and " + f"matches incoming data (NO CHANGES MADE): {target_domain_information}" # DEBUG: TerminalHelper.print_conditional( diff --git a/src/registrar/management/commands/utility/epp_data_containers.py b/src/registrar/management/commands/utility/epp_data_containers.py index 3fe170574..1f370dca7 100644 --- a/src/registrar/management/commands/utility/epp_data_containers.py +++ b/src/registrar/management/commands/utility/epp_data_containers.py @@ -4,7 +4,7 @@ A list of helper classes to facilitate handling data from verisign data exports. Regarding our dataclasses: Not intended to be used as models but rather as an alternative to storing as a dictionary. By keeping it as a dataclass instead of a dictionary, we can maintain data consistency. -""" +""" # noqa from dataclasses import dataclass, field from datetime import date from enum import Enum diff --git a/src/registrar/management/commands/utility/extra_transition_domain_helper.py b/src/registrar/management/commands/utility/extra_transition_domain_helper.py index b06bc5299..e7e1ae745 100644 --- a/src/registrar/management/commands/utility/extra_transition_domain_helper.py +++ b/src/registrar/management/commands/utility/extra_transition_domain_helper.py @@ -239,6 +239,7 @@ class LoadExtraTransitionDomain: total_transition_domains = len(updated_transition_domains) total_updates_made = TransitionDomain.objects.all().count() if total_transition_domains != total_updates_made: + # noqa here for line length logger.error( f"""{TerminalColors.FAIL} WARNING: something went wrong processing domain information data. @@ -251,7 +252,7 @@ class LoadExtraTransitionDomain: corrupt data. Please check logs to diagnose. ----- TERMINATING ---- - """ + """ # noqa ) sys.exit() @@ -654,7 +655,7 @@ class FileDataHolder: id_field: data_type(...), ... } - """ + """ # noqa def __init__( self, @@ -664,18 +665,18 @@ class FileDataHolder: id_field: str, ): # Metadata # - ## Filename inference metadata ## + # = Filename inference metadata =# self.regex = regex self.could_infer = False - ## "data" object metadata ## - ### Where the data is sourced from ### + # = "data" object metadata =# + # == Where the data is sourced from ==# self.filename = filename - ### What type the data is ### + # == What type the data is ==# self.data_type = data_type - ### What the id should be in the holding dict ### + # == What the id should be in the holding dict ==# # TODO - rename to id_field_name self.id_field = id_field @@ -868,8 +869,10 @@ class ExtraTransitionDomain: continue # Infer filename logic # - # This mode is used for internal development use and testing only. Rather than having - # to manually define the filename each time, we can infer what the filename + # This mode is used for + # internal development use and testing only. + # Rather than havingto manually define the + # filename each time, we can infer what the filename # actually is. # Not intended for use outside of that, as it is better to assume diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 05c37b271..1d6fb23a5 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -180,7 +180,7 @@ class TerminalHelper: # If the user decided to proceed return true. # Otherwise, either return false or exit this subroutine. - if proceed_execution == False: + if not proceed_execution: if system_exit_on_terminate: sys.exit() return False @@ -206,7 +206,9 @@ class TerminalHelper: filepath = f"{file_directory}{filename}.txt" # Write to file logger.info( - f"{TerminalColors.MAGENTA}Writing to file {filepath}...{TerminalColors.ENDC}" + f"{TerminalColors.MAGENTA}Writing to file " + f" {filepath}..." + f"{TerminalColors.ENDC}" ) with open(f"{filepath}", "w+") as f: f.write(file_contents) @@ -233,7 +235,7 @@ class TerminalHelper: length - Optional : character length of bar (Int) fill - Optional : bar fill character (Str) printEnd - Optional : end character (e.g. "\r", "\r\n") (Str) - """ + """ # noqa """ # Initial call to print 0% progress @@ -243,7 +245,7 @@ class TerminalHelper: time.sleep(0.1) # Update Progress Bar printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50) - """ + """ # noqa percent = ("{0:." + str(decimals) + "f}").format( 100 * (iteration / float(total)) diff --git a/src/registrar/management/commands/utility/transition_domain_arguments.py b/src/registrar/management/commands/utility/transition_domain_arguments.py index 11f3afe7c..3a31fb8e7 100644 --- a/src/registrar/management/commands/utility/transition_domain_arguments.py +++ b/src/registrar/management/commands/utility/transition_domain_arguments.py @@ -36,7 +36,7 @@ class TransitionDomainArguments: limitParse: Optional[int] = field(default=None, repr=True) # Filenames # - ## Adhocs ## + # = Adhocs =# agency_adhoc_filename: Optional[str] = field( default=EnumFilenames.AGENCY_ADHOC.value[1], repr=True ) @@ -50,7 +50,7 @@ class TransitionDomainArguments: default=EnumFilenames.AUTHORITY_ADHOC.value[1], repr=True ) - ## Data files ## + # = Data files =# domain_escrow_filename: Optional[str] = field( default=EnumFilenames.DOMAIN_ESCROW.value[1], repr=True ) diff --git a/src/registrar/tests/test_transition_domain_migrations.py b/src/registrar/tests/test_transition_domain_migrations.py index fb93e52b6..0a16d5359 100644 --- a/src/registrar/tests/test_transition_domain_migrations.py +++ b/src/registrar/tests/test_transition_domain_migrations.py @@ -47,8 +47,10 @@ class TestMigrations(TestCase): UserDomainRole.objects.all().delete() def run_load_domains(self): + # noqa here because splitting this up makes it confusing. + # ES501 with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa return_value=True, ): call_command( @@ -61,8 +63,10 @@ class TestMigrations(TestCase): call_command("transfer_transition_domains_to_domains") def run_master_script(self): + # noqa here (E501) because splitting this up makes it + # confusing to read. with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa return_value=True, ): call_command(