Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Generalize validation that pyplot commands are documented #24000

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

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations/24000-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``matplotlib.pyplot.get_plot_commands``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... is a pending deprecation. This is considered internal and no end-user
should need it.
17 changes: 10 additions & 7 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,20 +2028,23 @@ def thetagrids(angles=None, labels=None, fmt=None, **kwargs):
return lines, labels


_NON_PLOT_COMMANDS = {
'connect', 'disconnect', 'get_current_fig_manager', 'ginput',
'new_figure_manager', 'waitforbuttonpress'}


@_api.deprecated("3.7", pending=True)
def get_plot_commands():
"""
Get a sorted list of all of the plotting commands.
"""
NON_PLOT_COMMANDS = {
'connect', 'disconnect', 'get_current_fig_manager', 'ginput',
'new_figure_manager', 'waitforbuttonpress'}
return (name for name in _get_pyplot_commands()
if name not in NON_PLOT_COMMANDS)


def _get_pyplot_commands():
# This works by searching for all functions in this module and removing
# a few hard-coded exclusions, as well as all of the colormap-setting
# functions, and anything marked as private with a preceding underscore.
exclude = {'colormaps', 'colors', 'get_plot_commands',
*_NON_PLOT_COMMANDS, *colormaps}
exclude = {'colormaps', 'colors', 'get_plot_commands', *colormaps}
this_module = inspect.getmodule(get_plot_commands)
return sorted(
name for name, obj in globals().items()
Expand Down
41 changes: 36 additions & 5 deletions lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import difflib
import re

import numpy as np
import subprocess
Expand Down Expand Up @@ -367,10 +366,42 @@ def test_doc_pyplot_summary():
if not pyplot_docs.exists():
pytest.skip("Documentation sources not available")

lines = pyplot_docs.read_text()
m = re.search(r':nosignatures:\n\n(.*?)\n\n', lines, re.DOTALL)
doc_functions = set(line.strip() for line in m.group(1).split('\n'))
plot_commands = set(plt.get_plot_commands())
def extract_documented_functions(lines):
"""
Return a list of all the functions that are mentioned in the
autosummary blocks contained in *lines*.

An autosummary block looks like this::

.. autosummary::
:toctree: _as_gen
:template: autosummary.rst
:nosignatures:

plot
plot_date

"""
functions = []
in_autosummary = False
for line in lines:
if not in_autosummary:
if line.startswith(".. autosummary::"):
in_autosummary = True
else:
if not line or line.startswith(" :"):
# empty line or autosummary parameter
continue
if not line[0].isspace():
# no more indentation: end of autosummary block
in_autosummary = False
continue
functions.append(line.strip())
return functions

lines = pyplot_docs.read_text().split("\n")
doc_functions = set(extract_documented_functions(lines))
plot_commands = set(plt._get_pyplot_commands())
missing = plot_commands.difference(doc_functions)
if missing:
raise AssertionError(
Expand Down