Skip to content

Commit 791850c

Browse files
committed
Merge branch 'release/8.0.24'
2 parents bd5bbac + 3a7ae51 commit 791850c

File tree

9 files changed

+66
-28
lines changed

9 files changed

+66
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.diff
22
*.egg-info/
3+
*.so
34
*.patch
45
*.pyc
56
*__pycache__*

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ v8.0.24
1515
- WL#14239: Remove Python 2.7 support
1616
- WL#14212: Support connection close notification
1717
- WL#14027: Add support for Python 3.9
18+
- BUG#32029891: Add context manager support for pooled connections
1819

1920
v8.0.23
2021
=======

cpydist/__init__.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, Oracle and/or its affiliates.
1+
# Copyright (c) 2020, 2021, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -155,16 +155,38 @@ def finalize_options(self):
155155
log.set_threshold(1) # Set Distutils logging level to DEBUG
156156

157157
cmd_build_ext = self.distribution.get_command_obj("build_ext")
158-
cmd_build_ext.with_mysql_capi = self.with_mysql_capi
159-
cmd_build_ext.with_openssl_include_dir = self.with_openssl_include_dir
160-
cmd_build_ext.with_openssl_lib_dir = self.with_openssl_lib_dir
161-
cmd_build_ext.with_protobuf_include_dir = \
162-
self.with_protobuf_include_dir
163-
cmd_build_ext.with_protobuf_lib_dir = self.with_protobuf_lib_dir
164-
cmd_build_ext.with_protoc = self.with_protoc
165-
cmd_build_ext.extra_compile_args = self.extra_compile_args
166-
cmd_build_ext.extra_link_args = self.extra_link_args
167-
158+
cmd_build_ext.with_mysql_capi = (
159+
self.with_mysql_capi or
160+
os.environ.get("MYSQL_CAPI")
161+
)
162+
cmd_build_ext.with_openssl_include_dir = (
163+
self.with_openssl_include_dir or
164+
os.environ.get("OPENSSL_INCLUDE_DIR")
165+
)
166+
cmd_build_ext.with_openssl_lib_dir = (
167+
self.with_openssl_lib_dir or
168+
os.environ.get("OPENSSL_LIB_DIR")
169+
)
170+
cmd_build_ext.with_protobuf_include_dir = (
171+
self.with_protobuf_include_dir or
172+
os.environ.get("PROTOBUF_INCLUDE_DIR")
173+
)
174+
cmd_build_ext.with_protobuf_lib_dir = (
175+
self.with_protobuf_lib_dir or
176+
os.environ.get("PROTOBUF_LIB_DIR")
177+
)
178+
cmd_build_ext.with_protoc = (
179+
self.with_protoc or
180+
os.environ.get("PROTOC")
181+
)
182+
cmd_build_ext.extra_compile_args = (
183+
self.extra_compile_args or
184+
os.environ.get("EXTRA_COMPILE_ARGS")
185+
)
186+
cmd_build_ext.extra_link_args = (
187+
self.extra_link_args or
188+
os.environ.get("EXTRA_LINK_ARGS")
189+
)
168190
self._copy_vendor_libraries()
169191

170192
def remove_temp(self):

cpydist/bdist_deb.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, Oracle and/or its affiliates.
1+
# Copyright (c) 2020, 2021, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -255,10 +255,13 @@ def _populate_debian(self):
255255
"".format(copyright_file))
256256
with open(copyright_file, "r") as fp:
257257
# Skip to line just before the text we want to copy
258-
while not fp.readline().startswith("License: Commercial"):
259-
continue
260-
# Read the rest of the text (add a space before each line)
261-
lic_text = fp.read()
258+
while True:
259+
line = fp.readline()
260+
if not line:
261+
break
262+
if line.startswith("License: Commercial"):
263+
# Read the rest of the text
264+
lic_text = fp.read()
262265

263266
with open(control_file, "r") as fp:
264267
control_text = fp.read()

