Skip to content

Commit

Permalink
Gives up and just mocks everything when running on ReadTheDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Sybrandt committed Apr 30, 2020
1 parent 6db61f3 commit 640f994
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
14 changes: 0 additions & 14 deletions .readthedocs_mocked_requirements.txt

This file was deleted.

33 changes: 27 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../build_util'))
sys.path.insert(0, os.path.abspath('../agatha'))
import deps_util


# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -77,10 +75,33 @@
# If we are running on ReadTheDocs then we are going to have to mock up some
# expensive imports. Therefore, we did NOT install anything in the
# readthedocs_mocked_requirements file. These must be mocked instead.
if deps_util.running_on_read_the_docs():
autodoc_mock_imports = deps_util.parse_requirements(
"../.readthedocs_mocked_requirements.txt"
)
if "READTHEDOCS" in os.environ and os.environ["READTHEDOCS"].lower() == "true":
autodoc_mock_imports = [
'cloudpickle',
'dask',
'distributed',
'faiss',
'fsspec',
'gdown',
'gensim',
'h5py',
'lxml',
'networkx',
'nltk',
'numpy',
'pandas',
'protobuf',
'pygsheets',
'pytest',
'pytorch_lightning',
'scispacy',
'sentencepiece',
'spacy',
'sqlitedict',
'torch',
'tqdm',
'transformers',
]

# -- Options for HTML output -------------------------------------------------

Expand Down
29 changes: 17 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
import subprocess
import sys
import agatha
from build_util import deps_util

def parse_requirements(deps_path):
res = []
with open(deps_path) as req_file:
for line in req_file:
line = line.strip()
if len(line) > 0 and line[0] != '#':
res.append(line)
return res

proto_src_files = [
"agatha/config/config.proto",
Expand Down Expand Up @@ -82,17 +90,14 @@ class Install(_install):
def run(self):
_install.do_egg_install(self)

# Parse the requirements file
requirements = deps_util.parse_requirements("requirements.txt")
# If we are running on ReadTheDocs then we are going to have to mock up some
# expensive imports. Therefore, we do NOT want to install anything in the
# readthedocs_mocked_requirements file.
if deps_util.running_on_read_the_docs():
mock_path = ".readthedocs_mocked_requirements.txt"
print("REMOVING DEPENDENCIES FOUND IN", mock_path)
removed_reqs = deps_util.parse_requirements(mock_path)
requirements = list(set(requirements)-set(removed_reqs))
print("REMOVED:", removed_reqs)

# If running on ReadTheDocs, DO NOT install dependencies. Everything must be
# specified in the autodoc_mock_imports variable in docs/conf.py
if "READTHEDOCS" in os.environ and os.environ["READTHEDOCS"].lower() == "true":
requirements = []
else:
# Parse the requirements file
requirements = parse_requirements("requirements.txt")

setup(
name='Agatha',
Expand Down

0 comments on commit 640f994

Please sign in to comment.