1111 $ python make.py html
1212 $ python make.py latex
1313"""
14+ import importlib
1415import sys
1516import os
1617import shutil
2021import webbrowser
2122import jinja2
2223
23- import pandas
24-
2524
2625DOC_PATH = os .path .dirname (os .path .abspath (__file__ ))
2726SOURCE_PATH = os .path .join (DOC_PATH , 'source' )
@@ -134,7 +133,7 @@ def _process_single_doc(self, single_doc):
134133 self .single_doc = single_doc
135134 elif single_doc is not None :
136135 try :
137- obj = pandas
136+ obj = pandas # noqa: F821
138137 for name in single_doc .split ('.' ):
139138 obj = getattr (obj , name )
140139 except AttributeError :
@@ -332,7 +331,7 @@ def main():
332331 'compile, e.g. "indexing", "DataFrame.join"' ))
333332 argparser .add_argument ('--python-path' ,
334333 type = str ,
335- default = os .path .join (DOC_PATH , '..' ),
334+ default = os .path .dirname (DOC_PATH ),
336335 help = 'path' )
337336 argparser .add_argument ('-v' , action = 'count' , dest = 'verbosity' , default = 0 ,
338337 help = ('increase verbosity (can be repeated), '
@@ -343,7 +342,13 @@ def main():
343342 raise ValueError ('Unknown command {}. Available options: {}' .format (
344343 args .command , ', ' .join (cmds )))
345344
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
346349 os .environ ['PYTHONPATH' ] = args .python_path
350+ sys .path .append (args .python_path )
351+ globals ()['pandas' ] = importlib .import_module ('pandas' )
347352
348353 builder = DocBuilder (args .num_jobs , not args .no_api , args .single ,
349354 args .verbosity )
0 commit comments