Skip to content

Commit eaa13a0

Browse files
committed
Second attempt at fixing the missing site package functions.
This time we explicitly mock the missing functions using a lambda that returns an empty version of whatever types the methods usually return (hard coded into conf.py)
1 parent 83c6ded commit eaa13a0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/source/conf.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13+
import copy
1314
import os
1415
from pathlib import Path
1516
from m2r import MdInclude
@@ -49,7 +50,23 @@
4950
]
5051

5152
autodoc_typehints = 'description'
52-
autodoc_mock_imports = ["site"]
53+
54+
# mock missing site packages methods
55+
import site
56+
mock_site_methods = {
57+
# Format:
58+
# method name: return value
59+
'getusersitepackages': '',
60+
'getsitepackages': []
61+
}
62+
__fn = None
63+
for __name, __rval in mock_site_methods.items():
64+
if not hasattr(site, __name):
65+
__fn = lambda *args, __rval=copy.deepcopy(__rval), **kwargs: __rval
66+
setattr(site, __name, __fn)
67+
del __name
68+
del __rval
69+
del __fn
5370

5471
# Prefix each autosectionlabel with the name of the document it is in and a colon
5572
autosectionlabel_prefix_document = True

0 commit comments

Comments
 (0)