Skip to content

Commit

Permalink
Allow sphinx to import trame.env.paraview
Browse files Browse the repository at this point in the history
This adds an environment variable that allows the module to fail importing
silently. This environment variable is set when running sphinx.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed May 23, 2022
1 parent 95a8356 commit 83b74e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions docs/api/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Configuration file for the Sphinx documentation builder.

import os
from pathlib import Path

from sphinx.ext import apidoc
Expand Down Expand Up @@ -45,6 +46,11 @@

html_theme = "sphinx_rtd_theme"

# -- Modify environment variables --------------------------------------------

os.environ.update({
"TRAME_PARAVIEW_FAIL_SILENTLY": "True",
})

# -- Hooks for sphinx events -------------------------------------------------

Expand Down
26 changes: 15 additions & 11 deletions trame/env/paraview.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `--paraview /path/to/paraview/release` argument
- environment variable `TRAME_PARAVIEW=/path/to/paraview/release`
"""
import os
import platform
import sys

Expand All @@ -19,7 +20,9 @@

PV_HOME = utils.find_env_setting("--paraview", "TRAME_PARAVIEW")

if PV_HOME is None:
RAISE_ERRORS = os.getenv("TRAME_PARAVIEW_FAIL_SILENTLY") is None

if PV_HOME is None and RAISE_ERRORS:
msg = (
"trame.env.paraview was imported, but the paraview location was not "
"defined. Define it with either the argument '--paraview <path>' or "
Expand All @@ -44,13 +47,14 @@ def windows_paths():
"Windows": windows_paths,
}

if PV_HOME and platform.system() == "Darwin":
env_paths = {
"PYTHONPATH": ["Contents/Python"],
"DYLD_LIBRARY_PATH": ["Contents/Libraries"],
}
utils.rerun(PV_HOME, env_paths, ["PV_VENV", "VTK_VENV"])
else:
PV_LOADED = utils.prepend_python_path(PV_HOME, search_paths_dict)
if not PV_LOADED:
raise Exception(f"Failed to add paraview python libraries at {PV_HOME}")
if PV_HOME:
if platform.system() == "Darwin":
env_paths = {
"PYTHONPATH": ["Contents/Python"],
"DYLD_LIBRARY_PATH": ["Contents/Libraries"],
}
utils.rerun(PV_HOME, env_paths, ["PV_VENV", "VTK_VENV"])
else:
PV_LOADED = utils.prepend_python_path(PV_HOME, search_paths_dict)
if not PV_LOADED and RAISE_ERRORS:
raise Exception(f"Failed to add paraview python libraries at {PV_HOME}")

0 comments on commit 83b74e6

Please sign in to comment.