Skip to content

Commit fe61299

Browse files
WillAydjorisvandenbossche
authored andcommitted
DOC: fixed dynamic import mechanics of make.py (pandas-dev#20005)
1 parent 8a084eb commit fe61299

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

doc/make.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$ python make.py html
1212
$ python make.py latex
1313
"""
14+
import importlib
1415
import sys
1516
import os
1617
import shutil
@@ -20,8 +21,6 @@
2021
import webbrowser
2122
import jinja2
2223

23-
import pandas
24-
2524

2625
DOC_PATH = os.path.dirname(os.path.abspath(__file__))
2726
SOURCE_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

Comments
 (0)