From fa0ff37930b18dc29e31e4b77d379c09696d1aae Mon Sep 17 00:00:00 2001 From: Douglas RAILLARD Date: Fri, 3 May 2019 11:21:14 +0100 Subject: [PATCH] doc: source init_env for ReadTheDocs setup source init_env from conf.py, since it is the only place we can hook into to execute code for RTD. This allows getting all environment variable defined as on a regular setup, which is needed to generate parts of the documentation. --- doc/conf.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index a12c301d8..adf126d66 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -18,6 +18,8 @@ import re import subprocess import sys import unittest +import textwrap +import json from docutils import nodes from sphinx.util.docfields import TypedField @@ -30,6 +32,7 @@ sys.path.insert(0, os.path.abspath('../')) # Import our packages after modifying sys.path import lisa +from lisa.utils import LISA_HOME from lisa.doc.helpers import ( autodoc_process_test_method, autodoc_process_analysis_events ) @@ -82,6 +85,35 @@ def patched_make_field(self, types, domain, items, env=None): TypedField.make_field = patched_make_field + +RTD = (os.getenv('READTHEDOCS') == 'True') + +# For ReadTheDocs only: source init_env and get all env var defined by it. +if RTD: + source_env = { + **os.environ, + # LISA_USE_VENV=0 will avoid re-installing LISA automatically, + # which would be useless. + 'LISA_USE_VENV': '0', + } + # If LISA_HOME is set, sourcing the script won't work + source_env.pop('LISA_HOME', None) + + script = textwrap.dedent( + """ + source init_env >&2 && + python -c 'import os, json; print(json.dumps(dict(os.environ)))' + """ + ) + out = subprocess.check_output( + ['bash', '-c', script], + cwd=LISA_HOME, + # Reset the environment, including LISA_HOME to allow sourcing without + # any issue + env=source_env, + ) + os.environ.update(json.loads(out)) + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -- GitLab