From f606b8538772f618bef35459706f01f0d1235506 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 11 Jan 2024 16:03:42 +0100 Subject: [PATCH 1/2] More doctest fixes. This is incomplete but I'm going to try to deal with the following: 1) each line in a black example is after #308 it's own line, so try to collapse subsequent code blocks. 2) It seem that we get a number of report_failure, but failure is just when the output does not match, though when we have a block with multiple >>> in sequence and we ignore output on purpose they now are seen as failure. It's not super great and will need a buch of workaround --- papyri/gen.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/papyri/gen.py b/papyri/gen.py index a0424f20..bd4ce93d 100644 --- a/papyri/gen.py +++ b/papyri/gen.py @@ -30,7 +30,17 @@ from itertools import count from pathlib import Path from types import FunctionType, ModuleType -from typing import Any, Dict, FrozenSet, List, MutableMapping, Optional, Sequence, Tuple +from typing import ( + Any, + Dict, + FrozenSet, + List, + MutableMapping, + Optional, + Sequence, + Tuple, + Union, +) import io import jedi @@ -1139,12 +1149,57 @@ def report_failure(self, out, test, example, got): Code(tok_entries, got, ExecutionStatus.failure) ) - def get_example_section_data(self): + def get_example_section_data(self) -> Section: example_section_data = self._example_section_data self._example_section_data = Section([], None) return example_section_data + def _compact(self, example_section_data) -> Section: + """ + Compact consecutive execution items that do have the same execution status. + + TODO: + + This is not perfect as doctest tests that the output is the same, thus when we have a multiline block + If any of the intermediate items produce an output, the result will be failure. + """ + acc: List[Union[MText, Code]] = [] + current_code: Optional[ + Code + ] = None + + + for item in example_section_data: + if not isinstance(item, Code): + if current_code is not None: + acc.append(current_code) + acc.append(MText(str(current_code.out))) + acc.append(MText(str(current_code.ce_status))) + current_code = None + acc.append(item) + else: + if current_code is None: + assert item is not None + current_code = item + continue + + if current_code.ce_status == item.ce_status: + current_code = Code( + current_code.entries + item.entries, item.out, item.ce_status + ) + else: + acc.append(current_code) + acc.append(MText(str(current_code.out))) + acc.append(MText(str(current_code.ce_status))) + assert item is not None + current_code = item + + if current_code: + acc.append(current_code) + return Section(acc, None) + + class Gen: """ Core class to generate a DocBundle for a given library. @@ -1347,6 +1402,8 @@ def debugprint(*args): elif block: example_section_data.append(MText(block)) + example_section_data = doctest_runner._compact(example_section_data) + # TODO fix this if plt.close not called and still a lingering figure. fig_managers = _pylab_helpers.Gcf.get_all_fig_managers() if len(fig_managers) != 0: From 113a4c5e32e7a35bcfb674b7715f86227c03ad7d Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 22 Jan 2024 10:11:27 +0100 Subject: [PATCH 2/2] please linter --- papyri/gen.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/papyri/gen.py b/papyri/gen.py index bd4ce93d..0596cbb0 100644 --- a/papyri/gen.py +++ b/papyri/gen.py @@ -681,7 +681,7 @@ def visit(self, obj, stack): else: oroot = omod - if not oroot == self.root: + if oroot != self.root: return if obj in self.obj.values(): return @@ -1154,21 +1154,17 @@ def get_example_section_data(self) -> Section: self._example_section_data = Section([], None) return example_section_data - def _compact(self, example_section_data) -> Section: """ - Compact consecutive execution items that do have the same execution status. + Compact consecutive execution items that do have the same execution status. TODO: - This is not perfect as doctest tests that the output is the same, thus when we have a multiline block + This is not perfect as doctest tests that the output is the same, thus when we have a multiline block If any of the intermediate items produce an output, the result will be failure. """ acc: List[Union[MText, Code]] = [] - current_code: Optional[ - Code - ] = None - + current_code: Optional[Code] = None for item in example_section_data: if not isinstance(item, Code): @@ -2347,10 +2343,7 @@ def is_private(path): Determine if a import path, or fully qualified is private. that usually implies that (one of) the path part starts with a single underscore. """ - for p in path.split("."): - if p.startswith("_") and not p.startswith("__"): - return True - return False + return any(p.startswith("_") and not p.startswith("__") for p in path.split(".")) def find_cannonical(qa: str, aliases: List[str]):