Skip to content

Commit

Permalink
chore: switch linting and formatting to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Apr 26, 2024
1 parent 2e37568 commit bdda3e3
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Expand Up @@ -4,7 +4,7 @@

- [ ] Make sure you use [semantic commit messages](https://seesparkbox.com/foundry/semantic_commit_messages).
Examples: `"fix(google): Fixed foobar bug"`, `"feat(accounts): Added foobar feature"`.
- [ ] All Python code must formatted using Black, and clean from pep8 and isort issues.
- [ ] All Python code must formatted using `ruff format` and clean from `ruff check` issues.
- [ ] JavaScript code should adhere to [StandardJS](https://standardjs.com).
- [ ] If your changes are significant, please update `ChangeLog.rst`.
- [ ] If your change is substantial, feel free to add yourself to `AUTHORS`.
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Expand Up @@ -22,19 +22,18 @@ mo:

.PHONY: isort
isort:
isort .
ruff --select=I --fix

.PHONY: black
black:
black allauth/ setup.py
ruff format

.PHONY: test
test:
pytest allauth/

.PHONY: qa
qa:
flake8 allauth
isort --check-only --diff .
black --check .
ruff check
ruff format --check
djlint --check allauth examples
4 changes: 2 additions & 2 deletions allauth/account/adapter.py
Expand Up @@ -452,7 +452,7 @@ def pre_login(
signal_kwargs,
email,
signup,
redirect_url
redirect_url,
):
if not user.is_active:
return self.respond_user_inactive(request, user)
Expand All @@ -466,7 +466,7 @@ def post_login(
signal_kwargs,
email,
signup,
redirect_url
redirect_url,
):
from .utils import get_login_redirect_url

Expand Down
5 changes: 3 additions & 2 deletions allauth/account/utils.py
Expand Up @@ -405,8 +405,9 @@ def filter_users_by_username(*username):
else:
ret = get_user_model()._default_manager.filter(
**{
app_settings.USER_MODEL_USERNAME_FIELD
+ "__in": [u.lower() for u in username]
app_settings.USER_MODEL_USERNAME_FIELD + "__in": [
u.lower() for u in username
]
}
)
return ret
Expand Down
4 changes: 1 addition & 3 deletions allauth/mfa/models.py
Expand Up @@ -40,9 +40,7 @@ def wrap(self):
return {
self.Type.TOTP: TOTP,
self.Type.RECOVERY_CODES: RecoveryCodes,
}[
self.type
](self)
}[self.type](self)

def record_usage(self):
self.last_used_at = timezone.now()
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/internal/flows/login.py
Expand Up @@ -71,5 +71,5 @@ def record_authentication(request, sociallogin):
**{
"provider": sociallogin.account.provider,
"uid": sociallogin.account.uid,
}
},
)
4 changes: 1 addition & 3 deletions allauth/socialaccount/providers/baidu/views.py
Expand Up @@ -10,9 +10,7 @@ class BaiduOAuth2Adapter(OAuth2Adapter):
provider_id = "baidu"
access_token_url = "https://openapi.baidu.com/oauth/2.0/token"
authorize_url = "https://openapi.baidu.com/oauth/2.0/authorize"
profile_url = (
"https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser" # noqa
)
profile_url = "https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser" # noqa

