From e494b25a829d8911a5f62e5f2cf7ac526ff244cd Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 16 Mar 2021 13:26:38 +0100 Subject: [PATCH 01/12] Bump test step timeout in GHA to 3min --- .github/workflows/python-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index bdf7f135..d977652d 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -187,9 +187,9 @@ jobs: -vv # macOS-latest + CPython completes in 9-15s # macOS-11.0 + CPython completes in 8s-12s - # ubuntu-16.04 + CPython completes in 8s-13s + # ubuntu-16.04 + CPython completes in 8s-2m12s # ubuntu-16.04 + PyPy completes in 13s-16s - # ubuntu-18.04 + CPython completes in 8s-13s + # ubuntu-18.04 + CPython completes in 8s-2m12s # ubuntu-18.04 + PyPy completes in 13s-15s # ubuntu-20.04 + CPython completes in 8s-14s # ubuntu-20.04 + PyPy completes in 13s-16s @@ -197,7 +197,7 @@ jobs: # windows-latest + PyPy completes in 13s-24s # windows-2016 + CPython completes in 7s-11s # windows-2016 + PyPy completes in 13s-20s - timeout-minutes: 2 + timeout-minutes: 3 - name: Dump test logs on failure if: failure() shell: bash From 8d040f80a97f38a9ca9bf79e753408a7a04de1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Thu, 17 Dec 2020 10:50:26 +0100 Subject: [PATCH 02/12] Fix code for Python3 --- magicbus/plugins/loggers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index bab3c12b..45f45965 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -2,7 +2,7 @@ from magicbus.compat import ntob, unicodestr import datetime import sys - +import six from magicbus.plugins import SimplePlugin @@ -30,7 +30,7 @@ def log(self, msg, level): if self.encoding is not None: if isinstance(complete_msg, unicodestr): complete_msg = complete_msg.encode(self.encoding) - + complete_msg = six.ensure_str(complete_msg) self.stream.write(complete_msg) self.stream.flush() From 5e603e5c25e22117996519c5b17b73cb0c071f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Fri, 18 Dec 2020 13:08:32 +0100 Subject: [PATCH 03/12] Add six to required packages. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index d7eb2d90..cac336cb 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ ), python_requires='>=2.7', install_requires=[ + 'six', ], extras_require={ 'testing': [ From c58b6145fb2a372004dc2fa89f9c4fef196799bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Fri, 18 Dec 2020 16:24:57 +0100 Subject: [PATCH 04/12] A better fix for python3 support --- magicbus/plugins/loggers.py | 13 +++++++------ setup.py | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index 45f45965..d3399bf1 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -2,7 +2,6 @@ from magicbus.compat import ntob, unicodestr import datetime import sys -import six from magicbus.plugins import SimplePlugin @@ -10,7 +9,7 @@ class StreamLogger(SimplePlugin): default_format = '[%(timestamp)s] (Bus %(bus)s) %(message)s\n' - def __init__(self, bus, stream, level=None, format=None, encoding='utf-8'): + def __init__(self, bus, stream, level=None, format=None, encoding=None): SimplePlugin.__init__(self, bus) self.stream = stream self.level = level @@ -30,27 +29,29 @@ def log(self, msg, level): if self.encoding is not None: if isinstance(complete_msg, unicodestr): complete_msg = complete_msg.encode(self.encoding) - complete_msg = six.ensure_str(complete_msg) + else: + if not isinstance(complete_msg, unicodestr): + complete_msg = complete_msg.decode("utf-8") self.stream.write(complete_msg) self.stream.flush() class StdoutLogger(StreamLogger): - def __init__(self, bus, level=None, format=None, encoding='utf-8'): + def __init__(self, bus, level=None, format=None, encoding=None): StreamLogger.__init__(self, bus, sys.stdout, level, format, encoding) class StderrLogger(StreamLogger): - def __init__(self, bus, level=None, format=None, encoding='utf-8'): + def __init__(self, bus, level=None, format=None, encoding=None): StreamLogger.__init__(self, bus, sys.stderr, level, format, encoding) class FileLogger(StreamLogger): def __init__(self, bus, filename=None, file=None, - level=None, format=None, encoding='utf8'): + level=None, format=None, encoding=None): self.filename = filename if file is None: if filename is None: diff --git a/setup.py b/setup.py index cac336cb..d7eb2d90 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,6 @@ ), python_requires='>=2.7', install_requires=[ - 'six', ], extras_require={ 'testing': [ From c3eb18ff4123d6c3f2f2b5be2e3305ceae0863ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Thu, 28 Jan 2021 16:09:53 +0100 Subject: [PATCH 05/12] Revert changes for the StreamLogger and FileLogger --- magicbus/plugins/loggers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index d3399bf1..b88132ad 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -9,7 +9,7 @@ class StreamLogger(SimplePlugin): default_format = '[%(timestamp)s] (Bus %(bus)s) %(message)s\n' - def __init__(self, bus, stream, level=None, format=None, encoding=None): + def __init__(self, bus, stream, level=None, format=None, encoding='utf8'): SimplePlugin.__init__(self, bus) self.stream = stream self.level = level @@ -51,7 +51,7 @@ def __init__(self, bus, level=None, format=None, encoding=None): class FileLogger(StreamLogger): def __init__(self, bus, filename=None, file=None, - level=None, format=None, encoding=None): + level=None, format=None, encoding='utf8'): self.filename = filename if file is None: if filename is None: From 86f754c23644bb9e4d137b993e9c85b4d9e17bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Wed, 3 Feb 2021 10:20:08 +0100 Subject: [PATCH 06/12] Fix encoding name --- magicbus/plugins/loggers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index b88132ad..b1bf2a42 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -9,7 +9,7 @@ class StreamLogger(SimplePlugin): default_format = '[%(timestamp)s] (Bus %(bus)s) %(message)s\n' - def __init__(self, bus, stream, level=None, format=None, encoding='utf8'): + def __init__(self, bus, stream, level=None, format=None, encoding='utf-8'): SimplePlugin.__init__(self, bus) self.stream = stream self.level = level @@ -51,7 +51,7 @@ def __init__(self, bus, level=None, format=None, encoding=None): class FileLogger(StreamLogger): def __init__(self, bus, filename=None, file=None, - level=None, format=None, encoding='utf8'): + level=None, format=None, encoding='utf-8'): self.filename = filename if file is None: if filename is None: From 79d20a617df413a8e6d3f6fa32b67f986fa2a357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Wed, 3 Feb 2021 10:36:39 +0100 Subject: [PATCH 07/12] Revert last changes to check tests --- magicbus/plugins/loggers.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index b1bf2a42..1fee94df 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -29,29 +29,32 @@ def log(self, msg, level): if self.encoding is not None: if isinstance(complete_msg, unicodestr): complete_msg = complete_msg.encode(self.encoding) - else: - if not isinstance(complete_msg, unicodestr): - complete_msg = complete_msg.decode("utf-8") + # else: + # if not isinstance(complete_msg, unicodestr): + # complete_msg = complete_msg.decode("utf-8") self.stream.write(complete_msg) self.stream.flush() class StdoutLogger(StreamLogger): - def __init__(self, bus, level=None, format=None, encoding=None): + # def __init__(self, bus, level=None, format=None, encoding=None): + def __init__(self, bus, level=None, format=None, encoding="utf-8"): StreamLogger.__init__(self, bus, sys.stdout, level, format, encoding) class StderrLogger(StreamLogger): - def __init__(self, bus, level=None, format=None, encoding=None): + # def __init__(self, bus, level=None, format=None, encoding=None): + def __init__(self, bus, level=None, format=None, encoding='utf-8'): StreamLogger.__init__(self, bus, sys.stderr, level, format, encoding) class FileLogger(StreamLogger): def __init__(self, bus, filename=None, file=None, - level=None, format=None, encoding='utf-8'): + level=None, format=None, encoding='utf8'): + # level=None, format=None, encoding='utf-8'): self.filename = filename if file is None: if filename is None: From 1bb97e3b31c41acf0ac438707ea89f4dbbdb578c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Wed, 3 Feb 2021 10:49:57 +0100 Subject: [PATCH 08/12] Revert "Revert last changes to check tests" This reverts commit 28e9064247f91983968af3822cebe4b2a5a784bf. --- magicbus/plugins/loggers.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index 1fee94df..b1bf2a42 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -29,32 +29,29 @@ def log(self, msg, level): if self.encoding is not None: if isinstance(complete_msg, unicodestr): complete_msg = complete_msg.encode(self.encoding) - # else: - # if not isinstance(complete_msg, unicodestr): - # complete_msg = complete_msg.decode("utf-8") + else: + if not isinstance(complete_msg, unicodestr): + complete_msg = complete_msg.decode("utf-8") self.stream.write(complete_msg) self.stream.flush() class StdoutLogger(StreamLogger): - # def __init__(self, bus, level=None, format=None, encoding=None): - def __init__(self, bus, level=None, format=None, encoding="utf-8"): + def __init__(self, bus, level=None, format=None, encoding=None): StreamLogger.__init__(self, bus, sys.stdout, level, format, encoding) class StderrLogger(StreamLogger): - # def __init__(self, bus, level=None, format=None, encoding=None): - def __init__(self, bus, level=None, format=None, encoding='utf-8'): + def __init__(self, bus, level=None, format=None, encoding=None): StreamLogger.__init__(self, bus, sys.stderr, level, format, encoding) class FileLogger(StreamLogger): def __init__(self, bus, filename=None, file=None, - level=None, format=None, encoding='utf8'): - # level=None, format=None, encoding='utf-8'): + level=None, format=None, encoding='utf-8'): self.filename = filename if file is None: if filename is None: From 0bf9c28101b90a33788838826d22fd072f207806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Wed, 3 Feb 2021 14:25:03 +0100 Subject: [PATCH 09/12] Fix loggers code --- magicbus/plugins/loggers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index b1bf2a42..e5d22d44 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -30,8 +30,10 @@ def log(self, msg, level): if isinstance(complete_msg, unicodestr): complete_msg = complete_msg.encode(self.encoding) else: - if not isinstance(complete_msg, unicodestr): - complete_msg = complete_msg.decode("utf-8") + if isinstance(complete_msg, unicodestr): + encoding = self.encoding or "utf-8" + complete_msg = complete_msg.encode(encoding, errors="backslashreplace") + self.stream.write(complete_msg) self.stream.flush() From 35017cd5e99a4e14005c8a780a6be04971f2bf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Wed, 3 Feb 2021 14:41:33 +0100 Subject: [PATCH 10/12] Fix loggers code --- magicbus/plugins/loggers.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index e5d22d44..264317c3 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -26,13 +26,9 @@ def log(self, msg, level): } complete_msg = self.format % params - if self.encoding is not None: - if isinstance(complete_msg, unicodestr): - complete_msg = complete_msg.encode(self.encoding) - else: - if isinstance(complete_msg, unicodestr): - encoding = self.encoding or "utf-8" - complete_msg = complete_msg.encode(encoding, errors="backslashreplace") + if isinstance(complete_msg, unicodestr): + encoding = self.encoding or "utf-8" + complete_msg = complete_msg.encode(encoding, errors="backslashreplace") self.stream.write(complete_msg) self.stream.flush() From 7876e3acb64ee9d10197aa0f6c8e60f2cc3eeeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Thu, 4 Feb 2021 16:47:40 +0100 Subject: [PATCH 11/12] Revert the last loggers changes --- magicbus/plugins/loggers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index 264317c3..5c6b94ec 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -26,9 +26,12 @@ def log(self, msg, level): } complete_msg = self.format % params - if isinstance(complete_msg, unicodestr): - encoding = self.encoding or "utf-8" - complete_msg = complete_msg.encode(encoding, errors="backslashreplace") + if self.encoding is not None: + if isinstance(complete_msg, unicodestr): + complete_msg = complete_msg.encode(self.encoding) + else: + if not isinstance(complete_msg, unicodestr): + complete_msg = complete_msg.decode("utf-8") self.stream.write(complete_msg) self.stream.flush() From ed0558375da29e0157ea828315978a9c73b25438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Lipi=C5=84ski?= Date: Thu, 11 Feb 2021 16:51:40 +0100 Subject: [PATCH 12/12] clean code --- magicbus/plugins/loggers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magicbus/plugins/loggers.py b/magicbus/plugins/loggers.py index 5c6b94ec..f71c9cd2 100644 --- a/magicbus/plugins/loggers.py +++ b/magicbus/plugins/loggers.py @@ -2,6 +2,7 @@ from magicbus.compat import ntob, unicodestr import datetime import sys + from magicbus.plugins import SimplePlugin @@ -52,7 +53,7 @@ def __init__(self, bus, level=None, format=None, encoding=None): class FileLogger(StreamLogger): def __init__(self, bus, filename=None, file=None, - level=None, format=None, encoding='utf-8'): + level=None, format=None, encoding='utf8'): self.filename = filename if file is None: if filename is None: