| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import sys |
| 19 |
import os |
| 20 |
|
| 21 |
from docutils import nodes |
| 22 |
from docutils.parsers.rst import Directive |
| 23 |
|
| 24 |
|
| 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 |
|
| 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 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
return self.__class__ |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 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 |
|
| 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) |