Debian Codegraph @

doc/conf.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2010, 2011, 2012, 2013 Sebastian Wiesner <[email protected]>
3
4 # This library is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU Lesser General Public License as published by the
6 # Free Software Foundation; either version 2.1 of the License, or (at your
7 # option) any later version.
8
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 # for more details.
13
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18 import sys
19 import os
20
21 from docutils import nodes
22 from docutils.parsers.rst import Directive
23
24 # add the pyudev source directory to our path
25 doc_directory = os.path.dirname(os.path.abspath(__file__))
26 sys.path.append(os.path.normpath(os.path.join(doc_directory, os.pardir)))
27 # add the tests directory to our path to point autodoc on the testsuite plugins
28 sys.path.append(os.path.normpath(os.path.join(doc_directory, os.pardir, "tests")))
29
30
31 class Mock:
32 """
33 Mock modules.
34
35 Taken from
36 http://read-the-docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
37 with some slight changes.
38 """
39
40 @classmethod
41 def mock_modules(cls, *modules):
42 for module in modules:
43 sys.modules[module] = cls()
44
45 def __init__(self, *args, **kwargs):
46 pass
47
48 def __call__(self, *args, **kwargs):
49 return self.__class__()
50
51 def __getattr__(self, attribute):
52 if attribute in ("__file__", "__path__"):
53 return os.devnull
54 else:
55 # return the *class* object here. Mocked attributes may be used as
56 # base class in pyudev code, thus the returned mock object must
57 # behave as class, or else Sphinx autodoc will fail to recognize
58 # the mocked base class as such, and "autoclass" will become
59 # meaningless
60 return self.__class__
61
62
63 # mock out native modules used throughout pyudev to enable Sphinx autodoc even
64 # if these modules are unavailable, as on readthedocs.org
65 Mock.mock_modules(
66 "PyQt5",
67 "PyQt5.QtCore",
68 "PyQt4",
69 "PyQt4.QtCore",
70 "PySide",
71 "PySide.QtCore",
72 "glib",
73 "gobject",
74 "wx",
75 "wx.lib",
76 "wx.lib.newevent",
77 "pyudev._libudev",
78 )
79
80
81 # mock out the NewEvent function of wxPython. Let's praise the silly wx API
82 def NewEventMock():
83 yield "event_class"
84 yield "event_constant"
85
86
87 sys.modules["wx.lib.newevent"].NewEvent = NewEventMock
88
89
90 import pyudev
91
92 needs_sphinx = "1.0"
93
94 extensions = ["sphinx.ext.autodoc", "sphinx.ext.autosummary", "sphinx.ext.intersphinx"]
95
96 master_doc = "index"
97 exclude_patterns = ["_build/*"]
98 source_suffix = ".rst"
99
100 project = "pyudev"
101 copyright = "2010, 2011 Sebastian Wiesner"
102 version = ".".join(pyudev.__version__.split(".")[:2])
103 release = pyudev.__version__
104
105 templates_path = ["_templates"]
106 html_theme = "classic"
107 html_static_path = []
108 html_sidebars = {
109 "**": ["info.html", "localtoc.html", "relations.html", "sourcelink.html"]
110 }
111
112 intersphinx_mapping = {
113 "python": ("http://docs.python.org/", None),
114 "pytest": ("http://pytest.org/latest", None),
115 }
116
117
118 class UDevVersion(Directive):
119 """
120 Directive to document the minimum udev version to use an attribute or
121 method
122 """
123
124 has_content = False
125 required_arguments = 1
126 option_spec = {}
127
128 def run(self):
129 udevversion = self.arguments[0]
130 para = nodes.paragraph(udevversion, "", classes=["udevversion"])
131 text = "Required udev version: {0}".format(*self.arguments)
132 node = nodes.inline(udevversion, text, classes=["versionmodified"])
133 para.append(node)
134 return [para]
135
136
137 def setup(app):
138 from sphinx.ext.autodoc import cut_lines
139
140 app.connect("autodoc-process-docstring", cut_lines(2, what=["module"]))
141 app.add_directive("udevversion", UDevVersion)