Skip to content

Commit 1bddb30

Browse files
committed
Mock object for libquirc.so while building docs on the readthedocs.org
1 parent 22c6b6a commit 1bddb30

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

quirc/api/functions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
__all__ = ('version', 'new', 'destroy', 'resize', 'begin', 'end', 'count', 'extract', 'decode')
55

6+
import os
67
import ctypes
78
from ctypes.util import find_library
89

@@ -13,7 +14,14 @@
1314
c_int_pointer = ctypes.POINTER(ctypes.c_int)
1415
c_uint8_pointer = ctypes.POINTER(ctypes.c_uint8)
1516

16-
libquirc = ctypes.CDLL(find_library('quirc'))
17+
try:
18+
libquirc = ctypes.CDLL(find_library('quirc'))
19+
except OSError:
20+
if not 'READTHEDOCS' in os.environ:
21+
raise
22+
23+
from quirc.compat import Mock
24+
libquirc = Mock()
1725

1826
version = libquirc.quirc_version
1927
version.restype = ctypes.c_char_p

quirc/compat.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@
1616
import Image
1717
except ImportError:
1818
have_pil = False
19+
20+
21+
class Mock(object):
22+
"""Simple mock object for replacing `libquirc` library while building a docs on the readthedocs.org"""
23+
24+
def __init__(self, *args, **kwargs):
25+
pass
26+
27+
def __call__(self, *args, **kwargs):
28+
return Mock()
29+
30+
@classmethod
31+
def __getattr__(cls, name):
32+
if name in ('__file__', '__path__'):
33+
return '/dev/null'
34+
elif name[0] == name[0].upper():
35+
return type(name, (), {})
36+
else:
37+
return Mock()

0 commit comments

Comments
 (0)