Accepting request 1251791 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/1251791 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-executing?expand=0&rev=14
This commit is contained in:
BIN
executing-2.1.0.tar.gz
(Stored with Git LFS)
BIN
executing-2.1.0.tar.gz
(Stored with Git LFS)
Binary file not shown.
BIN
executing-2.2.0.tar.gz
(Stored with Git LFS)
Normal file
BIN
executing-2.2.0.tar.gz
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,147 +0,0 @@
|
||||
From 4acebfaa89196785ccc893d56b97ac8598c30e71 Mon Sep 17 00:00:00 2001
|
||||
From: Frank Hoffmann <15r10nk-git@polarbit.de>
|
||||
Date: Mon, 26 Aug 2024 21:43:13 +0200
|
||||
Subject: [PATCH 1/2] fix: backward compatibility fix for changed source
|
||||
positions in 3.12.6 (#85)
|
||||
|
||||
---
|
||||
executing/_position_node_finder.py | 65 ++++++++++
|
||||
tests/generate_small_sample.py | 9 -
|
||||
tests/small_samples/3e40f2921fbaf6ccbabb2fa5c3cd3a42b54914d66f7a67f8b2ade36f89ed761b.py | 3
|
||||
tests/test_main.py | 5
|
||||
4 files changed, 79 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/executing/_position_node_finder.py
|
||||
+++ b/executing/_position_node_finder.py
|
||||
@@ -242,6 +242,66 @@ class PositionNodeFinder(object):
|
||||
# keeping the old behaviour makes it possible to distinguish both cases.
|
||||
|
||||
return node.parent
|
||||
+
|
||||
+ if (
|
||||
+ sys.version_info >= (3, 12, 6)
|
||||
+ and instruction.opname in ("GET_ITER", "FOR_ITER")
|
||||
+ and isinstance(
|
||||
+ node.parent.parent,
|
||||
+ (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp),
|
||||
+ )
|
||||
+ and isinstance(node.parent,ast.comprehension)
|
||||
+ and node is node.parent.iter
|
||||
+ ):
|
||||
+ # same as above but only for comprehensions, see:
|
||||
+ # https://github.com/python/cpython/issues/123142
|
||||
+
|
||||
+ return node.parent.parent
|
||||
+
|
||||
+ if sys.version_info >= (3, 12,6) and instruction.opname == "CALL":
|
||||
+ before = self.instruction_before(instruction)
|
||||
+ if (
|
||||
+ before is not None
|
||||
+ and before.opname == "LOAD_CONST"
|
||||
+ and before.positions == instruction.positions
|
||||
+ and isinstance(node.parent, ast.withitem)
|
||||
+ and node is node.parent.context_expr
|
||||
+ ):
|
||||
+ # node positions for with-statements have change
|
||||
+ # and is now equal to the expression which created the context-manager
|
||||
+ # https://github.com/python/cpython/pull/120763
|
||||
+
|
||||
+ # with context_manager:
|
||||
+ # ...
|
||||
+
|
||||
+ # but there is one problem to distinguish call-expressions from __exit__()
|
||||
+
|
||||
+ # with context_manager():
|
||||
+ # ...
|
||||
+
|
||||
+ # the call for __exit__
|
||||
+
|
||||
+ # 20 1:5 1:22 LOAD_CONST(None)
|
||||
+ # 22 1:5 1:22 LOAD_CONST(None)
|
||||
+ # 24 1:5 1:22 LOAD_CONST(None)
|
||||
+ # 26 1:5 1:22 CALL() # <-- same source range as context_manager()
|
||||
+
|
||||
+ # but we can use the fact that the previous load for None
|
||||
+ # has the same source range as the call, wich can not happen for normal calls
|
||||
+
|
||||
+ # we return the same ast.With statement at the and to preserve backward compatibility
|
||||
+
|
||||
+ return node.parent.parent
|
||||
+
|
||||
+ if (
|
||||
+ sys.version_info >= (3, 12,6)
|
||||
+ and instruction.opname == "BEFORE_WITH"
|
||||
+ and isinstance(node.parent, ast.withitem)
|
||||
+ and node is node.parent.context_expr
|
||||
+ ):
|
||||
+ # handle positions changes for __enter__
|
||||
+ return node.parent.parent
|
||||
+
|
||||
return node
|
||||
|
||||
def known_issues(self, node: EnhancedAST, instruction: dis.Instruction) -> None:
|
||||
@@ -880,6 +940,11 @@ class PositionNodeFinder(object):
|
||||
def instruction(self, index: int) -> Optional[dis.Instruction]:
|
||||
return self.bc_dict.get(index,None)
|
||||
|
||||
+ def instruction_before(
|
||||
+ self, instruction: dis.Instruction
|
||||
+ ) -> Optional[dis.Instruction]:
|
||||
+ return self.bc_dict.get(instruction.offset - 2, None)
|
||||
+
|
||||
def opname(self, index: int) -> str:
|
||||
i=self.instruction(index)
|
||||
if i is None:
|
||||
--- a/tests/generate_small_sample.py
|
||||
+++ b/tests/generate_small_sample.py
|
||||
@@ -18,6 +18,7 @@ from rich.progress import Progress, trac
|
||||
from rich.syntax import Syntax
|
||||
from rich.console import Console
|
||||
import argparse
|
||||
+import ast
|
||||
|
||||
last_samples_dir = Path(__file__).parent / "last_samples"
|
||||
last_samples_dir.mkdir(exist_ok=True)
|
||||
@@ -64,6 +65,11 @@ def test_file(filename: Path):
|
||||
|
||||
test = TestFiles()
|
||||
try:
|
||||
+ ast.parse(code)
|
||||
+ except (RecursionError,SyntaxError):
|
||||
+ return True
|
||||
+
|
||||
+ try:
|
||||
with open(os.devnull, "w") as dev_null:
|
||||
with contextlib.redirect_stderr(dev_null):
|
||||
with contextlib.redirect_stdout(dev_null):
|
||||
@@ -122,9 +128,6 @@ def main():
|
||||
break_file.unlink()
|
||||
sys.exit(0)
|
||||
|
||||
- if time.time() > end_time:
|
||||
- print("Timeout")
|
||||
- sys.exit(0)
|
||||
|
||||
if not result:
|
||||
print(f"{filename} is failing the tests -> minimize\n")
|
||||
--- /dev/null
|
||||
+++ b/tests/small_samples/3e40f2921fbaf6ccbabb2fa5c3cd3a42b54914d66f7a67f8b2ade36f89ed761b.py
|
||||
@@ -0,0 +1,3 @@
|
||||
+async def wait():
|
||||
+ async with something:
|
||||
+ pass
|
||||
\ No newline at end of file
|
||||
--- a/tests/test_main.py
|
||||
+++ b/tests/test_main.py
|
||||
@@ -609,6 +609,11 @@ class TestStuff(unittest.TestCase):
|
||||
assert {i: i for i in iter_test(ast.DictComp)} == {1: 1, 2: 2}
|
||||
assert list(i for i in iter_test(ast.GeneratorExp)) == [1, 2]
|
||||
|
||||
+ assert [i for j in [0] for i in iter_test(ast.ListComp)] == [1, 2]
|
||||
+ assert {i for j in [0] for i in iter_test(ast.SetComp)} == {1, 2}
|
||||
+ assert {i: i for j in [0] for i in iter_test(ast.DictComp)} == {1: 1, 2: 2}
|
||||
+ assert list(i for j in [0] for i in iter_test(ast.GeneratorExp)) == [1, 2]
|
||||
+
|
||||
for i in iter_test(ast.For):
|
||||
assert i in (1, 2)
|
||||
|
125
pytest.patch
125
pytest.patch
@@ -1,125 +0,0 @@
|
||||
From 0edb6ca3d733d8cb3fd1ddc7994bde61991ac4c2 Mon Sep 17 00:00:00 2001
|
||||
From: Frank Hoffmann <44680962+15r10nk@users.noreply.github.com>
|
||||
Date: Sun, 12 Jan 2025 17:03:09 +0100
|
||||
Subject: [PATCH] fix: check for pytest compatibility (#94)
|
||||
|
||||
---
|
||||
executing/__init__.py | 5 ++++-
|
||||
executing/_pytest_utils.py | 16 ++++++++++++++++
|
||||
tests/conftest.py | 25 +++++++++++++++++++++++++
|
||||
tests/test_main.py | 5 -----
|
||||
tests/test_pytest.py | 5 +++++
|
||||
5 files changed, 50 insertions(+), 6 deletions(-)
|
||||
create mode 100644 executing/_pytest_utils.py
|
||||
create mode 100644 tests/conftest.py
|
||||
|
||||
diff --git a/executing/__init__.py b/executing/__init__.py
|
||||
index b645197..e5181a5 100644
|
||||
--- a/executing/__init__.py
|
||||
+++ b/executing/__init__.py
|
||||
@@ -10,6 +10,9 @@
|
||||
from collections import namedtuple
|
||||
_VersionInfo = namedtuple('_VersionInfo', ('major', 'minor', 'micro'))
|
||||
from .executing import Source, Executing, only, NotOneValueFound, cache, future_flags
|
||||
+
|
||||
+from ._pytest_utils import is_pytest_compatible
|
||||
+
|
||||
try:
|
||||
from .version import __version__ # type: ignore[import]
|
||||
if "dev" in __version__:
|
||||
@@ -22,4 +25,4 @@
|
||||
__version_info__ = _VersionInfo(*map(int, __version__.split('.')))
|
||||
|
||||
|
||||
-__all__ = ["Source"]
|
||||
+__all__ = ["Source","is_pytest_compatible"]
|
||||
diff --git a/executing/_pytest_utils.py b/executing/_pytest_utils.py
|
||||
new file mode 100644
|
||||
index 0000000..fab8693
|
||||
--- /dev/null
|
||||
+++ b/executing/_pytest_utils.py
|
||||
@@ -0,0 +1,16 @@
|
||||
+import sys
|
||||
+
|
||||
+
|
||||
+
|
||||
+def is_pytest_compatible() -> bool:
|
||||
+ """ returns true if executing can be used for expressions inside assert statements which are rewritten by pytest
|
||||
+ """
|
||||
+ if sys.version_info < (3, 11):
|
||||
+ return False
|
||||
+
|
||||
+ try:
|
||||
+ import pytest
|
||||
+ except ImportError:
|
||||
+ return False
|
||||
+
|
||||
+ return pytest.version_tuple >= (8, 3, 4)
|
||||
diff --git a/tests/conftest.py b/tests/conftest.py
|
||||
new file mode 100644
|
||||
index 0000000..5108348
|
||||
--- /dev/null
|
||||
+++ b/tests/conftest.py
|
||||
@@ -0,0 +1,25 @@
|
||||
+
|
||||
+
|
||||
+from typing import Optional, Sequence, Union
|
||||
+from executing._pytest_utils import is_pytest_compatible
|
||||
+import _pytest.assertion.rewrite as rewrite
|
||||
+import importlib.machinery
|
||||
+import types
|
||||
+
|
||||
+if not is_pytest_compatible():
|
||||
+ original_find_spec = rewrite.AssertionRewritingHook.find_spec
|
||||
+
|
||||
+
|
||||
+ def find_spec(
|
||||
+ self,
|
||||
+ name: str,
|
||||
+ path: Optional[Sequence[Union[str, bytes]]] = None,
|
||||
+ target: Optional[types.ModuleType] = None,
|
||||
+ ) -> Optional[importlib.machinery.ModuleSpec]:
|
||||
+
|
||||
+ if name == "tests.test_main":
|
||||
+ return None
|
||||
+ return original_find_spec(self, name, path, target)
|
||||
+
|
||||
+
|
||||
+ rewrite.AssertionRewritingHook.find_spec = find_spec
|
||||
diff --git a/tests/test_main.py b/tests/test_main.py
|
||||
index a3f92ee..e3bc9d6 100644
|
||||
--- a/tests/test_main.py
|
||||
+++ b/tests/test_main.py
|
||||
@@ -1,9 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
-"""
|
||||
-
|
||||
-assert rewriting will break executing
|
||||
-PYTEST_DONT_REWRITE
|
||||
-"""
|
||||
from __future__ import print_function, division
|
||||
import ast
|
||||
import contextlib
|
||||
diff --git a/tests/test_pytest.py b/tests/test_pytest.py
|
||||
index 281598d..5cbe0a2 100644
|
||||
--- a/tests/test_pytest.py
|
||||
+++ b/tests/test_pytest.py
|
||||
@@ -6,6 +6,7 @@
|
||||
from time import sleep
|
||||
|
||||
import asttokens
|
||||
+from executing._pytest_utils import is_pytest_compatible
|
||||
import pytest
|
||||
from littleutils import SimpleNamespace
|
||||
|
||||
@@ -124,6 +125,10 @@ def check_manual_linecache(filename):
|
||||
def test_exception_catching():
|
||||
frame = inspect.currentframe()
|
||||
|
||||
+ if is_pytest_compatible():
|
||||
+ assert isinstance(Source.executing(frame).node,ast.Call)
|
||||
+ return
|
||||
+
|
||||
executing.executing.TESTING = True # this is already the case in all other tests
|
||||
# Sanity check that this operation usually raises an exception.
|
||||
# This actually depends on executing not working in the presence of pytest.
|
@@ -1,3 +1,14 @@
|
||||
-------------------------------------------------------------------
|
||||
Mon Mar 10 09:25:36 UTC 2025 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>
|
||||
|
||||
- Update to 2.2.0
|
||||
* fix: backward compatibility fix for changed source positions in 3.12.6 (#85)
|
||||
* fix: handle changed positions for __exit__ of ast.With
|
||||
* update and fix table of contents link, 'libraries' → 'projects' (#93)
|
||||
* fix: check for pytest compatibility (#94)
|
||||
- Drop new-python-312.patch, merged upstream
|
||||
- Drop pytest.patch, merged upstream
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Jan 17 16:19:38 UTC 2025 - Markéta Machová <mmachova@suse.com>
|
||||
|
||||
|
@@ -26,16 +26,12 @@
|
||||
%endif
|
||||
%{?sle15_python_module_pythons}
|
||||
Name: python-executing%{psuffix}
|
||||
Version: 2.1.0
|
||||
Version: 2.2.0
|
||||
Release: 0
|
||||
Summary: Get the currently executing AST node of a frame, and other information
|
||||
License: MIT
|
||||
URL: https://github.com/alexmojaki/executing
|
||||
Source: https://files.pythonhosted.org/packages/source/e/executing/executing-%{version}.tar.gz
|
||||
# PATCH-FIX-UPSTREAM https://github.com/alexmojaki/executing/pull/86 fix: backward compatibility fix for changed source positions in 3.12.6
|
||||
Patch0: new-python-312.patch
|
||||
# PATCH-FIX-UPSTREAM https://github.com/alexmojaki/executing/pull/94 fix: check for pytest compatibility
|
||||
Patch1: pytest.patch
|
||||
BuildRequires: %{python_module devel}
|
||||
BuildRequires: %{python_module pip}
|
||||
BuildRequires: %{python_module setuptools_scm >= 4.0.0}
|
||||
|
Reference in New Issue
Block a user