14
0
forked from pool/python-loguru

Accepting request 993287 from home:bnavigator:branches:devel:languages:python

- Update to 0.6.0
  * Remove internal use of pickle.loads() considered as a security
    vulnerability referenced as CVE-2022-0329 (#563).
  * Modify coroutine sink to make it discard log messages when
    loop=None and no event loop is running (due to internally using
    asyncio.get_running_loop() in place of
    asyncio.get_event_loop()).
  * Remove the possibility to add a coroutine sink with
    enqueue=True if loop=None and no event loop is running.
  * Change default encoding of file sink to be utf8 instead of
    locale.getpreferredencoding() (#339).
  * Prevent non-ascii characters to be escaped while logging JSON
    message with serialize=True (#575, thanks @ponponon).
  * Fix flake8 errors and improve code readability (#353, thanks
    @AndrewYakimets).
- Drop merged patches:
  * loguru-exception-formatting-py39.patch
  * pytest-6.2-excepthooks.patch
- Add loguru-fix-repr-tests.patch
  * Fix "repr()" tests failing on Python 3.11 and Python 3.10.6
  * https://github.com/Delgan/loguru/commit/4fe21f66

OBS-URL: https://build.opensuse.org/request/show/993287
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-loguru?expand=0&rev=15
This commit is contained in:
2022-08-05 13:19:57 +00:00
committed by Git OBS Bridge
parent 4a059b5745
commit aed181b600
7 changed files with 173 additions and 260 deletions

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b28e72ac7a98be3d28ad28570299a393dfcd32e5e3f6a353dec94675767b6319
size 122800

3
loguru-0.6.0.tar.gz Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:066bd06758d0a513e9836fd9c6b5a75bfb3fd36841f4b996bc60b547a309d41c
size 123158

View File

@@ -1,161 +0,0 @@
From 19f518c5f1f355703ffc4ee62f0e1e397605863e Mon Sep 17 00:00:00 2001
From: Delgan <delgan.py@gmail.com>
Date: Sat, 13 Mar 2021 12:47:47 +0100
Subject: [PATCH] Fix unit tests for exception formatting for Python 3.9
Formatting changed, notably because absolute instead of relative paths
are used in traceback: https://bugs.python.org/issue20443
---
.../output/diagnose/indentation_error.txt | 1 -
.../output/diagnose/syntax_error.txt | 2 +-
.../others/syntaxerror_without_traceback.txt | 8 ++---
.../output/ownership/syntaxerror.txt | 10 +++---
tests/test_exceptions_formatting.py | 31 ++++++++++++++++++-
5 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/tests/exceptions/output/diagnose/indentation_error.txt b/tests/exceptions/output/diagnose/indentation_error.txt
index b2faa4d..d5b950a 100644
--- a/tests/exceptions/output/diagnose/indentation_error.txt
+++ b/tests/exceptions/output/diagnose/indentation_error.txt
@@ -7,6 +7,5 @@
File "<string>", line 4
print("foobar") #intentional faulty indentation here.
- ^
IndentationError: unexpected indent
diff --git a/tests/exceptions/output/diagnose/syntax_error.txt b/tests/exceptions/output/diagnose/syntax_error.txt
index 6e1f612..c8b0761 100644
--- a/tests/exceptions/output/diagnose/syntax_error.txt
+++ b/tests/exceptions/output/diagnose/syntax_error.txt
@@ -7,6 +7,6 @@
File "<string>", line 4
b = 7 *
- ^
+ ^
SyntaxError: invalid syntax
diff --git a/tests/exceptions/output/others/syntaxerror_without_traceback.txt b/tests/exceptions/output/others/syntaxerror_without_traceback.txt
index a4747ee..d798ba1 100644
--- a/tests/exceptions/output/others/syntaxerror_without_traceback.txt
+++ b/tests/exceptions/output/others/syntaxerror_without_traceback.txt
@@ -1,20 +1,20 @@
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
diff --git a/tests/exceptions/output/ownership/syntaxerror.txt b/tests/exceptions/output/ownership/syntaxerror.txt
index 1dc88ef..00763f6 100644
--- a/tests/exceptions/output/ownership/syntaxerror.txt
+++ b/tests/exceptions/output/ownership/syntaxerror.txt
@@ -13,7 +13,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
@@ -27,7 +27,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
@@ -40,7 +40,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
Traceback (most recent call last):
@@ -50,7 +50,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
Traceback (most recent call last):
@@ -60,5 +60,5 @@ Traceback (most recent call last):
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
diff --git a/tests/test_exceptions_formatting.py b/tests/test_exceptions_formatting.py
index 79c41f6..cad2dba 100644
--- a/tests/test_exceptions_formatting.py
+++ b/tests/test_exceptions_formatting.py
@@ -9,12 +9,41 @@
def normalize(exception):
"""Normalize exception output for reproducible test cases"""
- if os.name:
+ if os.name == "nt":
exception = re.sub(
r'File[^"]+"[^"]+\.py[^"]*"', lambda m: m.group().replace("\\", "/"), exception
)
exception = re.sub(r"(\r\n|\r|\n)", "\n", exception)
+ if sys.version_info >= (3, 9, 0):
+
+ def fix_filepath(match):
+ filepath = match.group(1)
+ pattern = (
+ r'((?:\x1b\[[0-9]*m)+)([^"]+?)((?:\x1b\[[0-9]*m)+)([^"]+?)((?:\x1b\[[0-9]*m)+)'
+ )
+ match = re.match(pattern, filepath)
+ start_directory = os.path.dirname(os.path.dirname(__file__))
+ if match:
+ groups = list(match.groups())
+ groups[1] = os.path.relpath(os.path.abspath(groups[1]), start_directory) + "/"
+ relpath = "".join(groups)
+ else:
+ relpath = os.path.relpath(os.path.abspath(filepath), start_directory)
+ return 'File "%s"' % relpath
+
+ exception = re.sub(
+ r'File "([^"]+\.py[^"]*)"',
+ fix_filepath,
+ exception,
+ )
+
+ if sys.version_info < (3, 9, 0):
+ if "SyntaxError" in exception:
+ exception = re.sub(r"(\n *)(\^ *\n)", r"\1 \2", exception)
+ elif "IndentationError" in exception:
+ exception = re.sub(r"\n *\^ *\n", "\n", exception)
+
exception = re.sub(
r'"[^"]*/somelib/__init__.py"', '"/usr/lib/python/somelib/__init__.py"', exception
)

140
loguru-fix-repr-tests.patch Normal file
View File

@@ -0,0 +1,140 @@
From 4fe21f66991abeb1905e24c3bc3c634543d959a2 Mon Sep 17 00:00:00 2001
From: Delgan <delgan.py@gmail.com>
Date: Sun, 17 Jul 2022 09:18:56 +0200
Subject: [PATCH] Fix "repr()" tests failing on Python 3.11
---
tests/test_repr.py | 87 +++++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 51 deletions(-)
diff --git a/tests/test_repr.py b/tests/test_repr.py
index ba48839..76f413d 100644
--- a/tests/test_repr.py
+++ b/tests/test_repr.py
@@ -1,34 +1,11 @@
-import builtins
import logging
import pathlib
import re
import sys
-from inspect import iscoroutinefunction
-import loguru
from loguru import logger
-class Wrapper:
- def __init__(self, wrapped, *, repr, name):
- self._wrapped = wrapped
- self._repr = repr
- self._name = name
- self.raised = False
-
- def __repr__(self):
- return self._repr
-
- def __getattr__(self, name):
- if name == "__name__":
- if self._name is None:
- self.raised = True
- raise AttributeError
- else:
- return self._name
- return getattr(self._wrapped, name)
-
-
def test_no_handler():
assert repr(logger) == "<loguru.logger handlers=[]>"
@@ -112,22 +89,30 @@ def my_function(message):
assert repr(logger) == "<loguru.logger handlers=[(id=0, level=10, sink=my_function)]>"
-def test_function_without_name(monkeypatch):
- function = Wrapper(lambda _: None, repr="<FunctionWithout>", name=None)
- monkeypatch.setattr(builtins, "callable", lambda x: x is function or callable(x))
+def test_callable_without_name():
+ class Function:
+ def __call__(self):
+ pass
+
+ def __repr__(self):
+ return "<FunctionWithout>"
- logger.add(function)
+ logger.add(Function())
assert repr(logger) == "<loguru.logger handlers=[(id=0, level=10, sink=<FunctionWithout>)]>"
- assert function.raised
-def test_function_with_empty_name(monkeypatch):
- function = Wrapper(lambda _: None, repr="<FunctionEmpty>", name="")
- monkeypatch.setattr(builtins, "callable", lambda x: x is function or callable(x))
+def test_callable_with_empty_name():
+ class Function:
+ __name__ = ""
+
+ def __call__(self):
+ pass
+
+ def __repr__(self):
+ return "<FunctionEmpty>"
- logger.add(function)
+ logger.add(Function())
assert repr(logger) == "<loguru.logger handlers=[(id=0, level=10, sink=<FunctionEmpty>)]>"
- assert not function.raised
def test_coroutine_function():
@@ -138,32 +123,32 @@ async def my_async_function(message):
assert repr(logger) == "<loguru.logger handlers=[(id=0, level=10, sink=my_async_function)]>"
-def test_coroutine_function_without_name(monkeypatch):
- async_function = Wrapper(lambda _: None, repr="<AsyncFunctionWithout>", name=None)
- monkeypatch.setattr(
- loguru._logger,
- "iscoroutinefunction",
- lambda x: x is async_function or iscoroutinefunction(x),
- )
+def test_coroutine_callable_without_name():
+ class CoroutineFunction:
+ async def __call__(self):
+ pass
+
+ def __repr__(self):
+ return "<AsyncFunctionWithout>"
- logger.add(async_function)
+ logger.add(CoroutineFunction())
assert (
repr(logger) == "<loguru.logger handlers=[(id=0, level=10, sink=<AsyncFunctionWithout>)]>"
)
- assert async_function.raised
-def test_coroutine_function_with_empty_name(monkeypatch):
- async_function = Wrapper(lambda _: None, repr="<AsyncFunctionEmpty>", name="")
- monkeypatch.setattr(
- loguru._logger,
- "iscoroutinefunction",
- lambda x: x is async_function or iscoroutinefunction(x),
- )
+def test_coroutine_function_with_empty_name():
+ class CoroutineFunction:
+ __name__ = ""
+
+ def __call__(self):
+ pass
+
+ def __repr__(self):
+ return "<AsyncFunctionEmpty>"
- logger.add(async_function)
+ logger.add(CoroutineFunction())
assert repr(logger) == "<loguru.logger handlers=[(id=0, level=10, sink=<AsyncFunctionEmpty>)]>"
- assert not async_function.raised
def test_standard_handler():

View File

@@ -1,87 +0,0 @@
From 31cf758ee9d22dbfa125f38153782fe20ac9dce5 Mon Sep 17 00:00:00 2001
From: Delgan <delgan.py@gmail.com>
Date: Sat, 19 Dec 2020 16:29:07 +0100
Subject: [PATCH] Fix failing tests due to new "excepthook" in threads
---
tests/test_add_option_enqueue.py | 44 +++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/tests/test_add_option_enqueue.py b/tests/test_add_option_enqueue.py
index 50e1843..4b7c891 100644
--- a/tests/test_add_option_enqueue.py
+++ b/tests/test_add_option_enqueue.py
@@ -4,6 +4,9 @@
import re
import sys
import pickle
+import contextlib
+import threading
+import traceback
class NotPicklable:
@@ -29,6 +32,27 @@ def write(self, message):
print(message, end="")
+@contextlib.contextmanager
+def default_threading_excepthook():
+ if not hasattr(threading, "excepthook"):
+ yield
+ return
+
+ # Pytest added "PytestUnhandledThreadExceptionWarning", we need to
+ # remove it temporarily for somes tests checking exceptions in threads.
+
+ def excepthook(args):
+ print("Exception in thread:", file=sys.stderr, flush=True)
+ traceback.print_exception(
+ args.exc_type, args.exc_value, args.exc_traceback, file=sys.stderr
+ )
+
+ old_excepthook = threading.excepthook
+ threading.excepthook = excepthook
+ yield
+ threading.excepthook = old_excepthook
+
+
def test_enqueue():
x = []
@@ -139,10 +163,11 @@ def test_not_caught_exception_queue_put(writer, capsys):
def test_not_caught_exception_queue_get(writer, capsys):
logger.add(writer, enqueue=True, catch=False, format="{message}")
- logger.info("It's fine")
- logger.bind(broken=NotUnpicklable()).info("Bye bye...")
- logger.info("It's not fine")
- logger.remove()
+ with default_threading_excepthook():
+ logger.info("It's fine")
+ logger.bind(broken=NotUnpicklable()).info("Bye bye...")
+ logger.info("It's not fine")
+ logger.remove()
out, err = capsys.readouterr()
lines = err.strip().splitlines()
@@ -152,13 +177,14 @@ def test_not_caught_exception_queue_get(writer, capsys):
assert lines[-1].endswith("UnpicklingError: You shall not de-serialize me!")
-def test_not_caught_exception_sink_write(capsys):
+def test_not_caught_exception_sink_write(monkeypatch, capsys):
logger.add(NotWritable(), enqueue=True, catch=False, format="{message}")
- logger.info("It's fine")
- logger.bind(fail=True).info("Bye bye...")
- logger.info("It's not fine")
- logger.remove()
+ with default_threading_excepthook():
+ logger.info("It's fine")
+ logger.bind(fail=True).info("Bye bye...")
+ logger.info("It's not fine")
+ logger.remove()
out, err = capsys.readouterr()
lines = err.strip().splitlines()

View File

@@ -1,3 +1,28 @@
-------------------------------------------------------------------
Fri Aug 5 11:11:57 UTC 2022 - Ben Greiner <code@bnavigator.de>
- Update to 0.6.0
* Remove internal use of pickle.loads() considered as a security
vulnerability referenced as CVE-2022-0329 (#563).
* Modify coroutine sink to make it discard log messages when
loop=None and no event loop is running (due to internally using
asyncio.get_running_loop() in place of
asyncio.get_event_loop()).
* Remove the possibility to add a coroutine sink with
enqueue=True if loop=None and no event loop is running.
* Change default encoding of file sink to be utf8 instead of
locale.getpreferredencoding() (#339).
* Prevent non-ascii characters to be escaped while logging JSON
message with serialize=True (#575, thanks @ponponon).
* Fix flake8 errors and improve code readability (#353, thanks
@AndrewYakimets).
- Drop merged patches:
* loguru-exception-formatting-py39.patch
* pytest-6.2-excepthooks.patch
- Add loguru-fix-repr-tests.patch
* Fix "repr()" tests failing on Python 3.11 and Python 3.10.6
* https://github.com/Delgan/loguru/commit/4fe21f66
-------------------------------------------------------------------
Thu Dec 9 18:04:19 UTC 2021 - Ben Greiner <code@bnavigator.de>

View File

@@ -1,7 +1,7 @@
#
# spec file for package python-loguru
#
# Copyright (c) 2021 SUSE LLC
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -19,17 +19,15 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
Name: python-loguru
Version: 0.5.3
Version: 0.6.0
Release: 0
Summary: Python logging component with a simple interface
License: MIT
Group: Development/Languages/Python
URL: https://github.com/Delgan/loguru
Source: https://files.pythonhosted.org/packages/source/l/loguru/loguru-%{version}.tar.gz
# PATCH-FIX-UPSTREAM pytest-6.2-excepthooks.patch
Patch0: https://github.com/Delgan/loguru/commit/31cf758ee9d22dbfa125f38153782fe20ac9dce5.patch#/pytest-6.2-excepthooks.patch
# PATCH-FIX-UPSTREAM loguru-exception-formatting-py39.patch
Patch1: https://github.com/Delgan/loguru/commit/19f518c5f1f355703ffc4ee62f0e1e397605863e.patch#/loguru-exception-formatting-py39.patch
# PATCH-FIX-UPSTREAM loguru-fix-repr-tests.patch https://github.com/Delgan/loguru/commit/4fe21f6 -- Fix "repr()" tests failing on Python 3.11 and Python 3.10.6
Patch1: loguru-fix-repr-tests.patch
BuildRequires: %{python_module aiocontextvars if %python-base < 3.7}
BuildRequires: %{python_module colorama}
BuildRequires: %{python_module pytest}
@@ -64,9 +62,7 @@ if [ $(getconf LONG_BIT) = 32 ]; then
# Threads have different references on 32-bit
donttest=" or (test_log_formatters and thread and not thread.name)"
fi
# different line numbers -- https://github.com/Delgan/loguru/issues/550
python310_donttest=" or (test_exceptions_formatting and formatting_with_context_manager)"
%pytest -k "not (donttestexprprefixdummy $donttest ${$python_donttest})"
%pytest -k "not (donttestexprprefixdummy $donttest)"
%files %{python_files}
%license LICENSE