Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding DB sessions based on SQLAlchemy 1, changing how to declare Base Model classes, and other code modernization #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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']
40 changes: 20 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ language: python
sudo: false
env:
global:
- REQUIREMENTS=requirements.txt
- TEST_REQUIREMENTS=social/tests/requirements.txt
- REQUIREMENTS=requirements.txt
- TEST_REQUIREMENTS=social/tests/requirements.txt
python:
- "2.7"
- '2.7'
matrix:
include:
- python: "pypy"
env:
- TEST_REQUIREMENTS=social/tests/requirements-pypy.txt
- python: "3.3"
env:
- REQUIREMENTS=requirements-python3.txt
- TEST_REQUIREMENTS=social/tests/requirements-python3.txt
- python: "3.4"
env:
- REQUIREMENTS=requirements-python3.txt
- TEST_REQUIREMENTS=social/tests/requirements-python3.txt
- python: pypy
env:
- TEST_REQUIREMENTS=social/tests/requirements-pypy.txt
- python: '3.3'
env:
- REQUIREMENTS=requirements-python3.txt
- TEST_REQUIREMENTS=social/tests/requirements-python3.txt
- python: '3.4'
env:
- REQUIREMENTS=requirements-python3.txt
- TEST_REQUIREMENTS=social/tests/requirements-python3.txt
addons:
apt:
packages:
- libxmlsec1-dev
- swig
- libxmlsec1-dev
- swig
install:
- "python setup.py -q install"
- "travis_retry pip install -r $REQUIREMENTS"
- "travis_retry pip install -r $TEST_REQUIREMENTS"
- python setup.py -q install
- travis_retry pip install -r $REQUIREMENTS
- travis_retry pip install -r $TEST_REQUIREMENTS
script:
- "nosetests --with-coverage --cover-package=social --where=social/tests"
- nosetests --with-coverage --cover-package=social --where=social/tests
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/python-social-auth/social-app-pyramid/commits/master)

