commit: 0a20229a63e6e400a3deab1e4f69114d4ff40733 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sat Feb 10 12:14:51 2024 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sat Feb 10 12:33:50 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0a20229a
dev-python/re-assert: Improve the `re` fallback patch Improve the `re` fallback patch to use it on PyPy even if `regex` is available. Fix returning some failure message when match fails. Update the dependency in `setup.cfg` as well. Deselect tests that rely on `regex`-specific output. Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> .../files/re-assert-1.1.0-re-fallback.patch | 34 +++++++++++++++++++--- ...t-1.1.0-r2.ebuild => re-assert-1.1.0-r3.ebuild} | 23 +++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/dev-python/re-assert/files/re-assert-1.1.0-re-fallback.patch b/dev-python/re-assert/files/re-assert-1.1.0-re-fallback.patch index ad04e09ae5bc..b292d48d6e0f 100644 --- a/dev-python/re-assert/files/re-assert-1.1.0-re-fallback.patch +++ b/dev-python/re-assert/files/re-assert-1.1.0-re-fallback.patch @@ -1,16 +1,42 @@ diff --git a/re_assert.py b/re_assert.py -index f6ea6b9..66479c3 100644 +index 840401e..8818da1 100644 --- a/re_assert.py +++ b/re_assert.py -@@ -3,7 +3,10 @@ from __future__ import annotations +@@ -1,8 +1,13 @@ ++import sys ++ from typing import Any + from typing import Optional from typing import Pattern -import regex -+try: ++if sys.implementation.name == "cpython": + import regex -+except ImportError: ++else: + import re as regex class Matches: # TODO: Generic[AnyStr] (binary pattern support) +@@ -12,6 +17,9 @@ class Matches: # TODO: Generic[AnyStr] (binary pattern support) + self._type = type(pattern) + + def _fail_message(self, fail: str) -> str: ++ if sys.implementation.name != "cpython": ++ return "regex failed to match" ++ + # binary search to find the longest substring match + pos, bound = 0, len(fail) + while pos < bound: +diff --git a/setup.cfg b/setup.cfg +index 46303ca..74cf999 100644 +--- a/setup.cfg ++++ b/setup.cfg +@@ -20,7 +20,7 @@ classifiers = + [options] + py_modules = re_assert + install_requires = +- regex ++ regex; python_implementation=="CPython" + python_requires = >=3.6.1 + + [bdist_wheel] diff --git a/dev-python/re-assert/re-assert-1.1.0-r2.ebuild b/dev-python/re-assert/re-assert-1.1.0-r3.ebuild similarity index 54% rename from dev-python/re-assert/re-assert-1.1.0-r2.ebuild rename to dev-python/re-assert/re-assert-1.1.0-r3.ebuild index 3265b1484c5a..9bb6563659de 100644 --- a/dev-python/re-assert/re-assert-1.1.0-r2.ebuild +++ b/dev-python/re-assert/re-assert-1.1.0-r3.ebuild @@ -34,3 +34,26 @@ PATCHES=( # use `re` as fallback since `regex` doesn't support PyPy "${FILESDIR}/${P}-re-fallback.patch" ) + +python_test() { + local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 + local EPYTEST_DESELECT=() + + case ${EPYTHON} in + pypy3) + EPYTEST_DESELECT+=( + # message/repr mismatches due to using `re` module + tests/re_assert_test.py::test_fail_at_beginning + tests/re_assert_test.py::test_fail_at_end_of_line + tests/re_assert_test.py::test_fail_at_end_of_line_mismatching_newline + tests/re_assert_test.py::test_fail_end_of_line_with_newline + tests/re_assert_test.py::test_fail_multiple_lines + tests/re_assert_test.py::test_match_with_tabs + tests/re_assert_test.py::test_matches_repr_with_flags + tests/re_assert_test.py::test_repr_with_failure + ) + ;; + esac + + epytest +}