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

Limit libraries to versions that only support Python >=3.7, add support for Python 3.11 #76

Merged
merged 17 commits into from
Aug 2, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

# Service containers to run with `container-job`
services:
Expand Down
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
- Peter Bengtsson (@peterbe)
- Graham Beckley (@grahamalama)
- Mike Cooper (@mythmon)
- Will Kahn-Greene (@willkg)
- Michael Kelly (@Osmose)
- Jannis Leidel (@jezdez)
- Les Orchard (@lmorchard)
- Mathieu Leplatre (@leplatrem)
- Les Orchard (@lmorchard)
Copy link
Member

Choose a reason for hiding this comment

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

nit: unneeded change.

- Mathieu Pillard (@diox)
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
---------

2023.8.0
~~~~~~~~~~~~~~~~~~~~~

- Add support for Django 4.2

- Drop support for Sanic 20

- Drop support for Flask 0.12, 1.0, and 1.1

- Add support for Python 3.11

2022.8.0 (2022-08-18)
~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 88
target-version = ['py37', 'py38', 'py39', 'py310']
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
include = '\.pyi?$'
exclude = '''
/(
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def read(*parts):
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Internet :: WWW/HTTP",
],
extras_require={
Expand Down
22 changes: 2 additions & 20 deletions src/dockerflow/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,10 @@
import time
import uuid

from django import VERSION
from django.utils.deprecation import MiddlewareMixin

from . import views

try:
from django.utils.deprecation import MiddlewareMixin
except ImportError: # pragma: no cover
MiddlewareMixin = object


# Computed once, reused in every request
_less_than_django_1_10 = VERSION < (1, 10)


def is_authenticated(user): # pragma: no cover
grahamalama marked this conversation as resolved.
Show resolved Hide resolved
"""Check if the user is authenticated but do it in a way that
it doesnt' cause a DeprecationWarning in Django >=1.10"""
if _less_than_django_1_10:
# Prior to Django 1.10, user.is_authenticated was a method
return user.is_authenticated()
return user.is_authenticated


class DockerflowMiddleware(MiddlewareMixin):
"""
Expand Down Expand Up @@ -66,7 +48,7 @@ def _build_extra_meta(self, request):
# modified earlier, so be sure to check for existence of these
# attributes before trying to use them.
if hasattr(request, "user"):
out["uid"] = is_authenticated(request.user) and request.user.pk or ""
out["uid"] = request.user.is_authenticated and request.user.pk or ""
if hasattr(request, "_id"):
out["rid"] = request._id
if hasattr(request, "_start_timestamp"):
Expand Down
4 changes: 3 additions & 1 deletion src/dockerflow/flask/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
This module contains a few built-in checks for the Flask integration.
"""
from sqlalchemy import text

from ... import health
from ...checks import ( # noqa
CRITICAL,
Expand Down Expand Up @@ -47,7 +49,7 @@ def check_database_connected(db):
errors = []
try:
with db.engine.connect() as connection:
connection.execute("SELECT 1;")
connection.execute(text("SELECT 1;"))
except DBAPIError as e:
msg = "DB-API error: {!s}".format(e)
errors.append(Error(msg, id=health.ERROR_DB_API_EXCEPTION))
Expand Down
1 change: 0 additions & 1 deletion src/dockerflow/sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(
*args,
**kwargs,
):

# The Dockerflow specific logger to be used by internals of this
# extension.
self.logger = logging.getLogger("dockerflow.sanic")
Expand Down
15 changes: 5 additions & 10 deletions src/dockerflow/sanic/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)


async def check_redis_connected(redis):
async def check_redis_connected(redis_client):
"""
A built-in check to connect to Redis using the given client and see
if it responds to the ``PING`` command.
Expand Down Expand Up @@ -54,22 +54,17 @@ async def check_redis_connected(redis):
dockerflow = Dockerflow(app, redis=redis)

"""
import aioredis

if aioredis.__version__.startswith("1."):
RedisConnectionError = aioredis.ConnectionClosedError
else:
RedisConnectionError = aioredis.ConnectionError
import redis

errors = []

try:
with await redis.conn as r:
with await redis_client.conn as r:
result = await r.ping()
except RedisConnectionError as e:
except redis.ConnectionError as e:
msg = "Could not connect to redis: {!s}".format(e)
errors.append(Error(msg, id=health.ERROR_CANNOT_CONNECT_REDIS))
except aioredis.RedisError as e:
except redis.RedisError as e:
errors.append(
Error('Redis error: "{!s}"'.format(e), id=health.ERROR_REDIS_EXCEPTION)
)
Expand Down
1 change: 1 addition & 0 deletions tests/constraints/django-4.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Django>=4.2,<4.3
Copy link
Member

Choose a reason for hiding this comment

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

😍

4 changes: 0 additions & 4 deletions tests/constraints/flask-0.12.txt

This file was deleted.

4 changes: 0 additions & 4 deletions tests/constraints/flask-1.0.txt

This file was deleted.

2 changes: 0 additions & 2 deletions tests/constraints/flask-1.1.txt

This file was deleted.

2 changes: 2 additions & 0 deletions tests/constraints/flask-2.0.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Flask<2.1
Werkzeug<2.1.0
SQLAlchemy<=1.4
Flask-SQLAlchemy<3.0
2 changes: 2 additions & 0 deletions tests/constraints/flask-2.1.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Flask<2.2
SQLAlchemy<=1.4
Flask-SQLAlchemy<3.0
3 changes: 0 additions & 3 deletions tests/constraints/sanic-20.txt

This file was deleted.

2 changes: 2 additions & 0 deletions tests/constraints/sanic-21.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Sanic>=21,<22
websockets<11
sanic-testing<22
6 changes: 1 addition & 5 deletions tests/django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
from django.db.utils import OperationalError, ProgrammingError
from django.http import HttpResponse
from django.test.utils import CaptureQueriesContext
from django.utils.deprecation import MiddlewareMixin

from dockerflow import health
from dockerflow.django import checks
from dockerflow.django.middleware import DockerflowMiddleware

try:
grahamalama marked this conversation as resolved.
Show resolved Hide resolved
from django.utils.deprecation import MiddlewareMixin
except ImportError: # pragma: no cover
MiddlewareMixin = object


@pytest.fixture
def reset_checks():
Expand Down
Loading
Loading