diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e7cfba1bd2..7113687191 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,3 +35,4 @@ repos: - id: flake8 additional_dependencies: - flake8-bugbear==23.9.16 + - flake8-comprehensions==3.14.0 diff --git a/src/MCPClient/lib/clientScripts/json_metadata_to_csv.py b/src/MCPClient/lib/clientScripts/json_metadata_to_csv.py index 6d25b4b28d..2ff69a1731 100755 --- a/src/MCPClient/lib/clientScripts/json_metadata_to_csv.py +++ b/src/MCPClient/lib/clientScripts/json_metadata_to_csv.py @@ -30,7 +30,7 @@ def fetch_keys(objects): # Column order is important so the output is consistent. # "filename" and "parts" must be column 0. # (They are mutually exclusive.) - keys = sorted(list(keys)) + keys = sorted(keys) if "filename" in keys: keys.remove("filename") keys.insert(0, "filename") diff --git a/src/MCPClient/lib/clientScripts/restructure_dip_for_content_dm_upload.py b/src/MCPClient/lib/clientScripts/restructure_dip_for_content_dm_upload.py index 838ac8b122..70cbac9263 100755 --- a/src/MCPClient/lib/clientScripts/restructure_dip_for_content_dm_upload.py +++ b/src/MCPClient/lib/clientScripts/restructure_dip_for_content_dm_upload.py @@ -82,9 +82,9 @@ def getItemCountType(structMap): """ divs_with_dmdsecs = structMap.findall(".//mets:div[@DMDID]", namespaces=ns.NSMAP) # If any are TYPE Directory, then it is compound - if any([e.get("TYPE") == "Directory" for e in divs_with_dmdsecs]): + if any(e.get("TYPE") == "Directory" for e in divs_with_dmdsecs): # If all are TYPE Directory then it is bulk - if all([e.get("TYPE") == "Directory" for e in divs_with_dmdsecs]): + if all(e.get("TYPE") == "Directory" for e in divs_with_dmdsecs): return "compound-dirs" else: return "compound-files" diff --git a/src/MCPClient/tests/test_create_aip_mets.py b/src/MCPClient/tests/test_create_aip_mets.py index f454b8a356..cacaff65be 100644 --- a/src/MCPClient/tests/test_create_aip_mets.py +++ b/src/MCPClient/tests/test_create_aip_mets.py @@ -826,7 +826,7 @@ def generate_aip_mets_v2_state(self): ) self.state = create_mets_v2.MetsState() self.state.globalStructMapCounter = random.choice( - [x for x in range(arbitrary_max_structmaps)] + list(range(arbitrary_max_structmaps)) ) self.structmap_div_element = create_mets_v2.createFileSec( job=Job("stub", "stub", []), diff --git a/src/MCPClient/tests/test_load_premis_events_from_xml.py b/src/MCPClient/tests/test_load_premis_events_from_xml.py index 9178cb328f..7589c2156d 100644 --- a/src/MCPClient/tests/test_load_premis_events_from_xml.py +++ b/src/MCPClient/tests/test_load_premis_events_from_xml.py @@ -223,7 +223,7 @@ def test_get_premis_element_children_identifiers(mocker): "params", [ {"original_name": "name", "expected_original_name": "name"}, - {"original_name": tuple(), "expected_original_name": ""}, + {"original_name": (), "expected_original_name": ""}, ], ids=["original_name_as_string", "original_name_as_empty_string"], ) diff --git a/src/MCPServer/lib/server/packages.py b/src/MCPServer/lib/server/packages.py index 74a76cbb0d..cad8587b7c 100644 --- a/src/MCPServer/lib/server/packages.py +++ b/src/MCPServer/lib/server/packages.py @@ -712,7 +712,7 @@ def set_variable(self, key, value, chain_link_id): unittype=self.UNIT_VARIABLE_TYPE, unituuid=self.uuid, variable=key, - defaults=dict(variablevalue=value, microservicechainlink=chain_link_id), + defaults={"variablevalue": value, "microservicechainlink": chain_link_id}, ) if created: message = "New UnitVariable %s created for %s: %s (MSCL: %s)" diff --git a/src/archivematicaCommon/lib/bindpid.py b/src/archivematicaCommon/lib/bindpid.py index ae0ac305c0..01172a5e0c 100755 --- a/src/archivematicaCommon/lib/bindpid.py +++ b/src/archivematicaCommon/lib/bindpid.py @@ -316,12 +316,12 @@ def _render_request_body(argsdict, resolve_url, qualified_resolve_urls): """ return _render_template( argsdict["pid_request_body_template"], - dict( - naming_authority=argsdict["naming_authority"], - pid=argsdict["desired_pid"], - base_resolve_url=resolve_url, - qualified_resolve_urls=qualified_resolve_urls, - ), + { + "naming_authority": argsdict["naming_authority"], + "pid": argsdict["desired_pid"], + "base_resolve_url": resolve_url, + "qualified_resolve_urls": qualified_resolve_urls, + }, ).encode("utf8") diff --git a/src/archivematicaCommon/lib/email_settings.py b/src/archivematicaCommon/lib/email_settings.py index 5420d0c96e..2e64f489e1 100644 --- a/src/archivematicaCommon/lib/email_settings.py +++ b/src/archivematicaCommon/lib/email_settings.py @@ -59,27 +59,27 @@ def get_settings(config): This should be invoked from a Django settings module and the result merged into the globals() dict. """ - settings = dict( + settings = { # Which backend to use? - EMAIL_BACKEND=config.get("email_backend"), + "EMAIL_BACKEND": config.get("email_backend"), # File Backend # See https://docs.djangoproject.com/en/dev/topics/email/#file-backend - EMAIL_FILE_PATH=config.get("email_file_path"), + "EMAIL_FILE_PATH": config.get("email_file_path"), # SMTP Backend # See https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend - EMAIL_HOST=config.get("email_host"), - EMAIL_HOST_PASSWORD=config.get("email_host_password"), - EMAIL_HOST_USER=config.get("email_host_user"), - EMAIL_PORT=config.get("email_port"), - EMAIL_SSL_CERTFILE=config.get("email_ssl_certfile"), - EMAIL_SSL_KEYFILE=config.get("email_ssl_keyfile"), - EMAIL_USE_SSL=config.get("email_use_ssl"), - EMAIL_USE_TLS=config.get("email_use_tls"), + "EMAIL_HOST": config.get("email_host"), + "EMAIL_HOST_PASSWORD": config.get("email_host_password"), + "EMAIL_HOST_USER": config.get("email_host_user"), + "EMAIL_PORT": config.get("email_port"), + "EMAIL_SSL_CERTFILE": config.get("email_ssl_certfile"), + "EMAIL_SSL_KEYFILE": config.get("email_ssl_keyfile"), + "EMAIL_USE_SSL": config.get("email_use_ssl"), + "EMAIL_USE_TLS": config.get("email_use_tls"), # General settings, not backend-specific - DEFAULT_FROM_EMAIL=config.get("default_from_email"), - EMAIL_SUBJECT_PREFIX=config.get("email_subject_prefix"), - EMAIL_TIMEOUT=config.get("email_timeout", None), - ) + "DEFAULT_FROM_EMAIL": config.get("default_from_email"), + "EMAIL_SUBJECT_PREFIX": config.get("email_subject_prefix"), + "EMAIL_TIMEOUT": config.get("email_timeout", None), + } settings["SERVER_EMAIL"] = config.get("server_email", settings["EMAIL_HOST_USER"]) return settings diff --git a/src/dashboard/src/components/administration/views.py b/src/dashboard/src/components/administration/views.py index d4f41f6ac2..082a6b07d9 100644 --- a/src/dashboard/src/components/administration/views.py +++ b/src/dashboard/src/components/administration/views.py @@ -561,7 +561,7 @@ def general(request): ) forms = (general_form, storage_form, checksum_form) - if all([form.is_valid() for form in forms]): + if all(form.is_valid() for form in forms): for item in forms: item.save() messages.info(request, _("Saved.")) diff --git a/src/dashboard/src/components/archival_storage/tests/test_archival_storage.py b/src/dashboard/src/components/archival_storage/tests/test_archival_storage.py index 91964ebf80..819834bc39 100644 --- a/src/dashboard/src/components/archival_storage/tests/test_archival_storage.py +++ b/src/dashboard/src/components/archival_storage/tests/test_archival_storage.py @@ -271,7 +271,7 @@ def test_search_as_csv(mocker, amsetup, admin_client, tmp_path): response.get(CONTENT_DISPOSITION) == 'attachment; filename="test-filename.csv"' ) - streamed_content = b"".join([content for content in response.streaming_content]) + streamed_content = b"".join(list(response.streaming_content)) csv_file = StringIO(streamed_content.decode("utf8")) assert csv_file.read() == ( diff --git a/src/dashboard/src/main/management/commands/rebuild_transfer_backlog.py b/src/dashboard/src/main/management/commands/rebuild_transfer_backlog.py index e2d6aa48d5..fc04f3797c 100644 --- a/src/dashboard/src/main/management/commands/rebuild_transfer_backlog.py +++ b/src/dashboard/src/main/management/commands/rebuild_transfer_backlog.py @@ -522,13 +522,11 @@ def _import_self_describing_transfer( """ transfer, created = Transfer.objects.get_or_create( uuid=transfer_uuid, - defaults=dict( - type="Standard", - diruuids=False, - currentlocation="%sharedPath%www/AIPsStore/transferBacklog/originals/" - + str(transfer_dir.name) - + "/", - ), + defaults={ + "type": "Standard", + "diruuids": False, + "currentlocation": f"%sharedPath%www/AIPsStore/transferBacklog/originals/{transfer_dir.name}/", + }, ) # The transfer did not exist, we need to populate everything else. diff --git a/src/dashboard/src/main/models.py b/src/dashboard/src/main/models.py index 47b49abe0b..3a00882b87 100644 --- a/src/dashboard/src/main/models.py +++ b/src/dashboard/src/main/models.py @@ -131,12 +131,9 @@ def get_dict(self, scope): {u'foo': u'bar'} """ - return { - key: value - for (key, value) in self.get_queryset() - .filter(scope=scope) - .values_list("name", "value") - } + return dict( + self.get_queryset().filter(scope=scope).values_list("name", "value") + ) def set_dict(self, scope, items): """ diff --git a/src/dashboard/tests/test_api.py b/src/dashboard/tests/test_api.py index 7650df79ff..c790feaf5a 100644 --- a/src/dashboard/tests/test_api.py +++ b/src/dashboard/tests/test_api.py @@ -517,10 +517,8 @@ def test_list_processing_configs(self): assert len(processing_configs) == 2 expected_names = sorted(["default", "automated"]) assert all( - [ - actual == expected - for actual, expected in zip(processing_configs, expected_names) - ] + actual == expected + for actual, expected in zip(processing_configs, expected_names) ) def test_get_existing_processing_config(self): diff --git a/src/dashboard/tests/test_filesystem_ajax.py b/src/dashboard/tests/test_filesystem_ajax.py index 6d87dc5a2a..a6eb3ec035 100644 --- a/src/dashboard/tests/test_filesystem_ajax.py +++ b/src/dashboard/tests/test_filesystem_ajax.py @@ -691,4 +691,4 @@ def test_copy_within_arrange(mocker, admin_client): # Verify SIPArrange instances were created as expected. assert models.SIPArrange.objects.count() == 2 - assert set(list(models.SIPArrange.objects.values_list(*attrs))) == expected + assert set(models.SIPArrange.objects.values_list(*attrs)) == expected diff --git a/src/dashboard/tests/test_transfer.py b/src/dashboard/tests/test_transfer.py index 310e7449fc..a7fce448b8 100644 --- a/src/dashboard/tests/test_transfer.py +++ b/src/dashboard/tests/test_transfer.py @@ -85,9 +85,7 @@ def test_component_post(admin_client): assert "Metadata saved." in response.content.decode() assert set( - list( - TransferMetadataFieldValue.objects.filter( - set=transfer_uuid, field__fieldname__in=["media_format", "media_number"] - ).values_list("fieldvalue") - ) + TransferMetadataFieldValue.objects.filter( + set=transfer_uuid, field__fieldname__in=["media_format", "media_number"] + ).values_list("fieldvalue") ) == {('3.5" floppy',), ("123",)}