doc: scripts: Retrieve west path at runtime
Since west is no longer part of the Zephyr tree, we can no longer hardcode its path anymore. Instead, use west itself to retrieve its path, in order to point the documentation build to the correct active west installation. This is optional, and the documentation build will still work if west is not installed on the system. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
1b5bed04e2
commit
8d5259af04
4 changed files with 43 additions and 9 deletions
27
doc/conf.py
27
doc/conf.py
|
@ -14,6 +14,7 @@
|
|||
|
||||
import sys
|
||||
import os
|
||||
from subprocess import CalledProcessError, check_output, DEVNULL
|
||||
|
||||
if "ZEPHYR_BASE" not in os.environ:
|
||||
sys.exit("$ZEPHYR_BASE environment variable undefined.")
|
||||
|
@ -26,11 +27,23 @@ ZEPHYR_BUILD = os.path.abspath(os.environ["ZEPHYR_BUILD"])
|
|||
# Add the 'extensions' directory to sys.path, to enable finding Sphinx
|
||||
# extensions within.
|
||||
sys.path.insert(0, os.path.join(ZEPHYR_BASE, 'doc', 'extensions'))
|
||||
# Also add west, to be able to pull in its API docs.
|
||||
sys.path.append(os.path.join(ZEPHYR_BASE, 'scripts', 'meta'))
|
||||
# HACK: also add the runners module, to work around some import issues
|
||||
# related to west's current packaging.
|
||||
sys.path.append(os.path.join(ZEPHYR_BASE, 'scripts', 'meta', 'west'))
|
||||
|
||||
west_found = False
|
||||
|
||||
try:
|
||||
desc = check_output(['west', 'list', '-f{abspath}', 'west'],
|
||||
stderr=DEVNULL,
|
||||
cwd=os.path.dirname(__file__))
|
||||
west_path = desc.decode(sys.getdefaultencoding()).strip()
|
||||
# Add west, to be able to pull in its API docs.
|
||||
sys.path.append(os.path.join(west_path, 'src'))
|
||||
west_found = True
|
||||
except FileNotFoundError as e:
|
||||
# west not installed
|
||||
pass
|
||||
except CalledProcessError as e:
|
||||
# west not able to list itself
|
||||
pass
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
|
@ -119,6 +132,10 @@ language = None
|
|||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
if not west_found:
|
||||
exclude_patterns.append('**/*west-apis*')
|
||||
else:
|
||||
exclude_patterns.append('**/*west-not-found*')
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
|
|
|
@ -221,10 +221,7 @@ upstream Zephyr, the runner should be added into a new or existing
|
|||
measure; when West learns how to manage multiple repositories, the
|
||||
copy will be removed.
|
||||
|
||||
API documentation for the core module follows.
|
||||
|
||||
.. automodule:: west.runners.core
|
||||
:members:
|
||||
API documentation for the core module can be found in :ref:`west-apis`.
|
||||
|
||||
Doing it By Hand
|
||||
****************
|
||||
|
|
10
doc/west/west-apis.rst
Normal file
10
doc/west/west-apis.rst
Normal file
|
@ -0,0 +1,10 @@
|
|||
:orphan:
|
||||
|
||||
.. _west-apis:
|
||||
|
||||
West APIs
|
||||
#########
|
||||
|
||||
.. automodule:: west.runners.core
|
||||
:members:
|
||||
|
10
doc/west/west-not-found.rst
Normal file
10
doc/west/west-not-found.rst
Normal file
|
@ -0,0 +1,10 @@
|
|||
:orphan:
|
||||
|
||||
.. _west-apis:
|
||||
|
||||
West APIs
|
||||
#########
|
||||
|
||||
The west APIs are not documented since west was missing during the
|
||||
documentation build.
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue