From 5f0bd45ca9a615a0367df3fc194f542eba371e78 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:42:36 +0900 Subject: [PATCH 1/7] 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 import errors found in several examples - Added pyproject.toml file after removing setup.py due to the introduction of PEP 517/518 - Fixed minimum installed version to Python 3.7 --- CHANGELOG.md | 5 +++ Makefile | 8 ++--- pyproject.toml | 55 +++++++++++++++++++++++++++++++ requirements.txt | 5 --- setup.cfg | 11 ------- setup.py | 37 --------------------- social_flask_sqlalchemy/models.py | 14 ++++---- 7 files changed, 68 insertions(+), 67 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c410024..c9632f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased](https://github.com/python-social-auth/social-app-flask-sqlalchemy/commits/master) +### Changed +- Modified model and access code to work with SQLAlchemy version 2 (Issue #3) +- Updated packaging information files per PEP 517, PEP 518 (Issue #4) +- Restricted Python minimum working version to 3.7 or higher to align with SQLAlchemy 2 (Issue #3) + ## [1.0.1](https://github.com/python-social-auth/social-app-flask-sqlalchemy/releases/tag/1.0.1) - 2017-01-29 ### Added diff --git a/Makefile b/Makefile index 53cf9f8..8b9b717 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,8 @@ build: - @ python setup.py sdist - @ python setup.py bdist_wheel --python-tag py2 - @ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 + @ python -m build publish: - @ python setup.py sdist upload - @ python setup.py bdist_wheel --python-tag py2 upload - @ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 upload + @ twine upload dist/* clean: @ find . -name '*.py[co]' -delete diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..faa8494 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,55 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = 'social-auth-app-flask-sqlalchemy' +dynamic = ["version"] +dependencies = [ + "six", + "sqlalchemy", + "social-auth-core>=1.0.0", + "social-auth-app-flask>=1.0.0", + "social-auth-storage-sqlalchemy>=1.0.1", +] +authors = [ + {name = "Matias Aguirre", email = "matiasaguirre@gmail.com"}, + {name = "Lee Ji-ho", email = "search5@gmail.com"}, +] +description = 'Python Social Authentication, SQLAlchemy Flask models integration.' +license = {text = 'BSD'} +keywords = ["flask", "sqlalchemy", "social auth"] +readme = "README.md" +classifiers=[ + 'Development Status :: 4 - Beta', + 'Topic :: Internet', + 'License :: OSI Approved :: BSD License', + 'Intended Audience :: Developers', + 'Environment :: Web Environment', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12' +] +requires-python = ">= 3.7" + +[project.urls] +Repository = 'https://github.com/python-social-auth/social-app-flask-sqlalchemy' +Documentation = 'http://python-social-auth.readthedocs.org' +Issues = 'https://github.com/python-social-auth/social-app-flask-sqlalchemy/issues' +Changelog = 'https://github.com/python-social-auth/social-app-flask-sqlalchemy/blob/master/CHANGELOG.md' + +[options] +zip_safe = false + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages] +find = {} + +[tool.setuptools.dynamic] +version = {attr = "social_flask_sqlalchemy.__version__"} diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c6b4e63..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -six -sqlalchemy -social-auth-core >= 1.0.0 -social-auth-app-flask >= 1.0.0 -social-auth-storage-sqlalchemy >= 1.0.1 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index d817985..0000000 --- a/setup.cfg +++ /dev/null @@ -1,11 +0,0 @@ -[flake8] -max-line-length = 119 -# Ignore some well known paths -exclude = .venv,.tox,dist,doc,build,*.egg,db/env.py,db/versions/*.py,site - -[nosetests] -verbosity=2 -with-coverage=1 -cover-erase=1 -cover-package=social -rednose=1 diff --git a/setup.py b/setup.py deleted file mode 100644 index 495ac7a..0000000 --- a/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -"""Setup file for easy installation""" -from os.path import join, dirname -from setuptools import setup - - -def long_description(): - return open(join(dirname(__file__), 'README.md')).read() - -def load_requirements(): - return open(join(dirname(__file__), 'requirements.txt')).readlines() - -setup( - name='social-auth-app-flask-sqlalchemy', - version=__import__('social_flask_sqlalchemy').__version__, - author='Matias Aguirre', - author_email='matiasaguirre@gmail.com', - description='Python Social Authentication, SQLAlchemy Flask ' - 'models integration.', - license='BSD', - keywords='flask, sqlalchemy, social auth', - url='https://github.com/python-social-auth/social-app-flask-sqlalchemy', - packages=['social_flask_sqlalchemy'], - long_description=long_description(), - install_requires=load_requirements(), - classifiers=[ - 'Development Status :: 4 - Beta', - 'Topic :: Internet', - 'License :: OSI Approved :: BSD License', - 'Intended Audience :: Developers', - 'Environment :: Web Environment', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3' - ], - zip_safe=False -) diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index db1f187..b25eab2 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -1,8 +1,7 @@ """Flask SQLAlchemy ORM models for Social Auth""" -from sqlalchemy import Column, String, ForeignKey -from sqlalchemy.orm import relationship, backref +from sqlalchemy import String, ForeignKey +from sqlalchemy.orm import relationship, backref, Mapped, mapped_column, DeclarativeBase from sqlalchemy.schema import UniqueConstraint -from sqlalchemy.ext.declarative import declarative_base from social_core.utils import setting_name, module_member from social_sqlalchemy.storage import SQLAlchemyUserMixin, \ @@ -13,7 +12,8 @@ BaseSQLAlchemyStorage -PSABase = declarative_base() +class PSABase(DeclarativeBase): + pass class _AppSession(PSABase): @@ -32,7 +32,6 @@ class UserSocialAuth(_AppSession, SQLAlchemyUserMixin): """Social Auth association model""" # Temporary override of constraints to avoid an error on the still-to-be # missing column uid. - __table_args__ = () @classmethod def user_model(cls): @@ -77,8 +76,7 @@ def init_social(app, session): User = module_member(app.config[setting_name('USER_MODEL')]) _AppSession._set_session(session) UserSocialAuth.__table_args__ = (UniqueConstraint('provider', 'uid'),) - UserSocialAuth.uid = Column(String(UID_LENGTH)) - UserSocialAuth.user_id = Column(User.id.type, ForeignKey(User.id), - nullable=False, index=True) + UserSocialAuth.user_id = mapped_column(ForeignKey(User.id), + nullable=False, index=True) UserSocialAuth.user = relationship(User, backref=backref('social_auth', lazy='dynamic')) From ab42bc5b29f31071c186ddd4f0a1875845064647 Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 15:34:26 +0900 Subject: [PATCH 2/7] flake8 add --- .pre-commit-config.yaml | 37 +++++++++++++++++++++++++++++++ pyproject.toml | 5 +++++ social_flask_sqlalchemy/models.py | 10 ++++----- 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aec596b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-merge-conflict + - id: debug-statements + - id: mixed-line-ending + args: [--fix=lf] +- repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: [--profile=black] +- repo: https://github.com/asottile/pyupgrade + rev: v3.15.1 + hooks: + - id: pyupgrade + args: [--py36-plus] +- repo: https://github.com/psf/black + rev: 24.2.0 + hooks: + - id: black +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 +- repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.12.0 + hooks: + - id: pretty-format-yaml + args: [--autofix, --indent, '2'] diff --git a/pyproject.toml b/pyproject.toml index faa8494..41523e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,3 +53,8 @@ find = {} [tool.setuptools.dynamic] version = {attr = "social_flask_sqlalchemy.__version__"} + +[tool.flake8] +max-line-length = 79 +# Ignore some well known paths +exclude = ['.venv','.tox','dist','doc','build','*.egg','db/env.py','db/versions/*.py','site','Pipfile','Pipfile.lock'] \ No newline at end of file diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index b25eab2..f81fe83 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -1,6 +1,7 @@ """Flask SQLAlchemy ORM models for Social Auth""" -from sqlalchemy import String, ForeignKey -from sqlalchemy.orm import relationship, backref, Mapped, mapped_column, DeclarativeBase +from sqlalchemy import ForeignKey +from sqlalchemy.orm import (relationship, backref, + mapped_column, DeclarativeBase) from sqlalchemy.schema import UniqueConstraint from social_core.utils import setting_name, module_member @@ -72,11 +73,10 @@ class FlaskStorage(BaseSQLAlchemyStorage): def init_social(app, session): - UID_LENGTH = app.config.get(setting_name('UID_LENGTH'), 255) User = module_member(app.config[setting_name('USER_MODEL')]) _AppSession._set_session(session) UserSocialAuth.__table_args__ = (UniqueConstraint('provider', 'uid'),) - UserSocialAuth.user_id = mapped_column(ForeignKey(User.id), - nullable=False, index=True) + UserSocialAuth.user_id = mapped_column( + ForeignKey(User.id), nullable=False, index=True) UserSocialAuth.user = relationship(User, backref=backref('social_auth', lazy='dynamic')) From 01e4ddb48bb5a771bad42eeff0971f89619b2bcd 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 06:35:36 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- social_flask_sqlalchemy/__init__.py | 2 +- social_flask_sqlalchemy/models.py | 40 +++++++++++++++++------------ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/social_flask_sqlalchemy/__init__.py b/social_flask_sqlalchemy/__init__.py index cd7ca49..5c4105c 100644 --- a/social_flask_sqlalchemy/__init__.py +++ b/social_flask_sqlalchemy/__init__.py @@ -1 +1 @@ -__version__ = '1.0.1' +__version__ = "1.0.1" diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index f81fe83..5b2ca80 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -1,17 +1,18 @@ """Flask SQLAlchemy ORM models for Social Auth""" + +from social_core.utils import module_member, setting_name +from social_sqlalchemy.storage import ( + BaseSQLAlchemyStorage, + SQLAlchemyAssociationMixin, + SQLAlchemyCodeMixin, + SQLAlchemyNonceMixin, + SQLAlchemyPartialMixin, + SQLAlchemyUserMixin, +) from sqlalchemy import ForeignKey -from sqlalchemy.orm import (relationship, backref, - mapped_column, DeclarativeBase) +from sqlalchemy.orm import DeclarativeBase, backref, mapped_column, relationship from sqlalchemy.schema import UniqueConstraint -from social_core.utils import setting_name, module_member -from social_sqlalchemy.storage import SQLAlchemyUserMixin, \ - SQLAlchemyAssociationMixin, \ - SQLAlchemyNonceMixin, \ - SQLAlchemyCodeMixin, \ - SQLAlchemyPartialMixin, \ - BaseSQLAlchemyStorage - class PSABase(DeclarativeBase): pass @@ -31,6 +32,7 @@ def _session(cls): class UserSocialAuth(_AppSession, SQLAlchemyUserMixin): """Social Auth association model""" + # Temporary override of constraints to avoid an error on the still-to-be # missing column uid. @@ -41,26 +43,30 @@ def user_model(cls): @classmethod def username_max_length(cls): user_model = cls.user_model() - return user_model.__table__.columns.get('username').type.length + return user_model.__table__.columns.get("username").type.length class Nonce(_AppSession, SQLAlchemyNonceMixin): """One use numbers""" + pass class Association(_AppSession, SQLAlchemyAssociationMixin): """OpenId account association""" + pass class Code(_AppSession, SQLAlchemyCodeMixin): """Mail validation single one time use code""" + pass class Partial(_AppSession, SQLAlchemyPartialMixin): """Partial pipeline storage""" + pass @@ -73,10 +79,12 @@ class FlaskStorage(BaseSQLAlchemyStorage): def init_social(app, session): - User = module_member(app.config[setting_name('USER_MODEL')]) + User = module_member(app.config[setting_name("USER_MODEL")]) _AppSession._set_session(session) - UserSocialAuth.__table_args__ = (UniqueConstraint('provider', 'uid'),) + UserSocialAuth.__table_args__ = (UniqueConstraint("provider", "uid"),) UserSocialAuth.user_id = mapped_column( - ForeignKey(User.id), nullable=False, index=True) - UserSocialAuth.user = relationship(User, backref=backref('social_auth', - lazy='dynamic')) + ForeignKey(User.id), nullable=False, index=True + ) + UserSocialAuth.user = relationship( + User, backref=backref("social_auth", lazy="dynamic") + ) From 09194bf535021feca087ed2673468211726c0d5c Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 15:38:39 +0900 Subject: [PATCH 4/7] E501 fix --- social_flask_sqlalchemy/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index 5b2ca80..0d9df10 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -10,7 +10,12 @@ SQLAlchemyUserMixin, ) from sqlalchemy import ForeignKey -from sqlalchemy.orm import DeclarativeBase, backref, mapped_column, relationship +from sqlalchemy.orm import ( + DeclarativeBase, + backref, + mapped_column, + relationship +) from sqlalchemy.schema import UniqueConstraint From 79e6b4ab5fde0a547708139dd33f32a308dfdd98 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 06:38:50 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- social_flask_sqlalchemy/models.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index 0d9df10..5b2ca80 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -10,12 +10,7 @@ SQLAlchemyUserMixin, ) from sqlalchemy import ForeignKey -from sqlalchemy.orm import ( - DeclarativeBase, - backref, - mapped_column, - relationship -) +from sqlalchemy.orm import DeclarativeBase, backref, mapped_column, relationship from sqlalchemy.schema import UniqueConstraint From f441edcffac0210bf91eb817a23f7302bba4ce7c Mon Sep 17 00:00:00 2001 From: ji-ho lee Date: Sun, 10 Mar 2024 15:41:07 +0900 Subject: [PATCH 6/7] fmt skip add --- social_flask_sqlalchemy/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index 5b2ca80..9025321 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -10,7 +10,8 @@ SQLAlchemyUserMixin, ) from sqlalchemy import ForeignKey -from sqlalchemy.orm import DeclarativeBase, backref, mapped_column, relationship +from sqlalchemy.orm import (DeclarativeBase, backref, # fmt: skip + mapped_column, relationship) from sqlalchemy.schema import UniqueConstraint From f60a7e3eccaef0de96d43185103e01e01b289d90 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 06:41:17 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- social_flask_sqlalchemy/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/social_flask_sqlalchemy/models.py b/social_flask_sqlalchemy/models.py index 9025321..8ced105 100644 --- a/social_flask_sqlalchemy/models.py +++ b/social_flask_sqlalchemy/models.py @@ -10,8 +10,12 @@ SQLAlchemyUserMixin, ) from sqlalchemy import ForeignKey -from sqlalchemy.orm import (DeclarativeBase, backref, # fmt: skip - mapped_column, relationship) +from sqlalchemy.orm import ( # fmt: skip + DeclarativeBase, + backref, + mapped_column, + relationship, +) from sqlalchemy.schema import UniqueConstraint