def complete_login(self, request, app, token, **kwargs):
resp = (
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/battlenet/views.py
Expand Up @@ -12,6 +12,7 @@
* The Battle.net API forum:
https://us.battle.net/en/forum/15051532/
"""

from django.conf import settings

from allauth.socialaccount.adapter import get_adapter
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/providers/drip/views.py
@@ -1,4 +1,5 @@
"""Views for Drip API."""

from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
Expand All @@ -8,7 +9,6 @@


class DripOAuth2Adapter(OAuth2Adapter):

"""OAuth2Adapter for Drip API v3."""

provider_id = "drip"
Expand Down
3 changes: 1 addition & 2 deletions allauth/socialaccount/providers/eventbrite/provider.py
@@ -1,4 +1,5 @@
"""Customise Provider classes for Eventbrite API v3."""

from allauth.account.models import EmailAddress
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.eventbrite.views import (
Expand All @@ -8,7 +9,6 @@


class EventbriteAccount(ProviderAccount):

"""ProviderAccount subclass for Eventbrite."""

def get_avatar_url(self):
Expand All @@ -17,7 +17,6 @@ def get_avatar_url(self):


class EventbriteProvider(OAuth2Provider):

"""OAuth2Provider subclass for Eventbrite."""

id = "eventbrite"
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/providers/eventbrite/tests.py
@@ -1,12 +1,12 @@
"""Test Eventbrite OAuth2 v3 Flow."""

from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase

from .provider import EventbriteProvider


class EventbriteTests(OAuth2TestsMixin, TestCase):

"""Test Class for Eventbrite OAuth2 v3."""

provider_id = EventbriteProvider.id
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/eventbrite/urls.py
@@ -1,4 +1,5 @@
"""Register urls for EventbriteProvider"""

from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns

from .provider import EventbriteProvider
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/providers/eventbrite/views.py
@@ -1,4 +1,5 @@
"""Views for Eventbrite API v3."""

from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
Expand All @@ -8,7 +9,6 @@


class EventbriteOAuth2Adapter(OAuth2Adapter):

"""OAuth2Adapter for Eventbrite API v3."""

provider_id = "eventbrite"
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/hubspot/views.py
@@ -1,4 +1,5 @@
"""Views for Hubspot API."""

from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
Expand Down
4 changes: 1 addition & 3 deletions allauth/socialaccount/providers/linkedin_oauth2/provider.py
Expand Up @@ -99,9 +99,7 @@ def get_avatar_url(self):
[
{},
],
)[
0
].get("identifier")
)[0].get("identifier")
if to_return:
return to_return
return super(LinkedInOAuth2Account, self).get_avatar_url()
Expand Down
3 changes: 1 addition & 2 deletions allauth/socialaccount/providers/mailchimp/provider.py
@@ -1,4 +1,5 @@
"""Customise Provider classes for MailChimp API v3."""

from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.mailchimp.views import (
MailChimpOAuth2Adapter,
Expand All @@ -7,7 +8,6 @@


class MailChimpAccount(ProviderAccount):

"""ProviderAccount subclass for MailChimp."""

def get_profile_url(self):
Expand All @@ -20,7 +20,6 @@ def get_avatar_url(self):


class MailChimpProvider(OAuth2Provider):

"""OAuth2Provider subclass for MailChimp v3."""

id = "mailchimp"
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/providers/mailchimp/tests.py
@@ -1,12 +1,12 @@
"""Test MailChimp OAuth2 v3 Flow."""

from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase

from .provider import MailChimpProvider


class MailChimpTests(OAuth2TestsMixin, TestCase):

"""Test Class for MailChimp OAuth2 v3."""

provider_id = MailChimpProvider.id
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/mailchimp/urls.py
@@ -1,4 +1,5 @@
"""Register urls for MailChimpProvider"""

from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns

from .provider import MailChimpProvider
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/providers/mailchimp/views.py
@@ -1,4 +1,5 @@
"""Views for MailChimp API v3."""

from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
Expand All @@ -8,7 +9,6 @@


class MailChimpOAuth2Adapter(OAuth2Adapter):

"""OAuth2Adapter for MailChimp API v3."""

provider_id = "mailchimp"
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/patreon/provider.py
@@ -1,6 +1,7 @@
"""
Provider for Patreon
"""

from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
from allauth.socialaccount.providers.patreon.views import PatreonOAuth2Adapter
Expand Down
4 changes: 3 additions & 1 deletion allauth/socialaccount/providers/quickbooks/views.py
Expand Up @@ -10,7 +10,9 @@ class QuickBooksOAuth2Adapter(OAuth2Adapter):
provider_id = "quickbooks"
access_token_url = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"
authorize_url = "https://appcenter.intuit.com/connect/oauth2"
profile_test = "https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo" # NOQA
profile_test = (
"https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo" # NOQA
)
profile_url = "https://accounts.platform.intuit.com/v1/openid_connect/userinfo"
profile_url_method = "GET"
access_token_method = "POST"
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/steam/views.py
Expand Up @@ -12,6 +12,7 @@
* Steam Partner API documentation
https://partner.steamgames.com/doc/features/auth#website
"""

from django.urls import reverse

from allauth.socialaccount.providers.openid.views import (
Expand Down
5 changes: 3 additions & 2 deletions allauth/socialaccount/providers/trainingpeaks/tests.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
"""
Run just this suite:
python manage.py test allauth.socialaccount.providers.trainingpeaks.tests.TrainingPeaksTests
Run just this suite:
python manage.py test allauth.socialaccount.providers.trainingpeaks.tests.TrainingPeaksTests
"""

from __future__ import unicode_literals

from collections import namedtuple
Expand Down
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/vimeo_oauth2/provider.py
@@ -1,6 +1,7 @@
"""
Provider for Patreon
"""

from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
from allauth.socialaccount.providers.vimeo_oauth2.views import (
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/sessions.py
Expand Up @@ -51,7 +51,7 @@ def save(self, response):
path=urlparse(response.url).path,
secure=settings.SESSION_COOKIE_SECURE,
httponly=None,
**kwargs
**kwargs,
)

def delete(self):
Expand Down
6 changes: 3 additions & 3 deletions allauth/socialaccount/tests/test_login.py
Expand Up @@ -47,9 +47,9 @@ def test_email_authentication(
settings.SOCIALACCOUNT_PROVIDERS = copy.deepcopy(
settings.SOCIALACCOUNT_PROVIDERS
)
settings.SOCIALACCOUNT_PROVIDERS["openid_connect"][
"EMAIL_AUTHENTICATION"
] = True
settings.SOCIALACCOUNT_PROVIDERS["openid_connect"]["EMAIL_AUTHENTICATION"] = (
True
)
else:
settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION = False
settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = auto_connect
Expand Down
1 change: 1 addition & 0 deletions examples/react-spa/backend/backend/urls.py
Expand Up @@ -14,6 +14,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.contrib import admin
from django.urls import include, path

Expand Down
1 change: 1 addition & 0 deletions examples/react-spa/backend/manage.py
@@ -1,5 +1,6 @@
#!/nix/store/qp5zys77biz7imbk6yy85q5pdv7qk84j-python3-3.11.6/bin/python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
@@ -1,3 +1,21 @@
[build-system]
requires = ['setuptools>=40.8.0']
build-backend = 'setuptools.build_meta'

[tool.ruff]
line-length = 88

[tool.ruff.lint.isort]
from-first = false
combine-as-imports = true
lines-after-imports = 2
extra-standard-library = ["types", "requests"]
known-first-party = ["allauth"]
section-order = ["future", "standard-library", "django", "third-party", "first-party", "local-folder"]

[tool.ruff.lint.isort.sections]
"django" = ["django"]

[tool.ruff.lint]
extend-select = ["I"]
extend-ignore = ["E203", "E501", "E231"]
18 changes: 0 additions & 18 deletions setup.cfg
Expand Up @@ -66,21 +66,3 @@ socialaccount =
exclude =
examples
tests

[isort]
indent=4
combine_star=1
combine_as_imports=1
include_trailing_comma=1
multi_line_output=3
lines_after_imports=2
known_django=django
extra_standard_library=types,requests
known_first_party=allauth
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER


[flake8]
max-line-length = 88
# Black
ignore = E203, W503, E501, E231
11 changes: 5 additions & 6 deletions shell.nix
Expand Up @@ -9,11 +9,10 @@ stdenv.mkDerivation {
djlint
nodejs
python310
python310Packages.django
python310Packages.flake8
python310Packages.daphne
python310Packages.debugpy
python310Packages.pycodestyle
python310Packages.pyls-flake8
python310Packages.django
python310Packages.pyls-ruff
python310Packages.pylsp-rope
python310Packages.pytest
python310Packages.pytest-cov
Expand All @@ -22,10 +21,10 @@ stdenv.mkDerivation {
python310Packages.python3-openid
python310Packages.python3-saml
python310Packages.qrcode
python310Packages.sphinx-rtd-theme
python310Packages.requests-oauthlib
python310Packages.ruff
python310Packages.sphinx-rtd-theme
python310Packages.tox
python310Packages.daphne
sphinx
twine
];
Expand Down

0 comments on commit bdda3e3

Please sign in to comment.