From 97abe3e3fed278ec36cc0e5ea3d5f8715b624ed4 Mon Sep 17 00:00:00 2001 From: vylmen <65908835+vylmen@users.noreply.github.com> Date: Wed, 5 Aug 2020 01:28:40 +0200 Subject: [PATCH] fix(isort): Unbreak CI by upgrading isort Migrate isort configuration, highlights: - Remove future library that is now strictly matched (__future__) and the default. - Sections is still needed, cause we have known_django - create a tox environment that will fix issues according to isort's wishes - Apply changes resulting from the previous --- .isort.cfg | 4 +--- allauth/account/adapter.py | 9 +++++---- allauth/account/app_settings.py | 4 ++-- allauth/socialaccount/providers/base.py | 2 +- allauth/socialaccount/providers/google/tests.py | 5 +++-- allauth/socialaccount/providers/ynab/tests.py | 5 +++-- allauth/utils.py | 5 +++-- tox.ini | 11 +++++++++-- 8 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.isort.cfg b/.isort.cfg index 38d081df08..ba699f3c78 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -6,8 +6,6 @@ include_trailing_comma=1 multi_line_output=3 lines_after_imports=2 known_django=django -known_future_library=future -known_standard_library=types,requests +extra_standard_library=types,requests known_first_party=allauth -default_section=THIRDPARTY sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER diff --git a/allauth/account/adapter.py b/allauth/account/adapter.py index bf2da84c39..8533ec47b9 100644 --- a/allauth/account/adapter.py +++ b/allauth/account/adapter.py @@ -196,7 +196,7 @@ def populate_username(self, request, user): username is already present it is assumed to be valid (unique). """ - from .utils import user_username, user_email, user_field + from .utils import user_email, user_field, user_username first_name = user_field(user, 'first_name') last_name = user_field(user, 'last_name') email = user_email(user) @@ -219,7 +219,7 @@ def save_user(self, request, user, form, commit=True): Saves a new `User` instance using information provided in the signup form. """ - from .utils import user_username, user_email, user_field + from .utils import user_email, user_field, user_username data = form.cleaned_data first_name = data.get('first_name') @@ -415,8 +415,9 @@ def is_safe_url(self, url): try: from django.utils.http import url_has_allowed_host_and_scheme except ImportError: - from django.utils.http import \ - is_safe_url as url_has_allowed_host_and_scheme + from django.utils.http import ( + is_safe_url as url_has_allowed_host_and_scheme, + ) return url_has_allowed_host_and_scheme(url, allowed_hosts=None) diff --git a/allauth/account/app_settings.py b/allauth/account/app_settings.py index a69fd5b77d..ffed204940 100644 --- a/allauth/account/app_settings.py +++ b/allauth/account/app_settings.py @@ -298,8 +298,8 @@ def PRESERVE_USERNAME_CASING(self): @property def USERNAME_VALIDATORS(self): from django.core.exceptions import ImproperlyConfigured - from allauth.utils import import_attribute - from allauth.utils import get_user_model + + from allauth.utils import get_user_model, import_attribute path = self._setting('USERNAME_VALIDATORS', None) if path: diff --git a/allauth/socialaccount/providers/base.py b/allauth/socialaccount/providers/base.py index 6db9b83425..7382de74fe 100644 --- a/allauth/socialaccount/providers/base.py +++ b/allauth/socialaccount/providers/base.py @@ -77,7 +77,7 @@ def sociallogin_from_response(self, request, response): :return: A populated instance of the `SocialLogin` model (unsaved). """ # NOTE: Avoid loading models at top due to registry boot... - from allauth.socialaccount.models import SocialLogin, SocialAccount + from allauth.socialaccount.models import SocialAccount, SocialLogin adapter = get_adapter(request) uid = self.extract_uid(response) diff --git a/allauth/socialaccount/providers/google/tests.py b/allauth/socialaccount/providers/google/tests.py index 76a196d78b..d59ef23b3c 100644 --- a/allauth/socialaccount/providers/google/tests.py +++ b/allauth/socialaccount/providers/google/tests.py @@ -51,8 +51,9 @@ def get_mocked_response(self, (repr(verified_email).lower()))) def test_google_compelete_login_401(self): - from allauth.socialaccount.providers.google.views import \ - GoogleOAuth2Adapter + from allauth.socialaccount.providers.google.views import ( + GoogleOAuth2Adapter, + ) class LessMockedResponse(MockedResponse): def raise_for_status(self): diff --git a/allauth/socialaccount/providers/ynab/tests.py b/allauth/socialaccount/providers/ynab/tests.py index d18f0ec4a2..eb50a71b6e 100644 --- a/allauth/socialaccount/providers/ynab/tests.py +++ b/allauth/socialaccount/providers/ynab/tests.py @@ -33,8 +33,9 @@ def get_mocked_response(self): """) def test_ynab_compelete_login_401(self): - from allauth.socialaccount.providers.ynab.views import \ - YNABOAuth2Adapter + from allauth.socialaccount.providers.ynab.views import ( + YNABOAuth2Adapter, + ) class LessMockedResponse(MockedResponse): def raise_for_status(self): diff --git a/allauth/utils.py b/allauth/utils.py index 71d7c71a97..3fb7701b62 100644 --- a/allauth/utils.py +++ b/allauth/utils.py @@ -96,10 +96,11 @@ def generate_username_candidates(basename): def generate_unique_username(txts, regex=None): - from .account.app_settings import USER_MODEL_USERNAME_FIELD - from .account.adapter import get_adapter from allauth.account.utils import filter_users_by_username + from .account.adapter import get_adapter + from .account.app_settings import USER_MODEL_USERNAME_FIELD + adapter = get_adapter() basename = _generate_unique_username_base(txts, regex) candidates = generate_username_candidates(basename) diff --git a/tox.ini b/tox.ini index 5a322a23a3..86596795f8 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,6 @@ setenv = PYTHONWARNINGS = all deps = coverage - py27: mock >= 1.0.1 django20: Django==2.0.* django21: Django==2.1.* django22: Django==2.2.* @@ -41,7 +40,15 @@ deps = isort commands = flake8 {posargs:{toxinidir}/allauth} - isort --check-only --skip-glob '*/migrations/*' --recursive --diff {posargs:{toxinidir}/allauth} + isort --check-only --skip-glob '*/migrations/*' --diff {posargs:{toxinidir}/allauth} + +[testenv:isort] +basepython = python3.7 +skip_install = True +deps = + isort >5 +commands = + isort --skip-glob '*/migrations/*' {posargs:{toxinidir}/allauth} [testenv:standardjs] skip_install = True