### Changed
- Modified model and access code to work with SQLAlchemy version 2 (Issue #4)
- Updated packaging information files per PEP 517, PEP 518 (Issue #5)
- Restricted Python minimum working version to 3.7 or higher to align with SQLAlchemy 2 (Issue #4)
- .pre-commit-config.yaml add

## [1.0.0](https://github.com/python-social-auth/social-app-pyramid/releases/tag/1.0.0) - 2017-01-22

### Added
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = 'social-auth-app-pyramid'
dynamic = ["version"]
dependencies = [
"six",
"social-auth-core>=1.0.0",
"social-auth-storage-sqlalchemy>=1.0.0",
]
authors = [
{name = "Matias Aguirre", email = "[email protected]"},
{name = "Lee Ji-ho", email = "[email protected]"},
]
description = 'Python Social Authentication, Pyramid integration.'
license = {text = 'BSD'}
keywords = ["pyramid", "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-pyramid'
Documentation = 'http://python-social-auth.readthedocs.org'
Issues = 'https://github.com/python-social-auth/social-app-pyramid/issues'
Changelog = 'https://github.com/python-social-auth/social-app-pyramid/blob/master/CHANGELOG.md'

[options]
zip_safe = false

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages]
find = {}

[tool.setuptools.dynamic]
version = {attr = "social_pyramid.__version__"}

[tool.flake8]
max-line-length = 80
# Ignore some well known paths
exclude = ['.venv','.tox','dist','doc','build','*.egg','db/env.py','db/versions/*.py','site','Pipfile','Pipfile.lock']
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

21 changes: 12 additions & 9 deletions social_pyramid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
__version__ = '1.0.0'
__version__ = "1.0.0"


def includeme(config):
from social_core.utils import setting_name

if config.registry.settings.get(setting_name('TRAILING_SLASH')):
extra = '/'
if config.registry.settings.get(setting_name("TRAILING_SLASH")):
extra = "/"
else:
extra = ''
extra = ""

config.add_route('social.auth', '/login/{backend}' + extra)
config.add_route('social.complete', '/complete/{backend}' + extra)
config.add_route('social.disconnect', '/disconnect/{backend}' + extra)
config.add_route('social.disconnect_association',
'/disconnect/{backend}/{association_id}' + extra)
config.add_route("social.auth", "/login/{backend}" + extra)
config.add_route("social.complete", "/complete/{backend}" + extra)
config.add_route("social.disconnect", "/disconnect/{backend}" + extra)
config.add_route(
"social.disconnect_association",
"/disconnect/{backend}/{association_id}" + extra,
)
47 changes: 28 additions & 19 deletions social_pyramid/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Pyramid SQLAlchemy ORM models for Social Auth"""
from sqlalchemy import Column, String, ForeignKey
from sqlalchemy.orm import relationship, backref

from social_core.utils import setting_name, module_member
from social_sqlalchemy.storage import SQLAlchemyUserMixin, \
SQLAlchemyAssociationMixin, \
SQLAlchemyNonceMixin, \
SQLAlchemyCodeMixin, \
SQLAlchemyPartialMixin, \
BaseSQLAlchemyStorage
from social_core.utils import module_member, setting_name
from social_sqlalchemy.storage import (
BaseSQLAlchemyStorage,
SQLAlchemyAssociationMixin,
SQLAlchemyCodeMixin,
SQLAlchemyNonceMixin,
SQLAlchemyPartialMixin,
SQLAlchemyUserMixin,
)
from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, backref, mapped_column, relationship


class PyramidStorage(BaseSQLAlchemyStorage):
Expand All @@ -20,13 +22,13 @@ class PyramidStorage(BaseSQLAlchemyStorage):


def init_social(config, Base, session):
if hasattr(config, 'registry'):
if hasattr(config, "registry"):
config = config.registry.settings
UID_LENGTH = config.get(setting_name('UID_LENGTH'), 255)
User = module_member(config[setting_name('USER_MODEL')])
UID_LENGTH = config.get(setting_name("UID_LENGTH"), 255)
User = module_member(config[setting_name("USER_MODEL")])
app_session = session

class _AppSession(object):
class _AppSession:
COMMIT_SESSION = False

@classmethod
Expand All @@ -35,34 +37,41 @@ def _session(cls):

class UserSocialAuth(_AppSession, Base, SQLAlchemyUserMixin):
"""Social Auth association model"""
uid = Column(String(UID_LENGTH))
user_id = Column(User.id.type, ForeignKey(User.id),
nullable=False, index=True)
user = relationship(User, backref=backref('social_auth',
lazy='dynamic'))

uid: Mapped[str] = mapped_column(String(UID_LENGTH))
user_id: Mapped[int] = mapped_column(
ForeignKey(User.id), nullable=False, index=True
)
user: Mapped["User"] = relationship( # fmt: skip
User, backref=backref("social_auth", lazy="dynamic")
)

@classmethod
def username_max_length(cls):
return User.__table__.columns.get('username').type.length
return User.__table__.columns.get("username").type.length

@classmethod
def user_model(cls):
return User

class Nonce(_AppSession, Base, SQLAlchemyNonceMixin):
"""One use numbers"""

pass

class Association(_AppSession, Base, SQLAlchemyAssociationMixin):
"""OpenId account association"""

pass

class Code(_AppSession, Base, SQLAlchemyCodeMixin):
"""Mail validation single one time use code"""

pass

class Partial(_AppSession, Base, SQLAlchemyPartialMixin):
"""Partial pipeline storage"""

pass

# Set the references in the storage class
Expand Down
14 changes: 6 additions & 8 deletions social_pyramid/strategy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from webob.multidict import NoVars

from pyramid.response import Response
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render

from social_core.utils import build_absolute_uri
from pyramid.response import Response
from social_core.strategy import BaseStrategy, BaseTemplateStrategy
from social_core.utils import build_absolute_uri
from webob.multidict import NoVars


class PyramidTemplateStrategy(BaseTemplateStrategy):
Expand All @@ -21,11 +19,11 @@ class PyramidStrategy(BaseStrategy):

def __init__(self, storage, request, tpl=None):
self.request = request
super(PyramidStrategy, self).__init__(storage, tpl)
super().__init__(storage, tpl)

def redirect(self, url):
"""Return a response redirect to the given URL"""
response = getattr(self.request, 'response', None)
response = getattr(self.request, "response", None)
if response is None:
response = HTTPFound(location=url)
else:
Expand All @@ -42,7 +40,7 @@ def html(self, content):

def request_data(self, merge=True):
"""Return current request data (POST or GET)"""
if self.request.method == 'POST':
if self.request.method == "POST":
if merge:
data = self.request.POST.copy()
if not isinstance(self.request.GET, NoVars):
Expand Down
Loading