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
|
# -*- coding: utf-8 -*-
# Copyright (C) 2010, 2011, 2012 Sebastian Wiesner <lunaryorn@gmail.com>
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version.
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import (print_function, division, unicode_literals,
absolute_import)
import sys
import os
from docutils import nodes
from docutils.parsers.rst import Directive
# add the pyudev source directory to our path
doc_directory = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.normpath(
os.path.join(doc_directory, os.pardir)))
# add the tests directory to our path to point autodoc on the testsuite plugins
sys.path.append(os.path.normpath(
os.path.join(doc_directory, os.pardir, 'tests')))
class Mock(object):
"""
Mock modules.
Taken from
http://read-the-docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
with some slight changes.
"""
@classmethod
def mock_modules(cls, *modules):
for module in modules:
sys.modules[module] = cls()
def __init__(self, *args, **kwargs):
pass
def __call__(self, *args, **kwargs):
return self.__class__()
def __getattr__(self, attribute):
if attribute in ('__file__', '__path__'):
return os.devnull
else:
# return the *class* object here. Mocked attributes may be used as
# base class in pyudev code, thus the returned mock object must
# behave as class, or else Sphinx autodoc will fail to recognize
# the mocked base class as such, and "autoclass" will become
# meaningless
return self.__class__
# mock out native modules used throughout pyudev to enable Sphinx autodoc even
# if these modules are unavailable, as on readthedocs.org
Mock.mock_modules('PyQt4', 'PyQt4.QtCore', 'PySide', 'PySide.QtCore',
'glib', 'gobject', 'wx', 'wx.lib', 'wx.lib.newevent',
'pyudev._libudev')
# mock out the NewEvent function of wxPython. Let's praise the silly wx API
def NewEventMock():
yield 'event_class'
yield 'event_constant'
sys.modules['wx.lib.newevent'].NewEvent = NewEventMock
import pyudev
needs_sphinx = '1.0'
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary',
'sphinx.ext.intersphinx', 'sphinxcontrib.issuetracker']
master_doc = 'index'
exclude_patterns = ['_build/*']
source_suffix = '.rst'
project = u'pyudev'
copyright = u'2010, 2011 Sebastian Wiesner'
version = '.'.join(pyudev.__version__.split('.')[:2])
release = pyudev.__version__
templates_path = ['_templates']
html_theme = 'default'
html_static_path = []
html_sidebars = {'**': ['info.html', 'localtoc.html', 'relations.html',
'sourcelink.html']}
intersphinx_mapping = {'python': ('http://docs.python.org/', None),
'pytest': ('http://pytest.org/latest', None),
'pyside': ('http://www.pyside.org/docs/pyside/', None)}
issuetracker = 'github'
issuetracker_project = 'lunaryorn/pyudev'
class UDevVersion(Directive):
"""
Directive to document the minimum udev version to use an attribute or
method
"""
has_content = False
required_arguments = 1
option_spec = {}
def run(self):
udevversion = self.arguments[0]
para = nodes.paragraph(udevversion, '', classes=['udevversion'])
text = 'Required udev version: {0}'.format(*self.arguments)
node = nodes.inline(udevversion, text, classes=['versionmodified'])
para.append(node)
return [para]
def setup(app):
from sphinx.ext.autodoc import cut_lines
app.connect(b'autodoc-process-docstring', cut_lines(2, what=['module']))
app.add_directive('udevversion', UDevVersion)
|