1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
from __future__ import annotations
import datetime
import os
from pathlib import Path
import re
import sys
import warnings
import pyvista
sys.path.append(str(Path(__file__).parent))
# Suppress invalid user data path when there is an issue with restoring the cache for CI
# https://github.com/pyvista/pyvista/pull/7747
warnings.filterwarnings(
'ignore',
message=r'Ignoring invalid PYVISTA_USERDATA_PATH.*',
category=UserWarning,
)
# -- General configuration ------------------------------------------------
templates_path = ['_templates']
source_suffix = '.rst'
root_doc = 'index'
project = 'tinypages'
year = datetime.datetime.now(tz=datetime.timezone.utc).date().year
copyright = f'2021-{year}, PyVista developers' # noqa: A001
version = '0.1'
release = '0.1'
exclude_patterns = ['_build']
pygments_style = 'sphinx'
extensions = [
'numpydoc',
'matplotlib.sphinxext.plot_directive',
'pyvista.ext.plot_directive',
# 'pyvista.ext.viewer_directive',
'sphinx.ext.autosummary',
'sphinx_design',
]
# -- Plot directive specific configuration --------------------------------
plot_setup = plot_cleanup = 'import pyvista'
# -- Options for HTML output ----------------------------------------------
html_theme = 'sphinx_book_theme'
html_static_path = ['_static']
# -- pyvista configuration ------------------------------------------------
pyvista.BUILDING_GALLERY = True
# -- .. pyvista-plot:: directive ----------------------------------------------
from numpydoc.docscrape_sphinx import SphinxDocString
IMPORT_PYVISTA_RE = r'\b(import +pyvista|from +pyvista +import)\b'
IMPORT_MATPLOTLIB_RE = r'\b(import +matplotlib|from +matplotlib +import)\b'
plot_setup = """
from pyvista import set_plot_theme as __s_p_t
__s_p_t('document')
del __s_p_t
"""
plot_cleanup = plot_setup
if value := os.environ.get('PLOT_SKIP'):
plot_skip = value.lower() == 'true'
if value := os.environ.get('PLOT_SKIP_OPTIONAL'):
plot_skip_optional = value.lower() == 'true'
def _str_examples(self):
examples_str = '\n'.join(self['Examples'])
if (
self.use_plots
and re.search(IMPORT_MATPLOTLIB_RE, examples_str)
and 'plot::' not in examples_str
):
out = []
out += self._str_header('Examples')
out += ['.. plot::', '']
out += self._str_indent(self['Examples'])
out += ['']
return out
elif re.search(IMPORT_PYVISTA_RE, examples_str) and 'plot-pyvista::' not in examples_str:
out = []
out += self._str_header('Examples')
out += ['.. pyvista-plot::', '']
out += self._str_indent(self['Examples'])
out += ['']
return out
else:
return self._str_section('Examples')
SphinxDocString._str_examples = _str_examples
|