11
11
$ python make.py html
12
12
$ python make.py latex
13
13
"""
14
+ import importlib
14
15
import sys
15
16
import os
16
17
import shutil
20
21
import webbrowser
21
22
import jinja2
22
23
23
- import pandas
24
-
25
24
26
25
DOC_PATH = os .path .dirname (os .path .abspath (__file__ ))
27
26
SOURCE_PATH = os .path .join (DOC_PATH , 'source' )
@@ -134,7 +133,7 @@ def _process_single_doc(self, single_doc):
134
133
self .single_doc = single_doc
135
134
elif single_doc is not None :
136
135
try :
137
- obj = pandas
136
+ obj = pandas # noqa: F821
138
137
for name in single_doc .split ('.' ):
139
138
obj = getattr (obj , name )
140
139
except AttributeError :
@@ -332,7 +331,7 @@ def main():
332
331
'compile, e.g. "indexing", "DataFrame.join"' ))
333
332
argparser .add_argument ('--python-path' ,
334
333
type = str ,
335
- default = os .path .join (DOC_PATH , '..' ),
334
+ default = os .path .dirname (DOC_PATH ),
336
335
help = 'path' )
337
336
argparser .add_argument ('-v' , action = 'count' , dest = 'verbosity' , default = 0 ,
338
337
help = ('increase verbosity (can be repeated), '
@@ -343,7 +342,13 @@ def main():
343
342
raise ValueError ('Unknown command {}. Available options: {}' .format (
344
343
args .command , ', ' .join (cmds )))
345
344
345
+ # Below we update both os.environ and sys.path. The former is used by
346
+ # external libraries (namely Sphinx) to compile this module and resolve
347
+ # the import of `python_path` correctly. The latter is used to resolve
348
+ # the import within the module, injecting it into the global namespace
346
349
os .environ ['PYTHONPATH' ] = args .python_path
350
+ sys .path .append (args .python_path )
351
+ globals ()['pandas' ] = importlib .import_module ('pandas' )
347
352
348
353
builder = DocBuilder (args .num_jobs , not args .no_api , args .single ,
349
354
args .verbosity )
0 commit comments