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 #4

Open
wants to merge 5 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'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python version 2.7 is specified, but the PR objectives mention setting the minimum Python version to 3.7. This version should be updated or removed to align with the new minimum version requirement.

- - '2.7'

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- '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'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python version 3.3 is specified, which is below the new minimum Python version of 3.7. This version should be updated or removed to reflect the updated requirements.

- - python: '3.3'

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- python: '3.3'

env:
- REQUIREMENTS=requirements-python3.txt
- TEST_REQUIREMENTS=social/tests/requirements-python3.txt
- python: '3.4'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python version 3.4 is specified, which is also below the new minimum Python version of 3.7. This version should be updated or removed to comply with the new version requirements.

- - python: '3.4'

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- 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
Comment on lines +28 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installation commands use python setup.py -q install, which might not align with the transition to PEP 517/518 as mentioned in the PR objectives. Consider using a more modern approach for package installation that is compatible with PEP 517/518, such as using pip to install the package directly from the source with the pyproject.toml file.

- - python setup.py -q install
+ - pip install .

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- python setup.py -q install
- travis_retry pip install -r $REQUIREMENTS
- travis_retry pip install -r $TEST_REQUIREMENTS
- pip 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-webpy/commits/master)

### Changed
- Modified model and access code to work with SQLAlchemy version 2 (Issue #1)
- Updated packaging information files per PEP 517, PEP 518 (Issue #2)
- Restricted Python minimum working version to 3.7 or higher to align with SQLAlchemy 2 (Issue #1)
- Fixed behavior of get_current_user function throwing a None error when executed (Issue #3)

## [1.0.0](https://github.com/python-social-auth/social-app-webpy/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-webpy'
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, web.py integration.'
license = {text = 'BSD'}
keywords = ["web.py", "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-webpy'
Documentation = 'http://python-social-auth.readthedocs.org'
Issues = 'https://github.com/python-social-auth/social-app-webpy/issues'
Changelog = 'https://github.com/python-social-auth/social-app-webpy/blob/master/CHANGELOG.md'

[options]
zip_safe = false

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

[tool.setuptools.packages]
find = {}

[tool.setuptools.dynamic]
version = {attr = "social_webpy.__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']
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion social_webpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = "1.0.0"
48 changes: 26 additions & 22 deletions social_webpy/app.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import web

from social_core.actions import do_auth, do_complete, do_disconnect

from .utils import psa, load_strategy, load_strategy

from .utils import load_strategy, psa

urls = (
r'/login/(?P<backend>[^/]+)/?', 'auth',
r'/complete/(?P<backend>[^/]+)/?', 'complete',
r'/disconnect/(?P<backend>[^/]+)/?', 'disconnect',
r'/disconnect/(?P<backend>[^/]+)/(?P<association_id>\d+)/?', 'disconnect',
r"/login/(?P<backend>[^/]+)/?",
"auth",
r"/complete/(?P<backend>[^/]+)/?",
"complete",
r"/disconnect/(?P<backend>[^/]+)/?",
"disconnect",
r"/disconnect/(?P<backend>[^/]+)/(?P<association_id>\d+)/?",
"disconnect",
)


class BaseViewClass(object):
class BaseViewClass:
def __init__(self, *args, **kwargs):
self.session = web.web_session
method = web.ctx.method == 'POST' and 'post' or 'get'
method = web.ctx.method == "POST" and "post" or "get"
self.strategy = load_strategy()
self.data = web.input(_method=method)
self.backend = None
self._user = None
super(BaseViewClass, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def get_current_user(self):
if not hasattr(self, '_user'):
if self.session.get('logged_in'):
self._user = self.strategy.get_user(
self.session.get('user_id')
if not hasattr(self, "_user"):
if self.session.get("logged_in"):
self._user = self.strategy.get_user( # fmt: skip
self.session.get("user_id")
)
else:
self._user = None
return self._user

def login_user(self, user):
self.session['logged_in'] = True
self.session['user_id'] = user.id
self.session["logged_in"] = True
self.session["user_id"] = user.id


class auth(BaseViewClass):
Expand All @@ -45,7 +46,7 @@ def GET(self, backend):
def POST(self, backend):
return self._auth(backend)

@psa('/complete/%(backend)s/')
@psa("/complete/%(backend)s/")
def _auth(self, backend):
return do_auth(self.backend)

Expand All @@ -57,20 +58,23 @@ def GET(self, backend, *args, **kwargs):
def POST(self, backend, *args, **kwargs):
return self._complete(backend, *args, **kwargs)

@psa('/complete/%(backend)s/')
@psa("/complete/%(backend)s/")
def _complete(self, backend, *args, **kwargs):
return do_complete(
self.backend,
login=lambda backend, user, social_user: self.login_user(user),
user=self.get_current_user(), *args, **kwargs
user=self.get_current_user(),
*args,
**kwargs,
)


class disconnect(BaseViewClass):
@psa()
def POST(self, backend, association_id=None):
return do_disconnect(self.backend, self.get_current_user(),
association_id)
return do_disconnect( # fmt: skip
self.backend, self.get_current_user(), association_id
)


app_social = web.application(urls, locals())
Loading