From 9fffa9ea640f6ab6830169b46dddfd8286f6d09d Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 9 Feb 2024 14:45:00 -0400 Subject: [PATCH] Update versions for our pre-commit linters (#6) * Update pre-commit version * Automated changes from black. --- .pre-commit-config.yaml | 16 ++++++++-------- tests/admin/test_library_admin_views.py | 6 +++--- tests/views/test_card_views.py | 8 +++++--- tests/views/test_verification_view.py | 3 ++- virtual_library_card/geoloc.py | 3 ++- virtual_library_card/urls.py | 1 + virtuallibrarycard/admin.py | 12 ++++++------ virtuallibrarycard/business_rules/library.py | 3 ++- .../business_rules/library_card.py | 3 ++- virtuallibrarycard/forms/forms.py | 12 ++++++------ virtuallibrarycard/views/views_library_card.py | 6 +++--- 11 files changed, 40 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 713889d..0d03ef8 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: v4.5.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.3.1 + rev: v3.15.0 hooks: - id: pyupgrade args: - --py38-plus - repo: https://github.com/myint/autoflake - rev: v2.0.0 + rev: v2.2.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: 24.1.1 hooks: - id: black name: Run black - repo: https://github.com/PyCQA/isort - rev: 5.11.5 + rev: 5.13.2 hooks: - id: isort name: Run isort - repo: https://github.com/sirosen/check-jsonschema - rev: 0.19.2 + rev: 0.28.0 hooks: - id: check-github-workflows - id: check-github-actions - repo: https://github.com/pappasam/toml-sort - rev: v0.22.1 + rev: v0.23.1 hooks: - id: toml-sort args: [] files: pyproject.toml - repo: https://github.com/jackdewinter/pymarkdown - rev: v0.9.8 + rev: v0.9.17 hooks: - id: pymarkdown args: diff --git a/tests/admin/test_library_admin_views.py b/tests/admin/test_library_admin_views.py index 7c3e0c1..4c90987 100644 --- a/tests/admin/test_library_admin_views.py +++ b/tests/admin/test_library_admin_views.py @@ -54,9 +54,9 @@ def _add_library_states_data( "library_email_domains-INITIAL_FORMS": 0, "library_email_domains-MIN_NUM_FORMS": 0, "library_email_domains-MAX_NUM_FORMS": 1000, - "library_email_domains-__prefix__-library": library.id - if library - else "", + "library_email_domains-__prefix__-library": ( + library.id if library else "" + ), } ) diff --git a/tests/views/test_card_views.py b/tests/views/test_card_views.py index 439d9cd..45ae0ee 100644 --- a/tests/views/test_card_views.py +++ b/tests/views/test_card_views.py @@ -323,9 +323,11 @@ def test_card_request_bad_data(self): self.assertFormError( resp.context["form"], field, - errors + ["First name is mandatory"] - if field == "first_name" - else errors, + ( + errors + ["First name is mandatory"] + if field == "first_name" + else errors + ), ) def test_card_request_no_patron_address(self): diff --git a/tests/views/test_verification_view.py b/tests/views/test_verification_view.py index 41459a6..a0e7c19 100644 --- a/tests/views/test_verification_view.py +++ b/tests/views/test_verification_view.py @@ -112,7 +112,8 @@ def test_no_password_form(self): def test_password_set_post(self): """Is the password set on a post to the verification form This sounds funny, but the password set form is on the email verification page - because a user may be created without a password, and will subsequently require a password to log in""" + because a user may be created without a password, and will subsequently require a password to log in + """ user = self._default_user token = Tokens.generate( TokenTypes.EMAIL_VERIFICATION, expires_in_days=1, email=user.email diff --git a/virtual_library_card/geoloc.py b/virtual_library_card/geoloc.py index 68b58dd..00d152d 100644 --- a/virtual_library_card/geoloc.py +++ b/virtual_library_card/geoloc.py @@ -65,7 +65,8 @@ class PostProcess: @classmethod def mapquest_reverse_geocode(cls, data: dict) -> None: """Some mapquest data is different than what we expect the hierarchy to be. - Eg. US territories are treated as countries on their own, they should be under the US Country.""" + Eg. US territories are treated as countries on their own, they should be under the US Country. + """ if ( len(data.get("results", [])) < 1 or len(locations := data["results"][0].get("locations", [])) < 1 diff --git a/virtual_library_card/urls.py b/virtual_library_card/urls.py index d331f16..b352b96 100644 --- a/virtual_library_card/urls.py +++ b/virtual_library_card/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.conf import settings from django.conf.urls.static import static from django.urls import include, path diff --git a/virtuallibrarycard/admin.py b/virtuallibrarycard/admin.py index d5f8ad7..123b17d 100644 --- a/virtuallibrarycard/admin.py +++ b/virtuallibrarycard/admin.py @@ -395,9 +395,9 @@ def change_view( """Overridden to add the password reset url extra context""" user = LibraryCard.objects.get(id=object_id).user if user: - extra_context[ - "reset_password_url" - ] = f"../../../customuser/{user.id}/password" + extra_context["reset_password_url"] = ( + f"../../../customuser/{user.id}/password" + ) return super().change_view(request, object_id, form_url, extra_context) @@ -524,9 +524,9 @@ def export_users_by_consent(request: HttpRequest): content.seek(0) response = StreamingHttpResponse(content, content_type="text/csv") - response[ - "Content-Disposition" - ] = f"attachment; filename=consented_users_{consent_type}_{datetime.datetime.now()}.csv" + response["Content-Disposition"] = ( + f"attachment; filename=consented_users_{consent_type}_{datetime.datetime.now()}.csv" + ) return response diff --git a/virtuallibrarycard/business_rules/library.py b/virtuallibrarycard/business_rules/library.py index 3786d4e..ee86722 100644 --- a/virtuallibrarycard/business_rules/library.py +++ b/virtuallibrarycard/business_rules/library.py @@ -37,7 +37,8 @@ def _place_hierarchy_match( country: str = None, ) -> bool: """Test from the current place all the way to the last parent available. - All levels of the place hierarchy MUST match even if the value isn't provided in the keyword args.""" + All levels of the place hierarchy MUST match even if the value isn't provided in the keyword args. + """ match_types = { Place.Types.COUNTRY: country, Place.Types.STATE: state, diff --git a/virtuallibrarycard/business_rules/library_card.py b/virtuallibrarycard/business_rules/library_card.py index a32c592..006a378 100644 --- a/virtuallibrarycard/business_rules/library_card.py +++ b/virtuallibrarycard/business_rules/library_card.py @@ -260,7 +260,8 @@ def iter_clean_lines(io: IO) -> Generator[str, None, None]: """Iterate over an IO object and ignore blank lines This is to specifically ignore empty last lines in csvs decoding is done through charset detection - This handles unicode BOM characters since we do not control how the browser might read the file""" + This handles unicode BOM characters since we do not control how the browser might read the file + """ # Detect charset and the decode entire file detectline = io.read(128) io.seek(0) diff --git a/virtuallibrarycard/forms/forms.py b/virtuallibrarycard/forms/forms.py index 8325cf3..a0c08c9 100644 --- a/virtuallibrarycard/forms/forms.py +++ b/virtuallibrarycard/forms/forms.py @@ -250,12 +250,12 @@ def __init__(self, *args, **kwargs): if ( instance and not instance.place ): # Edition just after creation form with minimal fields - self.fields[ - "email" - ].widget.value_from_datadict = lambda *args: self.instance.email - self.fields[ - "first_name" - ].widget.value_from_datadict = lambda *args: self.instance.first_name + self.fields["email"].widget.value_from_datadict = ( + lambda *args: self.instance.email + ) + self.fields["first_name"].widget.value_from_datadict = ( + lambda *args: self.instance.first_name + ) self.fields["email"].widget.attrs["disabled"] = True except KeyError as e: diff --git a/virtuallibrarycard/views/views_library_card.py b/virtuallibrarycard/views/views_library_card.py index bcc501c..8db4a08 100644 --- a/virtuallibrarycard/views/views_library_card.py +++ b/virtuallibrarycard/views/views_library_card.py @@ -158,9 +158,9 @@ def get_form_kwargs(self): def get_context_data(self, *args, **kwargs): context = super().get_context_data(**kwargs) - context[ - "patron_address_mandatory" - ] = self.model.library.patron_address_mandatory + context["patron_address_mandatory"] = ( + self.model.library.patron_address_mandatory + ) return context def get_success_url(self):