forked from qgis/QGIS-Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.py
408 lines (318 loc) · 14.6 KB
/
conf.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path 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.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'QGIS Documentation'
copyright = '2002-now, QGIS project'
author = 'QGIS Authors'
# -- General configuration ---------------------------------------------------
# The master toctree document.
master_doc = 'docs/index'
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = 'static/common/logo.png'
html_last_updated_fmt = '%b %d, %Y %H:%M'
# 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 = 'testing'
# 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.imgmath',
'sphinx.ext.intersphinx',
'sphinx.ext.doctest',
'sphinx.ext.extlinks',
'sphinx.ext.autodoc',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'venv',
'README.rst',
'readme_old.rst',
]
# -- Internationalisation ----------------------------------------------------
language = 'en'
locale_dirs = ['locale/'] # path is example but recommended.
gettext_compact = False # optional.
# -- 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 = 'alabaster'
html_theme = 'rtd_qgis'
# https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html#theme-options
# rtd / read the docs theme options:
html_theme_options = {
# collapse_navigation: With this enabled, navigation entries are not expandable – the [+] icons next to each entry are removed. Default: True
'collapse_navigation': True,
# sticky_navigation: Scroll the navigation with the main page content as you scroll the page. Default: True
'sticky_navigation': True,
# navigation_depth: The maximum depth of the table of contents tree. Set this to -1 to allow unlimited depth. Default: 4
'navigation_depth': 4,
# includehidden:Specifies if the navigation includes hidden table(s) of contents – that is, any toctree directive that is marked with the :hidden: option. Default: True,
# 'includehidden': True,
# canonical_url: This will specify a canonical URL meta link element to tell search engines which URL should be ranked as the primary URL for your documentation. This is important if you have multiple URLs that your documentation is available through. The URL points to the root path of the documentation and requires a trailing slash.
'canonical_url': 'https://docs.qgis.org/latest/en/',
# display_version: If True, the version number is shown at the top of the sidebar. Default: True,
'display_version': True,
# logo_only: Only display the logo image, do not display the project name at the top of the sidebar. Default: False,
'logo_only': False,
# prev_next_buttons_location': Location to display Next and Previous buttons. This can be either bottom, top, both , or None. Default: 'bottom',
'prev_next_buttons_location': 'both',
# style_external_links': Add an icon next to external links. Default: False,
'style_external_links': False,
# style_nav_header_background': Changes the background of the search area in the navigation bar. The value can be anything valid in a CSS background property. Default: 'white',
#'style_nav_header_background': 'Gray',
# Toc options
# titles_only: When enabled, page subheadings are not included in the navigation. Default: False
# 'titles_only': False,
}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = ['./themes']
html_favicon = 'static/common/qgis_logo.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 = ['static']
## for rtd themes, creating a html_context for the version/language part
import os
import sys
import yaml
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../'))
with open('docs_conf.yml', 'r') as f:
cfg = yaml.safe_load(f)
html_context = {
# When a QGIS version reaches end of life, set this to True to show an information
# message on the top of the page.
'outdated': False,
# When a new QGIS version is released, set this to False to remove the disclaimer
# information message on the top of the page.
'isTesting': True
}
# Add custom CSS when a top bar is needed to be shown (for testing or outdated versions)
if html_context['isTesting'] or html_context['outdated']:
html_css_files = ['css/qgis_topbar.css']
supported_languages = cfg['supported_languages'].replace(' ','').split(',')
version_list = cfg['version_list'].replace(' ','').split(',')
docs_url = 'https://docs.qgis.org/'
if version not in version_list:
raise ValueError('QGIS version is not in version list', version, version_list)
# This config value contains the locations and names of other projects that
# should be linked to in this documentation.
pyqgis_version = version if version != 'testing' else 'master'
intersphinx_mapping = {'pyqgis_api': ('https://qgis.org/pyqgis/{}/'.format(pyqgis_version), None)}
# This config value must be a dictionary of external sites, mapping unique short
# alias names to a base URL and a prefix.
api_version = version if version != 'testing' else ''
source_version = ''.join(['release-', version]).replace('.', '_') if version != 'testing' else 'master'
extlinks = {# api website: docs master branch points to '/' while x.y points to x.y
'api': ('https://qgis.org/api/{}%s'.format(''.join([version, '/']) if version != 'testing' else ''), None),
# pyqgis website: docs master branch points to 'master' and x.y points to x.y
'pyqgis': ('https://qgis.org/pyqgis/{}/%s'.format(pyqgis_version), None),
# code on github: docs master branch points to 'master' while x.y points to release-x_y
'source': ('https://github.com/qgis/QGIS/blob/{}/%s'.format(source_version), None)
}
context = {
# 'READTHEDOCS': True,
'version_downloads': True,
'versions': [ [v, docs_url+v] for v in version_list],
'supported_languages': [ [l, docs_url+version+'/'+l] for l in supported_languages],
'downloads': [ ['PDF', docs_url+version+'/pdf'] ], # ['HTML', '/builders.tgz'] ],
'display_github': not html_context['outdated'], # Do not display for outdated releases
'github_user': 'qgis',
'github_repo': 'QGIS-Documentation',
'github_version': 'master/',
'github_url':'https://github.com/qgis/QGIS-Documentation/edit/master',
'transifex_url': 'https://www.transifex.com/qgis/qgis-documentation/translate',
'pyqgis_version': pyqgis_version,
'source_version': source_version,
'api_version': api_version
}
if 'html_context' in globals():
html_context.update(context)
else:
html_context = context
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
latex_paper_size = 'a4'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('docs/user_manual/index', 'QGISUserGuide.tex', f'QGIS {version} User Guide', u'QGIS Project', 'manual'),
('docs/pyqgis_developer_cookbook/index', 'PyQGISDeveloperCookbook.tex', f'PyQGIS {version} developer cookbook', u'QGIS Project', 'manual'),
('docs/training_manual/index', 'QGISTrainingManual.tex', u'QGIS Training Manual', u'QGIS Project', 'manual'),
#('docs/developers_guide/index', 'QGISDevelopersGuide.tex', u'QGIS Developers Guide', u'QGIS Project', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
latex_logo = 'static/common/logo.png'
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
'preamble': u'''\\usepackage{combelow}
\\setcounter{tocdepth}{2}
\\usepackage{newunicodechar}
\\newunicodechar{Ș}{\\cb{S}}
\\newunicodechar{ș}{\\cb{s}}
\\newunicodechar{Ț}{\\cb{T}}
\\newunicodechar{ț}{\\cb{t}}
\\newunicodechar{≠}{$\\neq$}
\\newunicodechar{≥}{$\geq$}
\\newunicodechar{≤}{$\leq$}
\\newunicodechar{π}{$\pi$}
\\newunicodechar{}{ }'''
}
# -- Settings for Python code samples testing --------------------------------
# adding this because in pycookbook a lot of text is referencing classes, which cannot be found by sphinx
# eg: Map canvas is implemented as :class:`QgsMapCanvas` ...
# I hope somebody will create the real references for these so they can be removed here...
nitpick_ignore = [
('py:class', 'QDomElement'),
('py:class', 'QAction'),
('py:class', 'QMenu'),
('py:data', 'iface'),
('py:data', 'qgis.utils.iface'),
('py:func', 'classFactory'),
('py:func', '__init__'),
('py:func', 'initGui'),
('py:func', 'hide'),
('py:func', 'requestReady'),
('py:func', 'sendResponse'),
('py:func', 'serverClassFactory'),
('py:func', 'show'),
('py:func', 'showPluginHelp'),
('py:func', 'unload'),
('py:mod', 'qgis.core'),
('py:mod', 'qgis.gui'),
('py:mod', 'qgis.utils'),
]
# Add doctest configuration
doctest_path = ['/usr/share/qgis/python/plugins/', os.path.join(os.getcwd(), 'testdata', 'processing')]
doctest_global_setup = '''
import os
import sys
import tempfile
import shutil
# Copy all cookbook test data into a
# testdata directory (which is in .gitignore)
# This is necessary because some test files
# are modified during the tests and it's annoying
# to find them changed in git
try:
shutil.rmtree('testdata')
except:
pass
shutil.copytree('qgis-projects/python_cookbook', 'testdata')
# Prepare environment for QgsApplication
os.environ['QGIS_AUTH_DB_DIR_PATH'] = tempfile.mkdtemp()
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
from qgis.testing import start_app
from qgis.testing.mocked import get_iface
def start_qgis():
save_stdout = sys.stdout
try:
with open(os.devnull, 'w') as f:
sys.stdout = f
globals()['QGISAPP'] = start_app()
finally:
sys.stdout = save_stdout
sys.stdout = sys.stderr
from qgis.core import (
QgsProject,
QgsVectorLayer,
QgsFeature,
QgsGeometry,
QgsApplication,
QgsLayerTreeModel
)
from qgis.gui import (
QgsLayerTreeView,
QgsMessageBar,
)
from qgis.analysis import QgsNativeAlgorithms
# Expose the iface for plugins snippets
iface = get_iface()
# Mock activeLayer()
iface.activeLayer.return_value = QgsVectorLayer("Point?crs=4326&field=fid:integer&field=name:string", "temporary_points", "memory")
# Add a feature
f = QgsFeature(iface.activeLayer().fields())
f.setAttributes([1, 'First feature'])
f.setGeometry(QgsGeometry.fromWkt('point( 7 45)'))
iface.activeLayer().dataProvider().addFeatures([f])
# Mock messageBar
iface.messageBar.return_value = QgsMessageBar()
# Mock layerTreeView
layertree_view = QgsLayerTreeView()
layertree_model = QgsLayerTreeModel(QgsProject.instance().layerTreeRoot())
layertree_view.setModel(layertree_model)
iface.layerTreeView.return_value = layertree_view
iface.layertree_model = layertree_model
# Init processing plugin
import processing
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
return iface
def dump_tree(root):
"""Dump the layer tree for testing"""
def _print_children(parent, indent):
print('-' * indent, parent.name(), parent)
for c in parent.children():
_print_children(c, indent + 1)
_print_children(root, 1)
'''
doctest_test_doctest_blocks = ''
doctest_global_cleanup = '''
from qgis.core import QgsProject
QgsProject.instance().clear()
'''
# Make Sphinx doctest insensitive to object address differences,
# also 'output_....' processing alg ids
import doctest
import re
import sphinx.ext.doctest as ext_doctest
ADDRESS_RE = re.compile(r'\b0x[0-9a-f]{1,16}\b|_[a-z0-9]{8}_[a-z0-9]{4}_[a-z0-9]{4}_[a-z0-9]{4}_[a-z0-9]{12}')
class BetterDocTestRunner(ext_doctest.SphinxDocTestRunner):
def __init__(self, checker=None, verbose=None, optionflags=0):
checker = BetterOutputChecker()
doctest.DocTestRunner.__init__(self, checker, verbose, optionflags)
class BetterOutputChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
# Patch to test tasks output (which is in random order)
if want.startswith('Random') or got.startswith('Random'):
return True
want = ADDRESS_RE.sub('0x7f00ed991e80', want)
got = ADDRESS_RE.sub('0x7f00ed991e80', got)
return doctest.OutputChecker.check_output(self, want, got, optionflags)
ext_doctest.SphinxDocTestRunner = BetterDocTestRunner