Skip to content
Browse files

add set_sphinx_variables to factorize sphinx configuration over sever…

…al projects
  • Loading branch information...
sdpython committed Dec 30, 2014
1 parent fc470c8 commit 1dec2c00f822beb69b8fcc957cb45927cf0b8335
Showing with 292 additions and 316 deletions.
  1. +3 −2 README.rst
  2. +8 −314 _doc/sphinxdoc/source/
  3. +37 −0 _unittests/ut_helpgen/
  4. +244 −0 src/pyquickhelper/helpgen/
@@ -40,14 +40,15 @@ Versions
* **fix:** the setup does not need the file ``README.rst`` anymore
* **add:** function :func:`open_html_form <pyquickhelper.ipythonhelper.html_forms.open_html_form>`
* **fix:** fix a bad link to MathJax when converting notebook to HTML format
* **add:** add parameter timeout in function :func:`run_cmd`
* **fix:** :func:`run_cmd` now accepts something on the standard input
* **add:** add parameter timeout in function :func:`run_cmd <pyquickhelper.loghelper.flog.run_cmd>`
* **fix:** :func:`run_cmd <pyquickhelper.loghelper.flog.run_cmd>` now accepts something on the standard input
* **new:** class :class:`MagicCommandParser <pyquickhelper.ipythonhelper.magic_parser.MagicCommandParser>`
* **fix:** better behavior while running the unit test
* **change:** catch warnings when running the unit tests
* **change:** expose the function :func:`process_notebooks <pyquickhelper.helpgen.sphinx_main.process_notebooks>` to convert a notebook into html, pdf, rst, docx formats
* **add:** add simple statistics while generation the documentation
* **add:** add function :func:`clone <pyquickhelper.loghelper.repositories.pygit_helper.clone>` and :func:`rebase <pyquickhelper.loghelper.repositories.pygit_helper.rebase>` to clone or pull rebase a git repository
* **new:** function :func:`set_sphinx_variables <pyquickhelper.helpgen.default_conf.set_sphinx_variables>` to avoid copying the same configuration file over multiple projects
* **0.8 - 2014/11/03**
* **add:** Python version is now checked, ImportError is raised if it used on Python 2
* **new:** function :func:`run_doc_server <pyquickhelper.serverdoc.documentation_server.run_doc_server>` creates a local server to display documentation
@@ -8,318 +8,12 @@
import sys, os, datetime, re
import solar_theme

def extract_version_from_setup():
extract the version from assuming it is located in ../../..
and the version is specified by the following line: ``sversion = "..."``
setup = os.path.abspath(os.path.split(__file__)[0])
setup = os.path.join(setup, "..", "..", "..", "")
if os.path.exists(setup):
with open(setup,"r") as f : content =
exp = re.compile("sversion *= *['\\\"]([0-9.]+?)['\\\"]")
all = exp.findall(content)
if len(all) == 0:
raise Exception("unable to locate the version from")
if len(all) != 1 :
raise Exception("more than one version was found: " + str(all))
return all[0]
raise FileNotFoundError("unable to find, tried: " + setup)

project_var_name = "pyquickhelper"
author = "Xavier Dupré"
version = extract_version_from_setup()

# 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.
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0])))
#sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], project_var_name)))

# -- 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',

# Add any paths that contain templates here, relative to this directory.
templates_path = ['phdoc_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 = project_var_name + ' documentation'
copyright = '2014, ' + 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.
# The full version, including alpha/beta/rc tags.
version_file = os.path.abspath(os.path.join(os.path.split(__file__)[0], "..", "..", "..", "version.txt"))
try :
with open(version_file, "r") as ff : first_line = ff.readlines()[0].strip(" \n\r")
except FileNotFoundError :
first_line = "xxx"
release = '%s.%s' % (version, first_line)

# 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 = []

# 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.
# A list of prefixes that are ignored for sorting the Python module index (e.g., if this is set to ['foo.'], then is shown under B, not F).
# This can be handy if you document a project that consists of a single package.
# Works only for the HTML builder currently. Default is [].
modindex_common_prefix = [
project_var_name + ".",

# -- Options for HTML output ---------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'solar_theme' # 'sphinxdoc'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
shtml_theme_options = { "bodyfont":"Calibri"}

# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [solar_theme.theme_path]

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
html_title = "%s %s" % (project_var_name, release)

# 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 = "project_ico.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 = "project_ico.ico"

# 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 = ['phdoc_static']

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
__html_last_updated_fmt_dt =
html_last_updated_fmt = '%04d-%02d-%02d' % (__html_last_updated_fmt_dt.year, __html_last_updated_fmt_dt.month,

# 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 = '%s_doc' % project_var_name

# -- 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',
'%s_doc.tex' % project_var_name,
'%s Documentation' % project_var_name,

# 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',
'%s_doc' % project_var_name,
'%s Documentation' % project_var_name,

# 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', '%s_documentation' % project_var_name, '%s Documentation' % project_var_name,
author, '%s documentation' % project_var_name,
'One line description of project.',

# 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'

# for the autogeneration
autoclass_content = 'both'
autosummary_generate = True
#inheritance_graph_attrs = dict(rankdir="LR", size='"6.0, 8.0"', fontsize=14, ratio='compress')
#inheritance_node_attrs = dict(shape='ellipse', fontsize=14, height=0.75, color='dodgerblue1', style='filled')
graphviz_output_format = "svg"

if sys.platform.startswith("win"):
version = range(34,42)
for v in version:
graphviz_dot = r"C:\Program Files (x86)\Graphviz2.{0}\bin\dot.exe".format(v)
if os.path.exists(graphviz_dot):
graphviz_dot = "dot"

if sys.platform.startswith("win") :
if not os.path.exists(graphviz_dot):
raise FileNotFoundError(graphviz_dot)

def skip(app, what, name, obj, skip, options):
if name.startswith("_") and name not in \
[ "__qualname__",
return False
return skip

def setup(app):
app.connect("autodoc-skip-member", skip)
app.add_config_value('author', 'Xavier Dupré', True)
from pyquickhelper.helpgen.default_conf import set_sphinx_variables
set_sphinx_variables( __file__,
"Xavier Dupré",
@@ -0,0 +1,37 @@
@brief test log(time=8s)
@author Xavier Dupre

import sys, os, unittest, shutil

try :
import src
except ImportError :
path = os.path.normpath(os.path.abspath(os.path.join(os.path.split(__file__)[0], "..", "..")))
if path not in sys.path : sys.path.append(path)
import src

from src.pyquickhelper.loghelper.flog import fLOG
from src.pyquickhelper.helpgen.default_conf import set_sphinx_variables

class TestConfSphinx(unittest.TestCase):

def test_conf_sphinx(self) :
fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
ff = os.path.abspath(os.path.dirname(__file__))
ff = os.path.join(ff, "..", "..", "_doc", "sphinxdoc", "source", "")
assert os.path.exists(ff)
import solar_theme
d = { }
set_sphinx_variables(ff, "thisname", "XD", 2014, "solar_theme", solar_theme.theme_path, d)
for k,v in d.items():

if __name__ == "__main__" :
unittest.main ()

0 comments on commit 1dec2c0

Please sign in to comment.
You can’t perform that action at this time.