Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the doctest module in get_example_data #308

Merged
merged 40 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7b6ec43
First pass at using the doctest module in get_example_data
asmeurer Oct 20, 2023
8e11f52
Fix matplotlib showing the plots instead of saving them in doctests
asmeurer Oct 20, 2023
3dd390b
Move the PapyriDocTestRunner class to the module level
asmeurer Nov 10, 2023
0bbbabe
Handle filename and lineno not being accessible
asmeurer Nov 11, 2023
d65f57c
Fix a spelling error
asmeurer Nov 11, 2023
471d729
Fix generation of doctest plot figures
asmeurer Nov 11, 2023
bbcb40e
Remove unused variable
asmeurer Nov 11, 2023
29c66ac
Use ELLIPSIS option flag
asmeurer Nov 11, 2023
a13f7e4
First pass at using the doctest module in get_example_data
asmeurer Oct 20, 2023
9cdb1ae
Fix matplotlib showing the plots instead of saving them in doctests
asmeurer Oct 20, 2023
0fba48d
Move the PapyriDocTestRunner class to the module level
asmeurer Nov 10, 2023
24389a4
Handle filename and lineno not being accessible
asmeurer Nov 11, 2023
d946cc6
Fix a spelling error
asmeurer Nov 11, 2023
877026f
Fix generation of doctest plot figures
asmeurer Nov 11, 2023
cbd7fc0
Remove unused variable
asmeurer Nov 11, 2023
83be405
Use ELLIPSIS option flag
asmeurer Nov 11, 2023
1a0caee
add debug print
Carreau Nov 17, 2023
98304d2
debug log
Carreau Nov 17, 2023
236c309
cleanup
Carreau Nov 20, 2023
841ac12
... to >>>
Carreau Nov 20, 2023
ef6780e
debug and execute config
Carreau Nov 27, 2023
507e37c
don't execute in pandas
Carreau Nov 27, 2023
cfbacb7
Add Section.extend
asmeurer Dec 1, 2023
3e2409d
Split example sections into blocks
asmeurer Dec 1, 2023
8f6c1da
Merge branch 'doctest' of github.com:asmeurer/papyri into doctest
asmeurer Dec 1, 2023
a2da2d8
Fix errors from running doctests on SciPy
asmeurer Dec 1, 2023
6da0c62
Merge branch 'main' into doctest
asmeurer Dec 15, 2023
9bf10fb
Fix the --no-exec flag
asmeurer Dec 15, 2023
a1c8cdb
Excluse `set_numeric_ops` which seem to be the root of crash.
Carreau Dec 16, 2023
db1dbb4
reforamt to please linters
Carreau Dec 16, 2023
7ce945e
Merge branch 'main' into doctest
asmeurer Jan 4, 2024
4d114ff
Fix the doctest runner not maintaining the namespace across different…
asmeurer Jan 4, 2024
4100b5e
Use DocTestParser to parse doctest blocks
asmeurer Jan 4, 2024
dea1888
Don't generate text blocks for empty strings
asmeurer Jan 4, 2024
708dac9
Fix duplicate code entries in example section
asmeurer Jan 4, 2024
96502c7
Fix extending figures.
Carreau Jan 10, 2024
eb498cb
Apply suggestions from code review
Carreau Jan 10, 2024
4621cba
Rename config.exec to execute_doctests.
Carreau Jan 10, 2024
45a2fa3
Rename config.exec to execute_doctests.
Carreau Jan 10, 2024
81071b9
rename exec in a few more places
Carreau Jan 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename config.exec to execute_doctests.
  • Loading branch information
