Created
October 10, 2018 22:08
-
-
Save jay-johnson/d22cee17bf4223ab1081c310056b7c17 to your computer and use it in GitHub Desktop.
read the docs - sphinx conf.py for finding source code from the docs path - example code block from https://stock-analysis-engine.readthedocs.io/en/latest/README.html#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from unittest.mock import MagicMock | |
from recommonmark.parser import CommonMarkParser | |
from pprint import pprint | |
on_rtd = os.getenv("READTHEDOCS", "") != "" | |
# Using working source code sphinx conf.py on read the docs: | |
# https://github.com/mahmoud/boltons/blob/master/docs/conf.py#L20 | |
# If extensions (or modules to document with autodoc) are in another directory, | |
# add these directories to sys.path here. If the directory is relative to the | |
# documentation root, use os.path.abspath to make it absolute, like shown here. | |
CUR_PATH = os.path.dirname(os.path.abspath(__file__)) | |
PROJECT_PATH = os.path.abspath(CUR_PATH + '/../') | |
PACKAGE_SOURCE_PATH_FROM_DOCS = os.path.abspath('../../') | |
sys.path.insert(0, PROJECT_PATH) | |
sys.path.insert(0, PACKAGE_SOURCE_PATH_FROM_DOCS) | |
source_code_dirs = [ | |
'analysis_engine/', | |
'analysis_engine/iex/', | |
'analysis_engine/mocks/', | |
'analysis_engine/scripts/', | |
'analysis_engine/work_tasks/', | |
'analysis_engine/yahoo/' | |
] | |
for source_code_dir_name in source_code_dirs: | |
use_dir = '{}/{}'.format( | |
PACKAGE_SOURCE_PATH_FROM_DOCS, | |
source_code_dir_name) | |
if os.path.exists(use_dir): | |
sys.path.insert(0, use_dir) | |
if on_rtd: | |
os.system('ls -l {}'.format( | |
use_dir)) | |
else: | |
if on_rtd: | |
print('did not find from docs path dir: {}'.format( | |
use_dir)) | |
if on_rtd: | |
print('----------------------') | |
print('cur path: {}'.format( | |
CUR_PATH)) | |
print('paths:') | |
pprint(sys.path) | |
os.system( | |
'echo "source path from docs dir contents:' | |
'dirs: " && ls -l {}'.format( | |
PACKAGE_SOURCE_PATH_FROM_DOCS)) | |
print('----------------------') | |
# end of debugging pathing on read the docs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment