From 434e7eb3a527f2f4984c12140dc8ce36ee88295d Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:05:05 +0900 Subject: [PATCH 01/16] CI: Add django test --- ci/test_mysql.py | 44 +++++++++++++++++++++++++++++++++++ django.yaml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 ci/test_mysql.py create mode 100644 django.yaml diff --git a/ci/test_mysql.py b/ci/test_mysql.py new file mode 100644 index 00000000..72c0259a --- /dev/null +++ b/ci/test_mysql.py @@ -0,0 +1,44 @@ +# This is an example test settings file for use with the Django test suite. +# +# The 'sqlite3' backend requires only the ENGINE setting (an in- +# memory database will be used). All other backends will require a +# NAME and potentially authentication information. See the +# following section in the docs for more information: +# +# https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/ +# +# The different databases that Django supports behave differently in certain +# situations, so it is recommended to run the test suite against as many +# database backends as possible. You may want to create a separate settings +# file for each of the backends you test against. + +import pymysql +pymysql.install_as_MySQLdb() + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": "django_default", + "HOST": "127.0.0.1", + "USER": "scott", + "PASSWORD": "tiger", + "TEST": {"CHARSET": "utf8mb3", "COLLATION": "utf8mb3_general_ci"}, + }, + "other": { + "ENGINE": "django.db.backends.mysql", + "NAME": "django_other", + "HOST": "127.0.0.1", + "USER": "scott", + "PASSWORD": "tiger", + "TEST": {"CHARSET": "utf8mb3", "COLLATION": "utf8mb3_general_ci"}, + }, +} + +SECRET_KEY = "django_tests_secret_key" + +# Use a fast hasher to speed up tests. +PASSWORD_HASHERS = [ + "django.contrib.auth.hashers.MD5PasswordHasher", +] + +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" diff --git a/django.yaml b/django.yaml new file mode 100644 index 00000000..fdd77f07 --- /dev/null +++ b/django.yaml @@ -0,0 +1,60 @@ +name: Test + +on: + push: + # branches: ["main"] + pull_request: + +jobs: + django-test: + name: "Run Django LTS test suite" + runs-on: ubuntu-latest + env: + PIP_NO_PYTHON_VERSION_WARNING: 1 + PIP_DISABLE_PIP_VERSION_CHECK: 1 + DJANGO_VERSION: "3.2.19" + strategy: + matrix: + include: + # Django 3.2.9+ supports Python 3.10 + # https://docs.djangoproject.com/ja/3.2/releases/3.2/ + - django: "3.2.19" + python: "3.10" + + - django: "4.2.1" + python: "3.11" + + steps: + - name: Start MySQL + run: | + sudo systemctl start mysql.service + mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -proot mysql + mysql -uroot -proot -e "set global innodb_flush_log_at_trx_commit=0;" + mysql -uroot -proot -e "CREATE USER 'scott'@'%' IDENTIFIED BY 'tiger'; GRANT ALL ON *.* TO scott;" + mysql -uroot -proot -e "CREATE DATABASE django_default; CREATE DATABASE django_other;" + + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }}} + + - name: Install mysqlclient + run: | + #pip install mysqlclient # Use stable version + pip install . + + - name: Setup Django + run: | + sudo apt-get install libmemcached-dev + wget https://github.com/django/django/archive/${{ matrix.django }}.tar.gz + tar xf ${{ matrix.django }}.tar.gz + cp ci/test_mysql.py django-${{ matrix.django }}/tests/ + cd django-${{ matrix.django }} + pip install . -r tests/requirements/py3.txt + + - name: Run Django test + run: | + cd django-${{ matrix.django }}/tests/ + python ./runtests.py --settings=test_mysql From 7c556c07396f14ac0a0aac469b46601586a74834 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:07:55 +0900 Subject: [PATCH 02/16] Fix workflow name --- django.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django.yaml b/django.yaml index fdd77f07..53e7dc7b 100644 --- a/django.yaml +++ b/django.yaml @@ -1,4 +1,4 @@ -name: Test +name: Django test on: push: From e4d2c585bd9259a5c7860ef5bbcc186350ba2853 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:13:36 +0900 Subject: [PATCH 03/16] git mv --- django.yaml => .github/workflows/django.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename django.yaml => .github/workflows/django.yaml (98%) diff --git a/django.yaml b/.github/workflows/django.yaml similarity index 98% rename from django.yaml rename to .github/workflows/django.yaml index 53e7dc7b..6a8fd1c9 100644 --- a/django.yaml +++ b/.github/workflows/django.yaml @@ -12,7 +12,7 @@ jobs: env: PIP_NO_PYTHON_VERSION_WARNING: 1 PIP_DISABLE_PIP_VERSION_CHECK: 1 - DJANGO_VERSION: "3.2.19" + # DJANGO_VERSION: "3.2.19" strategy: matrix: include: From f7af7bb06f9c4401250a4b8bbdfb1dea9f418c1c Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:14:59 +0900 Subject: [PATCH 04/16] fixup --- .github/workflows/django.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index 6a8fd1c9..79d06feb 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -38,7 +38,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python }}} + python-version: ${{ matrix.python }} - name: Install mysqlclient run: | From 3225002360d4bc6fbb225a22031b6eb23b79207e Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:17:16 +0900 Subject: [PATCH 05/16] USE_TZ=False --- ci/test_mysql.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/test_mysql.py b/ci/test_mysql.py index 72c0259a..c1366c06 100644 --- a/ci/test_mysql.py +++ b/ci/test_mysql.py @@ -42,3 +42,5 @@ ] DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + +USE_TZ = False From 9e472751946e1e5493bfa63647860c4ce987c282 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:23:19 +0900 Subject: [PATCH 06/16] Improve mysqlclient compatibility --- ci/test_mysql.py | 1 + pymysql/__init__.py | 49 ++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ci/test_mysql.py b/ci/test_mysql.py index c1366c06..b97978a2 100644 --- a/ci/test_mysql.py +++ b/ci/test_mysql.py @@ -13,6 +13,7 @@ # file for each of the backends you test against. import pymysql + pymysql.install_as_MySQLdb() DATABASES = { diff --git a/pymysql/__init__.py b/pymysql/__init__.py index c0039c3f..a84f3ebd 100644 --- a/pymysql/__init__.py +++ b/pymysql/__init__.py @@ -47,11 +47,29 @@ ) -VERSION = (1, 0, 3) -if len(VERSION) > 3: - VERSION_STRING = "%d.%d.%d_%s" % VERSION +### for mysqlclient compatibility +### Django checks mysqlclient version. +version_info = (1, 4, 3, "final", 0) +if len(version_info) > 3: + __version__ = "%d.%d.%d_%s" % version_info else: - VERSION_STRING = "%d.%d.%d" % VERSION + __version__ = "%d.%d.%d" % version_info + + +def get_client_info(): # for MySQLdb compatibility + return __version__ + + +def install_as_MySQLdb(): + """ + After this function is called, any application that imports MySQLdb or + _mysql will unwittingly actually use pymysql. + """ + sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"] + + +# end of mysqlclient compatibility code + threadsafety = 1 apilevel = "2.0" paramstyle = "pyformat" @@ -109,31 +127,12 @@ def Binary(x): return bytes(x) -Connect = connect = Connection = connections.Connection - - -def get_client_info(): # for MySQLdb compatibility - return VERSION_STRING - - -# we include a doctored version_info here for MySQLdb compatibility -version_info = (1, 4, 0, "final", 0) - -NULL = "NULL" - -__version__ = get_client_info() - - def thread_safe(): return True # match MySQLdb.thread_safe() -def install_as_MySQLdb(): - """ - After this function is called, any application that imports MySQLdb or - _mysql will unwittingly actually use pymysql. - """ - sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"] +Connect = connect = Connection = connections.Connection +NULL = "NULL" __all__ = [ From 83dce1628dd91a485a6aaa8e19033df4049c829d Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:26:17 +0900 Subject: [PATCH 07/16] fixup --- pymysql/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pymysql/__init__.py b/pymysql/__init__.py index a84f3ebd..f0b7eb96 100644 --- a/pymysql/__init__.py +++ b/pymysql/__init__.py @@ -50,10 +50,7 @@ ### for mysqlclient compatibility ### Django checks mysqlclient version. version_info = (1, 4, 3, "final", 0) -if len(version_info) > 3: - __version__ = "%d.%d.%d_%s" % version_info -else: - __version__ = "%d.%d.%d" % version_info +__version__ = "1.4.3" def get_client_info(): # for MySQLdb compatibility From 0d3e43a0943bd863f2ff12f23d5895a4942cdcb4 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:26:32 +0900 Subject: [PATCH 08/16] Disable tests until django workflow become OK --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c3275cca..ae490b5e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,8 +1,8 @@ name: Test on: - push: - pull_request: + #push: + #pull_request: concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} From 0557cce76398a724ed7395de3ddf924378826e6b Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:28:55 +0900 Subject: [PATCH 09/16] fixup --- pymysql/connections.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index f4782939..6edac04c 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -25,7 +25,7 @@ EOFPacketWrapper, LoadLocalPacketWrapper, ) -from . import err, VERSION_STRING +from . import err, __version__ try: import ssl @@ -346,7 +346,7 @@ def _config(key, arg): self._connect_attrs = { "_client_name": "pymysql", "_pid": str(os.getpid()), - "_client_version": VERSION_STRING, + "_client_version": __version__, } if program_name: From f1197c692fbaa6788590dffa99af1bb31a9fc52c Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:33:35 +0900 Subject: [PATCH 10/16] fix build --- pymysql/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pymysql/__init__.py b/pymysql/__init__.py index f0b7eb96..65ed55d5 100644 --- a/pymysql/__init__.py +++ b/pymysql/__init__.py @@ -46,6 +46,9 @@ TimestampFromTicks, ) +# PyMySQL version. +# Used by setuptools. +VERSION = (1, 1, 0, "dev", 1) ### for mysqlclient compatibility ### Django checks mysqlclient version. From c8b68722d7d6abe973d6b8ad4d26b6e7120fb9ed Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 11:35:56 +0900 Subject: [PATCH 11/16] Install cryptography --- .github/workflows/django.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index 79d06feb..d7c89423 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -43,7 +43,7 @@ jobs: - name: Install mysqlclient run: | #pip install mysqlclient # Use stable version - pip install . + pip install .[rsa] - name: Setup Django run: | From 2f32b3c2212f4556d916b3f62a90e50f76ab38a2 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 12:45:16 +0900 Subject: [PATCH 12/16] fixup --- .github/workflows/django.yaml | 1 + pymysql/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index d7c89423..25a9b126 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -57,4 +57,5 @@ jobs: - name: Run Django test run: | cd django-${{ matrix.django }}/tests/ + rm -rf test_runner # test_runner does not using our test_mysql.py python ./runtests.py --settings=test_mysql diff --git a/pymysql/__init__.py b/pymysql/__init__.py index 65ed55d5..ab43c1a9 100644 --- a/pymysql/__init__.py +++ b/pymysql/__init__.py @@ -62,10 +62,10 @@ def get_client_info(): # for MySQLdb compatibility def install_as_MySQLdb(): """ - After this function is called, any application that imports MySQLdb or - _mysql will unwittingly actually use pymysql. + After this function is called, any application that imports MySQLdb + will unwittingly actually use pymysql. """ - sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"] + sys.modules["MySQLdb"] = sys.modules["pymysql"] # end of mysqlclient compatibility code From 2b1f1695eb5574192420d217e3b44b967afe8b6d Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 13:26:44 +0900 Subject: [PATCH 13/16] Skip admin_scripts too --- .github/workflows/django.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index 25a9b126..9a7e40c3 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -14,6 +14,7 @@ jobs: PIP_DISABLE_PIP_VERSION_CHECK: 1 # DJANGO_VERSION: "3.2.19" strategy: + fail-fast: false matrix: include: # Django 3.2.9+ supports Python 3.10 @@ -57,5 +58,5 @@ jobs: - name: Run Django test run: | cd django-${{ matrix.django }}/tests/ - rm -rf test_runner # test_runner does not using our test_mysql.py + rm -rf test_runner admin_scripts # test_runner does not using our test_mysql.py python ./runtests.py --settings=test_mysql From 23ac50d0546683500bad4079c0be3722740658d3 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 13:47:40 +0900 Subject: [PATCH 14/16] run oly backends test --- .github/workflows/django.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index 9a7e40c3..e46b0807 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -58,5 +58,7 @@ jobs: - name: Run Django test run: | cd django-${{ matrix.django }}/tests/ - rm -rf test_runner admin_scripts # test_runner does not using our test_mysql.py - python ./runtests.py --settings=test_mysql + # test_runner does not using our test_mysql.py + # We can't run whole django test suite for now. + # Run olly backends test + DJANGO_SETTINGS_MODULE=test_mysql python runtests.py backends From ba937a47744a5075c0f210b6ad4c6a7f7127550e Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 14:32:33 +0900 Subject: [PATCH 15/16] Give up passing django test suite --- .github/workflows/django.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index e46b0807..74518b1f 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -2,13 +2,14 @@ name: Django test on: push: - # branches: ["main"] - pull_request: + branches: ["main"] jobs: django-test: name: "Run Django LTS test suite" runs-on: ubuntu-latest + # There are some known difference between MySQLdb and PyMySQL. + continue-on-error: true env: PIP_NO_PYTHON_VERSION_WARNING: 1 PIP_DISABLE_PIP_VERSION_CHECK: 1 From 2779cb8953e44c478116be59cb24357fe07d5e40 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 25 May 2023 14:46:46 +0900 Subject: [PATCH 16/16] revert skipping tests. --- .github/workflows/django.yaml | 3 ++- .github/workflows/test.yaml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml index 74518b1f..da664f85 100644 --- a/.github/workflows/django.yaml +++ b/.github/workflows/django.yaml @@ -2,7 +2,8 @@ name: Django test on: push: - branches: ["main"] + # branches: ["main"] + # pull_request: jobs: django-test: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ae490b5e..c3275cca 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,8 +1,8 @@ name: Test on: - #push: - #pull_request: + push: + pull_request: concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}