From 93b4de1315d2b952028a221748c5b61458a58084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=ED=98=B8?= Date: Sat, 24 Feb 2024 13:29:46 +0900 Subject: [PATCH 01/18] Binding DB sessions based on SQLAlchemy 1, changing how to declare Base Model classes, and other code modernization - DB session binding based on SQLAlchemy 2, Base Model class declaration method change - Reflected select, delete code based on SQLAlchemy 2 - Changed how to declare Model class based on SQLAlchemy 2 - Fixed social login not connecting issue found while testing example program code (for example-pyramid) - Fixed issue with social connection termination (for example-cherrypy, example-tornado, example-webpy) - Added local_settings.py.template file to some example folders to make it easier to create local_settings.py files - Fixed import errors found in several examples --- CHANGELOG.md | 15 +++ example-cherrypy/example/app.py | 6 +- example-cherrypy/example/db/__init__.py | 5 +- example-cherrypy/example/db/saplugin.py | 8 +- example-cherrypy/example/db/user.py | 16 ++- example-flask-mongoengine/manage.py | 18 ++- example-flask-mongoengine/requirements.txt | 1 - example-flask-peewee/manage.py | 16 ++- example-flask-peewee/requirements.txt | 1 - example-flask/example/__init__.py | 9 +- example-flask/example/models/user.py | 22 +-- example-flask/manage.py | 22 +-- example-flask/requirements.txt | 1 - example-pyramid/example/__init__.py | 2 +- example-pyramid/example/auth.py | 3 +- .../example/local_settings.py.template | 126 +++++++++--------- example-pyramid/example/models.py | 27 ++-- .../example/scripts/initializedb.py | 2 +- example-pyramid/example/views.py | 1 - example-tornado/example/app.py | 17 ++- .../example/local_settings.py.template | 89 +++++++++++++ example-tornado/example/models.py | 18 +-- example-tornado/example/settings.py | 2 +- example-webpy/app.py | 117 +--------------- example-webpy/local_settings.py.template | 89 +++++++++++++ example-webpy/models.py | 23 ++-- example-webpy/settings.py | 103 ++++++++++++++ 27 files changed, 488 insertions(+), 271 deletions(-) mode change 100755 => 100644 example-flask/manage.py create mode 100644 example-tornado/example/local_settings.py.template create mode 100644 example-webpy/local_settings.py.template create mode 100644 example-webpy/settings.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a58ee..024b555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/). codebase - Use host 0.0.0.0 for test servers - Fix bug with example-flask-peewee import +- Fix bug with example-cherrypy import (Specify parent package name when importing setting, local_setting modules) +- Changed the DB session creation, DB connection closing, and DB model creation to align with SQLAlchemy 2. (for example-flask program) +- Removed flask-script package from requirements.txt as it doesn't work with recent flasks (programs: example-flask, example-flask-mongoengine, example-flask-peewee) +- Configured the manage.py file to use the CLI environment built into flask (programs: example-flask, example-flask-mongoengine, example-flask-peewee) as the flask-script package has been removed +- Changed the part that binds the DB session to comply with SQLAlchemy 2 (for example-pyramid program) +- Changed the part that fetches authenticated users from DB to be SQLAlchemy 2 based (for example-pyramid program) +- Removed all entries in the SOCIAL_AUTH_KEYS dictionary in local_settings.py.template into a single variable (tests showed that adding provider-supplied key information in SOCIAL_AUTH_KEYS caused errors on social login) (for example-pyramid program) +- Changed the DB model creation part. (for example-pyramid program) +- Error occurred when social login integration was completed because it was supposed to find google plus ID in the redirected URL. google plus is discontinued, so delete the part that gets plus ID. (for example-pyramid program) +- Changed the part that binds the DB session and creates the Base Model class to comply with SQLAlchemy 2 (for example-tornado, example-webpy program) +- Added local_settings.py.template file to reference other programs to easily generate local_settings.py (for example-tornado, example-webpy program) +- Fixed an error importing the local_settings module from settings.py (for the example-tornado program) +- Change the declaration of the Model class based on SQLAlchemy 2 (corresponds to the example-tornado, example-webpy program) +- Fix bug with example-webpy import +- Separated AUTHENTICATION_BACKENDS and PIPELINE entries into separate settings.py entries as web.config entries in app.py (for example-webpy program) \ No newline at end of file diff --git a/example-cherrypy/example/app.py b/example-cherrypy/example/app.py index 3ee8cea..47a51e9 100644 --- a/example-cherrypy/example/app.py +++ b/example-cherrypy/example/app.py @@ -2,7 +2,7 @@ import sys import cherrypy -import settings +from example import settings from common import filters from common.utils import common_context, url_for from jinja2 import Environment, FileSystemLoader @@ -66,7 +66,7 @@ def get_settings(module): SOCIAL_SETTINGS = get_settings(settings) try: - import local_settings + from example import local_settings SOCIAL_SETTINGS.update(get_settings(local_settings)) except ImportError: @@ -82,7 +82,7 @@ def run_app(listen_address="0.0.0.0:8001"): "server.socket_port": int(port), "server.socket_host": host, "tools.sessions.on": True, - "tools.sessions.storage_type": "ram", + "tools.sessions.storage_class": cherrypy.lib.sessions.RamSession, "tools.db.on": True, "tools.authenticate.on": True, "SOCIAL_AUTH_USER_MODEL": "example.db.user.User", diff --git a/example-cherrypy/example/db/__init__.py b/example-cherrypy/example/db/__init__.py index 860e542..f75ec44 100644 --- a/example-cherrypy/example/db/__init__.py +++ b/example-cherrypy/example/db/__init__.py @@ -1,3 +1,4 @@ -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import DeclarativeBase -Base = declarative_base() +class Base(DeclarativeBase): + pass diff --git a/example-cherrypy/example/db/saplugin.py b/example-cherrypy/example/db/saplugin.py index b670615..26043a4 100644 --- a/example-cherrypy/example/db/saplugin.py +++ b/example-cherrypy/example/db/saplugin.py @@ -1,13 +1,13 @@ from cherrypy.process import plugins from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker +from sqlalchemy.orm import Session class SAEnginePlugin(plugins.SimplePlugin): def __init__(self, bus, connection_string=None): self.sa_engine = None self.connection_string = connection_string - self.session = scoped_session(sessionmaker(autoflush=True, autocommit=False)) + self.session = Session(autoflush=True, autocommit=False) super().__init__(bus) def start(self): @@ -23,7 +23,7 @@ def stop(self): self.sa_engine = None def bind(self): - self.session.configure(bind=self.sa_engine) + self.session.bind = self.sa_engine return self.session def commit(self): @@ -33,4 +33,4 @@ def commit(self): self.session.rollback() raise finally: - self.session.remove() + self.session.close() diff --git a/example-cherrypy/example/db/user.py b/example-cherrypy/example/db/user.py index 2fc69bf..2576764 100644 --- a/example-cherrypy/example/db/user.py +++ b/example-cherrypy/example/db/user.py @@ -1,16 +1,18 @@ -from sqlalchemy import Boolean, Column, Integer, String +from sqlalchemy import Boolean, String +from sqlalchemy.orm import Mapped, mapped_column +from typing import Optional from . import Base class User(Base): __tablename__ = "users" - id = Column(Integer, primary_key=True) - username = Column(String(200)) - password = Column(String(200), default="") - name = Column(String(100)) - email = Column(String(200)) - active = Column(Boolean, default=True) + id: Mapped[int] = mapped_column(primary_key=True) + username: Mapped[str] = mapped_column(String(200)) + password: Mapped[str] = mapped_column(String(200), default="") + name: Mapped[Optional[str]] = mapped_column(String(100)) + email: Mapped[Optional[str]] = mapped_column(String(200)) + active: Mapped[bool] = mapped_column(default=True) def is_active(self): return self.active diff --git a/example-flask-mongoengine/manage.py b/example-flask-mongoengine/manage.py index 62e69c9..6d99d8b 100755 --- a/example-flask-mongoengine/manage.py +++ b/example-flask-mongoengine/manage.py @@ -1,11 +1,17 @@ #!/usr/bin/env python from example import app, db -from flask_script import Manager, Server, Shell +import click +from flask.cli import FlaskGroup -manager = Manager(app) -manager.add_command("runserver", Server()) -manager.add_command("shell", Shell(make_context=lambda: {"app": app, "db": db})) +@click.group(cls=FlaskGroup, create_app=lambda: app) +def cli(): + """Management script for the Example Flask Social Login application.""" -if __name__ == "__main__": - manager.run() + @app.shell_context_processor + def make_shell_context(): + return dict(db=db) + + +if __name__ == '__main__': + cli() diff --git a/example-flask-mongoengine/requirements.txt b/example-flask-mongoengine/requirements.txt index 3312328..f5591f7 100644 --- a/example-flask-mongoengine/requirements.txt +++ b/example-flask-mongoengine/requirements.txt @@ -1,4 +1,3 @@ -r ../requirements.txt -flask-script flask-mongoengine social-auth-app-flask-mongoengine diff --git a/example-flask-peewee/manage.py b/example-flask-peewee/manage.py index 4904628..7701959 100755 --- a/example-flask-peewee/manage.py +++ b/example-flask-peewee/manage.py @@ -1,13 +1,15 @@ #!/usr/bin/env python from example import app, database -from flask_script import Manager, Server, Shell +import click +from flask.cli import FlaskGroup -manager = Manager(app) -manager.add_command("runserver", Server()) -manager.add_command("shell", Shell(make_context=lambda: {"app": app})) +@click.group(cls=FlaskGroup, create_app=lambda: app) +def cli(): + """Management script for the Example Flask Social Login application.""" -@manager.command + +@app.cli.command() def syncdb(): from example.models.user import User from social_flask_peewee.models import FlaskStorage @@ -24,5 +26,5 @@ def syncdb(): model.create_table(True) -if __name__ == "__main__": - manager.run() +if __name__ == '__main__': + cli() diff --git a/example-flask-peewee/requirements.txt b/example-flask-peewee/requirements.txt index a57c0a8..100c350 100644 --- a/example-flask-peewee/requirements.txt +++ b/example-flask-peewee/requirements.txt @@ -1,3 +1,2 @@ -r ../requirements.txt -flask-script social-auth-app-flask-peewee diff --git a/example-flask/example/__init__.py b/example-flask/example/__init__.py index 88ee9f7..4a9bec4 100644 --- a/example-flask/example/__init__.py +++ b/example-flask/example/__init__.py @@ -10,7 +10,7 @@ from social_flask.utils import load_strategy from social_flask_sqlalchemy.models import init_social from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker +from sqlalchemy.orm import Session BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -25,8 +25,7 @@ # DB engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"]) -Session = sessionmaker(autocommit=False, autoflush=False, bind=engine) -db_session = scoped_session(Session) +db_session = Session(engine, autocommit=False, autoflush=False) app.register_blueprint(social_auth) init_social(app, db_session) @@ -42,7 +41,7 @@ @login_manager.user_loader def load_user(userid): try: - return models.user.User.query.get(int(userid)) + return db_session.get(models.user.User, int(userid)) except (TypeError, ValueError): pass @@ -60,7 +59,7 @@ def commit_on_success(error=None): else: db_session.rollback() - db_session.remove() + db_session.close() @app.context_processor diff --git a/example-flask/example/models/user.py b/example-flask/example/models/user.py index 2af04b7..7f4121f 100644 --- a/example-flask/example/models/user.py +++ b/example-flask/example/models/user.py @@ -1,20 +1,22 @@ +from typing import Optional from example import db_session from flask_login import UserMixin -from sqlalchemy import Boolean, Column, Integer, String -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy import String +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column -Base = declarative_base() -Base.query = db_session.query_property() + +class Base(DeclarativeBase): + pass class User(Base, UserMixin): __tablename__ = "users" - id = Column(Integer, primary_key=True) - username = Column(String(200)) - password = Column(String(200), default="") - name = Column(String(100)) - email = Column(String(200)) - active = Column(Boolean, default=True) + id: Mapped[int] = mapped_column(primary_key=True) + username: Mapped[str] = mapped_column(String(200)) + password: Mapped[str] = mapped_column(String(200), default="") + name: Mapped[Optional[str]] = mapped_column(String(100)) + email: Mapped[Optional[str]] = mapped_column(String(200)) + active: Mapped[bool] = mapped_column(default=True) def is_active(self): return self.active diff --git a/example-flask/manage.py b/example-flask/manage.py old mode 100755 new mode 100644 index 383962e..51c5c85 --- a/example-flask/manage.py +++ b/example-flask/manage.py @@ -1,15 +1,17 @@ -#!/usr/bin/env python +import click +from flask.cli import FlaskGroup from example import app, db_session, engine -from flask_script import Manager, Server, Shell -manager = Manager(app) -manager.add_command("runserver", Server()) -manager.add_command( - "shell", Shell(make_context=lambda: {"app": app, "db_session": db_session}) -) +@click.group(cls=FlaskGroup, create_app=lambda: app) +def cli(): + """Management script for the Example Flask Social Login application.""" -@manager.command + @app.shell_context_processor + def make_shell_context(): + return dict(db_session=db_session) + +@app.cli.command() def syncdb(): from example.models import user from social_flask_sqlalchemy import models @@ -18,5 +20,5 @@ def syncdb(): models.PSABase.metadata.create_all(engine) -if __name__ == "__main__": - manager.run() +if __name__ == '__main__': + cli() diff --git a/example-flask/requirements.txt b/example-flask/requirements.txt index 9ce1c8d..4f9fe7a 100644 --- a/example-flask/requirements.txt +++ b/example-flask/requirements.txt @@ -1,7 +1,6 @@ -r ../requirements.txt Flask Flask-Login -Flask-Script Werkzeug Jinja2 social-auth-app-flask diff --git a/example-pyramid/example/__init__.py b/example-pyramid/example/__init__.py index 5b8e7bb..c9e9afa 100644 --- a/example-pyramid/example/__init__.py +++ b/example-pyramid/example/__init__.py @@ -22,7 +22,7 @@ def get_settings(module): def main(global_config, **settings): """This function returns a Pyramid WSGI application.""" engine = engine_from_config(settings, "sqlalchemy.") - DBSession.configure(bind=engine) + DBSession.bind = engine Base.metadata.bind = engine session_factory = SignedCookieSessionFactory("thisisasecret") settings["jinja2.globals"] = {"url": utils.url_for} diff --git a/example-pyramid/example/auth.py b/example-pyramid/example/auth.py index 2faf33c..144e1a6 100644 --- a/example-pyramid/example/auth.py +++ b/example-pyramid/example/auth.py @@ -1,4 +1,5 @@ from example.models import DBSession, User +from sqlalchemy import select from pyramid.events import BeforeRender, subscriber from social_pyramid.utils import backends @@ -14,7 +15,7 @@ def login_required(request): def get_user(request): user_id = request.session.get("user_id") if user_id: - user = DBSession.query(User).filter(User.id == user_id).first() + user = DBSession.scalar(select(User).where(User.id == user_id)) else: user = None return user diff --git a/example-pyramid/example/local_settings.py.template b/example-pyramid/example/local_settings.py.template index 8fac843..479b3cd 100644 --- a/example-pyramid/example/local_settings.py.template +++ b/example-pyramid/example/local_settings.py.template @@ -1,94 +1,92 @@ -SOCIAL_AUTH_KEYS = { - 'SOCIAL_AUTH_GOOGLE_OAUTH2_KEY': '', - 'SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET': '', +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' - 'SOCIAL_AUTH_TWITTER_KEY': '', - 'SOCIAL_AUTH_TWITTER_SECRET': '', +SOCIAL_AUTH_TWITTER_KEY = '' +SOCIAL_AUTH_TWITTER_SECRET = '' - 'SOCIAL_AUTH_STRIPE_KEY': '', - 'SOCIAL_AUTH_STRIPE_SECRET': '', - 'SOCIAL_AUTH_STRIPE_SCOPE': [], +SOCIAL_AUTH_STRIPE_KEY = '' +SOCIAL_AUTH_STRIPE_SECRET = '' +SOCIAL_AUTH_STRIPE_SCOPE = [] - 'SOCIAL_AUTH_FACEBOOK_KEY': '', - 'SOCIAL_AUTH_FACEBOOK_SECRET': '', +SOCIAL_AUTH_FACEBOOK_KEY = '' +SOCIAL_AUTH_FACEBOOK_SECRET = '' - 'SOCIAL_AUTH_FACEBOOK_APP_KEY': '', - 'SOCIAL_AUTH_FACEBOOK_APP_SECRET': '', - 'SOCIAL_AUTH_FACEBOOK_APP_NAMESPACE': '', +SOCIAL_AUTH_FACEBOOK_APP_KEY = '' +SOCIAL_AUTH_FACEBOOK_APP_SECRET = '' +SOCIAL_AUTH_FACEBOOK_APP_NAMESPACE = '' - 'SOCIAL_AUTH_YAHOO_OAUTH_KEY': '', - 'SOCIAL_AUTH_YAHOO_OAUTH_SECRET': '', +SOCIAL_AUTH_YAHOO_OAUTH_KEY = '' +SOCIAL_AUTH_YAHOO_OAUTH_SECRET = '' - 'SOCIAL_AUTH_ANGEL_KEY': '', - 'SOCIAL_AUTH_ANGEL_SECRET': '', +SOCIAL_AUTH_ANGEL_KEY = '' +SOCIAL_AUTH_ANGEL_SECRET = '' - 'SOCIAL_AUTH_BEHANCE_KEY': '', - 'SOCIAL_AUTH_BEHANCE_SECRET': '', - 'SOCIAL_AUTH_BEHANCE_SCOPE': [], +SOCIAL_AUTH_BEHANCE_KEY = '' +SOCIAL_AUTH_BEHANCE_SECRET = '' +SOCIAL_AUTH_BEHANCE_SCOPE = [] - 'SOCIAL_AUTH_BITBUCKET_KEY': '', - 'SOCIAL_AUTH_BITBUCKET_SECRET': '', +SOCIAL_AUTH_BITBUCKET_KEY = '' +SOCIAL_AUTH_BITBUCKET_SECRET = '' - 'SOCIAL_AUTH_LINKEDIN_KEY': '', - 'SOCIAL_AUTH_LINKEDIN_SECRET': '', - 'SOCIAL_AUTH_LINKEDIN_SCOPE': [], +SOCIAL_AUTH_LINKEDIN_KEY = '' +SOCIAL_AUTH_LINKEDIN_SECRET = '' +SOCIAL_AUTH_LINKEDIN_SCOPE = [] - 'SOCIAL_AUTH_GITHUB_KEY': '', - 'SOCIAL_AUTH_GITHUB_SECRET': '', +SOCIAL_AUTH_GITHUB_KEY = '' +SOCIAL_AUTH_GITHUB_SECRET = '' - 'SOCIAL_AUTH_FOURSQUARE_KEY': '', - 'SOCIAL_AUTH_FOURSQUARE_SECRET': '', +SOCIAL_AUTH_FOURSQUARE_KEY = '' +SOCIAL_AUTH_FOURSQUARE_SECRET = '' - 'SOCIAL_AUTH_INSTAGRAM_KEY': '', - 'SOCIAL_AUTH_INSTAGRAM_SECRET': '', +SOCIAL_AUTH_INSTAGRAM_KEY = '' +SOCIAL_AUTH_INSTAGRAM_SECRET = '' - 'SOCIAL_AUTH_LIVE_KEY': '', - 'SOCIAL_AUTH_LIVE_SECRET': '', +SOCIAL_AUTH_LIVE_KEY = '' +SOCIAL_AUTH_LIVE_SECRET = '' - 'SOCIAL_AUTH_VKONTAKTE_OAUTH2_KEY': '', - 'SOCIAL_AUTH_VKONTAKTE_OAUTH2_SECRET': '', +SOCIAL_AUTH_VKONTAKTE_OAUTH2_KEY = '' +SOCIAL_AUTH_VKONTAKTE_OAUTH2_SECRET = '' - 'SOCIAL_AUTH_DAILYMOTION_KEY': '', - 'SOCIAL_AUTH_DAILYMOTION_SECRET': '', +SOCIAL_AUTH_DAILYMOTION_KEY = '' +SOCIAL_AUTH_DAILYMOTION_SECRET = '' - 'SOCIAL_AUTH_DISQUS_KEY': '', - 'SOCIAL_AUTH_DISQUS_SECRET': '', +SOCIAL_AUTH_DISQUS_KEY = '' +SOCIAL_AUTH_DISQUS_SECRET = '' - 'SOCIAL_AUTH_DROPBOX_KEY': '', - 'SOCIAL_AUTH_DROPBOX_SECRET': '', +SOCIAL_AUTH_DROPBOX_KEY = '' +SOCIAL_AUTH_DROPBOX_SECRET = '' - 'SOCIAL_AUTH_EVERNOTE_SANDBOX_KEY': '', - 'SOCIAL_AUTH_EVERNOTE_SANDBOX_SECRET': '', +SOCIAL_AUTH_EVERNOTE_SANDBOX_KEY = '' +SOCIAL_AUTH_EVERNOTE_SANDBOX_SECRET = '' - 'SOCIAL_AUTH_FITBIT_KEY': '', - 'SOCIAL_AUTH_FITBIT_SECRET': '', +SOCIAL_AUTH_FITBIT_KEY = '' +SOCIAL_AUTH_FITBIT_SECRET = '' - 'SOCIAL_AUTH_FLICKR_KEY': '', - 'SOCIAL_AUTH_FLICKR_SECRET': '', +SOCIAL_AUTH_FLICKR_KEY = '' +SOCIAL_AUTH_FLICKR_SECRET = '' - 'SOCIAL_AUTH_SOUNDCLOUD_KEY': '', - 'SOCIAL_AUTH_SOUNDCLOUD_SECRET': '', +SOCIAL_AUTH_SOUNDCLOUD_KEY = '' +SOCIAL_AUTH_SOUNDCLOUD_SECRET = '' - 'SOCIAL_AUTH_STOCKTWITS_KEY': '', - 'SOCIAL_AUTH_STOCKTWITS_SECRET': '', +SOCIAL_AUTH_STOCKTWITS_KEY = '' +SOCIAL_AUTH_STOCKTWITS_SECRET = '' - 'SOCIAL_AUTH_TRIPIT_KEY': '', - 'SOCIAL_AUTH_TRIPIT_SECRET': '', +SOCIAL_AUTH_TRIPIT_KEY = '' +SOCIAL_AUTH_TRIPIT_SECRET = '' - 'SOCIAL_AUTH_TWILIO_KEY': '', - 'SOCIAL_AUTH_TWILIO_SECRET': '', +SOCIAL_AUTH_TWILIO_KEY = '' +SOCIAL_AUTH_TWILIO_SECRET = '' - 'SOCIAL_AUTH_XING_KEY': '', - 'SOCIAL_AUTH_XING_SECRET': '', +SOCIAL_AUTH_XING_KEY = '' +SOCIAL_AUTH_XING_SECRET = '' - 'SOCIAL_AUTH_YANDEX_OAUTH2_KEY': '', - 'SOCIAL_AUTH_YANDEX_OAUTH2_SECRET': '', - 'SOCIAL_AUTH_YANDEX_OAUTH2_API_URL': '', +SOCIAL_AUTH_YANDEX_OAUTH2_KEY = '' +SOCIAL_AUTH_YANDEX_OAUTH2_SECRET = '' +SOCIAL_AUTH_YANDEX_OAUTH2_API_URL = '' - 'SOCIAL_AUTH_REDDIT_KEY': '', - 'SOCIAL_AUTH_REDDIT_SECRET': '', - 'SOCIAL_AUTH_REDDIT_AUTH_EXTRA_ARGUMENTS': {}, -} +SOCIAL_AUTH_REDDIT_KEY = '' +SOCIAL_AUTH_REDDIT_SECRET = '' +SOCIAL_AUTH_REDDIT_AUTH_EXTRA_ARGUMENTS = {} def includeme(config): diff --git a/example-pyramid/example/models.py b/example-pyramid/example/models.py index 1856b3f..778a1a6 100644 --- a/example-pyramid/example/models.py +++ b/example-pyramid/example/models.py @@ -1,21 +1,26 @@ -from sqlalchemy import Boolean, Column, Integer, String -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import scoped_session, sessionmaker +from typing import Optional + +from sqlalchemy import String +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session from zope.sqlalchemy import register -DBSession = scoped_session(sessionmaker(expire_on_commit=False)) +DBSession = Session(expire_on_commit=False) register(DBSession) -Base = declarative_base() + + +class Base(DeclarativeBase): + pass class User(Base): __tablename__ = "users" - id = Column(Integer, primary_key=True) - username = Column(String(200)) - email = Column(String(200)) - password = Column(String(200), default="") - name = Column(String(100)) - active = Column(Boolean, default=True) + + id: Mapped[int] = mapped_column(primary_key=True) + username: Mapped[str] = mapped_column(String(200)) + email: Mapped[str] = mapped_column(String(200)) + password: Mapped[str] = mapped_column(String(200), default="") + name: Mapped[Optional[str]] = mapped_column(String(100)) + active: Mapped[bool] = mapped_column(default=True) def is_active(self): return self.active diff --git a/example-pyramid/example/scripts/initializedb.py b/example-pyramid/example/scripts/initializedb.py index 01ceddc..152c028 100644 --- a/example-pyramid/example/scripts/initializedb.py +++ b/example-pyramid/example/scripts/initializedb.py @@ -28,7 +28,7 @@ def main(argv=sys.argv): settings = get_appsettings(config_uri, options=options) init_social(get_settings(app_settings), Base, DBSession) engine = engine_from_config(settings, "sqlalchemy.") - DBSession.configure(bind=engine) + DBSession.bind = engine Base.metadata.create_all(engine) diff --git a/example-pyramid/example/views.py b/example-pyramid/example/views.py index 48b1bfc..74219c9 100644 --- a/example-pyramid/example/views.py +++ b/example-pyramid/example/views.py @@ -21,7 +21,6 @@ def done(request): request.registry.settings["SOCIAL_AUTH_AUTHENTICATION_BACKENDS"], load_strategy(request), user=get_user(request), - plus_id=request.registry.settings["SOCIAL_AUTH_GOOGLE_PLUS_KEY"], ) diff --git a/example-tornado/example/app.py b/example-tornado/example/app.py index d4f593f..ed593bc 100644 --- a/example-tornado/example/app.py +++ b/example-tornado/example/app.py @@ -1,6 +1,6 @@ import os -import settings +from example import settings import tornado.options import tornado.web from common import filters @@ -9,26 +9,28 @@ from social_tornado.routes import SOCIAL_AUTH_ROUTES from social_tornado.utils import load_strategy from sqlalchemy import create_engine -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import scoped_session, sessionmaker +from sqlalchemy.orm import Session, DeclarativeBase from tornado_jinja2 import Jinja2Loader BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DATABASE_NAME = "sqlite:///{dbname}".format(dbname=os.path.join(BASE_DIR, "db.sqlite3")) engine = create_engine(DATABASE_NAME, echo=False) -session = scoped_session(sessionmaker(bind=engine)) -Base = declarative_base() +session = Session(engine) + + +class Base(DeclarativeBase): + pass class BaseHandler(tornado.web.RequestHandler): def render_home(self, **extra): - from models import User + from example.models import User user_id = self.get_secure_cookie("user_id") if user_id: - user = session.query(User).get(int(user_id)) + user = session.get(User, int(user_id)) else: user = None @@ -39,6 +41,7 @@ def render_home(self, **extra): plus_id=getattr(settings, "SOCIAL_AUTH_GOOGLE_PLUS_KEY", None), **extra ) + self.render("home.html", **context) diff --git a/example-tornado/example/local_settings.py.template b/example-tornado/example/local_settings.py.template new file mode 100644 index 0000000..a919630 --- /dev/null +++ b/example-tornado/example/local_settings.py.template @@ -0,0 +1,89 @@ +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' + +SOCIAL_AUTH_TWITTER_KEY = '' +SOCIAL_AUTH_TWITTER_SECRET = '' + +SOCIAL_AUTH_STRIPE_KEY = '' +SOCIAL_AUTH_STRIPE_SECRET = '' +SOCIAL_AUTH_STRIPE_SCOPE = [] + +SOCIAL_AUTH_FACEBOOK_KEY = '' +SOCIAL_AUTH_FACEBOOK_SECRET = '' + +SOCIAL_AUTH_FACEBOOK_APP_KEY = '' +SOCIAL_AUTH_FACEBOOK_APP_SECRET = '' +SOCIAL_AUTH_FACEBOOK_APP_NAMESPACE = '' + +SOCIAL_AUTH_YAHOO_OAUTH_KEY = '' +SOCIAL_AUTH_YAHOO_OAUTH_SECRET = '' + +SOCIAL_AUTH_ANGEL_KEY = '' +SOCIAL_AUTH_ANGEL_SECRET = '' + +SOCIAL_AUTH_BEHANCE_KEY = '' +SOCIAL_AUTH_BEHANCE_SECRET = '' +SOCIAL_AUTH_BEHANCE_SCOPE = [] + +SOCIAL_AUTH_BITBUCKET_KEY = '' +SOCIAL_AUTH_BITBUCKET_SECRET = '' + +SOCIAL_AUTH_LINKEDIN_KEY = '' +SOCIAL_AUTH_LINKEDIN_SECRET = '' +SOCIAL_AUTH_LINKEDIN_SCOPE = [] + +SOCIAL_AUTH_GITHUB_KEY = '' +SOCIAL_AUTH_GITHUB_SECRET = '' + +SOCIAL_AUTH_FOURSQUARE_KEY = '' +SOCIAL_AUTH_FOURSQUARE_SECRET = '' + +SOCIAL_AUTH_INSTAGRAM_KEY = '' +SOCIAL_AUTH_INSTAGRAM_SECRET = '' + +SOCIAL_AUTH_LIVE_KEY = '' +SOCIAL_AUTH_LIVE_SECRET = '' + +SOCIAL_AUTH_VKONTAKTE_OAUTH2_KEY = '' +SOCIAL_AUTH_VKONTAKTE_OAUTH2_SECRET = '' + +SOCIAL_AUTH_DAILYMOTION_KEY = '' +SOCIAL_AUTH_DAILYMOTION_SECRET = '' + +SOCIAL_AUTH_DISQUS_KEY = '' +SOCIAL_AUTH_DISQUS_SECRET = '' + +SOCIAL_AUTH_DROPBOX_KEY = '' +SOCIAL_AUTH_DROPBOX_SECRET = '' + +SOCIAL_AUTH_EVERNOTE_SANDBOX_KEY = '' +SOCIAL_AUTH_EVERNOTE_SANDBOX_SECRET = '' + +SOCIAL_AUTH_FITBIT_KEY = '' +SOCIAL_AUTH_FITBIT_SECRET = '' + +SOCIAL_AUTH_FLICKR_KEY = '' +SOCIAL_AUTH_FLICKR_SECRET = '' + +SOCIAL_AUTH_SOUNDCLOUD_KEY = '' +SOCIAL_AUTH_SOUNDCLOUD_SECRET = '' + +SOCIAL_AUTH_STOCKTWITS_KEY = '' +SOCIAL_AUTH_STOCKTWITS_SECRET = '' + +SOCIAL_AUTH_TRIPIT_KEY = '' +SOCIAL_AUTH_TRIPIT_SECRET = '' + +SOCIAL_AUTH_TWILIO_KEY = '' +SOCIAL_AUTH_TWILIO_SECRET = '' + +SOCIAL_AUTH_XING_KEY = '' +SOCIAL_AUTH_XING_SECRET = '' + +SOCIAL_AUTH_YANDEX_OAUTH2_KEY = '' +SOCIAL_AUTH_YANDEX_OAUTH2_SECRET = '' +SOCIAL_AUTH_YANDEX_OAUTH2_API_URL = '' + +SOCIAL_AUTH_REDDIT_KEY = '' +SOCIAL_AUTH_REDDIT_SECRET = '' +SOCIAL_AUTH_REDDIT_AUTH_EXTRA_ARGUMENTS = {} diff --git a/example-tornado/example/models.py b/example-tornado/example/models.py index e09f4a5..a273453 100644 --- a/example-tornado/example/models.py +++ b/example-tornado/example/models.py @@ -1,15 +1,17 @@ -from app import Base -from sqlalchemy import Column, Integer, String +from example.app import Base +from sqlalchemy import String +from sqlalchemy.orm import Mapped, mapped_column class User(Base): __tablename__ = "users" - id = Column(Integer, primary_key=True) - username = Column(String(30), nullable=False) - first_name = Column(String(30), nullable=True) - last_name = Column(String(30), nullable=True) - email = Column(String(75), nullable=False) - password = Column(String(128), nullable=True) + + id: Mapped[int] = mapped_column(primary_key=True) + username: Mapped[str] = mapped_column(String(30), nullable=False) + first_name: Mapped[str] = mapped_column(String(30), nullable=True) + last_name: Mapped[str] = mapped_column(String(30), nullable=True) + email: Mapped[str] = mapped_column(String(75), nullable=False) + password: Mapped[str] = mapped_column(String(128), nullable=True) def is_authenticated(self): return True diff --git a/example-tornado/example/settings.py b/example-tornado/example/settings.py index d6ae8ae..bef46ec 100644 --- a/example-tornado/example/settings.py +++ b/example-tornado/example/settings.py @@ -108,4 +108,4 @@ "social_core.pipeline.debug.debug", ) -from local_settings import * +from example.local_settings import * diff --git a/example-webpy/app.py b/example-webpy/app.py index 80a1d5d..9988338 100644 --- a/example-webpy/app.py +++ b/example-webpy/app.py @@ -1,122 +1,22 @@ import os -import sys -import local_settings +from example import settings +from example import local_settings import web from common import filters from common.utils import common_context, url_for from social_core.utils import setting_name from social_webpy.utils import load_strategy from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker +from sqlalchemy.orm import Session from web.contrib.template import render_jinja BASE_DIR = os.path.dirname(os.path.abspath(__file__)) web.config.debug = False web.config[setting_name("USER_MODEL")] = "models.User" -web.config[setting_name("AUTHENTICATION_BACKENDS")] = ( - "social_core.backends.amazon.AmazonOAuth2", - "social_core.backends.angel.AngelOAuth2", - "social_core.backends.aol.AOLOpenId", - "social_core.backends.appsfuel.AppsfuelOAuth2", - "social_core.backends.beats.BeatsOAuth2", - "social_core.backends.behance.BehanceOAuth2", - "social_core.backends.belgiumeid.BelgiumEIDOpenId", - "social_core.backends.bitbucket.BitbucketOAuth", - "social_core.backends.box.BoxOAuth2", - "social_core.backends.clef.ClefOAuth2", - "social_core.backends.coinbase.CoinbaseOAuth2", - "social_core.backends.coursera.CourseraOAuth2", - "social_core.backends.dailymotion.DailymotionOAuth2", - "social_core.backends.deezer.DeezerOAuth2", - "social_core.backends.disqus.DisqusOAuth2", - "social_core.backends.douban.DoubanOAuth2", - "social_core.backends.dropbox.DropboxOAuth", - "social_core.backends.dropbox.DropboxOAuth2", - "social_core.backends.eveonline.EVEOnlineOAuth2", - "social_core.backends.evernote.EvernoteSandboxOAuth", - "social_core.backends.facebook.FacebookAppOAuth2", - "social_core.backends.facebook.FacebookOAuth2", - "social_core.backends.fedora.FedoraOpenId", - "social_core.backends.fitbit.FitbitOAuth2", - "social_core.backends.flickr.FlickrOAuth", - "social_core.backends.foursquare.FoursquareOAuth2", - "social_core.backends.github.GithubOAuth2", - "social_core.backends.google.GoogleOAuth", - "social_core.backends.google.GoogleOAuth2", - "social_core.backends.google.GoogleOpenId", - "social_core.backends.google.GooglePlusAuth", - "social_core.backends.google_openidconnect.GoogleOpenIdConnect", - "social_core.backends.instagram.InstagramOAuth2", - "social_core.backends.jawbone.JawboneOAuth2", - "social_core.backends.kakao.KakaoOAuth2", - "social_core.backends.linkedin.LinkedinOAuth", - "social_core.backends.linkedin.LinkedinOAuth2", - "social_core.backends.live.LiveOAuth2", - "social_core.backends.livejournal.LiveJournalOpenId", - "social_core.backends.mailru.MailruOAuth2", - "social_core.backends.mendeley.MendeleyOAuth", - "social_core.backends.mendeley.MendeleyOAuth2", - "social_core.backends.mineid.MineIDOAuth2", - "social_core.backends.mixcloud.MixcloudOAuth2", - "social_core.backends.nationbuilder.NationBuilderOAuth2", - "social_core.backends.odnoklassniki.OdnoklassnikiOAuth2", - "social_core.backends.open_id.OpenIdAuth", - "social_core.backends.openstreetmap.OpenStreetMapOAuth", - "social_core.backends.persona.PersonaAuth", - "social_core.backends.podio.PodioOAuth2", - "social_core.backends.rdio.RdioOAuth1", - "social_core.backends.rdio.RdioOAuth2", - "social_core.backends.readability.ReadabilityOAuth", - "social_core.backends.reddit.RedditOAuth2", - "social_core.backends.runkeeper.RunKeeperOAuth2", - "social_core.backends.sketchfab.SketchfabOAuth2", - "social_core.backends.skyrock.SkyrockOAuth", - "social_core.backends.soundcloud.SoundcloudOAuth2", - "social_core.backends.spotify.SpotifyOAuth2", - "social_core.backends.stackoverflow.StackoverflowOAuth2", - "social_core.backends.steam.SteamOpenId", - "social_core.backends.stocktwits.StocktwitsOAuth2", - "social_core.backends.stripe.StripeOAuth2", - "social_core.backends.suse.OpenSUSEOpenId", - "social_core.backends.thisismyjam.ThisIsMyJamOAuth1", - "social_core.backends.trello.TrelloOAuth", - "social_core.backends.tripit.TripItOAuth", - "social_core.backends.tumblr.TumblrOAuth", - "social_core.backends.twilio.TwilioAuth", - "social_core.backends.twitter.TwitterOAuth", - "social_core.backends.vk.VKOAuth2", - "social_core.backends.weibo.WeiboOAuth2", - "social_core.backends.wunderlist.WunderlistOAuth2", - "social_core.backends.xing.XingOAuth", - "social_core.backends.yahoo.YahooOAuth", - "social_core.backends.yahoo.YahooOpenId", - "social_core.backends.yammer.YammerOAuth2", - "social_core.backends.yandex.YandexOAuth2", - "social_core.backends.vimeo.VimeoOAuth1", - "social_core.backends.lastfm.LastFmAuth", - "social_core.backends.moves.MovesOAuth2", - "social_core.backends.vend.VendOAuth2", - "social_core.backends.email.EmailAuth", - "social_core.backends.username.UsernameAuth", - "social_core.backends.upwork.UpworkOAuth", -) -web.config[setting_name("PIPELINE")] = ( - "social_core.pipeline.social_auth.social_details", - "social_core.pipeline.social_auth.social_uid", - "social_core.pipeline.social_auth.auth_allowed", - "social_core.pipeline.social_auth.social_user", - "social_core.pipeline.user.get_username", - "common.pipeline.require_email", - "social_core.pipeline.mail.mail_validation", - "social_core.pipeline.user.create_user", - "social_core.pipeline.social_auth.associate_user", - "social_core.pipeline.debug.debug", - "social_core.pipeline.social_auth.load_extra_data", - "social_core.pipeline.user.user_details", - "social_core.pipeline.debug.debug", -) +web.config[setting_name("AUTHENTICATION_BACKENDS")] = settings.SOCIAL_AUTH_AUTHENTICATION_BACKENDS +web.config[setting_name("PIPELINE")] = settings.SOCIAL_AUTH_PIPELINE for name, value in local_settings.__dict__.items(): if name.startswith("SOCIAL_AUTH"): @@ -192,7 +92,7 @@ def GET(self): def load_sqla(handler): - web.ctx.orm = scoped_session(sessionmaker(bind=engine)) + web.ctx.orm = Session(engine) try: return handler() except web.HTTPError: @@ -205,14 +105,11 @@ def load_sqla(handler): web.ctx.orm.commit() -Session = sessionmaker(bind=engine) -Session.configure(bind=engine) - app = web.application(urls, locals()) app.add_processor(load_sqla) session = web.session.Session( app, web.session.DiskStore(os.path.join(BASE_DIR, "sessions")) ) -web.db_session = Session() +web.db_session = Session(engine) web.web_session = session diff --git a/example-webpy/local_settings.py.template b/example-webpy/local_settings.py.template new file mode 100644 index 0000000..a919630 --- /dev/null +++ b/example-webpy/local_settings.py.template @@ -0,0 +1,89 @@ +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' + +SOCIAL_AUTH_TWITTER_KEY = '' +SOCIAL_AUTH_TWITTER_SECRET = '' + +SOCIAL_AUTH_STRIPE_KEY = '' +SOCIAL_AUTH_STRIPE_SECRET = '' +SOCIAL_AUTH_STRIPE_SCOPE = [] + +SOCIAL_AUTH_FACEBOOK_KEY = '' +SOCIAL_AUTH_FACEBOOK_SECRET = '' + +SOCIAL_AUTH_FACEBOOK_APP_KEY = '' +SOCIAL_AUTH_FACEBOOK_APP_SECRET = '' +SOCIAL_AUTH_FACEBOOK_APP_NAMESPACE = '' + +SOCIAL_AUTH_YAHOO_OAUTH_KEY = '' +SOCIAL_AUTH_YAHOO_OAUTH_SECRET = '' + +SOCIAL_AUTH_ANGEL_KEY = '' +SOCIAL_AUTH_ANGEL_SECRET = '' + +SOCIAL_AUTH_BEHANCE_KEY = '' +SOCIAL_AUTH_BEHANCE_SECRET = '' +SOCIAL_AUTH_BEHANCE_SCOPE = [] + +SOCIAL_AUTH_BITBUCKET_KEY = '' +SOCIAL_AUTH_BITBUCKET_SECRET = '' + +SOCIAL_AUTH_LINKEDIN_KEY = '' +SOCIAL_AUTH_LINKEDIN_SECRET = '' +SOCIAL_AUTH_LINKEDIN_SCOPE = [] + +SOCIAL_AUTH_GITHUB_KEY = '' +SOCIAL_AUTH_GITHUB_SECRET = '' + +SOCIAL_AUTH_FOURSQUARE_KEY = '' +SOCIAL_AUTH_FOURSQUARE_SECRET = '' + +SOCIAL_AUTH_INSTAGRAM_KEY = '' +SOCIAL_AUTH_INSTAGRAM_SECRET = '' + +SOCIAL_AUTH_LIVE_KEY = '' +SOCIAL_AUTH_LIVE_SECRET = '' + +SOCIAL_AUTH_VKONTAKTE_OAUTH2_KEY = '' +SOCIAL_AUTH_VKONTAKTE_OAUTH2_SECRET = '' + +SOCIAL_AUTH_DAILYMOTION_KEY = '' +SOCIAL_AUTH_DAILYMOTION_SECRET = '' + +SOCIAL_AUTH_DISQUS_KEY = '' +SOCIAL_AUTH_DISQUS_SECRET = '' + +SOCIAL_AUTH_DROPBOX_KEY = '' +SOCIAL_AUTH_DROPBOX_SECRET = '' + +SOCIAL_AUTH_EVERNOTE_SANDBOX_KEY = '' +SOCIAL_AUTH_EVERNOTE_SANDBOX_SECRET = '' + +SOCIAL_AUTH_FITBIT_KEY = '' +SOCIAL_AUTH_FITBIT_SECRET = '' + +SOCIAL_AUTH_FLICKR_KEY = '' +SOCIAL_AUTH_FLICKR_SECRET = '' + +SOCIAL_AUTH_SOUNDCLOUD_KEY = '' +SOCIAL_AUTH_SOUNDCLOUD_SECRET = '' + +SOCIAL_AUTH_STOCKTWITS_KEY = '' +SOCIAL_AUTH_STOCKTWITS_SECRET = '' + +SOCIAL_AUTH_TRIPIT_KEY = '' +SOCIAL_AUTH_TRIPIT_SECRET = '' + +SOCIAL_AUTH_TWILIO_KEY = '' +SOCIAL_AUTH_TWILIO_SECRET = '' + +SOCIAL_AUTH_XING_KEY = '' +SOCIAL_AUTH_XING_SECRET = '' + +SOCIAL_AUTH_YANDEX_OAUTH2_KEY = '' +SOCIAL_AUTH_YANDEX_OAUTH2_SECRET = '' +SOCIAL_AUTH_YANDEX_OAUTH2_API_URL = '' + +SOCIAL_AUTH_REDDIT_KEY = '' +SOCIAL_AUTH_REDDIT_SECRET = '' +SOCIAL_AUTH_REDDIT_AUTH_EXTRA_ARGUMENTS = {} diff --git a/example-webpy/models.py b/example-webpy/models.py index 4c0c0be..f56e995 100644 --- a/example-webpy/models.py +++ b/example-webpy/models.py @@ -1,17 +1,22 @@ -from sqlalchemy import Boolean, Column, Integer, String -from sqlalchemy.ext.declarative import declarative_base +from typing import Optional -Base = declarative_base() +from sqlalchemy import String +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column + + +class Base(DeclarativeBase): + pass class User(Base): __tablename__ = "users" - id = Column(Integer, primary_key=True) - username = Column(String(200)) - password = Column(String(200), default="") - name = Column(String(100)) - email = Column(String(200)) - active = Column(Boolean, default=True) + + id: Mapped[int] = mapped_column(primary_key=True) + username: Mapped[str] = mapped_column(String(200)) + password: Mapped[str] = mapped_column(String(200), default="") + name: Mapped[Optional[str]] = mapped_column(String(100)) + email: Mapped[str] = mapped_column(String(200)) + active: Mapped[bool] = mapped_column(default=True) def is_active(self): return self.active diff --git a/example-webpy/settings.py b/example-webpy/settings.py new file mode 100644 index 0000000..f8e7da6 --- /dev/null +++ b/example-webpy/settings.py @@ -0,0 +1,103 @@ +SOCIAL_AUTH_AUTHENTICATION_BACKENDS = ( + "social_core.backends.amazon.AmazonOAuth2", + "social_core.backends.angel.AngelOAuth2", + "social_core.backends.aol.AOLOpenId", + "social_core.backends.appsfuel.AppsfuelOAuth2", + "social_core.backends.beats.BeatsOAuth2", + "social_core.backends.behance.BehanceOAuth2", + "social_core.backends.belgiumeid.BelgiumEIDOpenId", + "social_core.backends.bitbucket.BitbucketOAuth", + "social_core.backends.box.BoxOAuth2", + "social_core.backends.clef.ClefOAuth2", + "social_core.backends.coinbase.CoinbaseOAuth2", + "social_core.backends.coursera.CourseraOAuth2", + "social_core.backends.dailymotion.DailymotionOAuth2", + "social_core.backends.deezer.DeezerOAuth2", + "social_core.backends.disqus.DisqusOAuth2", + "social_core.backends.douban.DoubanOAuth2", + "social_core.backends.dropbox.DropboxOAuth", + "social_core.backends.dropbox.DropboxOAuth2", + "social_core.backends.eveonline.EVEOnlineOAuth2", + "social_core.backends.evernote.EvernoteSandboxOAuth", + "social_core.backends.facebook.FacebookAppOAuth2", + "social_core.backends.facebook.FacebookOAuth2", + "social_core.backends.fedora.FedoraOpenId", + "social_core.backends.fitbit.FitbitOAuth2", + "social_core.backends.flickr.FlickrOAuth", + "social_core.backends.foursquare.FoursquareOAuth2", + "social_core.backends.github.GithubOAuth2", + "social_core.backends.google.GoogleOAuth", + "social_core.backends.google.GoogleOAuth2", + "social_core.backends.google.GoogleOpenId", + "social_core.backends.google.GooglePlusAuth", + "social_core.backends.google_openidconnect.GoogleOpenIdConnect", + "social_core.backends.instagram.InstagramOAuth2", + "social_core.backends.jawbone.JawboneOAuth2", + "social_core.backends.kakao.KakaoOAuth2", + "social_core.backends.linkedin.LinkedinOAuth", + "social_core.backends.linkedin.LinkedinOAuth2", + "social_core.backends.live.LiveOAuth2", + "social_core.backends.livejournal.LiveJournalOpenId", + "social_core.backends.mailru.MailruOAuth2", + "social_core.backends.mendeley.MendeleyOAuth", + "social_core.backends.mendeley.MendeleyOAuth2", + "social_core.backends.mineid.MineIDOAuth2", + "social_core.backends.mixcloud.MixcloudOAuth2", + "social_core.backends.nationbuilder.NationBuilderOAuth2", + "social_core.backends.odnoklassniki.OdnoklassnikiOAuth2", + "social_core.backends.open_id.OpenIdAuth", + "social_core.backends.openstreetmap.OpenStreetMapOAuth", + "social_core.backends.persona.PersonaAuth", + "social_core.backends.podio.PodioOAuth2", + "social_core.backends.rdio.RdioOAuth1", + "social_core.backends.rdio.RdioOAuth2", + "social_core.backends.readability.ReadabilityOAuth", + "social_core.backends.reddit.RedditOAuth2", + "social_core.backends.runkeeper.RunKeeperOAuth2", + "social_core.backends.sketchfab.SketchfabOAuth2", + "social_core.backends.skyrock.SkyrockOAuth", + "social_core.backends.soundcloud.SoundcloudOAuth2", + "social_core.backends.spotify.SpotifyOAuth2", + "social_core.backends.stackoverflow.StackoverflowOAuth2", + "social_core.backends.steam.SteamOpenId", + "social_core.backends.stocktwits.StocktwitsOAuth2", + "social_core.backends.stripe.StripeOAuth2", + "social_core.backends.suse.OpenSUSEOpenId", + "social_core.backends.thisismyjam.ThisIsMyJamOAuth1", + "social_core.backends.trello.TrelloOAuth", + "social_core.backends.tripit.TripItOAuth", + "social_core.backends.tumblr.TumblrOAuth", + "social_core.backends.twilio.TwilioAuth", + "social_core.backends.twitter.TwitterOAuth", + "social_core.backends.vk.VKOAuth2", + "social_core.backends.weibo.WeiboOAuth2", + "social_core.backends.wunderlist.WunderlistOAuth2", + "social_core.backends.xing.XingOAuth", + "social_core.backends.yahoo.YahooOAuth", + "social_core.backends.yahoo.YahooOpenId", + "social_core.backends.yammer.YammerOAuth2", + "social_core.backends.yandex.YandexOAuth2", + "social_core.backends.vimeo.VimeoOAuth1", + "social_core.backends.lastfm.LastFmAuth", + "social_core.backends.moves.MovesOAuth2", + "social_core.backends.vend.VendOAuth2", + "social_core.backends.email.EmailAuth", + "social_core.backends.username.UsernameAuth", + "social_core.backends.upwork.UpworkOAuth", +) + +SOCIAL_AUTH_PIPELINE = ( + "social_core.pipeline.social_auth.social_details", + "social_core.pipeline.social_auth.social_uid", + "social_core.pipeline.social_auth.auth_allowed", + "social_core.pipeline.social_auth.social_user", + "social_core.pipeline.user.get_username", + "common.pipeline.require_email", + "social_core.pipeline.mail.mail_validation", + "social_core.pipeline.user.create_user", + "social_core.pipeline.social_auth.associate_user", + "social_core.pipeline.debug.debug", + "social_core.pipeline.social_auth.load_extra_data", + "social_core.pipeline.user.user_details", + "social_core.pipeline.debug.debug", +) From e063508160840a24d5d8ef5576df8e71e475af72 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 24 Feb 2024 05:09:53 +0000 Subject: [PATCH 02/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-cherrypy/example/app.py | 2 +- example-cherrypy/example/db/__init__.py | 1 + example-cherrypy/example/db/user.py | 3 ++- example-flask-mongoengine/manage.py | 4 ++-- example-flask-peewee/manage.py | 4 ++-- example-flask/example/models/user.py | 1 + example-flask/manage.py | 5 +++-- example-pyramid/example/auth.py | 2 +- example-pyramid/example/models.py | 2 +- example-tornado/example/app.py | 4 ++-- example-tornado/example/models.py | 2 +- example-webpy/app.py | 7 ++++--- 12 files changed, 21 insertions(+), 16 deletions(-) diff --git a/example-cherrypy/example/app.py b/example-cherrypy/example/app.py index 47a51e9..49ab7c8 100644 --- a/example-cherrypy/example/app.py +++ b/example-cherrypy/example/app.py @@ -2,9 +2,9 @@ import sys import cherrypy -from example import settings from common import filters from common.utils import common_context, url_for +from example import settings from jinja2 import Environment, FileSystemLoader from social_cherrypy.utils import backends, load_strategy from social_cherrypy.views import CherryPyPSAViews diff --git a/example-cherrypy/example/db/__init__.py b/example-cherrypy/example/db/__init__.py index f75ec44..fa2b68a 100644 --- a/example-cherrypy/example/db/__init__.py +++ b/example-cherrypy/example/db/__init__.py @@ -1,4 +1,5 @@ from sqlalchemy.orm import DeclarativeBase + class Base(DeclarativeBase): pass diff --git a/example-cherrypy/example/db/user.py b/example-cherrypy/example/db/user.py index 2576764..e69c882 100644 --- a/example-cherrypy/example/db/user.py +++ b/example-cherrypy/example/db/user.py @@ -1,6 +1,7 @@ +from typing import Optional + from sqlalchemy import Boolean, String from sqlalchemy.orm import Mapped, mapped_column -from typing import Optional from . import Base diff --git a/example-flask-mongoengine/manage.py b/example-flask-mongoengine/manage.py index 6d99d8b..984146e 100755 --- a/example-flask-mongoengine/manage.py +++ b/example-flask-mongoengine/manage.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from example import app, db import click +from example import app, db from flask.cli import FlaskGroup @@ -13,5 +13,5 @@ def make_shell_context(): return dict(db=db) -if __name__ == '__main__': +if __name__ == "__main__": cli() diff --git a/example-flask-peewee/manage.py b/example-flask-peewee/manage.py index 7701959..bc72f8d 100755 --- a/example-flask-peewee/manage.py +++ b/example-flask-peewee/manage.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from example import app, database import click +from example import app, database from flask.cli import FlaskGroup @@ -26,5 +26,5 @@ def syncdb(): model.create_table(True) -if __name__ == '__main__': +if __name__ == "__main__": cli() diff --git a/example-flask/example/models/user.py b/example-flask/example/models/user.py index 7f4121f..27a69b1 100644 --- a/example-flask/example/models/user.py +++ b/example-flask/example/models/user.py @@ -1,4 +1,5 @@ from typing import Optional + from example import db_session from flask_login import UserMixin from sqlalchemy import String diff --git a/example-flask/manage.py b/example-flask/manage.py index 51c5c85..e334709 100644 --- a/example-flask/manage.py +++ b/example-flask/manage.py @@ -1,6 +1,6 @@ import click -from flask.cli import FlaskGroup from example import app, db_session, engine +from flask.cli import FlaskGroup @click.group(cls=FlaskGroup, create_app=lambda: app) @@ -11,6 +11,7 @@ def cli(): def make_shell_context(): return dict(db_session=db_session) + @app.cli.command() def syncdb(): from example.models import user @@ -20,5 +21,5 @@ def syncdb(): models.PSABase.metadata.create_all(engine) -if __name__ == '__main__': +if __name__ == "__main__": cli() diff --git a/example-pyramid/example/auth.py b/example-pyramid/example/auth.py index 144e1a6..d57b9a2 100644 --- a/example-pyramid/example/auth.py +++ b/example-pyramid/example/auth.py @@ -1,7 +1,7 @@ from example.models import DBSession, User -from sqlalchemy import select from pyramid.events import BeforeRender, subscriber from social_pyramid.utils import backends +from sqlalchemy import select def login_user(backend, user, user_social_auth): diff --git a/example-pyramid/example/models.py b/example-pyramid/example/models.py index 778a1a6..d781af0 100644 --- a/example-pyramid/example/models.py +++ b/example-pyramid/example/models.py @@ -1,7 +1,7 @@ from typing import Optional from sqlalchemy import String -from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session +from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column from zope.sqlalchemy import register DBSession = Session(expire_on_commit=False) diff --git a/example-tornado/example/app.py b/example-tornado/example/app.py index ed593bc..be8e962 100644 --- a/example-tornado/example/app.py +++ b/example-tornado/example/app.py @@ -1,15 +1,15 @@ import os -from example import settings import tornado.options import tornado.web from common import filters from common.utils import common_context, url_for +from example import settings from jinja2 import Environment, FileSystemLoader from social_tornado.routes import SOCIAL_AUTH_ROUTES from social_tornado.utils import load_strategy from sqlalchemy import create_engine -from sqlalchemy.orm import Session, DeclarativeBase +from sqlalchemy.orm import DeclarativeBase, Session from tornado_jinja2 import Jinja2Loader BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/example-tornado/example/models.py b/example-tornado/example/models.py index a273453..e074541 100644 --- a/example-tornado/example/models.py +++ b/example-tornado/example/models.py @@ -5,7 +5,7 @@ class User(Base): __tablename__ = "users" - + id: Mapped[int] = mapped_column(primary_key=True) username: Mapped[str] = mapped_column(String(30), nullable=False) first_name: Mapped[str] = mapped_column(String(30), nullable=True) diff --git a/example-webpy/app.py b/example-webpy/app.py index 9988338..e620981 100644 --- a/example-webpy/app.py +++ b/example-webpy/app.py @@ -1,10 +1,9 @@ import os -from example import settings -from example import local_settings import web from common import filters from common.utils import common_context, url_for +from example import local_settings, settings from social_core.utils import setting_name from social_webpy.utils import load_strategy from sqlalchemy import create_engine @@ -15,7 +14,9 @@ web.config.debug = False web.config[setting_name("USER_MODEL")] = "models.User" -web.config[setting_name("AUTHENTICATION_BACKENDS")] = settings.SOCIAL_AUTH_AUTHENTICATION_BACKENDS +web.config[setting_name("AUTHENTICATION_BACKENDS")] = ( + settings.SOCIAL_AUTH_AUTHENTICATION_BACKENDS +) web.config[setting_name("PIPELINE")] = settings.SOCIAL_AUTH_PIPELINE for name, value in local_settings.__dict__.items(): From 55c7d748064710ff1ee978a8dbce446bd77df2b9 Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:20:56 +0900 Subject: [PATCH 03/18] 1st PEP 8 fix --- example-cherrypy/example/app.py | 16 +++++++++------- example-cherrypy/example/db/saplugin.py | 2 +- example-cherrypy/example/db/user.py | 2 +- example-cherrypy/manage.py | 8 +++----- example-common/filters.py | 2 +- example-django-mongoengine/app/admin.py | 2 +- .../app/templatetags/backend_utils.py | 2 +- example-django-mongoengine/app/tests.py | 2 +- example-django-mongoengine/app/views.py | 5 +---- example-django-mongoengine/example/settings.py | 2 +- example-django-mongoengine/manage.py | 2 +- example-django/app/admin.py | 2 +- example-django/app/templatetags/backend_utils.py | 2 +- example-django/app/tests.py | 2 +- example-django/app/views.py | 6 +----- example-django/example/settings.py | 2 +- example-django/manage.py | 2 +- example-flask-mongoengine/example/__init__.py | 5 ++--- .../example/models/__init__.py | 4 ++-- example-flask-mongoengine/example/models/user.py | 2 +- .../example/routes/__init__.py | 4 ++-- example-flask-mongoengine/example/settings.py | 2 -- example-flask-peewee/example/__init__.py | 4 +--- example-flask-peewee/example/models/__init__.py | 4 ++-- example-flask-peewee/example/routes/__init__.py | 4 ++-- example-flask-peewee/manage.py | 2 +- example-flask/example/__init__.py | 5 ++--- example-flask/example/models/__init__.py | 4 ++-- example-flask/example/models/user.py | 1 - example-flask/example/routes/__init__.py | 4 ++-- example-pyramid/example/__init__.py | 2 -- example-tornado/example/settings.py | 2 +- example-tornado/manage.py | 2 +- example-webpy/app.py | 6 ++---- 34 files changed, 50 insertions(+), 68 deletions(-) diff --git a/example-cherrypy/example/app.py b/example-cherrypy/example/app.py index 49ab7c8..f509df5 100644 --- a/example-cherrypy/example/app.py +++ b/example-cherrypy/example/app.py @@ -1,12 +1,11 @@ import os -import sys import cherrypy from common import filters from common.utils import common_context, url_for from example import settings from jinja2 import Environment, FileSystemLoader -from social_cherrypy.utils import backends, load_strategy +from social_cherrypy.utils import load_strategy from social_cherrypy.views import CherryPyPSAViews from social_core.utils import setting_name @@ -15,7 +14,8 @@ from .db.user import User BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -DATABASE_NAME = "sqlite:///{dbname}".format(dbname=os.path.join(BASE_DIR, "db.sqlite3")) +DATABASE_NAME = "sqlite:///{dbname}".format( # fix: skip + dbname=os.path.join(BASE_DIR, "db.sqlite3")) SAEnginePlugin(cherrypy.engine, DATABASE_NAME).subscribe() @@ -38,9 +38,9 @@ def render_home(self): cherrypy.config[setting_name("AUTHENTICATION_BACKENDS")], load_strategy(), user=getattr(cherrypy.request, "user", None), - plus_id=cherrypy.config.get(setting_name("SOCIAL_AUTH_GOOGLE_PLUS_KEY")), ) - return cherrypy.tools.jinja2env.get_template("home.html").render(**context) + return cherrypy.tools.jinja2env.get_template( # fix: skip + "home.html").render(**context) def load_user(): @@ -56,10 +56,11 @@ def session_commit(): def get_settings(module): + not_in_items = ["__builtins__", "__file__"] return { key: value for key, value in module.__dict__.items() - if key not in module.__builtins__ and key not in ["__builtins__", "__file__"] + if key not in module.__builtins__ and key not in not_in_items } @@ -71,7 +72,8 @@ def get_settings(module): SOCIAL_SETTINGS.update(get_settings(local_settings)) except ImportError: raise RuntimeError( - "Define a local_settings.py using " "local_settings.py.template as base" + "Define a local_settings.py using " # fix: skip + "local_settings.py.template as base" ) diff --git a/example-cherrypy/example/db/saplugin.py b/example-cherrypy/example/db/saplugin.py index 26043a4..82005a7 100644 --- a/example-cherrypy/example/db/saplugin.py +++ b/example-cherrypy/example/db/saplugin.py @@ -29,7 +29,7 @@ def bind(self): def commit(self): try: self.session.commit() - except: + except Exception: self.session.rollback() raise finally: diff --git a/example-cherrypy/example/db/user.py b/example-cherrypy/example/db/user.py index e69c882..48a57cf 100644 --- a/example-cherrypy/example/db/user.py +++ b/example-cherrypy/example/db/user.py @@ -1,6 +1,6 @@ from typing import Optional -from sqlalchemy import Boolean, String +from sqlalchemy import String from sqlalchemy.orm import Mapped, mapped_column from . import Base diff --git a/example-cherrypy/manage.py b/example-cherrypy/manage.py index 2833953..22733a7 100755 --- a/example-cherrypy/manage.py +++ b/example-cherrypy/manage.py @@ -3,6 +3,9 @@ import cherrypy from sqlalchemy import create_engine +from example.app import DATABASE_NAME, run_app +from example.db import Base +from social_cherrypy.models import SocialBase cherrypy.config.update( { @@ -10,11 +13,6 @@ } ) -from example.app import DATABASE_NAME, run_app -from example.db import Base -from example.db.user import User -from social_cherrypy.models import SocialBase - if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == "syncdb": engine = create_engine(DATABASE_NAME) diff --git a/example-common/filters.py b/example-common/filters.py index 27c1c9e..cd7d596 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] for n in range(0, len(value), items)] + return [value[n: n + items] for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/admin.py b/example-django-mongoengine/app/admin.py index 8c38f3f..4fd5490 100644 --- a/example-django-mongoengine/app/admin.py +++ b/example-django-mongoengine/app/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +from django.contrib import admin # noqa: F401 # Register your models here. diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 03032dc..56cbaa3 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n: n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django-mongoengine/app/tests.py b/example-django-mongoengine/app/tests.py index 7ce503c..e55d689 100644 --- a/example-django-mongoengine/app/tests.py +++ b/example-django-mongoengine/app/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +from django.test import TestCase # noqa: F401 # Create your tests here. diff --git a/example-django-mongoengine/app/views.py b/example-django-mongoengine/app/views.py index 5e24d72..f966797 100644 --- a/example-django-mongoengine/app/views.py +++ b/example-django-mongoengine/app/views.py @@ -1,15 +1,12 @@ import json -from django.conf import settings from django.contrib.auth import login from django.contrib.auth import logout as auth_logout from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect -from social_core.backends.google import GooglePlusAuth from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 -from social_core.backends.utils import load_backends -from social_django.utils import load_strategy, psa +from social_django.utils import psa from .decorators import render_to diff --git a/example-django-mongoengine/example/settings.py b/example-django-mongoengine/example/settings.py index 87728e9..eaae70a 100644 --- a/example-django-mongoengine/example/settings.py +++ b/example-django-mongoengine/example/settings.py @@ -273,6 +273,6 @@ STATIC_URL = "/static/" try: - from example.local_settings import * + from example.local_settings import * # noqa: F401,F403 except ImportError: pass diff --git a/example-django-mongoengine/manage.py b/example-django-mongoengine/manage.py index 72c4bb0..9036db9 100755 --- a/example-django-mongoengine/manage.py +++ b/example-django-mongoengine/manage.py @@ -11,7 +11,7 @@ # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: - import django + import django # noqa: F401 except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " diff --git a/example-django/app/admin.py b/example-django/app/admin.py index 8c38f3f..4fd5490 100644 --- a/example-django/app/admin.py +++ b/example-django/app/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +from django.contrib import admin # noqa: F401 # Register your models here. diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 740d72b..eebb2b7 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n: n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/tests.py b/example-django/app/tests.py index 7ce503c..e55d689 100644 --- a/example-django/app/tests.py +++ b/example-django/app/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +from django.test import TestCase # noqa: F401 # Create your tests here. diff --git a/example-django/app/views.py b/example-django/app/views.py index ba61b75..b22146e 100644 --- a/example-django/app/views.py +++ b/example-django/app/views.py @@ -1,15 +1,11 @@ import json - -from django.conf import settings from django.contrib.auth import login from django.contrib.auth import logout as auth_logout from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect -from social_core.backends.google import GooglePlusAuth from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 -from social_core.backends.utils import load_backends -from social_django.utils import load_strategy, psa +from social_django.utils import psa from .decorators import render_to diff --git a/example-django/example/settings.py b/example-django/example/settings.py index 0aabcf6..26d7252 100644 --- a/example-django/example/settings.py +++ b/example-django/example/settings.py @@ -272,6 +272,6 @@ STATIC_URL = "/static/" try: - from example.local_settings import * + from example.local_settings import * # noqa: F401,F403 except ImportError: pass diff --git a/example-django/manage.py b/example-django/manage.py index 72c4bb0..9036db9 100755 --- a/example-django/manage.py +++ b/example-django/manage.py @@ -11,7 +11,7 @@ # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: - import django + import django # noqa: F401 except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " diff --git a/example-flask-mongoengine/example/__init__.py b/example-flask-mongoengine/example/__init__.py index f86026b..ae85ce9 100644 --- a/example-flask-mongoengine/example/__init__.py +++ b/example-flask-mongoengine/example/__init__.py @@ -3,13 +3,14 @@ from common import filters from common.utils import common_context from common.utils import url_for as common_url_for -from flask import Flask, g, url_for +from flask import Flask, g from flask_login import LoginManager, current_user from flask_mongoengine import MongoEngine from social_flask.routes import social_auth from social_flask.template_filters import backends from social_flask.utils import load_strategy from social_flask_mongoengine.models import init_social +from example import models BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -32,8 +33,6 @@ login_manager.login_message = "" login_manager.init_app(app) -from example import models, routes - @login_manager.user_loader def load_user(userid): diff --git a/example-flask-mongoengine/example/models/__init__.py b/example-flask-mongoengine/example/models/__init__.py index fde4944..f627dcd 100644 --- a/example-flask-mongoengine/example/models/__init__.py +++ b/example-flask-mongoengine/example/models/__init__.py @@ -1,2 +1,2 @@ -from example.models import user -from social_flask_sqlalchemy import models +from example.models import user # noqa: F401 +from social_flask_sqlalchemy import models # noqa: F401 diff --git a/example-flask-mongoengine/example/models/user.py b/example-flask-mongoengine/example/models/user.py index d37c0ac..6491716 100644 --- a/example-flask-mongoengine/example/models/user.py +++ b/example-flask-mongoengine/example/models/user.py @@ -1,6 +1,6 @@ from example import db from flask_login import UserMixin -from mongoengine import BooleanField, EmailField, ListField, ReferenceField, StringField +from mongoengine import BooleanField, EmailField, StringField from social_flask_mongoengine.models import FlaskStorage diff --git a/example-flask-mongoengine/example/routes/__init__.py b/example-flask-mongoengine/example/routes/__init__.py index 9797f20..50f2c6f 100644 --- a/example-flask-mongoengine/example/routes/__init__.py +++ b/example-flask-mongoengine/example/routes/__init__.py @@ -1,2 +1,2 @@ -from example.routes import main -from social_flask import routes +from example.routes import main # noqa: F401 +from social_flask import routes # noqa: F401 diff --git a/example-flask-mongoengine/example/settings.py b/example-flask-mongoengine/example/settings.py index a976f4b..84ae24f 100644 --- a/example-flask-mongoengine/example/settings.py +++ b/example-flask-mongoengine/example/settings.py @@ -1,5 +1,3 @@ -from os.path import abspath, dirname, join - SECRET_KEY = "random-secret-key" SESSION_COOKIE_NAME = "python_social_auth_mongoengine_session" DEBUG = True diff --git a/example-flask-peewee/example/__init__.py b/example-flask-peewee/example/__init__.py index c9bf04c..578e410 100644 --- a/example-flask-peewee/example/__init__.py +++ b/example-flask-peewee/example/__init__.py @@ -3,7 +3,7 @@ from common import filters from common.utils import common_context from common.utils import url_for as common_url_for -from flask import Flask, g, url_for +from flask import Flask, g from flask_login import LoginManager, current_user from peewee import SqliteDatabase from social_flask.routes import social_auth @@ -36,8 +36,6 @@ login_manager.login_message = "" login_manager.init_app(app) -from example import models, routes - @login_manager.user_loader def load_user(userid): diff --git a/example-flask-peewee/example/models/__init__.py b/example-flask-peewee/example/models/__init__.py index d86b607..2515e67 100644 --- a/example-flask-peewee/example/models/__init__.py +++ b/example-flask-peewee/example/models/__init__.py @@ -1,2 +1,2 @@ -from example.models import user -from social_flask_peewee import models +from example.models import user # noqa: F401 +from social_flask_peewee import models # noqa: F401 diff --git a/example-flask-peewee/example/routes/__init__.py b/example-flask-peewee/example/routes/__init__.py index 9797f20..50f2c6f 100644 --- a/example-flask-peewee/example/routes/__init__.py +++ b/example-flask-peewee/example/routes/__init__.py @@ -1,2 +1,2 @@ -from example.routes import main -from social_flask import routes +from example.routes import main # noqa: F401 +from social_flask import routes # noqa: F401 diff --git a/example-flask-peewee/manage.py b/example-flask-peewee/manage.py index bc72f8d..f9d7f01 100755 --- a/example-flask-peewee/manage.py +++ b/example-flask-peewee/manage.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import click -from example import app, database +from example import app from flask.cli import FlaskGroup diff --git a/example-flask/example/__init__.py b/example-flask/example/__init__.py index 4a9bec4..f45f778 100644 --- a/example-flask/example/__init__.py +++ b/example-flask/example/__init__.py @@ -3,7 +3,7 @@ from common import filters from common.utils import common_context from common.utils import url_for as common_url_for -from flask import Flask, g, url_for +from flask import Flask, g from flask_login import LoginManager, current_user from social_flask.routes import social_auth from social_flask.template_filters import backends @@ -11,6 +11,7 @@ from social_flask_sqlalchemy.models import init_social from sqlalchemy import create_engine from sqlalchemy.orm import Session +from example import models BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -35,8 +36,6 @@ login_manager.login_message = "" login_manager.init_app(app) -from example import models, routes - @login_manager.user_loader def load_user(userid): diff --git a/example-flask/example/models/__init__.py b/example-flask/example/models/__init__.py index fde4944..f627dcd 100644 --- a/example-flask/example/models/__init__.py +++ b/example-flask/example/models/__init__.py @@ -1,2 +1,2 @@ -from example.models import user -from social_flask_sqlalchemy import models +from example.models import user # noqa: F401 +from social_flask_sqlalchemy import models # noqa: F401 diff --git a/example-flask/example/models/user.py b/example-flask/example/models/user.py index 27a69b1..0a7977c 100644 --- a/example-flask/example/models/user.py +++ b/example-flask/example/models/user.py @@ -1,6 +1,5 @@ from typing import Optional -from example import db_session from flask_login import UserMixin from sqlalchemy import String from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column diff --git a/example-flask/example/routes/__init__.py b/example-flask/example/routes/__init__.py index 9797f20..50f2c6f 100644 --- a/example-flask/example/routes/__init__.py +++ b/example-flask/example/routes/__init__.py @@ -1,2 +1,2 @@ -from example.routes import main -from social_flask import routes +from example.routes import main # noqa: F401 +from social_flask import routes # noqa: F401 diff --git a/example-pyramid/example/__init__.py b/example-pyramid/example/__init__.py index c9e9afa..2fb9ce3 100644 --- a/example-pyramid/example/__init__.py +++ b/example-pyramid/example/__init__.py @@ -1,5 +1,3 @@ -import sys - import example.local_settings as app_local_settings import example.settings as app_settings from common import filters, utils diff --git a/example-tornado/example/settings.py b/example-tornado/example/settings.py index bef46ec..799a3ce 100644 --- a/example-tornado/example/settings.py +++ b/example-tornado/example/settings.py @@ -108,4 +108,4 @@ "social_core.pipeline.debug.debug", ) -from example.local_settings import * +from example.local_settings import * # noqa: F401,E402,F403 diff --git a/example-tornado/manage.py b/example-tornado/manage.py index ec5d45d..f0f9f94 100755 --- a/example-tornado/manage.py +++ b/example-tornado/manage.py @@ -9,7 +9,7 @@ if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == "syncdb": - from example.models import User + from example.models import User # noqa: F401 init_social(Base, session, tornado_settings) Base.metadata.create_all(engine) diff --git a/example-webpy/app.py b/example-webpy/app.py index e620981..c07d5d0 100644 --- a/example-webpy/app.py +++ b/example-webpy/app.py @@ -9,6 +9,7 @@ from sqlalchemy import create_engine from sqlalchemy.orm import Session from web.contrib.template import render_jinja +from social_webpy import app as social_app BASE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -25,9 +26,6 @@ web.config[setting_name("LOGIN_REDIRECT_URL")] = "/done/" -from social_webpy import app as social_app -from social_webpy.utils import backends, psa - urls = ( "^/$", "main", @@ -99,7 +97,7 @@ def load_sqla(handler): except web.HTTPError: web.ctx.orm.commit() raise - except: + except Exception: web.ctx.orm.rollback() raise finally: From 96aa71b346e0cddaeec03872a59c089e99e37892 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:21:08 +0000 Subject: [PATCH 04/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-cherrypy/example/app.py | 8 +++++--- example-cherrypy/manage.py | 2 +- example-common/filters.py | 2 +- .../app/templatetags/backend_utils.py | 2 +- example-django/app/templatetags/backend_utils.py | 2 +- example-django/app/views.py | 1 + example-flask-mongoengine/example/__init__.py | 2 +- example-flask/example/__init__.py | 2 +- example-webpy/app.py | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/example-cherrypy/example/app.py b/example-cherrypy/example/app.py index f509df5..e4903a1 100644 --- a/example-cherrypy/example/app.py +++ b/example-cherrypy/example/app.py @@ -15,7 +15,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DATABASE_NAME = "sqlite:///{dbname}".format( # fix: skip - dbname=os.path.join(BASE_DIR, "db.sqlite3")) + dbname=os.path.join(BASE_DIR, "db.sqlite3") +) SAEnginePlugin(cherrypy.engine, DATABASE_NAME).subscribe() @@ -39,8 +40,9 @@ def render_home(self): load_strategy(), user=getattr(cherrypy.request, "user", None), ) - return cherrypy.tools.jinja2env.get_template( # fix: skip - "home.html").render(**context) + return cherrypy.tools.jinja2env.get_template("home.html").render( # fix: skip + **context + ) def load_user(): diff --git a/example-cherrypy/manage.py b/example-cherrypy/manage.py index 22733a7..8c87f24 100755 --- a/example-cherrypy/manage.py +++ b/example-cherrypy/manage.py @@ -2,10 +2,10 @@ import sys import cherrypy -from sqlalchemy import create_engine from example.app import DATABASE_NAME, run_app from example.db import Base from social_cherrypy.models import SocialBase +from sqlalchemy import create_engine cherrypy.config.update( { diff --git a/example-common/filters.py b/example-common/filters.py index cd7d596..27c1c9e 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n: n + items] for n in range(0, len(value), items)] + return [value[n : n + items] for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 56cbaa3..03032dc 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n: n + 10] for n in range(0, len(backends), 10)] + return [backends[n : n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index eebb2b7..740d72b 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n: n + 10] for n in range(0, len(backends), 10)] + return [backends[n : n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/views.py b/example-django/app/views.py index b22146e..8711ae5 100644 --- a/example-django/app/views.py +++ b/example-django/app/views.py @@ -1,4 +1,5 @@ import json + from django.contrib.auth import login from django.contrib.auth import logout as auth_logout from django.contrib.auth.decorators import login_required diff --git a/example-flask-mongoengine/example/__init__.py b/example-flask-mongoengine/example/__init__.py index ae85ce9..bd8846f 100644 --- a/example-flask-mongoengine/example/__init__.py +++ b/example-flask-mongoengine/example/__init__.py @@ -3,6 +3,7 @@ from common import filters from common.utils import common_context from common.utils import url_for as common_url_for +from example import models from flask import Flask, g from flask_login import LoginManager, current_user from flask_mongoengine import MongoEngine @@ -10,7 +11,6 @@ from social_flask.template_filters import backends from social_flask.utils import load_strategy from social_flask_mongoengine.models import init_social -from example import models BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/example-flask/example/__init__.py b/example-flask/example/__init__.py index f45f778..50dd858 100644 --- a/example-flask/example/__init__.py +++ b/example-flask/example/__init__.py @@ -3,6 +3,7 @@ from common import filters from common.utils import common_context from common.utils import url_for as common_url_for +from example import models from flask import Flask, g from flask_login import LoginManager, current_user from social_flask.routes import social_auth @@ -11,7 +12,6 @@ from social_flask_sqlalchemy.models import init_social from sqlalchemy import create_engine from sqlalchemy.orm import Session -from example import models BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/example-webpy/app.py b/example-webpy/app.py index c07d5d0..74a0dc5 100644 --- a/example-webpy/app.py +++ b/example-webpy/app.py @@ -5,11 +5,11 @@ from common.utils import common_context, url_for from example import local_settings, settings from social_core.utils import setting_name +from social_webpy import app as social_app from social_webpy.utils import load_strategy from sqlalchemy import create_engine from sqlalchemy.orm import Session from web.contrib.template import render_jinja -from social_webpy import app as social_app BASE_DIR = os.path.dirname(os.path.abspath(__file__)) From 010a756b6c5e3a5d1e79c1e3fa16e31f873c669f Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:26:38 +0900 Subject: [PATCH 05/18] 2nd pep8 fix --- example-cherrypy/example/app.py | 5 ++--- example-common/filters.py | 8 +++++--- example-common/pipeline.py | 12 ++++++++---- example-common/utils.py | 3 ++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/example-cherrypy/example/app.py b/example-cherrypy/example/app.py index e4903a1..1cb6ff7 100644 --- a/example-cherrypy/example/app.py +++ b/example-cherrypy/example/app.py @@ -40,9 +40,8 @@ def render_home(self): load_strategy(), user=getattr(cherrypy.request, "user", None), ) - return cherrypy.tools.jinja2env.get_template("home.html").render( # fix: skip - **context - ) + jinja2env = cherrypy.tools.jinja2env + return jinja2env.get_template("home.html").render(**context) def load_user(): diff --git a/example-common/filters.py b/example-common/filters.py index 27c1c9e..e248e5e 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,15 +38,17 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] for n in range(0, len(value), items)] + return [value[n: n + items] for n in range(0, len(value), items)] def social_backends(backends): - return filter_backends(backends, lambda name, backend: name not in LEGACY_NAMES) + return filter_backends( # fix: skip + backends, lambda name, backend: name not in LEGACY_NAMES) def legacy_backends(backends): - return filter_backends(backends, lambda name, backend: name in LEGACY_NAMES) + return filter_backends( # fix: skip + backends, lambda name, backend: name in LEGACY_NAMES) def oauth_backends(backends): diff --git a/example-common/pipeline.py b/example-common/pipeline.py index 3c6e0ba..f04b395 100644 --- a/example-common/pipeline.py +++ b/example-common/pipeline.py @@ -11,11 +11,13 @@ def require_email(strategy, details, user=None, is_new=False, *args, **kwargs): details["email"] = email else: current_partial = kwargs.get("current_partial") - return strategy.redirect(f"/email?partial_token={current_partial.token}") + return strategy.redirect( # fix: skip + f"/email?partial_token={current_partial.token}") @partial -def require_country(strategy, details, user=None, is_new=False, *args, **kwargs): +def require_country( # fix: skip + strategy, details, user=None, is_new=False, *args, **kwargs): if kwargs.get("ajax"): return elif is_new and not details.get("country"): @@ -24,7 +26,8 @@ def require_country(strategy, details, user=None, is_new=False, *args, **kwargs) details["country"] = country else: current_partial = kwargs.get("current_partial") - return strategy.redirect(f"/country?partial_token={current_partial.token}") + return strategy.redirect( # fix: skip + f"/country?partial_token={current_partial.token}") @partial @@ -37,4 +40,5 @@ def require_city(strategy, details, user=None, is_new=False, *args, **kwargs): details["city"] = city else: current_partial = kwargs.get("current_partial") - return strategy.redirect(f"/city?partial_token={current_partial.token}") + return strategy.redirect( # fix: skip + f"/city?partial_token={current_partial.token}") diff --git a/example-common/utils.py b/example-common/utils.py index 7698b5e..3b6b90c 100644 --- a/example-common/utils.py +++ b/example-common/utils.py @@ -16,7 +16,8 @@ def associations(user, strategy): return list(user_associations) -def common_context(authentication_backends, strategy, user=None, plus_id=None, **extra): +def common_context( # fix: skip + authentication_backends, strategy, user=None, plus_id=None, **extra): """Common view context""" context = { "user": user, From f4d595cc723c91a67746f99356f7006ad2776135 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:26:49 +0000 Subject: [PATCH 06/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-common/filters.py | 8 +++++--- example-common/pipeline.py | 12 ++++++++---- example-common/utils.py | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index e248e5e..6080877 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,17 +38,19 @@ def icon_name(name): def slice_by(value, items): - return [value[n: n + items] for n in range(0, len(value), items)] + return [value[n : n + items] for n in range(0, len(value), items)] def social_backends(backends): return filter_backends( # fix: skip - backends, lambda name, backend: name not in LEGACY_NAMES) + backends, lambda name, backend: name not in LEGACY_NAMES + ) def legacy_backends(backends): return filter_backends( # fix: skip - backends, lambda name, backend: name in LEGACY_NAMES) + backends, lambda name, backend: name in LEGACY_NAMES + ) def oauth_backends(backends): diff --git a/example-common/pipeline.py b/example-common/pipeline.py index f04b395..aeb16a8 100644 --- a/example-common/pipeline.py +++ b/example-common/pipeline.py @@ -12,12 +12,14 @@ def require_email(strategy, details, user=None, is_new=False, *args, **kwargs): else: current_partial = kwargs.get("current_partial") return strategy.redirect( # fix: skip - f"/email?partial_token={current_partial.token}") + f"/email?partial_token={current_partial.token}" + ) @partial def require_country( # fix: skip - strategy, details, user=None, is_new=False, *args, **kwargs): + strategy, details, user=None, is_new=False, *args, **kwargs +): if kwargs.get("ajax"): return elif is_new and not details.get("country"): @@ -27,7 +29,8 @@ def require_country( # fix: skip else: current_partial = kwargs.get("current_partial") return strategy.redirect( # fix: skip - f"/country?partial_token={current_partial.token}") + f"/country?partial_token={current_partial.token}" + ) @partial @@ -41,4 +44,5 @@ def require_city(strategy, details, user=None, is_new=False, *args, **kwargs): else: current_partial = kwargs.get("current_partial") return strategy.redirect( # fix: skip - f"/city?partial_token={current_partial.token}") + f"/city?partial_token={current_partial.token}" + ) diff --git a/example-common/utils.py b/example-common/utils.py index 3b6b90c..f282433 100644 --- a/example-common/utils.py +++ b/example-common/utils.py @@ -17,7 +17,8 @@ def associations(user, strategy): def common_context( # fix: skip - authentication_backends, strategy, user=None, plus_id=None, **extra): + authentication_backends, strategy, user=None, plus_id=None, **extra +): """Common view context""" context = { "user": user, From 830c7a9f2e1182e0d072cf0c578b2224b8ae35cf Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:49:44 +0900 Subject: [PATCH 07/18] PEP8 working --- example-common/filters.py | 2 +- example-django-mongoengine/app/decorators.py | 1 - example-django-mongoengine/app/mail.py | 5 ++-- .../app/templatetags/backend_utils.py | 5 ++-- example-django-mongoengine/app/views.py | 2 +- .../example/settings.py | 24 +++++++++++++++---- example-django-mongoengine/example/urls.py | 3 ++- example-django/app/decorators.py | 1 - example-django/app/mail.py | 5 ++-- example-django/app/models.py | 3 ++- .../app/templatetags/backend_utils.py | 2 +- example-django/app/views.py | 2 +- example-django/example/settings.py | 24 +++++++++++++++---- example-flask-mongoengine/example/__init__.py | 3 ++- example-flask-peewee/example/__init__.py | 3 ++- example-flask-peewee/example/models/user.py | 3 ++- example-flask/example/__init__.py | 3 ++- example-pyramid/example/__init__.py | 3 ++- example-pyramid/example/views.py | 3 ++- example-tornado/example/app.py | 3 ++- example-webpy/app.py | 1 - 21 files changed, 71 insertions(+), 30 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 6080877..726a4d7 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] for n in range(0, len(value), items)] + return [value[n:n + items] for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/decorators.py b/example-django-mongoengine/app/decorators.py index 09f4007..2bbad50 100644 --- a/example-django-mongoengine/app/decorators.py +++ b/example-django-mongoengine/app/decorators.py @@ -24,7 +24,6 @@ def wrapper(request, *args, **kwargs): settings.AUTHENTICATION_BACKENDS, load_strategy(), request.user, - plus_id=getattr(settings, "SOCIAL_AUTH_GOOGLE_PLUS_KEY", None), **out ), ) diff --git a/example-django-mongoengine/app/mail.py b/example-django-mongoengine/app/mail.py index f01fceb..8adfbd4 100644 --- a/example-django-mongoengine/app/mail.py +++ b/example-django-mongoengine/app/mail.py @@ -4,8 +4,9 @@ def send_validation(strategy, backend, code, partial_token): - url = "{}?verification_code={}&partial_token={}".format( - reverse("social:complete", args=(backend.name,)), code.code, partial_token + url = "{}?verification_code={}&partial_token={}".format( # fix: skip + reverse("social:complete", args=(backend.name,)), # fix: skip + code.code, partial_token ) url = strategy.request.build_absolute_uri(url) send_mail( diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 03032dc..d9e5770 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n:n + 10] for n in range(0, len(backends), 10)] @register.filter @@ -80,7 +80,8 @@ def associated(context, backend): context["association"] = None if user and user.is_authenticated(): try: - context["association"] = user.social_auth.filter(provider=backend.name)[0] + context["association"] = user.social_auth.filter( # fix: skip + provider=backend.name)[0] except IndexError: pass return "" diff --git a/example-django-mongoengine/app/views.py b/example-django-mongoengine/app/views.py index f966797..8e90341 100644 --- a/example-django-mongoengine/app/views.py +++ b/example-django-mongoengine/app/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 -from social_django.utils import psa +from social_django.utils import psa, load_strategy from .decorators import render_to diff --git a/example-django-mongoengine/example/settings.py b/example-django-mongoengine/example/settings.py index eaae70a..ab95178 100644 --- a/example-django-mongoengine/example/settings.py +++ b/example-django-mongoengine/example/settings.py @@ -237,18 +237,34 @@ # Password validation # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators +UserAttributeSimilarityValidator = ( # fix: skip + "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" +) + +MinimumLengthValidator = ( # fix: skip + "django.contrib.auth.password_validation.MinimumLengthValidator" +) + +CommonPasswordValidator = ( # fix: skip + "django.contrib.auth.password_validation.CommonPasswordValidator" +) + +NumericPasswordValidator = ( # fix: skip + "django.contrib.auth.password_validation.NumericPasswordValidator" +) + AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + "NAME": UserAttributeSimilarityValidator, }, { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + "NAME": MinimumLengthValidator, }, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + "NAME": CommonPasswordValidator, }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + "NAME": NumericPasswordValidator, }, ] diff --git a/example-django-mongoengine/example/urls.py b/example-django-mongoengine/example/urls.py index 49e2fe7..2e314dc 100644 --- a/example-django-mongoengine/example/urls.py +++ b/example-django-mongoengine/example/urls.py @@ -9,7 +9,8 @@ url(r"^login/$", app_views.home), url(r"^logout/$", app_views.logout), url(r"^done/$", app_views.done, name="done"), - url(r"^ajax-auth/(?P[^/]+)/$", app_views.ajax_auth, name="ajax-auth"), + url(r"^ajax-auth/(?P[^/]+)/$", # fix: skip + app_views.ajax_auth, name="ajax-auth"), url(r"^email/$", app_views.require_email, name="require_email"), url(r"", include("social_django.urls")), ] diff --git a/example-django/app/decorators.py b/example-django/app/decorators.py index 09f4007..2bbad50 100644 --- a/example-django/app/decorators.py +++ b/example-django/app/decorators.py @@ -24,7 +24,6 @@ def wrapper(request, *args, **kwargs): settings.AUTHENTICATION_BACKENDS, load_strategy(), request.user, - plus_id=getattr(settings, "SOCIAL_AUTH_GOOGLE_PLUS_KEY", None), **out ), ) diff --git a/example-django/app/mail.py b/example-django/app/mail.py index 40cc4cc..0101ff5 100644 --- a/example-django/app/mail.py +++ b/example-django/app/mail.py @@ -4,8 +4,9 @@ def send_validation(strategy, backend, code, partial_token): - url = "{}?verification_code={}&partial_token={}".format( - reverse("social:complete", args=(backend.name,)), code.code, partial_token + url = "{}?verification_code={}&partial_token={}".format( # fix: skip + reverse("social:complete", args=(backend.name,)), # fix: skip + code.code, partial_token # fix: skip ) url = strategy.request.build_absolute_uri(url) send_mail( diff --git a/example-django/app/models.py b/example-django/app/models.py index 0cbb60a..40a50cf 100644 --- a/example-django/app/models.py +++ b/example-django/app/models.py @@ -1,5 +1,6 @@ from django.db import models -from social_django.models import USER_MODEL, AbstractUserSocialAuth, DjangoStorage +from social_django.models import ( # fix: skip + USER_MODEL, AbstractUserSocialAuth, DjangoStorage) class CustomUserSocialAuth(AbstractUserSocialAuth): diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 740d72b..30d43ad 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n:n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/views.py b/example-django/app/views.py index 8711ae5..40648a5 100644 --- a/example-django/app/views.py +++ b/example-django/app/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 -from social_django.utils import psa +from social_django.utils import psa, load_strategy from .decorators import render_to diff --git a/example-django/example/settings.py b/example-django/example/settings.py index 26d7252..ba7126b 100644 --- a/example-django/example/settings.py +++ b/example-django/example/settings.py @@ -236,18 +236,34 @@ # Password validation # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators +UserAttributeSimilarityValidator = ( # fix: skip + "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" +) + +MinimumLengthValidator = ( # fix: skip + "django.contrib.auth.password_validation.MinimumLengthValidator" +) + +CommonPasswordValidator = ( # fix: skip + "django.contrib.auth.password_validation.CommonPasswordValidator" +) + +NumericPasswordValidator = ( # fix: skip + "django.contrib.auth.password_validation.NumericPasswordValidator" +) + AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + "NAME": UserAttributeSimilarityValidator, }, { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + "NAME": MinimumLengthValidator, }, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + "NAME": CommonPasswordValidator, }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + "NAME": NumericPasswordValidator, }, ] diff --git a/example-flask-mongoengine/example/__init__.py b/example-flask-mongoengine/example/__init__.py index bd8846f..748c239 100644 --- a/example-flask-mongoengine/example/__init__.py +++ b/example-flask-mongoengine/example/__init__.py @@ -15,7 +15,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # App -app = Flask(__name__, template_folder=os.path.join(BASE_DIR, "common", "templates")) +template_folder = os.path.join(BASE_DIR, "common", "templates") +app = Flask(__name__, template_folder=template_folder) app.config.from_object("example.settings") try: diff --git a/example-flask-peewee/example/__init__.py b/example-flask-peewee/example/__init__.py index 578e410..e87807a 100644 --- a/example-flask-peewee/example/__init__.py +++ b/example-flask-peewee/example/__init__.py @@ -16,7 +16,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # App -app = Flask(__name__, template_folder=os.path.join(BASE_DIR, "common", "templates")) +template_folder = os.path.join(BASE_DIR, "common", "templates") +app = Flask(__name__, template_folder=template_folder) app.config.from_object("example.settings") try: diff --git a/example-flask-peewee/example/models/user.py b/example-flask-peewee/example/models/user.py index 4a94163..6b5b2f7 100644 --- a/example-flask-peewee/example/models/user.py +++ b/example-flask-peewee/example/models/user.py @@ -7,7 +7,8 @@ # model definitions -- the standard "pattern" is to define a base model class -# that specifies which database to use. then, any subclasses will automatically +# that specifies which database to use. +# then, any subclasses will automatically # use the correct storage. class BaseModel(Model): class Meta: diff --git a/example-flask/example/__init__.py b/example-flask/example/__init__.py index 50dd858..ac89c42 100644 --- a/example-flask/example/__init__.py +++ b/example-flask/example/__init__.py @@ -16,7 +16,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # App -app = Flask(__name__, template_folder=os.path.join(BASE_DIR, "common", "templates")) +template_folder = os.path.join(BASE_DIR, "common", "templates") +app = Flask(__name__, template_folder=template_folder) app.config.from_object("example.settings") try: diff --git a/example-pyramid/example/__init__.py b/example-pyramid/example/__init__.py index 2fb9ce3..422067f 100644 --- a/example-pyramid/example/__init__.py +++ b/example-pyramid/example/__init__.py @@ -10,10 +10,11 @@ def get_settings(module): + not_in_filters = ["__builtins__", "__file__"] return { key: value for key, value in module.__dict__.items() - if key not in module.__builtins__ and key not in ["__builtins__", "__file__"] + if key not in module.__builtins__ and key not in not_in_filters } diff --git a/example-pyramid/example/views.py b/example-pyramid/example/views.py index 74219c9..9a55da5 100644 --- a/example-pyramid/example/views.py +++ b/example-pyramid/example/views.py @@ -24,7 +24,8 @@ def done(request): ) -@view_config(route_name="email_required", renderer="common:templates/home.jinja2") +@view_config(route_name="email_required", # fix: skip + renderer="common:templates/home.jinja2") def email_required(request): strategy = load_strategy(request) partial_token = request.GET.get("partial_token") diff --git a/example-tornado/example/app.py b/example-tornado/example/app.py index be8e962..b1f9b1d 100644 --- a/example-tornado/example/app.py +++ b/example-tornado/example/app.py @@ -13,7 +13,8 @@ from tornado_jinja2 import Jinja2Loader BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -DATABASE_NAME = "sqlite:///{dbname}".format(dbname=os.path.join(BASE_DIR, "db.sqlite3")) +DATABASE_NAME = "sqlite:///{dbname}".format( # fix: skip + dbname=os.path.join(BASE_DIR, "db.sqlite3")) engine = create_engine(DATABASE_NAME, echo=False) session = Session(engine) diff --git a/example-webpy/app.py b/example-webpy/app.py index 74a0dc5..88f82f4 100644 --- a/example-webpy/app.py +++ b/example-webpy/app.py @@ -59,7 +59,6 @@ def render_home(self, **extra): web.config[setting_name("AUTHENTICATION_BACKENDS")], load_strategy(), user=self.get_current_user(), - plus_id=web.config.get(setting_name("SOCIAL_AUTH_GOOGLE_PLUS_KEY")), **extra ) return render.home(**context) From a509d64dc5e94bb3c0f7328090c0b82c9dcafc87 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:49:56 +0000 Subject: [PATCH 08/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-common/filters.py | 2 +- example-django-mongoengine/app/mail.py | 3 ++- .../app/templatetags/backend_utils.py | 5 +++-- example-django-mongoengine/app/views.py | 2 +- example-django-mongoengine/example/urls.py | 7 +++++-- example-django/app/mail.py | 3 ++- example-django/app/models.py | 7 +++++-- example-django/app/templatetags/backend_utils.py | 2 +- example-django/app/views.py | 2 +- example-pyramid/example/views.py | 5 +++-- example-tornado/example/app.py | 3 ++- 11 files changed, 26 insertions(+), 15 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 726a4d7..6080877 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n:n + items] for n in range(0, len(value), items)] + return [value[n : n + items] for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/mail.py b/example-django-mongoengine/app/mail.py index 8adfbd4..506e7b5 100644 --- a/example-django-mongoengine/app/mail.py +++ b/example-django-mongoengine/app/mail.py @@ -6,7 +6,8 @@ def send_validation(strategy, backend, code, partial_token): url = "{}?verification_code={}&partial_token={}".format( # fix: skip reverse("social:complete", args=(backend.name,)), # fix: skip - code.code, partial_token + code.code, + partial_token, ) url = strategy.request.build_absolute_uri(url) send_mail( diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index d9e5770..f8f71d4 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n + 10] for n in range(0, len(backends), 10)] + return [backends[n : n + 10] for n in range(0, len(backends), 10)] @register.filter @@ -81,7 +81,8 @@ def associated(context, backend): if user and user.is_authenticated(): try: context["association"] = user.social_auth.filter( # fix: skip - provider=backend.name)[0] + provider=backend.name + )[0] except IndexError: pass return "" diff --git a/example-django-mongoengine/app/views.py b/example-django-mongoengine/app/views.py index 8e90341..0c7d7a4 100644 --- a/example-django-mongoengine/app/views.py +++ b/example-django-mongoengine/app/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 -from social_django.utils import psa, load_strategy +from social_django.utils import load_strategy, psa from .decorators import render_to diff --git a/example-django-mongoengine/example/urls.py b/example-django-mongoengine/example/urls.py index 2e314dc..71d21e4 100644 --- a/example-django-mongoengine/example/urls.py +++ b/example-django-mongoengine/example/urls.py @@ -9,8 +9,11 @@ url(r"^login/$", app_views.home), url(r"^logout/$", app_views.logout), url(r"^done/$", app_views.done, name="done"), - url(r"^ajax-auth/(?P[^/]+)/$", # fix: skip - app_views.ajax_auth, name="ajax-auth"), + url( + r"^ajax-auth/(?P[^/]+)/$", # fix: skip + app_views.ajax_auth, + name="ajax-auth", + ), url(r"^email/$", app_views.require_email, name="require_email"), url(r"", include("social_django.urls")), ] diff --git a/example-django/app/mail.py b/example-django/app/mail.py index 0101ff5..34b9ddb 100644 --- a/example-django/app/mail.py +++ b/example-django/app/mail.py @@ -6,7 +6,8 @@ def send_validation(strategy, backend, code, partial_token): url = "{}?verification_code={}&partial_token={}".format( # fix: skip reverse("social:complete", args=(backend.name,)), # fix: skip - code.code, partial_token # fix: skip + code.code, + partial_token, # fix: skip ) url = strategy.request.build_absolute_uri(url) send_mail( diff --git a/example-django/app/models.py b/example-django/app/models.py index 40a50cf..9ec504b 100644 --- a/example-django/app/models.py +++ b/example-django/app/models.py @@ -1,6 +1,9 @@ from django.db import models -from social_django.models import ( # fix: skip - USER_MODEL, AbstractUserSocialAuth, DjangoStorage) +from social_django.models import ( # fix: skip + USER_MODEL, + AbstractUserSocialAuth, + DjangoStorage, +) class CustomUserSocialAuth(AbstractUserSocialAuth): diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 30d43ad..740d72b 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n + 10] for n in range(0, len(backends), 10)] + return [backends[n : n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/views.py b/example-django/app/views.py index 40648a5..31eadf0 100644 --- a/example-django/app/views.py +++ b/example-django/app/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 -from social_django.utils import psa, load_strategy +from social_django.utils import load_strategy, psa from .decorators import render_to diff --git a/example-pyramid/example/views.py b/example-pyramid/example/views.py index 9a55da5..1a848f9 100644 --- a/example-pyramid/example/views.py +++ b/example-pyramid/example/views.py @@ -24,8 +24,9 @@ def done(request): ) -@view_config(route_name="email_required", # fix: skip - renderer="common:templates/home.jinja2") +@view_config( + route_name="email_required", renderer="common:templates/home.jinja2" # fix: skip +) def email_required(request): strategy = load_strategy(request) partial_token = request.GET.get("partial_token") diff --git a/example-tornado/example/app.py b/example-tornado/example/app.py index b1f9b1d..38cc344 100644 --- a/example-tornado/example/app.py +++ b/example-tornado/example/app.py @@ -14,7 +14,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DATABASE_NAME = "sqlite:///{dbname}".format( # fix: skip - dbname=os.path.join(BASE_DIR, "db.sqlite3")) + dbname=os.path.join(BASE_DIR, "db.sqlite3") +) engine = create_engine(DATABASE_NAME, echo=False) session = Session(engine) From a60326a815f4e1c3d0cadf4305cf89588e997137 Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:52:39 +0900 Subject: [PATCH 09/18] PEP8 2nd working --- example-common/filters.py | 2 +- example-django-mongoengine/app/templatetags/backend_utils.py | 2 +- example-django/app/templatetags/backend_utils.py | 2 +- example-pyramid/example/views.py | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 6080877..ceab6e8 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] for n in range(0, len(value), items)] + return [value[n:n+items] for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index f8f71d4..bf30297 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n:n+10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 740d72b..209e2a1 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n:n+10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-pyramid/example/views.py b/example-pyramid/example/views.py index 1a848f9..4da18f5 100644 --- a/example-pyramid/example/views.py +++ b/example-pyramid/example/views.py @@ -24,8 +24,9 @@ def done(request): ) -@view_config( - route_name="email_required", renderer="common:templates/home.jinja2" # fix: skip +@view_config( # fix: skip + route_name="email_required", # fix: skip + renderer="common:templates/home.jinja2" # fix: skip ) def email_required(request): strategy = load_strategy(request) From dbc3d62151c5250cd55f608bac5d0886e454f0ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:52:56 +0000 Subject: [PATCH 10/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-common/filters.py | 2 +- example-django-mongoengine/app/templatetags/backend_utils.py | 2 +- example-django/app/templatetags/backend_utils.py | 2 +- example-pyramid/example/views.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index ceab6e8..6080877 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n:n+items] for n in range(0, len(value), items)] + return [value[n : n + items] for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index bf30297..f8f71d4 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n+10] for n in range(0, len(backends), 10)] + return [backends[n : n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 209e2a1..740d72b 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n+10] for n in range(0, len(backends), 10)] + return [backends[n : n + 10] for n in range(0, len(backends), 10)] @register.filter diff --git a/example-pyramid/example/views.py b/example-pyramid/example/views.py index 4da18f5..88d8ce4 100644 --- a/example-pyramid/example/views.py +++ b/example-pyramid/example/views.py @@ -26,7 +26,7 @@ def done(request): @view_config( # fix: skip route_name="email_required", # fix: skip - renderer="common:templates/home.jinja2" # fix: skip + renderer="common:templates/home.jinja2", # fix: skip ) def email_required(request): strategy = load_strategy(request) From 5cc7e50a6c71624d0331f704741a5875d5d7e5ae Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:55:24 +0900 Subject: [PATCH 11/18] E203 fix --- example-common/filters.py | 2 +- example-django-mongoengine/app/templatetags/backend_utils.py | 2 +- example-django/app/templatetags/backend_utils.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 6080877..1343741 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] for n in range(0, len(value), items)] + return [value[n:n + items] for n in range(0, len(value), items)] # noqa: E203 def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index f8f71d4..3581126 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n:n + 10] for n in range(0, len(backends), 10)] # noqa: E203 @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 740d72b..5998686 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] + return [backends[n:n + 10] for n in range(0, len(backends), 10)] # noqa: E203 @register.filter From 1b5c162c0db40603b45bd0d06288f79ac229ec5c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:55:35 +0000 Subject: [PATCH 12/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-common/filters.py | 2 +- example-django-mongoengine/app/templatetags/backend_utils.py | 2 +- example-django/app/templatetags/backend_utils.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 1343741..997e675 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,7 @@ def icon_name(name): def slice_by(value, items): - return [value[n:n + items] for n in range(0, len(value), items)] # noqa: E203 + return [value[n : n + items] for n in range(0, len(value), items)] # noqa: E203 def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 3581126..407efb9 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n + 10] for n in range(0, len(backends), 10)] # noqa: E203 + return [backends[n : n + 10] for n in range(0, len(backends), 10)] # noqa: E203 @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 5998686..b9d3a94 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,7 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n + 10] for n in range(0, len(backends), 10)] # noqa: E203 + return [backends[n : n + 10] for n in range(0, len(backends), 10)] # noqa: E203 @register.filter From 52771cebc7264ee089e517e04008e7e6795ef068 Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:58:16 +0900 Subject: [PATCH 13/18] PEP8 working --- example-common/filters.py | 3 ++- example-django-mongoengine/app/templatetags/backend_utils.py | 3 ++- example-django/app/templatetags/backend_utils.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 997e675..491a461 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,7 +38,8 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] for n in range(0, len(value), items)] # noqa: E203 + return [value[n : n + items] # fix: skip + for n in range(0, len(value), items)] # noqa: E203 def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 407efb9..31a88aa 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,7 +49,8 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] # noqa: E203 + return [backends[n : n + 10] # fix: skip + for n in range(0, len(backends), 10)] # noqa: E203 @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index b9d3a94..19a28a1 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,7 +50,8 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] for n in range(0, len(backends), 10)] # noqa: E203 + return [backends[n:n + 10] # fix: skip + for n in range(0, len(backends), 10)] # noqa: E203 @register.filter From f5afd8b3d8adcdaca83ea0eab0fd67ffa55c5bfd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:58:28 +0000 Subject: [PATCH 14/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-common/filters.py | 5 +++-- example-django-mongoengine/app/templatetags/backend_utils.py | 5 +++-- example-django/app/templatetags/backend_utils.py | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 491a461..f6380b2 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,8 +38,9 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] # fix: skip - for n in range(0, len(value), items)] # noqa: E203 + return [ + value[n : n + items] for n in range(0, len(value), items) # fix: skip + ] # noqa: E203 def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 31a88aa..61de51a 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,8 +49,9 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] # fix: skip - for n in range(0, len(backends), 10)] # noqa: E203 + return [ + backends[n : n + 10] for n in range(0, len(backends), 10) # fix: skip + ] # noqa: E203 @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 19a28a1..06c3721 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -50,8 +50,9 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n:n + 10] # fix: skip - for n in range(0, len(backends), 10)] # noqa: E203 + return [ + backends[n : n + 10] for n in range(0, len(backends), 10) # fix: skip + ] # noqa: E203 @register.filter From 870463caa60db7e01133fd3029d2adb95ef1eb5a Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 17:59:54 +0900 Subject: [PATCH 15/18] E203 fix --- example-common/filters.py | 4 ++-- example-django-mongoengine/app/templatetags/backend_utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 491a461..03c6cb6 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,8 +38,8 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] # fix: skip - for n in range(0, len(value), items)] # noqa: E203 + return [value[n : n + items] # fix: skip # noqa: E203 + for n in range(0, len(value), items)] def social_backends(backends): diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 31a88aa..6b4112a 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,8 +49,8 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] # fix: skip - for n in range(0, len(backends), 10)] # noqa: E203 + return [backends[n : n + 10] # fix: skip # noqa: E203 + for n in range(0, len(backends), 10)] @register.filter From 0caca5466f7b9ecfd61d0db2858e251f78ea397f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:02:00 +0000 Subject: [PATCH 16/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../app/templatetags/backend_utils.py | 6 ++++-- example-django/app/templatetags/backend_utils.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example-django-mongoengine/app/templatetags/backend_utils.py b/example-django-mongoengine/app/templatetags/backend_utils.py index 6b4112a..03af81c 100644 --- a/example-django-mongoengine/app/templatetags/backend_utils.py +++ b/example-django-mongoengine/app/templatetags/backend_utils.py @@ -49,8 +49,10 @@ def social_backends(backends): if name not in ["username", "email"] ] backends.sort(key=lambda b: b[0]) - return [backends[n : n + 10] # fix: skip # noqa: E203 - for n in range(0, len(backends), 10)] + return [ + backends[n : n + 10] # fix: skip # noqa: E203 + for n in range(0, len(backends), 10) + ] @register.filter diff --git a/example-django/app/templatetags/backend_utils.py b/example-django/app/templatetags/backend_utils.py index 028920c..148b3a2 100644 --- a/example-django/app/templatetags/backend_utils.py +++ b/example-django/app/templatetags/backend_utils.py @@ -51,7 +51,7 @@ def social_backends(backends): ] backends.sort(key=lambda b: b[0]) return [ - backends[n : n + 10] # fix: skip # noqa: E203 + backends[n : n + 10] # fix: skip # noqa: E203 for n in range(0, len(backends), 10) ] From f24fc114c2e7a81ce2b99e9d32c1dd67dd3c3838 Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 18:03:01 +0900 Subject: [PATCH 17/18] error fix --- .pre-commit-config.yaml | 1 - example-common/filters.py | 6 ------ 2 files changed, 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23019de..aec596b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,6 @@ repos: rev: v4.5.0 hooks: - id: check-merge-conflict - - id: check-json - id: debug-statements - id: mixed-line-ending args: [--fix=lf] diff --git a/example-common/filters.py b/example-common/filters.py index feef036..03c6cb6 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,14 +38,8 @@ def icon_name(name): def slice_by(value, items): -<<<<<<< HEAD return [value[n : n + items] # fix: skip # noqa: E203 for n in range(0, len(value), items)] -======= - return [ - value[n : n + items] for n in range(0, len(value), items) # fix: skip - ] # noqa: E203 ->>>>>>> f5afd8b3d8adcdaca83ea0eab0fd67ffa55c5bfd def social_backends(backends): From e6b31e0105e9104d85b7d8909bea3b2ffb468973 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:03:14 +0000 Subject: [PATCH 18/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example-common/filters.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example-common/filters.py b/example-common/filters.py index 03c6cb6..b0ef3df 100644 --- a/example-common/filters.py +++ b/example-common/filters.py @@ -38,8 +38,10 @@ def icon_name(name): def slice_by(value, items): - return [value[n : n + items] # fix: skip # noqa: E203 - for n in range(0, len(value), items)] + return [ + value[n : n + items] # fix: skip # noqa: E203 + for n in range(0, len(value), items) + ] def social_backends(backends):