Skip to content

Commit 63660b1

Browse files
committed
add Flask 3 support
1 parent dc1db1e commit 63660b1

File tree

10 files changed

+47
-32
lines changed

10 files changed

+47
-32
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0
3+
rev: v4.4.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: mixed-line-ending
88
args: ['--fix=lf']
99
description: Forces to replace line ending by the UNIX 'lf' character.
1010
- repo: https://github.com/psf/black
11-
rev: 22.1.0
11+
rev: 23.9.1
1212
hooks:
1313
- id: black
1414
language_version: python3
15-
args: [-t, py310]

.travis.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
language: python
22
sudo: required
3-
dist: bionic
3+
dist: jammy
44
python:
5-
- "3.7"
65
- "3.8"
76
- "3.9"
7+
- "3.10"
8+
- "3.11"
89
env:
9-
- FLASK=2.0.2
10+
- FLASK=3.0.0
11+
- FLASK=2.3.3
12+
- FLASK=2.2.5
13+
- FLASK=2.1.3
14+
- FLASK=2.0.3
1015
- FLASK=1.1.4
1116
- FLASK=1.0.4
1217
install:

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ PYTHON=${VENV_NAME}/bin/python3
77
.DEFAULT: help
88
help:
99
@echo "make dev"
10-
@echo " prepare development environment, use only once"
10+
@echo " prepare development environment, use only once"
1111
@echo "make clean"
12-
@echo " delete development environment"
12+
@echo " delete development environment"
1313
@echo "make update"
14-
@echo " update dependencies"
14+
@echo " update dependencies"
1515
@echo "make test"
16-
@echo " run tests"
16+
@echo " run tests"
1717
@echo "make lint"
18-
@echo " run black"
18+
@echo " run black"
1919
@echo "make pre-commit"
20-
@echo " run pre-commit hooks"
20+
@echo " run pre-commit hooks"
2121

2222
dev:
2323
make venv
@@ -41,7 +41,7 @@ test: venv
4141
${PYTHON} -m pytest
4242

4343
lint: venv
44-
$(VENV_NAME)/bin/black -t py310 --exclude $(VENV_NAME) .
44+
$(VENV_NAME)/bin/black --exclude $(VENV_NAME) .
4545

4646
pre-commit: venv
4747
$(VENV_NAME)/bin/pre-commit

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ pip install flask-mysqldb
1515
```
1616

1717
Flask-MySQLdb depends, and will install for you, recent versions of Flask
18-
(0.12.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient-python).
19-
Flask-MySQLdb is compatible with and tested with Python 3.7+. It _should_ work on any
20-
version from Python 2.7 and up, but is not supported.
18+
(1.0.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient).
19+
Flask-MySQLdb is compatible with and tested with Python 3.8+.
2120

2221
Next, add a ``MySQL`` instance to your code:
2322

dev_requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
black==22.1.0
2-
pre-commit==2.17.0
3-
mysqlclient==1.4.3
1+
black==23.9.1
2+
pre-commit==3.4.0
3+
mysqlclient==2.2.0
44

55
-r requirements.txt

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ def __getattr__(cls, name):
5858

5959
# General information about the project.
6060
project = "Flask-MySQLdb"
61-
copyright = "2022, Alexandre Ferland"
61+
copyright = "2023, Alexandre Ferland"
6262

6363
# The version info for the project you're documenting, acts as replacement for
6464
# |version| and |release|, also used in various other places throughout the
6565
# built documents.
6666
#
6767
# The short X.Y version.
68-
version = "1.0.1"
68+
version = "2.0.0"
6969
# The full version, including alpha/beta/rc tags.
70-
release = "1.0.1"
70+
release = "2.0.0"
7171

7272
# The language for content autogenerated by Sphinx. Refer to documentation
7373
# for a list of supported languages.

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ History
9696

9797
Changes:
9898

99+
- 2.0.0: October 4, 2023
100+
101+
- Add support for Flask 3.0.0+.
102+
99103
- 1.0.1: February 13, 2022
100104

101105
- Fix documentation.

flask_mysqldb/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
from importlib.metadata import version
2+
flask_major_version = int(version("flask")[0])
3+
14
import MySQLdb
25
from MySQLdb import cursors
3-
from flask import _app_ctx_stack, current_app
6+
from flask import current_app
7+
if flask_major_version >= 3:
8+
from flask import g
9+
ctx = g
10+
else:
11+
from flask import _app_ctx_stack
12+
ctx = _app_ctx_stack.top
413

514

6-
class MySQL(object):
15+
class MySQL:
716
def __init__(self, app=None):
817
self.app = app
918
if app is not None:
@@ -95,13 +104,11 @@ def connection(self):
95104
unsuccessful.
96105
"""
97106

98-
ctx = _app_ctx_stack.top
99107
if ctx is not None:
100108
if not hasattr(ctx, "mysql_db"):
101109
ctx.mysql_db = self.connect
102110
return ctx.mysql_db
103111

104112
def teardown(self, exception):
105-
ctx = _app_ctx_stack.top
106113
if hasattr(ctx, "mysql_db"):
107114
ctx.mysql_db.close()

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Flask==2.3.2
2-
mock==4.0.3
3-
mysqlclient==1.4.3
1+
Flask==3.0.0
2+
mock==5.1.0
3+
mysqlclient==2.2.0

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setup(
1616
name="Flask-MySQLdb",
17-
version="1.0.1",
17+
version="2.0.0",
1818
url="https://github.com/alexferl/flask-mysqldb",
1919
license="MIT",
2020
author="Alexandre Ferland",
@@ -26,15 +26,16 @@
2626
zip_safe=False,
2727
include_package_data=True,
2828
platforms="any",
29-
install_requires=["Flask>=0.12.4", "mysqlclient>=1.3.7"],
29+
install_requires=["Flask>=1.0.4", "mysqlclient>=2.2.0"],
3030
classifiers=[
3131
"Environment :: Web Environment",
3232
"Intended Audience :: Developers",
3333
"License :: OSI Approved :: MIT License",
3434
"Operating System :: OS Independent",
35-
"Programming Language :: Python :: 3.7",
3635
"Programming Language :: Python :: 3.8",
3736
"Programming Language :: Python :: 3.9",
37+
"Programming Language :: Python :: 3.10",
38+
"Programming Language :: Python :: 3.11",
3839
"Topic :: Software Development :: Libraries :: Python Modules",
3940
],
4041
)

0 commit comments

Comments
 (0)