-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.py
80 lines (68 loc) · 2.92 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, select_autoescape
from typing import Optional
from documenteer.conf.guide import * # noqa: F401 F403
from rspdocs.phalanx.service import PhalanxEnvService
from rspdocs.phalanx.models import PhalanxEnv
env_cache_path = Path(__file__).parent.joinpath(".phalanxenvs.json")
env_service = PhalanxEnvService.load_from_cache_file(env_cache_path)
# Select the environment given the sphinx tag (-t on sphinx-build CLI)
# Default to the primary env if a tag is not set.
env_names = env_service.envs.env_names
rsp_env: Optional[PhalanxEnv] = None
for env_name in env_names:
if env_name in tags: # noqa: F405 F821
rsp_env = env_service.envs[env_name]
break
if rsp_env is None:
rsp_env = env_service.envs.primary
_config_template_loader = FileSystemLoader(".")
_jinja_env = Environment(
loader=_config_template_loader, autoescape=select_autoescape()
)
rst_epilog = _jinja_env.get_template("rst_epilog.rst.jinja").render(
env=rsp_env
)
# Configure Jinja Sphinx extension
jinja_contexts = {"rsp": {"env": rsp_env, "all_envs": env_service.envs}}
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = [
"**/*.in.rst", # rst files meant to be used for include directives
"**/*.rst.jinja", # Jinja templates for sphinx-jinja
]
# Ignore specific files that are ignored because the relevant services
# aren't available in that environment.
if not rsp_env.portal_url:
exclude_patterns.append("guides/portal/**/*.rst")
exclude_patterns.append("guides/getting-started/portal-first-steps.rst")
if not rsp_env.nb_url:
exclude_patterns.append("guides/nb/**/*.rst")
exclude_patterns.append("guides/getting-started/notebook-first-steps.rst")
if not rsp_env.api_tap_url:
exclude_patterns.append("guides/auth/using-topcat-outside-rsp.rst")
if not rsp_env.times_square_url:
exclude_patterns.append("guides/times-square/*.rst")
exclude_patterns.append("guides/times-square/**/*.rst")
# Add environment switcher
version = rsp_env.title # noqa: F405
html_theme_options["switcher"] = { # noqa: F405
"json_url": (
"https://gist.githubusercontent.com/jonathansick/bbe902507790911d4017"
"3f11a4a1a256/raw/50267ee4dc957bd817e93a12c79a1702377e6ae1"
"/rsp-versions.json"
),
"version_match": rsp_env.title,
}
html_theme_options["navbar_center"] = [ # noqa: F405
"version-switcher",
"navbar-nav",
]
html_theme_options["navbar_align"] = "left" # noqa: F405
# Update doc_path for the "Edit on GitHub" link. The DocumenteerGuide preset
# doesn't work here because docs/ doesn't contain the Sphinx conf.py.
html_context["doc_path"] = "docs" # noqa: F405
html_static_path.append("docs/_static/versions.json") # noqa: F405
# Delete any objects that needn't be pickled with the Sphinx configuration
del _config_template_loader
del _jinja_env