jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] Add support for PyMySQL 1.0.0+

- pymysql.Connection() postionial parameter order has been changed
several times as is dopped since 1.0 where keyword only parameters
are required. Therefore always use keyword parameters but use the
renamed 'database' instead of 'db', 'password' instead 'passwd';
the latter are deprecated.
- Require PyMySQ >= 0.6.6 due to Cursor context manager support;
Python 3.5 is dropped with 1.0.0
- Require PyMySQ >= 1.0.0 due to Connection context manager support
- use contextlib.closing() context manager for PyMySQ < 1.0.0

See:
https://github.com/PyMySQL/PyMySQL/pull/930/commits/26a1370cc98eb8605a71e3cc59c3d4ddad765faa

Change-Id: Ida4e5edf2920b4302ff89ec1f4ea1e4e0a1da74d
---
M pywikibot/data/mysql.py
M requirements.txt
2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/pywikibot/data/mysql.py b/pywikibot/data/mysql.py
index 956b9d0..4ba0b5f 100644
--- a/pywikibot/data/mysql.py
+++ b/pywikibot/data/mysql.py
@@ -1,10 +1,9 @@
"""Miscellaneous helper functions for mysql queries."""
#
-# (C) Pywikibot team, 2016-2020
+# (C) Pywikibot team, 2016-2021
#
# Distributed under the terms of the MIT license.
#
-from contextlib import closing
from typing import Optional

import pywikibot
@@ -16,7 +15,7 @@


from pywikibot import config2 as config
-from pywikibot.tools import deprecated_args
+from pywikibot.tools import deprecated_args, PYTHON_VERSION


@deprecated_args(encoding=None)
@@ -52,16 +51,20 @@

if config.db_connect_file is None:
credentials = {'user': config.db_username,
- 'passwd': config.db_password}
+ 'password': config.db_password}
else:
credentials = {'read_default_file': config.db_connect_file}

- with closing(pymysql.connect(config.db_hostname_format.format(dbname),
- db=config.db_name_format.format(dbname),
+ connection = pymysql.connect(host=config.db_hostname_format.format(dbname),
+ database=config.db_name_format.format(dbname),
port=config.db_port,
charset='utf8',
- **credentials)) as conn, \
- closing(conn.cursor()) as cursor:
+ **credentials)
+ if PYTHON_VERSION < (3, 6):
+ from contextlib import closing
+ connection = closing(connection)
+
+ with connection as conn, conn.cursor() as cursor:

if verbose:
_query = cursor.mogrify(query, params)
diff --git a/requirements.txt b/requirements.txt
index de654f8..d99d263 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -45,7 +45,8 @@
mwparserfromhell>=0.3.3

# The mysql generator in pagegenerators depends on PyMySQL
-PyMySQL
+PyMySQL >= 0.6.6, < 1.0.0 ; python_version < '3.6'
+PyMySQL >= 1.0.0 ; python_version >= '3.6'

# core HTML comparison parser in diff module
beautifulsoup4

To view, visit change 673462. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ida4e5edf2920b4302ff89ec1f4ea1e4e0a1da74d
Gerrit-Change-Number: 673462
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Hashar <hashar@free.fr>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged