|
8 | 8 | ## notice and this notice are preserved. This file is offered as-is, |
9 | 9 | ## without any warranty. |
10 | 10 |
|
11 | | -import ctypes |
12 | 11 | import distutils.cmd |
13 | | -import unittest.mock |
14 | 12 |
|
15 | 13 | import setuptools |
16 | 14 | import setuptools.command.sdist |
|
32 | 30 | has_sphinx = False |
33 | 31 |
|
34 | 32 |
|
35 | | -# List of C libraries that microscope can make use of, and may be |
36 | | -# required to support specific devices. We need to create stubs of |
37 | | -# them to build the documentation. Their names here are their name |
38 | | -# when used to construct ctypes' CDLL and WinDLL. |
39 | | -optional_c_libs = [ |
40 | | - # Alpao SDK |
41 | | - "ASDK", |
42 | | - "libasdk.so", |
43 | | - # Andor's atcore (SDK3) |
44 | | - "atcore", |
45 | | - "atcore.so", |
46 | | - # Andor's SDK for (EM)CCD cameras |
47 | | - "atmcd32d", |
48 | | - "atmcd32d.so", |
49 | | - "atmcd64d", |
50 | | - "atmcd64d.so", |
51 | | - # Andor's atutility (SDK3) |
52 | | - "atutility", |
53 | | - "atutility.so", |
54 | | - # Boston Micromachines Corporation (BMC) SDK |
55 | | - "BMC", |
56 | | - "libBMC.so.3", |
57 | | - # Mirao52e SDK (windows only) |
58 | | - "mirao52e", |
59 | | - # pvcam's SDK |
60 | | - "pvcam.so", |
61 | | - "pvcam32", |
62 | | - "pvcam64", |
63 | | -] |
64 | | - |
65 | 33 | # Shadow the sphinx provided command, in order to run sphinx-apidoc |
66 | 34 | # before sphinx-build. This builds the rst files with the actual |
67 | 35 | # package inline documentation. |
|
79 | 47 |
|
80 | 48 | apidoc_ini_args = ["sphinx-apidoc"] |
81 | 49 |
|
82 | | - # Building the documentation using the module docstrings causes |
83 | | - # the modules to be imported. Modules that wrap the optional C |
84 | | - # libraries will try to access the library functions, which means |
85 | | - # that those optional C libraries are required to build the |
86 | | - # documentation. So we patch ctypes.CDLL to intercept a request |
87 | | - # for those libraries and inject a stub instead. |
88 | | - # |
89 | | - # At import time, some of our modules will also make calls to |
90 | | - # functions in the optional C libraries. Because of this, a stub |
91 | | - # for the library is not enough, those functions will need to |
92 | | - # behave well enough to not cause an error during import. |
93 | | - stub_c_attrs = { |
94 | | - "AT_InitialiseLibrary.return_value": 0, # AT_SUCCESS |
95 | | - "AT_InitialiseUtilityLibrary.return_value": 0, # AT_SUCCESS |
96 | | - } |
97 | | - stub_c_dll = unittest.mock.MagicMock() |
98 | | - stub_c_dll.configure_mock(**stub_c_attrs) |
99 | | - |
100 | | - real_c_dll = ctypes.CDLL |
101 | | - |
102 | | - def cdll_diversion(name, *args, **kwargs): |
103 | | - if name in optional_c_libs: |
104 | | - return stub_c_dll |
105 | | - else: |
106 | | - return real_c_dll(name, *args, **kwargs) |
107 | | - |
108 | 50 | class BuildDoc(sphinx.setup_command.BuildDoc): |
109 | 51 | def run(self): |
110 | 52 | apidoc.main( |
111 | 53 | apidoc_ini_args |
112 | 54 | + [ |
113 | 55 | "--separate", # each module on its own page |
| 56 | + "--private", # include private modules |
114 | 57 | "--module-first", |
115 | 58 | "--tocfile", |
116 | 59 | "index", |
117 | 60 | "--output-dir", |
118 | 61 | "doc/api", |
119 | 62 | "microscope", |
120 | | - # exclude win32 so docs will build on other platforms |
121 | | - "microscope/win32.py", |
122 | 63 | # exclude the testsuite |
123 | 64 | "microscope/testsuite/", |
| 65 | + # exclude the wrappers to shared libraries |
| 66 | + "microscope/_wrappers/", |
124 | 67 | # exclude the deprecated devices and deviceserver that |
125 | 68 | # are kept for backwards compatibility only. |
126 | 69 | "microscope/devices.py", |
127 | 70 | "microscope/deviceserver.py", |
| 71 | + "microscope/lasers/", |
| 72 | + "microscope/cameras/_SDK3.py", |
| 73 | + "microscope/cameras/_SDK3Cam.py", |
128 | 74 | ] |
129 | 75 | ) |
130 | | - |
131 | | - with unittest.mock.patch("ctypes.CDLL", new=cdll_diversion): |
132 | | - with unittest.mock.patch( |
133 | | - "ctypes.WinDLL", new=cdll_diversion, create=True |
134 | | - ): |
135 | | - super().run() |
| 76 | + super().run() |
136 | 77 |
|
137 | 78 | else: |
138 | 79 |
|
@@ -215,5 +156,8 @@ def make_distribution(self): |
215 | 156 | "source_dir": ("setup.py", "doc"), |
216 | 157 | }, |
217 | 158 | }, |
218 | | - cmdclass={"build_sphinx": BuildDoc, "sdist": sdist}, |
| 159 | + cmdclass={ |
| 160 | + "build_sphinx": BuildDoc, |
| 161 | + "sdist": sdist, |
| 162 | + }, |
219 | 163 | ) |
0 commit comments