Skip to content

Commit 43e8fd3

Browse files
committed
add autocommit and extra_kwargs config
1 parent d3e763e commit 43e8fd3

File tree

13 files changed

+364
-262
lines changed

13 files changed

+364
-262
lines changed

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: mixed-line-ending
8+
args: ['--fix=lf']
9+
description: Forces to replace line ending by the UNIX 'lf' character.
10+
- repo: https://github.com/psf/black
11+
rev: 22.1.0
12+
hooks:
13+
- id: black
14+
language_version: python3
15+
args: [-t, py310]

AUTHORS

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

55
Alexandre Ferland (admiralobvious)
66
Alex Vishnya (Sp1tF1r3)
7+
Shaun (shaunpud)

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Alexandre Ferland
3+
Copyright (c) 2022 Alexandre Ferland
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.PHONY: help dev clean update test lint pre-commit
2+
3+
VENV_NAME?=venv
4+
VENV_ACTIVATE=. $(VENV_NAME)/bin/activate
5+
PYTHON=${VENV_NAME}/bin/python3
6+
7+
.DEFAULT: help
8+
help:
9+
@echo "make dev"
10+
@echo " prepare development environment, use only once"
11+
@echo "make clean"
12+
@echo " delete development environment"
13+
@echo "make update"
14+
@echo " update dependencies"
15+
@echo "make test"
16+
@echo " run tests"
17+
@echo "make lint"
18+
@echo " run black"
19+
@echo "make pre-commit"
20+
@echo " run pre-commit hooks"
21+
22+
dev:
23+
make venv
24+
25+
venv: $(VENV_NAME)/bin/activate
26+
$(VENV_NAME)/bin/activate:
27+
test -d $(VENV_NAME) || virtualenv -p python3 $(VENV_NAME)
28+
${PYTHON} -m pip install -U pip
29+
${PYTHON} -m pip install -r dev_requirements.txt
30+
$(VENV_NAME)/bin/pre-commit install
31+
touch $(VENV_NAME)/bin/activate
32+
33+
clean:
34+
rm -rf venv
35+
36+
update:
37+
${PYTHON} -m pip install -U -r dev_requirements.txt
38+
$(VENV_NAME)/bin/pre-commit install
39+
40+
test: venv
41+
${PYTHON} -m pytest
42+
43+
lint: venv
44+
$(VENV_NAME)/bin/black -t py310 --exclude $(VENV_NAME) .
45+
46+
pre-commit: venv
47+
$(VENV_NAME)/bin/pre-commit

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ Flask-MySQLdb provides MySQL connection for Flask.
88
Quickstart
99
----------
1010

