diff --git a/loguru-exception-formatting-py39.patch b/loguru-exception-formatting-py39.patch new file mode 100644 index 0000000..80010c9 --- /dev/null +++ b/loguru-exception-formatting-py39.patch @@ -0,0 +1,161 @@ +From 19f518c5f1f355703ffc4ee62f0e1e397605863e Mon Sep 17 00:00:00 2001 +From: Delgan +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 "", 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 "", 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 "", line 1 + foo = +- ^ ++ ^ + SyntaxError: invalid syntax + + File "", line 1 + foo = +- ^ ++ ^ + SyntaxError: invalid syntax + + File "", line 1 + foo = +- ^ ++ ^ + SyntaxError: invalid syntax + + File "", 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 "", line 1 + foo = +- ^ ++ ^ + + SyntaxError: invalid syntax + +@@ -27,7 +27,7 @@ + exec("foo =") + File "", line 1 + foo = +- ^ ++ ^ + + SyntaxError: invalid syntax + +@@ -40,7 +40,7 @@ + exec("foo =") + File "", line 1 + foo = +- ^ ++ ^ + SyntaxError: invalid syntax + + Traceback (most recent call last): +@@ -50,7 +50,7 @@ + exec("foo =") + File "", line 1 + foo = +- ^ ++ ^ + SyntaxError: invalid syntax + + Traceback (most recent call last): +@@ -60,5 +60,5 @@ Traceback (most recent call last): + exec("foo =") + File "", 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 + ) diff --git a/python-loguru.changes b/python-loguru.changes index a0e28e9..ea20bca 100644 --- a/python-loguru.changes +++ b/python-loguru.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Sun Apr 18 12:17:42 UTC 2021 - Ben Greiner + +- Add loguru-exception-formatting-py39.patch + https://github.com/Delgan/loguru/commit/19f518c5 for changed + exception formatting in Python 3.9 + ------------------------------------------------------------------- Fri Feb 19 01:51:00 UTC 2021 - John Vandenberg diff --git a/python-loguru.spec b/python-loguru.spec index 9d8dc1b..d39cf7e 100644 --- a/python-loguru.spec +++ b/python-loguru.spec @@ -26,13 +26,16 @@ 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 +BuildRequires: %{python_module aiocontextvars if %python-base < 3.7} BuildRequires: %{python_module colorama} BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros -BuildRequires: ((python3-aiocontextvars and python3-base < 3.7) or (python36-aiocontextvars and python36-base)) %if 0%{?python_version_nodots} < 37 Requires: python-aiocontextvars %endif @@ -46,8 +49,7 @@ Python logging component providing a single object which dispatches log messages to configured handlers. %prep -%setup -q -n loguru-%{version} -%patch0 -p1 +%autosetup -p1 -n loguru-%{version} %build %python_build