cpydist/data/deb/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Priority: extra
33
Section: python
44
Maintainer: MySQL Release Engineering <[email protected]>
55
Build-Depends:
6-
debhelper (>= 9.0.0), dh-python, python (>= 3.5.0) | python3 (>= 3.5.0)
6+
debhelper (>= 9.0.0), dh-python, python (>= 3.6.0) | python3 (>= 3.6.0)
77
Standards-Version: 3.9.8
88
Homepage: http://dev.mysql.com/downloads/connector/python/
9-
X-Python3-Version: >= 3.5
9+
X-Python3-Version: >= 3.6
1010

1111
Package: mysql-connector-python-py3
1212
Architecture: any

cpydist/data/deb/rules

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/make -f
22

33

4-
# Copyright (c) 2014, 2020, Oracle and/or its affiliates.
4+
# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License, version 2.0, as
@@ -30,6 +30,8 @@
3030
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3131

3232
export DH_VERBOSE = 1
33+
export PYBUILD_DISABLE=test
34+
export PYBUILD_DISABLE_python2=1
3335

3436
PY3_BUILD_LIB_OPT = --build-lib=build/python3
3537

@@ -69,20 +71,17 @@ endif
6971

7072
# Check whether we have Python v3 support
7173
ifneq ($(shell which py3versions 2>/dev/null),)
72-
WITHPYTHON="python3"
73-
PYTHON3_SUPPORTED=$(shell py3versions -sv)
74+
PYTHON3_SUPPORTED=$(shell py3versions -sv)
7475
endif
7576

7677
ifneq ($(BYTE_CODE_ONLY),)
7778
BYTE_CODE_ONLY_OPT = --byte-code-only
78-
EXTRA_OPTIONS_DH =
7979
else
8080
BYTE_CODE_ONLY_OPT =
81-
EXTRA_OPTIONS_DH = --buildsystem=python_distutils --with $(WITHPYTHON)
8281
endif
8382

8483
%:
85-
dh $@ $(EXTRA_OPTIONS_DH)
84+
dh $@ --with python3 --buildsystem=pybuild
8685

8786
override_dh_auto_install:
8887

@@ -103,7 +102,9 @@ override_dh_auto_install:
103102
done
104103

105104
override_dh_python3:
106-
dh_python3 --no-ext-rename
105+
ifeq ($(BYTE_CODE_ONLY),)
106+
py3clean .
107+
endif
107108

108109
ifneq ($(BYTE_CODE_ONLY),)
109110
override_dh_pysupport:

cpydist/data/rpm/mysql-connector-python.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Summary: Standardized MySQL database driver for Python
7575
Name: mysql-connector-python%{?product_suffix}
7676
Version: %{version}
7777
Release: 1%{?version_extra:.%{version_extra}}%{?byte_code_only:.1}%{?dist}
78-
License: Copyright (c) 2015, 2020, Oracle and/or its affiliates. Under %{?license_type} license as shown in the Description field.
78+
License: Copyright (c) 2015, 2021, Oracle and/or its affiliates. Under %{?license_type} license as shown in the Description field.
7979
URL: https://dev.mysql.com/downloads/connector/python/
8080
Source0: https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python%{?product_suffix}-%{version}.tar.gz
8181

lib/mysql/connector/pooling.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -111,6 +111,12 @@ def __init__(self, pool, cnx):
111111
self._cnx_pool = pool
112112
self._cnx = cnx
113113

114+
def __enter__(self):
115+
return self
116+
117+
def __exit__(self, exc_type, exc_value, traceback):
118+
self.close()
119+
114120
def __getattr__(self, attr):
115121
"""Calls attributes of the MySQLConnection instance"""
116122
return getattr(self._cnx, attr)

tests/test_pooling.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -333,6 +333,10 @@ def test_get_connection(self):
333333
self.assertEqual(1, pcnx.autocommit)
334334
pcnx.close()
335335

336+
# Get connection from pool using a context manager
337+
with cnxpool.get_connection() as pcnx:
338+
self.assertTrue(isinstance(pcnx, pooling.PooledMySQLConnection))
339+
336340
def test__remove_connections(self):
337341
dbconfig = tests.get_mysql_config()
338342
if tests.MYSQL_VERSION < (5, 7):

0 commit comments

Comments
 (0)