11-
First, install Flask-MySQLdb:
12-
13-
$ pip install flask-mysqldb
14-
11+
First, you _may_ need to install some dependencies for [mysqlclient](https://github.com/PyMySQL/mysqlclient)
12+
if you don't already have them, see [here](https://github.com/PyMySQL/mysqlclient#install).
13+
14+
Second, install Flask-MySQLdb:
15+
```shell
16+
pip install flask-mysqldb
17+
```
18+
1519
Flask-MySQLdb depends, and will install for you, recent versions of Flask
16-
(0.12.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient-python). Flask-MySQLdb is compatible
17-
with and tested on Python 2.7, 3.5, 3.6 and 3.7.
20+
(0.12.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient-python).
21+
Flask-MySQLdb is compatible with and tested with Python 3.7+. It _should_ work on any
22+
version from Python 2.7 and up, but is not supported.
1823

1924
Next, add a ``MySQL`` instance to your code:
2025

@@ -24,29 +29,36 @@ from flask_mysqldb import MySQL
2429

2530
app = Flask(__name__)
2631

27-
app.config['MYSQL_USER'] = 'user'
28-
app.config['MYSQL_PASSWORD'] = 'password'
29-
app.config['MYSQL_DB'] = 'database'
30-
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
32+
# Required
33+
app.config["MYSQL_USER"] = "user"
34+
app.config["MYSQL_PASSWORD"] = "password"
35+
app.config["MYSQL_DB"] = "database"
36+
# Extra configs, optional:
37+
app.config["MYSQL_CURSORCLASS"] = "DictCursor"
38+
app.config["MYSQL_EXTRA_KWARGS"] = {"ssl": {"ca": "/path/to/ca-file"}}
3139

3240
mysql = MySQL(app)
3341

34-
@app.route('/')
42+
@app.route("/")
3543
def users():
3644
cur = mysql.connection.cursor()
37-
cur.execute('''SELECT user, host FROM mysql.user''')
45+
cur.execute("""SELECT user, host FROM mysql.user""")
3846
rv = cur.fetchall()
3947
return str(rv)
4048

41-
if __name__ == '__main__':
49+
if __name__ == "__main__":
4250
app.run(debug=True)
4351
```
4452

4553
Other configuration directives can be found [here](http://flask-mysqldb.readthedocs.io/en/latest/#configuration).
4654

4755
Why
4856
---
49-
Why would you want to use this extension versus just using MySQLdb by itself? The only reason is that the extension was made using Flask's best pratices in relation to resources that need caching on the [app context](http://flask.pocoo.org/docs/0.12/appcontext/#context-usage). What that means is that the extension will manage creating and teardown the connection to MySQL for you while with if you were just using MySQLdb you would have to do it yourself.
57+
Why would you want to use this extension versus just using MySQLdb by itself?
58+
The only reason is that the extension was made using Flask's best practices in relation
59+
to resources that need caching on the [app context](http://flask.pocoo.org/docs/0.12/appcontext/#context-usage).
60+
What that means is that the extension will manage creating and teardown the connection to MySQL
61+
for you while with if you were just using MySQLdb you would have to do it yourself.
5062

5163

5264
Resources

dev_requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
mysqlclient==1.4.2.post1
1+
black==22.1.0
2+
mysqlclient==1.4.3
23

34
-r requirements.txt
Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
# flasky extensions. flasky pygments style based on tango style
22
from pygments.style import Style
3-
from pygments.token import Keyword, Name, Comment, String, Error, \
4-
Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
3+
from pygments.token import (
4+
Keyword,
5+
Name,
6+
Comment,
7+
String,
8+
Error,
9+
Number,
10+
Operator,
11+
Generic,
12+
Whitespace,
13+
Punctuation,
14+
Other,
15+
Literal,
16+
)
517

618

719
class FlaskyStyle(Style):
@@ -10,77 +22,68 @@ class FlaskyStyle(Style):
1022

1123
styles = {
1224
# No corresponding class for the following:
13-
#Text: "", # class: ''
14-
Whitespace: "underline #f8f8f8", # class: 'w'
15-
Error: "#a40000 border:#ef2929", # class: 'err'
16-
Other: "#000000", # class 'x'
17-
18-
Comment: "italic #8f5902", # class: 'c'
19-
Comment.Preproc: "noitalic", # class: 'cp'
20-
21-
Keyword: "bold #004461", # class: 'k'
22-
Keyword.Constant: "bold #004461", # class: 'kc'
23-
Keyword.Declaration: "bold #004461", # class: 'kd'
24-
Keyword.Namespace: "bold #004461", # class: 'kn'
25-
Keyword.Pseudo: "bold #004461", # class: 'kp'
26-
Keyword.Reserved: "bold #004461", # class: 'kr'
27-
Keyword.Type: "bold #004461", # class: 'kt'
28-
29-
Operator: "#582800", # class: 'o'
30-
Operator.Word: "bold #004461", # class: 'ow' - like keywords
31-
32-
Punctuation: "bold #000000", # class: 'p'
33-
25+
# Text: "", # class: ''
26+
Whitespace: "underline #f8f8f8", # class: 'w'
27+
Error: "#a40000 border:#ef2929", # class: 'err'
28+
Other: "#000000", # class 'x'
29+
Comment: "italic #8f5902", # class: 'c'
30+
Comment.Preproc: "noitalic", # class: 'cp'
31+
Keyword: "bold #004461", # class: 'k'
32+
Keyword.Constant: "bold #004461", # class: 'kc'
33+
Keyword.Declaration: "bold #004461", # class: 'kd'
34+
Keyword.Namespace: "bold #004461", # class: 'kn'
35+
Keyword.Pseudo: "bold #004461", # class: 'kp'
36+
Keyword.Reserved: "bold #004461", # class: 'kr'
37+
Keyword.Type: "bold #004461", # class: 'kt'
38+
Operator: "#582800", # class: 'o'
39+
Operator.Word: "bold #004461", # class: 'ow' - like keywords
40+
Punctuation: "bold #000000", # class: 'p'
3441
# because special names such as Name.Class, Name.Function, etc.
3542
# are not recognized as such later in the parsing, we choose them
3643
# to look the same as ordinary variables.
37-
Name: "#000000", # class: 'n'
38-
Name.Attribute: "#c4a000", # class: 'na' - to be revised
39-
Name.Builtin: "#004461", # class: 'nb'
40-
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
41-
Name.Class: "#000000", # class: 'nc' - to be revised
42-
Name.Constant: "#000000", # class: 'no' - to be revised
43-
Name.Decorator: "#888", # class: 'nd' - to be revised
44-
Name.Entity: "#ce5c00", # class: 'ni'
45-
Name.Exception: "bold #cc0000", # class: 'ne'
46-
Name.Function: "#000000", # class: 'nf'
47-
Name.Property: "#000000", # class: 'py'
48-
Name.Label: "#f57900", # class: 'nl'
49-
Name.Namespace: "#000000", # class: 'nn' - to be revised
50-
Name.Other: "#000000", # class: 'nx'
51-
Name.Tag: "bold #004461", # class: 'nt' - like a keyword
52-
Name.Variable: "#000000", # class: 'nv' - to be revised
53-
Name.Variable.Class: "#000000", # class: 'vc' - to be revised
54-
Name.Variable.Global: "#000000", # class: 'vg' - to be revised
55-
Name.Variable.Instance: "#000000", # class: 'vi' - to be revised
56-
57-
Number: "#990000", # class: 'm'
58-
59-
Literal: "#000000", # class: 'l'
60-
Literal.Date: "#000000", # class: 'ld'
61-
62-
String: "#4e9a06", # class: 's'
63-
String.Backtick: "#4e9a06", # class: 'sb'
64-
String.Char: "#4e9a06", # class: 'sc'
65-
String.Doc: "italic #8f5902", # class: 'sd' - like a comment
66-
String.Double: "#4e9a06", # class: 's2'
67-
String.Escape: "#4e9a06", # class: 'se'
68-
String.Heredoc: "#4e9a06", # class: 'sh'
69-
String.Interpol: "#4e9a06", # class: 'si'
70-
String.Other: "#4e9a06", # class: 'sx'
71-
String.Regex: "#4e9a06", # class: 'sr'
72-
String.Single: "#4e9a06", # class: 's1'
73-
String.Symbol: "#4e9a06", # class: 'ss'
74-
75-
Generic: "#000000", # class: 'g'
76-
Generic.Deleted: "#a40000", # class: 'gd'
77-
Generic.Emph: "italic #000000", # class: 'ge'
78-
Generic.Error: "#ef2929", # class: 'gr'
79-
Generic.Heading: "bold #000080", # class: 'gh'
80-
Generic.Inserted: "#00A000", # class: 'gi'
81-
Generic.Output: "#888", # class: 'go'
82-
Generic.Prompt: "#745334", # class: 'gp'
83-
Generic.Strong: "bold #000000", # class: 'gs'
84-
Generic.Subheading: "bold #800080", # class: 'gu'
85-
Generic.Traceback: "bold #a40000", # class: 'gt'
44+
Name: "#000000", # class: 'n'
45+
Name.Attribute: "#c4a000", # class: 'na' - to be revised
46+
Name.Builtin: "#004461", # class: 'nb'
47+
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
48+
Name.Class: "#000000", # class: 'nc' - to be revised
49+
Name.Constant: "#000000", # class: 'no' - to be revised
50+
Name.Decorator: "#888", # class: 'nd' - to be revised
51+
Name.Entity: "#ce5c00", # class: 'ni'
52+
Name.Exception: "bold #cc0000", # class: 'ne'
53+
Name.Function: "#000000", # class: 'nf'
54+
Name.Property: "#000000", # class: 'py'
55+
Name.Label: "#f57900", # class: 'nl'
56+
Name.Namespace: "#000000", # class: 'nn' - to be revised
57+
Name.Other: "#000000", # class: 'nx'
58+
Name.Tag: "bold #004461", # class: 'nt' - like a keyword
59+
Name.Variable: "#000000", # class: 'nv' - to be revised
60+
Name.Variable.Class: "#000000", # class: 'vc' - to be revised
61+
Name.Variable.Global: "#000000", # class: 'vg' - to be revised
62+
Name.Variable.Instance: "#000000", # class: 'vi' - to be revised
63+
Number: "#990000", # class: 'm'
64+
Literal: "#000000", # class: 'l'
65+
Literal.Date: "#000000", # class: 'ld'
66+
String: "#4e9a06", # class: 's'
67+
String.Backtick: "#4e9a06", # class: 'sb'
68+
String.Char: "#4e9a06", # class: 'sc'
69+
String.Doc: "italic #8f5902", # class: 'sd' - like a comment
70+
String.Double: "#4e9a06", # class: 's2'
71+
String.Escape: "#4e9a06", # class: 'se'
72+
String.Heredoc: "#4e9a06", # class: 'sh'
73+
String.Interpol: "#4e9a06", # class: 'si'
74+
String.Other: "#4e9a06", # class: 'sx'
75+
String.Regex: "#4e9a06", # class: 'sr'
76+
String.Single: "#4e9a06", # class: 's1'
77+
String.Symbol: "#4e9a06", # class: 'ss'
78+
Generic: "#000000", # class: 'g'
79+
Generic.Deleted: "#a40000", # class: 'gd'
80+
Generic.Emph: "italic #000000", # class: 'ge'
81+
Generic.Error: "#ef2929", # class: 'gr'
82+
Generic.Heading: "bold #000080", # class: 'gh'
83+
Generic.Inserted: "#00A000", # class: 'gi'
84+
Generic.Output: "#888", # class: 'go'
85+
Generic.Prompt: "#745334", # class: 'gp'
86+
Generic.Strong: "bold #000000", # class: 'gs'
87+
Generic.Subheading: "bold #800080", # class: 'gu'
88+
Generic.Traceback: "bold #a40000", # class: 'gt'
8689
}

0 commit comments

Comments
 (0)