Skip to content

Commit b3c13cd

Browse files
authored
Merge pull request #33 from alexferl/add_flask_3_support
add Flask 3 support
2 parents dc1db1e + 11bbf62 commit b3c13cd

18 files changed

+204
-81
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 2
10+
11+
[*.py]
12+
indent_size = 4
13+
14+
[Makefile]
15+
indent_style = tab
16+
indent_size = 4

.github/workflows/test.yaml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
build:
11+
runs-on: '${{ matrix.os }}'
12+
strategy:
13+
matrix:
14+
include:
15+
- os: ubuntu-latest
16+
python-version: '3.8'
17+
FLASK: 3.0.0
18+
- os: ubuntu-latest
19+
python-version: '3.8'
20+
FLASK: 2.3.3
21+
- os: ubuntu-latest
22+
python-version: '3.8'
23+
FLASK: 2.2.5
24+
- os: ubuntu-latest
25+
python-version: '3.8'
26+
FLASK: 2.1.3
27+
- os: ubuntu-latest
28+
python-version: '3.8'
29+
FLASK: 2.0.3
30+
- os: ubuntu-latest
31+
python-version: '3.8'
32+
FLASK: 1.1.4
33+
- os: ubuntu-latest
34+
python-version: '3.8'
35+
FLASK: 1.0.4
36+
- os: ubuntu-latest
37+
python-version: '3.9'
38+
FLASK: 3.0.0
39+
- os: ubuntu-latest
40+
python-version: '3.9'
41+
FLASK: 2.3.3
42+
- os: ubuntu-latest
43+
python-version: '3.9'
44+
FLASK: 2.2.5
45+
- os: ubuntu-latest
46+
python-version: '3.9'
47+
FLASK: 2.1.3
48+
- os: ubuntu-latest
49+
python-version: '3.9'
50+
FLASK: 2.0.3
51+
- os: ubuntu-latest
52+
python-version: '3.9'
53+
FLASK: 1.1.4
54+
- os: ubuntu-latest
55+
python-version: '3.9'
56+
FLASK: 1.0.4
57+
- os: ubuntu-latest
58+
python-version: '3.10'
59+
FLASK: 3.0.0
60+
- os: ubuntu-latest
61+
python-version: '3.10'
62+
FLASK: 2.3.3
63+
- os: ubuntu-latest
64+
python-version: '3.10'
65+
FLASK: 2.2.5
66+
- os: ubuntu-latest
67+
python-version: '3.10'
68+
FLASK: 2.1.3
69+
- os: ubuntu-latest
70+
python-version: '3.10'
71+
FLASK: 2.0.3
72+
- os: ubuntu-latest
73+
python-version: '3.10'
74+
FLASK: 1.1.4
75+
- os: ubuntu-latest
76+
python-version: '3.10'
77+
FLASK: 1.0.4
78+
- os: ubuntu-latest
79+
python-version: '3.11'
80+
FLASK: 3.0.0
81+
- os: ubuntu-latest
82+
python-version: '3.11'
83+
FLASK: 2.3.3
84+
- os: ubuntu-latest
85+
python-version: '3.11'
86+
FLASK: 2.2.5
87+
- os: ubuntu-latest
88+
python-version: '3.11'
89+
FLASK: 2.1.3
90+
- os: ubuntu-latest
91+
python-version: '3.11'
92+
FLASK: 2.0.3
93+
- os: ubuntu-latest
94+
python-version: '3.11'
95+
FLASK: 1.1.4
96+
- os: ubuntu-latest
97+
python-version: '3.11'
98+
FLASK: 1.0.4
99+
steps:
100+
- name: 'Set up Python ${{ matrix.python-version }}'
101+
uses: actions/setup-python@v2
102+
with:
103+
python-version: '${{ matrix.python-version }}'
104+
- uses: actions/checkout@v2
105+
- run: pip install Flask==$FLASK
106+
env:
107+
FLASK: '${{ matrix.FLASK }}'
108+
- run: pip install -r dev_requirements.txt
109+
- run: pytest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ coverage.xml
5353
# Sphinx documentation
5454
docs/_build/
5555

56+
# pytest
57+
.pytest_cache
58+
5659
# PyCharm
5760
.idea/

.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: 0 additions & 15 deletions
This file was deleted.

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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+
pytest==7.4.2
4+
mysqlclient==2.2.0
45

56
-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/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0.0

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()

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"

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.cfg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[metadata]
2+
name = Flask-MySQLdb
3+
version = file: flask_mysqldb/VERSION
4+
author = Alexandre Ferland
5+
author_email = me@alexferl.com
6+
url = https://github.com/alexferl/flask-mysqldb
7+
description = MySQLdb extension for Flask
8+
long_description = file: README.md
9+
long_description_content_type = text/markdown
10+
license = MIT
11+
classifiers =
12+
"Environment :: Web Environment"
13+
"Intended Audience :: Developers"
14+
"License :: OSI Approved :: MIT License"
15+
"Operating System :: OS Independent"
16+
"Programming Language :: Python :: 3.8"
17+
"Programming Language :: Python :: 3.9"
18+
"Programming Language :: Python :: 3.10"
19+
"Programming Language :: Python :: 3.11"
20+
"Topic :: Software Development :: Libraries :: Python Modules"
21+
22+
[options]
23+
zip_safe = False
24+
include_package_data = True
25+
python_requires = >=3.8
26+
install_requires =
27+
Flask>=1.0.4
28+
mysqlclient>=2.2.0

setup.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/__init__.py

Whitespace-only changes.

tests/test_mysqldb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask import Flask
2+
from flask_mysqldb import MySQL
3+
4+
app = Flask(__name__)
5+
6+
7+
def test_instantiate():
8+
MySQL(app)

0 commit comments

Comments
 (0)