abipy/docs/conf.py

486 lines
16 KiB
Python

# -*- coding: utf-8 -*-
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this autogenerated file.
#
# All configuration values have a default; values that are commented out serve to show the default.
import sys
import os
import shutil
# Remove matplotlib agg warnings from generated doc when using plt.show
import warnings
#warnings.filterwarnings("ignore", category=UserWarning,
# message='Matplotlib is currently using agg, which is a'
# ' non-GUI backend, so cannot show the figure.')
if not sys.warnoptions:
warnings.simplefilter("ignore")
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
ABIPY_ROOT = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
sys.path.insert(0, ABIPY_ROOT)
import imp
mod_name = os.path.join(ABIPY_ROOT, "abipy", "core", "release.py")
relmod = imp.load_source(mod_name, mod_name)
on_rtd = os.environ.get('READTHEDOCS') == 'True'
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.graphviz',
'sphinx.ext.napoleon', # For Google Python Style Guide
'sphinx.ext.inheritance_diagram',
'sphinxcontrib.programoutput',
"sphinxarg.ext", # CLI doc
'sphinxcontrib.bibtex',
"jupyter_sphinx",
#'nbsphinx',
#"releases",
#'sphinx.ext.coverage',
#'sphinx_gallery.gen_gallery',
]
# Activate build of sphinx-gallery.
with_gallery = True
if with_gallery:
extensions.append('sphinx_gallery.gen_gallery')
# Add any Sphinx extension module names here, as strings. They can
# be extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
import matplotlib
# Use seaborn settings.
#import seaborn as sns
#sns.set(context=options.seaborn, style='darkgrid', palette='deep',
# font='sans-serif', font_scale=1, color_codes=False, rc=None)
extensions += [
'IPython.sphinxext.ipython_directive',
'IPython.sphinxext.ipython_console_highlighting',
'matplotlib.sphinxext.plot_directive',
]
# Add local extensions (not available on PyPi)
#sys.path.insert(0, os.path.join(ABIPY_ROOT, "docs", "my_extensions"))
#extensions += [
# 'youtube',
#]
#########################
# Spinx Gallery Settings
#########################
mpl = matplotlib
mpl.use("Agg")
mpl.rcParams['figure.dpi'] = 300
#def reset_mpl(gallery_conf, fname):
# """reset matplotlib to always use the seaborn style."""
# # https://542-25860190-gh.circle-artifacts.com/0/rtd_html/advanced_configuration.html#resetting-modules
# #from matplotlib import style
# #style.use('ggplot')
# import seaborn as sns
# rc = {'figure.dpi': 300}
# sns.set(context='talk', style='darkgrid', palette='deep', font='sans-serif', font_scale=1, color_codes=True, rc=rc)
#import glob
#from sphinx_gallery.gen_rst import figure_rst
#
#class PNGScraper(object):
# # https://sphinx-gallery.readthedocs.io/en/latest/advanced_configuration.html#image-scrapers
# def __init__(self):
# self.seen = set()
#
# def __call__(self, block, block_vars, gallery_conf):
# pngs = sorted(glob.glob(os.path.join(os.getcwd(), '*.png')))
# image_names = []
# image_path_iterator = block_vars['image_path_iterator']
# for png in pngs:
# if png not in self.seen:
# self.seen |= set(png)
# image_names.append(image_path_iterator.next())
# shutil.copyfile(png, image_names[-1])
# return figure_rst(image_names, gallery_conf['src_dir'])
# Set plotly renderer to capture _repr_html_ for sphinx-gallery
# https://sphinx-gallery.github.io/stable/auto_examples/plot_9_plotly.html
import plotly.io as pio
pio.renderers.default = 'sphinx_gallery'
# Here we change the default value of show used in the plotly decorator.
from abipy.tools.plotting import set_plotly_default_show
set_plotly_default_show(False)
if with_gallery:
print("Will build sphinx-gallery")
from sphinx_gallery.sorting import ExampleTitleSortKey
sphinx_gallery_conf = {
#'only_warn_on_example_error': True,
'abort_on_example_error': True,
'log_level': {'backreference_missing': 'warning'},
#
# path to your examples scripts
'examples_dirs': [
"../abipy/examples/plot",
"../abipy/examples/flows",
],
# path where to save gallery generated examples
'gallery_dirs': [
"gallery",
"flow_gallery",
],
'filename_pattern': "(/plot*|/run_*)",
'default_thumb_file': '_static/abipy_logo.png',
'within_subsection_order': ExampleTitleSortKey,
'backreferences_dir': None,
#'reset_modules': (reset_mpl,),
'reference_url': {
'abipy': None, # The module you locally document uses None
'numpy': 'https://docs.scipy.org/doc/numpy/',
'matplotlib': 'https://matplotlib.org',
'pandas': "http://pandas.pydata.org/pandas-docs/stable/",
"pymatgen": "https://pymatgen.org/",
},
#'image_scrapers': ('matplotlib',),
#'image_scrapers': ('matplotlib', PNGScraper()),
#'image_scrapers': ('matplotlib', plotly),
# capture raw HTML or, if not present, __repr__ of last expression in each code block
'capture_repr': (),
#'capture_repr': ('_repr_html_', '__repr__'),
#
# https://sphinx-gallery.github.io/stable/configuration.html#binder-links
#'binder': {
# # Required keys
# 'org': 'abinit',
# 'repo': 'abipy',
# # Can be any branch, tag, or commit hash. Use a branch that hosts your docs.
# 'branch': 'gh-pages',
# #'ref': 'gh-pages',
# # Any URL of a binderhub deployment. Must be full URL (e.g. https://mybinder.org).
# 'binderhub_url': 'https://mybinder.org',
# # A list of paths (relative to conf.py) to dependency files that Binder uses to infer
# # the environment needed to run your examples
# 'dependencies': ["../binder/environment.yml", "../binder/postBuild"],
# # Optional keys
# # A prefix to prepend to any filepaths in Binder links.
# #'filepath_prefix': '<prefix>'
# # Jupyter notebooks for Binder will be copied to this directory (relative to built documentation root).
# #'notebooks_dir': '<notebooks-directory-name>'
# # Whether Binder links should start Jupyter Lab instead of the Jupyter Notebook interface.
# #'use_jupyter_lab': False,
# },
}
# Generate the API documentation when building
autosummary_generate = True
numpydoc_show_class_members = False
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'abipy'
copyright = '2023, ' + relmod.author
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = relmod.__version__
# The full version, including alpha/beta/rc tags.
release = relmod.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build', '**.ipynb_checkpoints', "links.rst"]
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# Activate the theme.
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# (Optional) Logo. Should be small enough to fit the navbar (ideally 24x24).
# Path should be relative to the ``_static`` files directory.
#html_logo = "my_logo.png"
def setup(app):
"""
Sphinx automatically calls your setup function defined in "conf.py" during the build process for you.
There is no need to, nor should you, call this function directly in your code.
See http://www.sphinx-doc.org/en/stable/extdev/appapi.html
"""
# Add custom css in _static
#app.add_stylesheet("my_style.css")
app.add_css_file("my_style.css")
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top of the sidebar.
#html_logo = "_static/abipy_logo.png"
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'abipydoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'abipy.tex', 'AbiPy Documentation', 'M. Giantomassi', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'abipy', 'abipy Documentation',
", ".join(list(a[0] for a in relmod.authors.values())), 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'abipy', 'abipy Documentation',
'M. Giantomassi', 'abipy', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'python': ('https://docs.python.org/{.major}'.format(sys.version_info), None),
'numpy': ('https://numpy.org/doc/stable/', None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"pandas": ("http://pandas.pydata.org/pandas-docs/stable/", None),
'matplotlib': ('https://matplotlib.org/stable/', None),
"monty": ("https://pythonhosted.org/monty/", None),
"pymatgen": ("https://pymatgen.org/", None),
'mayavi': ('http://docs.enthought.com/mayavi/mayavi', None),
}
# If true, Sphinx will warn about all references where the target cannot be found.
# Default is False. You can activate this mode temporarily using the -n command-line switch.
#nitpicky = True
# A string of reStructuredText that will be included at the end of every source file that is read.
# This is the right place to add substitutions that should be available in every file.
with open("links.rst", "rt") as fh:
rst_epilog = fh.read()
# http://www.sphinx-doc.org/en/stable/ext/extlinks.html#confval-extlinks
# :abivar:`ecut`
#ABINIT_DOCS_URL =
#extlinks = {'
# "abivar" : (ABINIT_DOC_ULRS + '/abinit/%s', "")
# api_url' : (settings.BASE_URL + '%s', settings.BASE_URL)
#}
autodoc_member_order = "bysource"
#'members', 'undoc-members', 'private-members', 'special-members', 'inherited-members' and 'show-inheritance'.
#autodoc_default_flags = ["show-inheritance", "inherited-members", "special-members"]
# From https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#custom-formatting-sorting-and-labelling
# pybtex provides a very powerful way to create and register new styles, using setuptools entry points,
# as documented here: http://docs.pybtex.org/api/plugins.html
bibtex_bibfiles = ['abiref.bib']
from pybtex.style.formatting.plain import Style
from pybtex.style.labels.alpha import LabelStyle
class AbiPyLabelStyle(LabelStyle):
def format_label(self, entry):
return entry.key
class AbiPyStyle(Style):
default_label_style = 'abipy'
from pybtex.plugin import register_plugin
register_plugin('pybtex.style.labels', 'abipy', AbiPyLabelStyle)
register_plugin('pybtex.style.formatting', 'abipystyle', AbiPyStyle)
# This is for releases http://releases.readthedocs.io/en/latest/usage.html
releases_github_path = "abinit/abipy"