Carreau committed Jan 10, 2024
commit 4621cbaded8177b61b04cc513d05b6d908f4ac04
2 changes: 1 addition & 1 deletion examples/IPython.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ module = 'IPython'
logo = "img/ipython-logo.png"
exec_failure = "fallback"
docs_path = "~/dev/IPython/docs/source"
exec = true
execute_doctests = true
execute_exclude_patterns = [
'IPython.lib.display:Audio',
'IPython.core.display_functions:display'
2 changes: 1 addition & 1 deletion examples/matplotlib.toml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ examples_exclude = [
"lines_bars_and_markers/marker_reference.py",
"lines_bars_and_markers/multivariate_marker_plot.py",
]
exec = true
execute_doctests = true

[global.expected_errors]
IncorrectInternalDocsLen = [
2 changes: 1 addition & 1 deletion examples/networkx.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ submodules = []

# docs_path = '~/dev/numpy/doc/source'

exec = true
execute_doctests = true
exclude_jedi = ['networkx.algorithms.planarity.PlanarEmbedding']
exec_failure = 'fallback'
source = 'https://github.com/networkx/networkx'
2 changes: 1 addition & 1 deletion examples/papyri.toml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ submodules = ['examples']
examples_folder = '~/dev/papyri/docs/examples/'
logo = "../papyri-logo.png"
docs_path = "~/dev/papyri/docs"
exec = true
execute_doctests = true
exec_failure = 'raise'
exclude= ["papyri.utils:FullQual","papyri.utils:Cannonical" ]
[global.directives]
2 changes: 1 addition & 1 deletion examples/scipy.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[global]
module = 'scipy'
logo = "img/scipy_logo.png"
exec = true
execute_doctests = true
submodules = [ "signal","misc"]
exclude = [
# OTHER.
32 changes: 19 additions & 13 deletions papyri/gen.py
Original file line number Diff line number Diff line change
@@ -406,7 +406,6 @@ class Config:
exclude: Sequence[str] = () # list of dotted object name to exclude from collection
examples_folder: Optional[str] = None # < to path ?
submodules: Sequence[str] = ()
exec: bool = False
source: Optional[str] = None
homepage: Optional[str] = None
docs: Optional[str] = None
@@ -514,7 +513,7 @@ def gen_main(
conf["fail_unseen_error"] = fail_unseen_error
config = Config(**conf, dry_run=dry_run, dummy_progress=dummy_progress)
if exec_ is not None:
config.exec = exec_
config.execute_doctests = exec_
if infer is not None:
config.infer = infer

@@ -1145,6 +1144,7 @@ def get_example_section_data(self):
self._example_section_data = Section([], None)
return example_section_data


class Gen:
"""
Core class to generate a DocBundle for a given library.
@@ -1221,7 +1221,7 @@ def filter(self, record):
self._doctree: Dict[str, str] = {}

def get_example_data(
self, example_section, *, obj, qa: str, config, log
self, example_section, *, obj: Any, qa: str, config: Config, log: logging.Logger
) -> Tuple[Section, List[Any]]:
"""Extract example section data from a NumpyDocString

@@ -1243,7 +1243,7 @@ def get_example_data(
have to be imported imported in docstrings. This should become a high
level option at some point. Note that for method classes, the class should
be made available but currently is not.
qa
qa : str
The fully qualified name of current object
config : Config
Current configuration
@@ -1328,14 +1328,20 @@ def debugprint(*args):
blocks = doctest.DocTestParser().parse(example_code, name=qa)
for block in blocks:
if isinstance(block, doctest.Example):
doctests = doctest.DocTest([block],
globs=doctest_runner.globs,
name=qa, filename=filename,
lineno=lineno, docstring=example_code)
if config.exec:
doctests = doctest.DocTest(
[block],
globs=doctest_runner.globs,
name=qa,
filename=filename,
lineno=lineno,
docstring=example_code,
)
if config.execute_doctests:
doctest_runner.run(doctests, out=debugprint, clear_globs=False)
doctest_runner.globs.update(doctests.globs)
example_section_data.extend(doctest_runner.get_example_section_data())
example_section_data.extend(
doctest_runner.get_example_section_data()
)
else:
example_section_data.append(MText(block.source))
elif block:
@@ -1818,7 +1824,7 @@ def collect_examples(self, folder: Path, config):
script = example.read_text()
ce_status = "None"
figs = []
if config.exec:
if config.execute_doctests:
with executor:
try:
executor.exec(script, name=str(example))
@@ -2154,8 +2160,8 @@ def collect_api_docs(self, root: str, limit_to: List[str]) -> None:
continue
if not isinstance(target_item, ModuleType):
arbitrary = []
ex = self.config.exec
if self.config.exec and any(
ex = self.config.execute_doctests
if self.config.execute_doctests and any(
qa.startswith(pat) for pat in self.config.execute_exclude_patterns
):
ex = False
Loading