8000 Merge pull request #24000 from timhoffm/pyplot-test · matplotlib/matplotlib@f4f9528 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4f9528

Browse files
authored
Merge pull request #24000 from timhoffm/pyplot-test
Generalize validation that pyplot commands are documented
2 parents 9bcdd60 + 352bb1f commit f4f9528

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``matplotlib.pyplot.get_plot_commands``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... is a pending deprecation. This is considered internal and no end-user
5+
should need it.

lib/matplotlib/pyplot.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,20 +2028,23 @@ def thetagrids(angles=None, labels=None, fmt=None, **kwargs):
20282028
return lines, labels
20292029

20302030

2031-
_NON_PLOT_COMMANDS = {
2032-
'connect', 'disconnect', 'get_current_fig_manager', 'ginput',
2033-
'new_figure_manager', 'waitforbuttonpress'}
2034-
2035-
2031+
@_api.deprecated("3.7", pending=True)
20362032
def get_plot_commands():
20372033
"""
20382034
Get a sorted list of all of the plotting commands.
20392035
"""
2036+
NON_PLOT_COMMANDS = {
2037+
'connect', 'disconnect', 'get_current_fig_manager', 'ginput',
2038+
'new_figure_manager', 'waitforbuttonpress'}
2039+
return (name for name in _get_pyplot_commands()
2040+
if name not in NON_PLOT_COMMANDS)
2041+
2042+
2043+
def _get_pyplot_commands():
20402044
# This works by searching for all functions in this module and removing
20412045
# a few hard-coded exclusions, as well as all of the colormap-setting
20422046
# functions, and anything marked as private with a preceding underscore.
2043-
exclude = {'colormaps', 'colors', 'get_plot_commands',
2044-
*_NON_PLOT_COMMANDS, *colormaps}
2047+
exclude = {'colormaps', 'colors', 'get_plot_commands', *colormaps}
20452048
this_module = inspect.getmodule(get_plot_commands)
20462049
return sorted(
20472050
name for name, obj in globals().items()

lib/matplotlib/tests/test_pyplot.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import difflib
2-
import re
32

43
import numpy as np
54
import subprocess
@@ -367,10 +366,42 @@ def test_doc_pyplot_summary():
367366
if not pyplot_docs.exists():
368367
pytest.skip("Documentation sources not available")
369368

370-
lines = pyplot_docs.read_text()
371-
m = re.search(r':nosignatures:\n\n(.*?)\n\n', lines, re.DOTALL)
372-
doc_functions = set(line.strip() for line in m.group(1).split('\n'))
373-
plot_commands = set(plt.get_plot_commands())
369+
def extract_documented_functions(lines):
370+
"""
371+
Return a list of all the functions that are mentioned in the
372+
autosummary blocks contained in *lines*.
373+
374+
An autosummary block looks like this::
375+
376+
.. autosummary::
377+
:toctree: _as_gen
378+
:template: autosummary.rst
379+
:nosignatures:
380+
381+
plot
382+
plot_date
383+
384+
"""
385+
functions = []
386+
in_autosummary = False
387+
for line in lines:
388+
if not in_autosummary:
389+
if line.startswith(".. autosummary::"):
390+
in_autosummary = True
391+
else:
392+
if not line or line.startswith(" :"):
393+
# empty line or autosummary parameter
394+
continue
395+
if not line[0].isspace():
396+
# no more indentation: end of autosummary block
397+
in_autosummary = False
398+
continue
399+
functions.append(line.strip())
400+
return functions
401+
402+
lines = pyplot_docs.read_text().split("\n")
403+
doc_functions = set(extract_documented_functions(lines))
404+
plot_commands = set(plt._get_pyplot_commands())
374405
missing = plot_commands.difference(doc_functions)
375406
if missing:
376407
raise AssertionError(

0 commit comments

Comments
 (0)
0