From 85757991a10516505fcc85abf3112c807853c1dccae084eba577f6d7fa741411 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Mon, 23 Mar 2020 06:36:48 +0000 Subject: [PATCH 1/2] - Add stdout-encoding-set.patch to use sys.stdout.reconfigure() for Python 3. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-sqlparse?expand=0&rev=19 --- python-sqlparse.changes | 5 ++++ python-sqlparse.spec | 2 ++ stdout-encoding-set.patch | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 stdout-encoding-set.patch diff --git a/python-sqlparse.changes b/python-sqlparse.changes index b96400f..ef892e4 100644 --- a/python-sqlparse.changes +++ b/python-sqlparse.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Mon Mar 23 06:35:19 UTC 2020 - Steve Kowalik + +- Add stdout-encoding-set.patch to use sys.stdout.reconfigure() for Python 3. + ------------------------------------------------------------------- Mon Mar 9 16:22:39 UTC 2020 - Dirk Mueller diff --git a/python-sqlparse.spec b/python-sqlparse.spec index e8cd491..97feae3 100644 --- a/python-sqlparse.spec +++ b/python-sqlparse.spec @@ -25,6 +25,7 @@ License: BSD-3-Clause Group: Development/Languages/Python URL: https://github.com/andialbrecht/sqlparse Source: https://files.pythonhosted.org/packages/source/s/sqlparse/sqlparse-%{version}.tar.gz +Patch0: stdout-encoding-set.patch BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} BuildRequires: fdupes @@ -42,6 +43,7 @@ parsing, splitting and formatting SQL statements. %prep %setup -q -n sqlparse-%{version} sed -i -e '1{\,^#!%{_bindir}/env python,d}' sqlparse/__main__.py sqlparse/cli.py +%autopatch -p1 %build %python_build diff --git a/stdout-encoding-set.patch b/stdout-encoding-set.patch new file mode 100644 index 0000000..4b0a26e --- /dev/null +++ b/stdout-encoding-set.patch @@ -0,0 +1,52 @@ +Index: sqlparse-0.3.1/tests/test_cli.py +=================================================================== +--- sqlparse-0.3.1.orig/tests/test_cli.py ++++ sqlparse-0.3.1/tests/test_cli.py +@@ -78,7 +78,10 @@ def test_script(): + def test_encoding_utf8_stdout(filepath, load_file, capfd): + path = filepath('encoding_utf8.sql') + expected = load_file('encoding_utf8.sql', 'utf-8') +- sys.stdout.encoding = 'utf-8' ++ if sys.hexversion >= 0x3070000: ++ sys.stdout.reconfigure(encoding='utf-8') ++ else: ++ sys.stdout.encoding = 'utf-8' + sqlparse.cli.main([path]) + out, _ = capfd.readouterr() + assert out == expected +@@ -96,7 +99,10 @@ def test_encoding_utf8_output_file(filep + def test_encoding_gbk_stdout(filepath, load_file, capfd): + path = filepath('encoding_gbk.sql') + expected = load_file('encoding_gbk.sql', 'gbk') +- sys.stdout.encoding = 'gbk' ++ if sys.hexversion >= 0x3070000: ++ sys.stdout.reconfigure(encoding='gbk') ++ else: ++ sys.stdout.encoding = 'gbk' + sqlparse.cli.main([path, '--encoding', 'gbk']) + out, _ = capfd.readouterr() + assert out == expected +@@ -117,7 +123,10 @@ def test_encoding_stdin_utf8(filepath, l + old_stdin = sys.stdin + with open(path, 'r') as f: + sys.stdin = f +- sys.stdout.encoding = 'utf-8' ++ if sys.hexversion >= 0x3070000: ++ sys.stdout.reconfigure(encoding='utf-8') ++ else: ++ sys.stdout.encoding = 'utf-8' + sqlparse.cli.main(['-']) + sys.stdin = old_stdin + out, _ = capfd.readouterr() +@@ -130,7 +139,10 @@ def test_encoding_stdin_gbk(filepath, lo + old_stdin = sys.stdin + with open(path, 'r') as stream: + sys.stdin = stream +- sys.stdout.encoding = 'gbk' ++ if sys.hexversion >= 0x3070000: ++ sys.stdout.reconfigure(encoding='gbk') ++ else: ++ sys.stdout.encoding = 'gbk' + sqlparse.cli.main(['-', '--encoding', 'gbk']) + sys.stdin = old_stdin + out, _ = capfd.readouterr() From 7b6436d15d38ffc5aa3833679d2524bda927c51071c22db07964e7c183bfe550 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Tue, 24 Mar 2020 02:46:35 +0000 Subject: [PATCH 2/2] - Add stdout-encoding-set.patch to use sys.stdout.reconfigure() if the stream is an instance of TextIOWrapper to support a pytest change. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-sqlparse?expand=0&rev=20 --- python-sqlparse.changes | 5 +++-- stdout-encoding-set.patch | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/python-sqlparse.changes b/python-sqlparse.changes index ef892e4..6948036 100644 --- a/python-sqlparse.changes +++ b/python-sqlparse.changes @@ -1,7 +1,8 @@ ------------------------------------------------------------------- -Mon Mar 23 06:35:19 UTC 2020 - Steve Kowalik +Tue Mar 24 02:45:39 UTC 2020 - Steve Kowalik -- Add stdout-encoding-set.patch to use sys.stdout.reconfigure() for Python 3. +- Add stdout-encoding-set.patch to use sys.stdout.reconfigure() if + the stream is an instance of TextIOWrapper to support a pytest change. ------------------------------------------------------------------- Mon Mar 9 16:22:39 UTC 2020 - Dirk Mueller diff --git a/stdout-encoding-set.patch b/stdout-encoding-set.patch index 4b0a26e..010dc66 100644 --- a/stdout-encoding-set.patch +++ b/stdout-encoding-set.patch @@ -2,48 +2,55 @@ Index: sqlparse-0.3.1/tests/test_cli.py =================================================================== --- sqlparse-0.3.1.orig/tests/test_cli.py +++ sqlparse-0.3.1/tests/test_cli.py -@@ -78,7 +78,10 @@ def test_script(): +@@ -1,5 +1,6 @@ + # -*- coding: utf-8 -*- + ++import io + import subprocess + import sys + +@@ -78,7 +79,10 @@ def test_script(): def test_encoding_utf8_stdout(filepath, load_file, capfd): path = filepath('encoding_utf8.sql') expected = load_file('encoding_utf8.sql', 'utf-8') - sys.stdout.encoding = 'utf-8' -+ if sys.hexversion >= 0x3070000: ++ if isinstance(sys.stdout, io.TextIOWrapper): + sys.stdout.reconfigure(encoding='utf-8') + else: + sys.stdout.encoding = 'utf-8' sqlparse.cli.main([path]) out, _ = capfd.readouterr() assert out == expected -@@ -96,7 +99,10 @@ def test_encoding_utf8_output_file(filep +@@ -96,7 +100,10 @@ def test_encoding_utf8_output_file(filep def test_encoding_gbk_stdout(filepath, load_file, capfd): path = filepath('encoding_gbk.sql') expected = load_file('encoding_gbk.sql', 'gbk') - sys.stdout.encoding = 'gbk' -+ if sys.hexversion >= 0x3070000: ++ if isinstance(sys.stdout, io.TextIOWrapper): + sys.stdout.reconfigure(encoding='gbk') + else: + sys.stdout.encoding = 'gbk' sqlparse.cli.main([path, '--encoding', 'gbk']) out, _ = capfd.readouterr() assert out == expected -@@ -117,7 +123,10 @@ def test_encoding_stdin_utf8(filepath, l +@@ -117,7 +124,10 @@ def test_encoding_stdin_utf8(filepath, l old_stdin = sys.stdin with open(path, 'r') as f: sys.stdin = f - sys.stdout.encoding = 'utf-8' -+ if sys.hexversion >= 0x3070000: ++ if isinstance(sys.stdout, io.TextIOWrapper): + sys.stdout.reconfigure(encoding='utf-8') + else: + sys.stdout.encoding = 'utf-8' sqlparse.cli.main(['-']) sys.stdin = old_stdin out, _ = capfd.readouterr() -@@ -130,7 +139,10 @@ def test_encoding_stdin_gbk(filepath, lo +@@ -130,7 +140,10 @@ def test_encoding_stdin_gbk(filepath, lo old_stdin = sys.stdin with open(path, 'r') as stream: sys.stdin = stream - sys.stdout.encoding = 'gbk' -+ if sys.hexversion >= 0x3070000: ++ if isinstance(sys.stdout, io.TextIOWrapper): + sys.stdout.reconfigure(encoding='gbk') + else: + sys.stdout.encoding = 'gbk'