1# -*- coding: utf-8 -*-
2#
3# FontParts documentation build configuration file, created by
4# sphinx-quickstart on Thu Mar 24 13:04:20 2016.
5#
6# This file is execfile()d with the current directory set to its
7# containing dir.
8#
9# Note that not all possible configuration values are present in this
10# autogenerated file.
11#
12# All configuration values have a default; values that are commented out
13# serve to show the default.
14
15import sys
16import os
17
18# ------------
19# Mock Imports
20
21# This try/except is a hack around an issue in Mac OS 10.11.5.
22# Specifically, mock requires a version of six that is later
23# than the one that comes installed with the OS. This hack
24# tries to import defcon and if it can't, it kicks to mock.
25# This makes both local and readthedocs compilation work.
26try:
27    import defcon
28except ImportError:
29    from mock import Mock as MagicMock
30
31    class Mock(MagicMock):
32        @classmethod
33        def __getattr__(cls, name):
34            return Mock()
35
36    MOCK_MODULES = [
37        'fontTools',
38        'fontTools.misc',
39        'fontTools.misc.py23',
40        'fontTools.pens',
41        'fontTools.pens.basePen',
42        'fontMath',
43        'ufoLib',
44        'ufoLib.pointPen',
45        'defcon'
46    ]
47    sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
48
49# / Mock Imports
50# --------------
51
52# ------------
53# Monkey Patch
54#
55# https://github.com/sphinx-doc/sphinx/issues/1254
56#
57from fontParts.base.base import dynamicProperty
58dynamicProperty.__get__ = lambda self, *args, **kwargs: self
59#
60# /MonkeyPatch
61# ------------
62
63# If extensions (or modules to document with autodoc) are in another directory,
64# add these directories to sys.path here. If the directory is relative to the
65# documentation root, use os.path.abspath to make it absolute, like shown here.
66#sys.path.insert(0, os.path.abspath('.'))
67
68# -- General configuration ------------------------------------------------
69
70# If your documentation needs a minimal Sphinx version, state it here.
71#needs_sphinx = '1.0'
72
73# Add any Sphinx extension module names here, as strings. They can be
74# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
75# ones.
76extensions = [
77    'sphinx.ext.autodoc',
78    'sphinx.ext.todo',
79    'sphinx.ext.coverage',
80    'sphinx.ext.ifconfig',
81    'sphinx.ext.viewcode',
82    'sphinx.ext.autosummary',
83]
84
85autodoc_member_order = 'bysource'
86autoclass_content = 'both'
87
88# Add any paths that contain templates here, relative to this directory.
89templates_path = ['_templates']
90
91# The suffix(es) of source filenames.
92# You can specify multiple suffix as a list of string:
93# source_suffix = ['.rst', '.md']
94source_suffix = '.rst'
95
96# The encoding of source files.
97#source_encoding = 'utf-8-sig'
98
99# The master toctree document.
100master_doc = 'contents' # was 'index'
101
102# General information about the project.
103project = u'FontParts'
104copyright = u'2016, Dr. Rob O. Fab'
105author = u'Dr. Rob O. Fab'
106
107# The version info for the project you're documenting, acts as replacement for
108# |version| and |release|, also used in various other places throughout the
109# built documents.
110#
111# The short X.Y version.
112version = u'0.1'
113# The full version, including alpha/beta/rc tags.
114release = u'0.1'
115
116# The language for content autogenerated by Sphinx. Refer to documentation
117# for a list of supported languages.
118#
119# This is also used if you do content translation via gettext catalogs.
120# Usually you set "language" from the command line for these cases.
121language = None
122
123# There are two options for replacing |today|: either, you set today to some
124# non-false value, then it is used:
125#today = ''
126# Else, today_fmt is used as the format for a strftime call.
127#today_fmt = '%B %d, %Y'
128
129# List of patterns, relative to source directory, that match files and
130# directories to ignore when looking for source files.
131exclude_patterns = []
132
133# The reST default role (used for this markup: `text`) to use for all
134# documents.
135#default_role = None
136
137# If true, '()' will be appended to :func: etc. cross-reference text.
138add_function_parentheses = False
139
140# If true, the current module name will be prepended to all description
141# unit titles (such as .. function::).
142#add_module_names = True
143
144# If true, sectionauthor and moduleauthor directives will be shown in the
145# output. They are ignored by default.
146#show_authors = False
147
148# The name of the Pygments (syntax highlighting) style to use.
149pygments_style = 'sphinx'
150
151# A list of ignored prefixes for module index sorting.
152#modindex_common_prefix = []
153
154# If true, keep warnings as "system message" paragraphs in the built documents.
155#keep_warnings = False
156
157# If true, `todo` and `todoList` produce output, else they produce nothing.
158todo_include_todos = True
159
160
161# -- Options for HTML output ----------------------------------------------
162
163# The theme to use for HTML and HTML Help pages.  See the documentation for
164# a list of builtin themes.
165html_theme = 'fontPartsTheme'
166
167# Theme options are theme-specific and customize the look and feel of a theme
168# further.  For a list of options available for each theme, see the
169# documentation.
170#html_theme_options = {}
171
172# Add any paths that contain custom themes here, relative to this directory.
173sys.path.append(os.path.abspath('_themes'))
174html_theme_path = ['_themes']
175
176# The name for this set of Sphinx documents.  If None, it defaults to
177# "<project> v<release> documentation".
178#html_title = None
179
180# A shorter title for the navigation bar.  Default is the same as html_title.
181#html_short_title = None
182
183# The name of an image file (relative to this directory) to place at the top
184# of the sidebar.
185#html_logo = None
186
187# The name of an image file (relative to this directory) to use as a favicon of
188# the docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
189# pixels large.
190#html_favicon = None
191
192# Add any paths that contain custom static files (such as style sheets) here,
193# relative to this directory. They are copied after the builtin static files,
194# so a file named "default.css" will overwrite the builtin "default.css".
195html_static_path = ['_static']
196
197# Add any extra paths that contain custom files (such as robots.txt or
198# .htaccess) here, relative to this directory. These files are copied
199# directly to the root of the documentation.
200#html_extra_path = []
201
202# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
203# using the given strftime format.
204#html_last_updated_fmt = '%b %d, %Y'
205
206# If true, SmartyPants will be used to convert quotes and dashes to
207# typographically correct entities.
208#html_use_smartypants = True
209
210# Custom sidebar templates, maps document names to template names.
211#html_sidebars = {}
212
213# Additional templates that should be rendered to pages, maps page names to
214# template names.
215#html_additional_pages = {}
216
217# If false, no module index is generated.
218#html_domain_indices = True
219
220# If false, no index is generated.
221#html_use_index = True
222
223# If true, the index is split into individual pages for each letter.
224#html_split_index = False
225
226# If true, links to the reST sources are added to the pages.
227#html_show_sourcelink = True
228
229# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
230#html_show_sphinx = True
231
232# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
233#html_show_copyright = True
234
235# If true, an OpenSearch description file will be output, and all pages will
236# contain a <link> tag referring to it.  The value of this option must be the
237# base URL from which the finished HTML is served.
238#html_use_opensearch = ''
239
240# This is the file name suffix for HTML files (e.g. ".xhtml").
241#html_file_suffix = None
242
243# Language to be used for generating the HTML full-text search index.
244# Sphinx supports the following languages:
245#   'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
246#   'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
247#html_search_language = 'en'
248
249# A dictionary with options for the search language support, empty by default.
250# Now only 'ja' uses this config value
251#html_search_options = {'type': 'default'}
252
253# The name of a javascript file (relative to the configuration directory) that
254# implements a search results scorer. If empty, the default will be used.
255#html_search_scorer = 'scorer.js'
256
257# Output file base name for HTML help builder.
258htmlhelp_basename = 'FontPartsdoc'
259
260# -- Options for LaTeX output ---------------------------------------------
261
262latex_elements = {
263# The paper size ('letterpaper' or 'a4paper').
264#'papersize': 'letterpaper',
265
266# The font size ('10pt', '11pt' or '12pt').
267#'pointsize': '10pt',
268
269# Additional stuff for the LaTeX preamble.
270#'preamble': '',
271
272# Latex figure (float) alignment
273#'figure_align': 'htbp',
274}
275
276# Grouping the document tree into LaTeX files. List of tuples
277# (source start file, target name, title,
278#  author, documentclass [howto, manual, or own class]).
279latex_documents = [
280    (master_doc, 'FontParts.tex', u'FontParts Documentation',
281     u'Dr. Rob O. Fab', 'manual'),
282]
283
284# The name of an image file (relative to this directory) to place at the top of
285# the title page.
286#latex_logo = None
287
288# For "manual" documents, if this is true, then toplevel headings are parts,
289# not chapters.
290#latex_use_parts = False
291
292# If true, show page references after internal links.
293#latex_show_pagerefs = False
294
295# If true, show URL addresses after external links.
296#latex_show_urls = False
297
298# Documents to append as an appendix to all manuals.
299#latex_appendices = []
300
301# If false, no module index is generated.
302#latex_domain_indices = True
303
304
305# -- Options for manual page output ---------------------------------------
306
307# One entry per manual page. List of tuples
308# (source start file, name, description, authors, manual section).
309man_pages = [
310    (master_doc, 'fontparts', u'FontParts Documentation',
311     [author], 1)
312]
313
314# If true, show URL addresses after external links.
315#man_show_urls = False
316
317
318# -- Options for Texinfo output -------------------------------------------
319
320# Grouping the document tree into Texinfo files. List of tuples
321# (source start file, target name, title, author,
322#  dir menu entry, description, category)
323texinfo_documents = [
324    (master_doc, 'FontParts', u'FontParts Documentation',
325     author, 'FontParts', 'One line description of project.',
326     'Miscellaneous'),
327]
328
329# Documents to append as an appendix to all manuals.
330#texinfo_appendices = []
331
332# If false, no module index is generated.
333#texinfo_domain_indices = True
334
335# How to display URL addresses: 'footnote', 'no', or 'inline'.
336#texinfo_show_urls = 'footnote'
337
338# If true, do not generate a @detailmenu in the "Top" node's menu.
339#texinfo_no_detailmenu = False
340
341
342####################
343
344
345# custom directives
346
347from docutils import nodes
348from docutils.statemachine import ViewList
349
350from sphinx import addnodes
351from sphinx.util import rst
352from docutils.parsers.rst import directives
353from sphinx.ext.autosummary import Autosummary, import_by_name, get_import_prefixes_from_env, autosummary_table
354
355
356class AutosummaryMethodList(Autosummary):
357
358    option_spec = dict(Autosummary.option_spec)
359    option_spec["hidesummary"] = directives.flag
360
361    def get_items(self, names):
362        """
363        Subclass get items
364        to get support for all methods in an given object
365        """
366        env = self.state.document.settings.env
367        prefixes = get_import_prefixes_from_env(env)
368        methodNames = []
369        for name in names:
370            methodNames.append(name)
371            _, obj, _, _ = import_by_name(name, prefixes=prefixes)
372            methodNames.extend(["%s.%s" % (name, method) for method in dir(obj) if not method.startswith("_")])
373        return super(AutosummaryMethodList, self).get_items(methodNames)
374
375    def get_table(self, items):
376        """
377        Subclass to get support for `hidesummary` as options
378        to enable displaying the short summary in the table
379        """
380        hidesummary = 'hidesummary' in self.options
381        table_spec = addnodes.tabular_col_spec()
382        table_spec['spec'] = 'p{0.5\linewidth}p{0.5\linewidth}'
383
384        table = autosummary_table('')
385        real_table = nodes.table('', classes=['longtable'])
386        table.append(real_table)
387        group = nodes.tgroup('', cols=2)
388        real_table.append(group)
389        group.append(nodes.colspec('', colwidth=10))
390        group.append(nodes.colspec('', colwidth=90))
391        body = nodes.tbody('')
392        group.append(body)
393
394        def append_row(*column_texts):
395            row = nodes.row('')
396            for text in column_texts:
397                node = nodes.paragraph('')
398                vl = ViewList()
399                vl.append(text, '<autosummary>')
400                self.state.nested_parse(vl, 0, node)
401                try:
402                    if isinstance(node[0], nodes.paragraph):
403                        node = node[0]
404                except IndexError:
405                    pass
406                row.append(nodes.entry('', node))
407            body.append(row)
408
409        for name, sig, summary, real_name in items:
410            qualifier = 'obj'
411            if 'nosignatures' not in self.options:
412                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, rst.escape(sig))
413            else:
414                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
415            col2 = summary
416            if hidesummary:
417                append_row(col1)
418            else:
419                append_row(col1, col2)
420
421        return [table_spec, table]
422
423def setup(app):
424    app.add_directive('autosummarymethodlist', AutosummaryMethodList)
425
426
427from pygments.style import Style
428from pygments.token import Keyword, Name, Comment, String, Error, \
429     Number, Operator, Generic
430
431class YourStyle(Style):
432    default_style = ""
433    styles = {
434        Comment:                'italic #888',
435        Keyword:                'bold #005',
436        Name:                   '#f00',
437        Name.Function:          '#0f0',
438        Name.Class:             'bold #0f0',
439        String:                 'bg:#eee #111'
440    }