From 3dc715264aaf7f2abfd2750dbbc990a845c8ff14 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Tue, 11 Feb 2025 10:04:19 -0400 Subject: [PATCH 1/2] Update pre-commit --- .pre-commit-config.yaml | 16 +++++++------- .../4f716132bf58_upload_logos_to_s3.py | 3 ++- .../7dc7590e1819_remove_library_logo.py | 1 + ...1780_remove_admins_with_empty_passwords.py | 1 + .../versions/aa6b44e2e879_library_logo_url.py | 1 + app.py | 7 ++++--- controller.py | 2 +- model.py | 10 ++++----- scripts.py | 8 +++---- tests/fixtures/database.py | 6 +++--- tests/test_adobe_vendor_id.py | 21 ++++++++----------- tests/test_controller.py | 4 +++- tests/test_util_string_helpers.py | 1 + util/app_server.py | 1 + util/flask_util.py | 1 + util/problem_detail.py | 2 +- 16 files changed, 45 insertions(+), 40 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 17ac535f..4cf6265b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -17,14 +17,14 @@ repos: - id: mixed-line-ending - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.19.1 hooks: - id: pyupgrade args: - --py310-plus - repo: https://github.com/myint/autoflake - rev: v2.0.0 + rev: v2.3.1 hooks: - id: autoflake args: @@ -33,32 +33,32 @@ repos: - --ignore-init-module-imports - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 25.1.0 hooks: - id: black name: Run black - repo: https://github.com/PyCQA/isort - rev: 5.11.5 + rev: 6.0.0 hooks: - id: isort name: Run isort - repo: https://github.com/sirosen/check-jsonschema - rev: 0.19.2 + rev: 0.31.1 hooks: - id: check-github-workflows - id: check-github-actions - repo: https://github.com/pappasam/toml-sort - rev: v0.22.1 + rev: v0.24.2 hooks: - id: toml-sort args: [] files: pyproject.toml - repo: https://github.com/jackdewinter/pymarkdown - rev: v0.9.8 + rev: v0.9.27 hooks: - id: pymarkdown args: diff --git a/alembic/versions/4f716132bf58_upload_logos_to_s3.py b/alembic/versions/4f716132bf58_upload_logos_to_s3.py index 2a64cd6d..993f7ee9 100644 --- a/alembic/versions/4f716132bf58_upload_logos_to_s3.py +++ b/alembic/versions/4f716132bf58_upload_logos_to_s3.py @@ -5,6 +5,7 @@ Create Date: 2022-12-01 08:22:19.889670+00:00 """ + import logging from dataclasses import dataclass @@ -32,7 +33,7 @@ def upgrade() -> None: log.setLevel(logging.INFO) connection = op.get_bind() result = connection.execute("SELECT internal_urn, name, logo FROM libraries;") - for (lib_uuid, lib_name, lib_logo) in result: + for lib_uuid, lib_name, lib_logo in result: if lib_logo: log.info(f"Uploading logo for {lib_name}") uploaded_path = LibraryLogoStore.write_from_b64( diff --git a/alembic/versions/7dc7590e1819_remove_library_logo.py b/alembic/versions/7dc7590e1819_remove_library_logo.py index 7162aeb5..e70a8622 100644 --- a/alembic/versions/7dc7590e1819_remove_library_logo.py +++ b/alembic/versions/7dc7590e1819_remove_library_logo.py @@ -5,6 +5,7 @@ Create Date: 2023-04-28 07:20:50.401126+00:00 """ + import sqlalchemy as sa from alembic import op diff --git a/alembic/versions/9b462df21780_remove_admins_with_empty_passwords.py b/alembic/versions/9b462df21780_remove_admins_with_empty_passwords.py index b4e805cd..24015974 100644 --- a/alembic/versions/9b462df21780_remove_admins_with_empty_passwords.py +++ b/alembic/versions/9b462df21780_remove_admins_with_empty_passwords.py @@ -5,6 +5,7 @@ Create Date: 2023-04-20 21:34:10.306771+00:00 """ + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/aa6b44e2e879_library_logo_url.py b/alembic/versions/aa6b44e2e879_library_logo_url.py index 37bdaef4..8f86f8e7 100644 --- a/alembic/versions/aa6b44e2e879_library_logo_url.py +++ b/alembic/versions/aa6b44e2e879_library_logo_url.py @@ -5,6 +5,7 @@ Create Date: 2022-11-28 08:41:40.026366+00:00 """ + import sqlalchemy as sa from alembic import op diff --git a/app.py b/app.py index 264e8098..0a8d9d82 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ """Library registry web application.""" + import os import sys import urllib.parse @@ -239,9 +240,9 @@ def application_version(): @returns_problem_detail def hearbeat(): version_info = application_version() - version_info[ - "WARNING" - ] = "The /heartbeat endpoint is deprecated. Please use /version.json instead." + version_info["WARNING"] = ( + "The /heartbeat endpoint is deprecated. Please use /version.json instead." + ) return version_info diff --git a/controller.py b/controller.py index 264c15e3..8b81249a 100644 --- a/controller.py +++ b/controller.py @@ -459,7 +459,7 @@ def library_details(self, uuid, library=None, patron_count=None): def _areas(self, areas): result = {} - for (a, b) in [ + for a, b in [ (ServiceArea.FOCUS, "focus"), (ServiceArea.ELIGIBILITY, "service"), ]: diff --git a/model.py b/model.py index 4cb795d0..d763a8eb 100644 --- a/model.py +++ b/model.py @@ -31,7 +31,9 @@ create_engine, ) from sqlalchemy import exc as sa_exc -from sqlalchemy import func +from sqlalchemy import ( + func, +) from sqlalchemy.exc import IntegrityError, MultipleResultsFound, NoResultFound from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import ( @@ -509,7 +511,7 @@ def patron_counts_by_library(self, _db, libraries): # Convert the results to a dictionary. results = dict() - for (library_id, count) in rows: + for library_id, count in rows: results[library_id] = count return results @@ -1217,7 +1219,6 @@ def get_hyperlink(cls, library, rel): class LibraryAlias(Base): - """An alternate name for a library.""" __tablename__ = "libraryalias" @@ -1527,7 +1528,6 @@ def overlaps_not_counting_border(self, qu): return qu.filter(intersects).filter(touches == False) def lookup_inside(self, name, using_overlap=False, using_external_source=True): - """Look up a named Place that is geographically 'inside' this Place. :param name: The name of a place, such as "Boston" or @@ -1707,7 +1707,6 @@ def __repr__(self): class PlaceAlias(Base): - """An alternate name for a place.""" __tablename__ = "placealiases" @@ -2284,7 +2283,6 @@ def _decode(self, _db, token, supposed_signature): class ExternalIntegration(Base): - """An external integration contains configuration for connecting to a third-party API. """ diff --git a/scripts.py b/scripts.py index 98fec119..f6b5ba33 100644 --- a/scripts.py +++ b/scripts.py @@ -286,7 +286,7 @@ def run(self, cmd_args=None, place_class=Place): service_area, focus_area = AuthenticationDocument.parse_service_and_focus_area( self._db, service_area, focus_area, place_class ) - for (valid, unknown, ambiguous) in [service_area, focus_area]: + for valid, unknown, ambiguous in [service_area, focus_area]: if unknown: raise ValueError("Unknown places: %r" % list(unknown.items())) if ambiguous: @@ -637,9 +637,9 @@ def do_run(self, _db=None, cmd_args=None, output=sys.stdout): 'Invalid delegate: %s. Expected something ending with "/AdobeAuth/"' % delegate ) - integration.setting( - Configuration.ADOBE_VENDOR_ID_DELEGATE_URL - ).value = json.dumps(delegates) + integration.setting(Configuration.ADOBE_VENDOR_ID_DELEGATE_URL).value = ( + json.dumps(delegates) + ) _db.commit() diff --git a/tests/fixtures/database.py b/tests/fixtures/database.py index edda12e9..2511f3d7 100644 --- a/tests/fixtures/database.py +++ b/tests/fixtures/database.py @@ -538,9 +538,9 @@ def directory(self) -> str: @pytest.fixture(scope="function") -def temporary_directory_configuration() -> Iterable[ - TemporaryDirectoryConfigurationFixture -]: +def temporary_directory_configuration() -> ( + Iterable[TemporaryDirectoryConfigurationFixture] +): fix = TemporaryDirectoryConfigurationFixture.create() yield fix fix.close() diff --git a/tests/test_adobe_vendor_id.py b/tests/test_adobe_vendor_id.py index 966eef8d..bb757dd9 100644 --- a/tests/test_adobe_vendor_id.py +++ b/tests/test_adobe_vendor_id.py @@ -48,14 +48,11 @@ def dequeue(self, *args, **kwargs): class TestAdobeVendorIdController: - def test_signin_handler(self): - ... + def test_signin_handler(self): ... - def test_userinfo_handler(self): - ... + def test_userinfo_handler(self): ... - def test_status_handler(self): - ... + def test_status_handler(self): ... class VendorIDFixture: @@ -74,9 +71,9 @@ def integration(self): goal=ExternalIntegration.DRM_GOAL, ) integration.setting(Configuration.ADOBE_VENDOR_ID).value = "VENDORID" - integration.setting( - Configuration.ADOBE_VENDOR_ID_NODE_VALUE - ).value = self.NODE_VALUE + integration.setting(Configuration.ADOBE_VENDOR_ID_NODE_VALUE).value = ( + self.NODE_VALUE + ) return integration @@ -107,9 +104,9 @@ def test_accessor_vendor_id_not_configured( def test_accessor_with_delegates(self, vendor_id_fixture: VendorIDFixture): integration = vendor_id_fixture.integration() - integration.setting( - Configuration.ADOBE_VENDOR_ID_DELEGATE_URL - ).value = json.dumps(["delegate"]) + integration.setting(Configuration.ADOBE_VENDOR_ID_DELEGATE_URL).value = ( + json.dumps(["delegate"]) + ) vendor_id, node_value, delegates = Configuration.vendor_id( vendor_id_fixture.db.session ) diff --git a/tests/test_controller.py b/tests/test_controller.py index d39d7968..5e8a4a9c 100644 --- a/tests/test_controller.py +++ b/tests/test_controller.py @@ -1775,7 +1775,7 @@ def test_register_fails_on_missing_email_in_authentication_document( ): fixture = registry_controller_fixture - for (rel, error, badlink) in ( + for rel, error, badlink in ( ( "http://librarysimplified.org/rel/designated-agent/copyright", "Invalid or missing copyright designated agent email address", @@ -1850,6 +1850,7 @@ def test_registration_fails_if_email_server_fails( """Even if everything looks good, registration can fail if the library registry can't send out the validation emails. """ + # Simulate an SMTP server that won't accept email for # whatever reason. class NonfunctionalEmailer(MockEmailer): @@ -1895,6 +1896,7 @@ def test_registration_fails_if_email_server_unusable( WHEN: A registration is requested THEN: A ProblemDetail of an appropriate type should be returned """ + # Simulate an SMTP server that is wholly unresponsive class UnresponsiveEmailer(Emailer): def _send_email(*args): diff --git a/tests/test_util_string_helpers.py b/tests/test_util_string_helpers.py index 9f39c3b8..78182c5b 100644 --- a/tests/test_util_string_helpers.py +++ b/tests/test_util_string_helpers.py @@ -1,4 +1,5 @@ """Test the helper objects in util.string.""" + import base64 as stdlib_base64 import re diff --git a/util/app_server.py b/util/app_server.py index f6345279..9a78e26f 100644 --- a/util/app_server.py +++ b/util/app_server.py @@ -1,4 +1,5 @@ """Implement logic common to more than one of the Simplified applications.""" + import logging import sys import traceback diff --git a/util/flask_util.py b/util/flask_util.py index 7af1b78a..6a17baa3 100644 --- a/util/flask_util.py +++ b/util/flask_util.py @@ -1,4 +1,5 @@ """Utilities for Flask applications.""" + import ipaddress import re diff --git a/util/problem_detail.py b/util/problem_detail.py index 0b3432e0..fcc947d2 100644 --- a/util/problem_detail.py +++ b/util/problem_detail.py @@ -2,6 +2,7 @@ As per http://datatracker.ietf.org/doc/draft-ietf-appsawg-http-problem/ """ + import json as j import logging @@ -22,7 +23,6 @@ def json(type, status, title, detail=None, instance=None, debug_message=None): class ProblemDetail: - """A common type of problem.""" JSON_MEDIA_TYPE = JSON_MEDIA_TYPE From 67c3b3e46828507f4856f343aa378613ae171e08 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Tue, 11 Feb 2025 11:59:40 -0400 Subject: [PATCH 2/2] Roll back isort version --- .pre-commit-config.yaml | 2 +- model.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4cf6265b..865e3c5e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: name: Run black - repo: https://github.com/PyCQA/isort - rev: 6.0.0 + rev: 5.13.2 hooks: - id: isort name: Run isort diff --git a/model.py b/model.py index d763a8eb..989d3ae0 100644 --- a/model.py +++ b/model.py @@ -31,9 +31,7 @@ create_engine, ) from sqlalchemy import exc as sa_exc -from sqlalchemy import ( - func, -) +from sqlalchemy import func from sqlalchemy.exc import IntegrityError, MultipleResultsFound, NoResultFound from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import (