[tor-commits] [bridgedb/master] Mock C-extensions out for doc building.

isis at torproject.org isis at torproject.org
Sun Jan 12 06:06:33 UTC 2014


commit 4cdf880516388c93086ff6e60e4e9f4c761005db
Author: Isis Lovecruft <isis at torproject.org>
Date:   Tue Nov 26 12:39:15 2013 +0000

    Mock C-extensions out for doc building.
---
 doc/sphinx/source/conf.py |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/doc/sphinx/source/conf.py b/doc/sphinx/source/conf.py
index 686a055..49d5305 100644
--- a/doc/sphinx/source/conf.py
+++ b/doc/sphinx/source/conf.py
@@ -42,6 +42,33 @@ import bridgedb.test
 import bridgedb.Tests
 import bridgedb.Util
 
+
+class Mock(object):
+    """Used to fake the presence of Python C-extensions for documentation
+    building. See
+    http://docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
+    """
+    def __init__(self, *args, **kwargs):
+        pass
+
+    def __call__(self, *args, **kwargs):
+        return Mock()
+
+    @classmethod
+    def __getattr__(cls, name):
+        if name in ('__file__', '__path__'):
+            return '/dev/null'
+        elif name[0] == name[0].upper():
+            mockType = type(name, (), {})
+            mockType.__module__ = __name__
+            return mockType
+        else:
+            return Mock()
+
+MOCK_MODULES = ['pygpgme']
+for mod_name in MOCK_MODULES:
+    sys.modules[mod_name] = Mock()
+
 # -- Autodoc settings ----------------------------------------------------------
 autodoc_member_order = 'bysource'
 autodoc_default_flags = ['members',





More information about the tor-commits mailing list