|
19 | 19 | package_folder = "../../sage_sample"
|
20 | 20 | authors = u"Matthias Koeppe, Sébastien Labbé, Viviane Pons, Nicolas M. Thiéry, ... with inspiration from many"
|
21 | 21 |
|
| 22 | +import six |
22 | 23 | import sys
|
23 | 24 | import os
|
24 |
| - |
25 | 25 | from sage.env import SAGE_DOC_SRC, SAGE_DOC, SAGE_SRC
|
26 | 26 |
|
27 | 27 | try:
|
|
31 | 31 |
|
32 | 32 |
|
33 | 33 |
|
| 34 | + |
34 | 35 | # If extensions (or modules to document with autodoc) are in another directory,
|
35 | 36 | # add these directories to sys.path here. If the directory is relative to the
|
36 | 37 | # documentation root, use os.path.abspath to make it absolute, like shown here.
|
37 |
| -sys.path.append(os.path.abspath(package_folder)) |
38 |
| -sys.path.append(os.path.join(SAGE_SRC, "sage_setup", "docbuild", "ext")) |
| 38 | +sys.path.insert(0, os.path.abspath(package_folder)) |
| 39 | +#sys.path.append(os.path.join(SAGE_SRC, "sage_setup", "docbuild", "ext")) |
| 40 | + |
| 41 | + |
| 42 | +print("Using sys.path = {}".format(sys.path)) |
39 | 43 |
|
40 | 44 | # -- General configuration ------------------------------------------------
|
41 | 45 |
|
|
46 | 50 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
47 | 51 | # ones.
|
48 | 52 | extensions = [
|
49 |
| - #'sphinx.ext.autodoc', |
50 |
| - 'sage_autodoc', |
51 |
| - 'sage_package.sphinx', |
| 53 | + 'sphinx.ext.autodoc', |
| 54 | + #'sage_autodoc', ## Not available on conda-forge sage! |
| 55 | + #'sage_package.sphinx', |
52 | 56 | 'sphinx.ext.doctest',
|
53 | 57 | 'sphinx.ext.coverage',
|
| 58 | + 'sphinx.ext.extlinks', |
| 59 | + 'matplotlib.sphinxext.plot_directive', |
| 60 | + #'sphinxcontrib.bibtex' |
54 | 61 | ]
|
55 | 62 |
|
| 63 | +### from Sage src/doc/common/conf.py |
| 64 | +# This code is executed before each ".. PLOT::" directive in the Sphinx |
| 65 | +# documentation. It defines a 'sphinx_plot' function that displays a Sage object |
| 66 | +# through matplotlib, so that it will be displayed in the HTML doc. |
| 67 | +plot_html_show_source_link = False |
| 68 | +plot_pre_code = """ |
| 69 | +def sphinx_plot(graphics, **kwds): |
| 70 | + import matplotlib.image as mpimg |
| 71 | + from sage.misc.temporary_file import tmp_filename |
| 72 | + import matplotlib.pyplot as plt |
| 73 | + ## Option handling is taken from Graphics.save |
| 74 | + try: |
| 75 | + from sage.plot.multigraphics import GraphicsArray |
| 76 | + except ImportError: |
| 77 | + from sage.plot.graphics import GraphicsArray |
| 78 | + options = dict() |
| 79 | + if not isinstance(graphics, GraphicsArray): |
| 80 | + options.update(graphics.SHOW_OPTIONS) |
| 81 | + options.update(graphics._extra_kwds) |
| 82 | + options.update(kwds) |
| 83 | + dpi = options.pop('dpi', None) |
| 84 | + transparent = options.pop('transparent', None) |
| 85 | + fig_tight = options.pop('fig_tight', None) |
| 86 | + figsize = options.pop('figsize', None) |
| 87 | + ## figsize handling is taken from Graphics.matplotlib() |
| 88 | + if figsize is not None and not isinstance(figsize, (list, tuple)): |
| 89 | + # in this case, figsize is a number and should be positive |
| 90 | + try: |
| 91 | + figsize = float(figsize) # to pass to mpl |
| 92 | + except TypeError: |
| 93 | + raise TypeError("figsize should be a positive number, not {0}".format(figsize)) |
| 94 | + if figsize > 0: |
| 95 | + default_width, default_height=rcParams['figure.figsize'] |
| 96 | + figsize=(figsize, default_height*figsize/default_width) |
| 97 | + else: |
| 98 | + raise ValueError("figsize should be positive, not {0}".format(figsize)) |
| 99 | +
|
| 100 | + if figsize is not None: |
| 101 | + # then the figsize should be two positive numbers |
| 102 | + if len(figsize) != 2: |
| 103 | + raise ValueError("figsize should be a positive number " |
| 104 | + "or a list of two positive numbers, not {0}".format(figsize)) |
| 105 | + figsize = (float(figsize[0]),float(figsize[1])) # floats for mpl |
| 106 | + if not (figsize[0] > 0 and figsize[1] > 0): |
| 107 | + raise ValueError("figsize should be positive numbers, " |
| 108 | + "not {0} and {1}".format(figsize[0],figsize[1])) |
| 109 | +
|
| 110 | + plt.figure(figsize=figsize) |
| 111 | + if isinstance(graphics, GraphicsArray): |
| 112 | + ## from GraphicsArray.save |
| 113 | + figure = plt.gcf() |
| 114 | + rows = graphics.nrows() |
| 115 | + cols = graphics.ncols() |
| 116 | + for i, g in enumerate(graphics): |
| 117 | + subplot = figure.add_subplot(rows, cols, i + 1) |
| 118 | + g_options = copy(options) |
| 119 | + g_options.update(g.SHOW_OPTIONS) |
| 120 | + g_options.update(g._extra_kwds) |
| 121 | + g_options.pop('dpi', None) |
| 122 | + g_options.pop('transparent', None) |
| 123 | + g_options.pop('fig_tight', None) |
| 124 | + g.matplotlib(figure=figure, sub=subplot, **g_options) |
| 125 | + else: |
| 126 | + figure = graphics.matplotlib(figure=plt.gcf(), figsize=figsize, **options) |
| 127 | + plt.tight_layout(pad=0) |
| 128 | + plt.margins(0) |
| 129 | + plt.show() |
| 130 | +
|
| 131 | +from sage.all_cmdline import * |
| 132 | +""" |
| 133 | + |
| 134 | +plot_html_show_formats = False |
| 135 | +plot_formats = ['svg', 'pdf', 'png'] |
| 136 | + |
56 | 137 | # Add any paths that contain templates here, relative to this directory.
|
57 | 138 | # templates_path = ['_templates']
|
58 | 139 | templates_path = [os.path.join(SAGE_DOC_SRC, 'common', 'templates'), '_templates']
|
|
72 | 153 | # |version| and |release|, also used in various other places throughout the
|
73 | 154 | # built documents.
|
74 | 155 | #
|
75 |
| -# The short X.Y version. |
76 |
| -version = open("../../VERSION").read().strip() |
| 156 | +from pkg_resources import get_distribution, DistributionNotFound |
77 | 157 | # The full version, including alpha/beta/rc tags.
|
78 |
| -release = version |
| 158 | +try: |
| 159 | + release = get_distribution('sage-numerical-interactive-mip').version |
| 160 | +except DistributionNotFound: |
| 161 | + release = "0.2" |
| 162 | +#print("############# release reported: {} ##################".format(release)) |
| 163 | +# The short X.Y version. |
| 164 | +version = '.'.join(release.split('.')[:2]) |
79 | 165 |
|
80 | 166 | # The language for content autogenerated by Sphinx. Refer to documentation
|
81 | 167 | # for a list of supported languages.
|
|
115 | 201 | # If true, keep warnings as "system message" paragraphs in the built documents.
|
116 | 202 | #keep_warnings = False
|
117 | 203 |
|
118 |
| -pythonversion = sys.version.split(' ')[0] |
119 |
| -# Python and Sage trac ticket shortcuts. For example, :trac:`7549` . |
120 |
| -extlinks = { |
121 |
| - 'python': ('https://docs.python.org/release/'+pythonversion+'/%s', ''), |
122 |
| - 'trac': ('http://trac.sagemath.org/%s', 'trac ticket #'), |
123 |
| - 'wikipedia': ('https://en.wikipedia.org/wiki/%s', 'Wikipedia article '), |
124 |
| - 'arxiv': ('http://arxiv.org/abs/%s', 'Arxiv '), |
125 |
| - 'oeis': ('https://oeis.org/%s', 'OEIS sequence '), |
126 |
| - 'doi': ('https://dx.doi.org/%s', 'doi:'), |
127 |
| - 'mathscinet': ('http://www.ams.org/mathscinet-getitem?mr=%s', 'MathSciNet ') |
128 |
| - } |
129 |
| - |
130 | 204 | # -- Options for HTML output ----------------------------------------------
|
131 | 205 |
|
132 | 206 | # The theme to use for HTML and HTML Help pages. See the documentation for
|
133 | 207 | # a list of builtin themes.
|
134 |
| -html_theme = 'default' |
| 208 | +html_theme = 'sage' |
| 209 | +html_theme_path = ['../themes'] |
135 | 210 |
|
136 | 211 | # Theme options are theme-specific and customize the look and feel of a theme
|
137 | 212 | # further. For a list of options available for each theme, see the
|
138 | 213 | # documentation.
|
139 | 214 | html_theme_options = {}
|
140 | 215 |
|
141 |
| - |
142 |
| -# Add any paths that contain custom themes here, relative to this directory. |
143 |
| -#html_theme_path = [] |
144 |
| -#html_theme_path = [os.path.join(SAGE_DOC_SRC, 'common', 'themes')] |
145 |
| -html_theme_path = [os.path.join(SAGE_DOC_SRC, 'common', 'themes', 'sage')] |
146 |
| - |
147 | 216 | # The name for this set of Sphinx documents. If None, it defaults to
|
148 | 217 | # "<project> v<release> documentation".
|
149 | 218 |
|
|
162 | 231 | # Add any paths that contain custom static files (such as style sheets) here,
|
163 | 232 | # relative to this directory. They are copied after the builtin static files,
|
164 | 233 | # so a file named "default.css" will overwrite the builtin "default.css".
|
165 |
| -#html_static_path = ['_static'] |
166 |
| -html_static_path = [] |
| 234 | +html_static_path = [] #['_static'] |
167 | 235 |
|
168 | 236 | # Add any extra paths that contain custom files (such as robots.txt or
|
169 | 237 | # .htaccess) here, relative to this directory. These files are copied
|
|
232 | 300 | # (source start file, target name, title,
|
233 | 301 | # author, documentclass [howto, manual, or own class]).
|
234 | 302 | latex_documents = [
|
235 |
| - ('index', package_name + '.tex', u'Documentation of ' + unicode(package_name), |
| 303 | + ('index', package_name + '.tex', u'Documentation of ' + six.text_type(package_name), |
236 | 304 | authors, 'manual'),
|
237 | 305 | ]
|
238 | 306 |
|
|
262 | 330 | # One entry per manual page. List of tuples
|
263 | 331 | # (source start file, name, description, authors, manual section).
|
264 | 332 | man_pages = [
|
265 |
| - ('index', package_name, unicode(package_name) + u" documentation", |
| 333 | + ('index', package_name, six.text_type(package_name) + u" documentation", |
266 | 334 | [authors], 1)
|
267 | 335 | ]
|
268 | 336 |
|
|
276 | 344 | # (source start file, target name, title, author,
|
277 | 345 | # dir menu entry, description, category)
|
278 | 346 | texinfo_documents = [
|
279 |
| - ('index', package_name, unicode(package_name) + u" documentation", |
| 347 | + ('index', package_name, six.text_type(package_name) + u" documentation", |
280 | 348 | authors, package_name, project,
|
281 | 349 | 'Miscellaneous'),
|
282 | 350 | ]
|
|
310 | 378 | # this is broken for now
|
311 | 379 | # html_theme_options['mathjax_macros'] = sage_mathjax_macros()
|
312 | 380 |
|
313 |
| - from pkg_resources import Requirement, working_set |
314 |
| - sagenb_path = working_set.find(Requirement.parse('sagenb')).location |
315 |
| - mathjax_relative = os.path.join('sagenb','data','mathjax') |
| 381 | + ## from pkg_resources import Requirement, working_set |
| 382 | + ## sagenb_path = working_set.find(Requirement.parse('sagenb')).location |
| 383 | + ## mathjax_relative = os.path.join('sagenb','data','mathjax') |
316 | 384 |
|
317 |
| - # It would be really nice if sphinx would copy the entire mathjax directory, |
318 |
| - # (so we could have a _static/mathjax directory), rather than the contents of the directory |
| 385 | + ## # It would be really nice if sphinx would copy the entire mathjax directory, |
| 386 | + ## # (so we could have a _static/mathjax directory), rather than the contents of the directory |
319 | 387 |
|
320 |
| - mathjax_static = os.path.join(sagenb_path, mathjax_relative) |
321 |
| - html_static_path.append(mathjax_static) |
322 |
| - exclude_patterns=['**/'+os.path.join(mathjax_relative, i) for i in ('docs', 'README*', 'test', |
323 |
| - 'unpacked', 'LICENSE')] |
| 388 | + ## mathjax_static = os.path.join(sagenb_path, mathjax_relative) |
| 389 | + ## html_static_path.append(mathjax_static) |
| 390 | + ## exclude_patterns=['**/'+os.path.join(mathjax_relative, i) for i in ('docs', 'README*', 'test', |
| 391 | + ## 'unpacked', 'LICENSE')] |
| 392 | + from sage.env import SAGE_LOCAL, SAGE_SHARE |
| 393 | + html_static_path.append(SAGE_LOCAL + "/lib/mathjax") # conda |
| 394 | + html_static_path.append(SAGE_SHARE + "/mathjax") # sage distribution |
324 | 395 | else:
|
325 | 396 | extensions.append('sphinx.ext.pngmath')
|
326 | 397 |
|
@@ -349,3 +420,26 @@ def __init__(self, **options):
|
349 | 420 | \makeatother
|
350 | 421 | \renewcommand{\ttdefault}{txtt}
|
351 | 422 | '''
|
| 423 | + |
| 424 | +##################################################### |
| 425 | +# add LaTeX macros for Sage |
| 426 | + |
| 427 | +from sage.misc.latex_macros import sage_latex_macros |
| 428 | + |
| 429 | +try: |
| 430 | + pngmath_latex_preamble # check whether this is already defined |
| 431 | +except NameError: |
| 432 | + pngmath_latex_preamble = "" |
| 433 | + |
| 434 | +for macro in sage_latex_macros(): |
| 435 | + # used when building latex and pdf versions |
| 436 | + latex_elements['preamble'] += macro + '\n' |
| 437 | + # used when building html version |
| 438 | + pngmath_latex_preamble += macro + '\n' |
| 439 | + |
| 440 | + |
| 441 | +## The following is needed on conda-forge sagemath |
| 442 | +from sage.repl.user_globals import initialize_globals |
| 443 | +import sage.all |
| 444 | +my_globs = dict() |
| 445 | +initialize_globals(sage.all, my_globs) |
0 commit comments