|
5 | 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html
|
6 | 6 |
|
7 | 7 | import sys
|
| 8 | +from importlib import metadata |
| 9 | +from pathlib import Path |
| 10 | +from subprocess import check_output |
8 | 11 |
|
9 | 12 | import requests
|
10 | 13 |
|
11 | 14 | # -- General configuration ------------------------------------------------
|
12 | 15 |
|
13 |
| -# TODO do we want to set this from code? |
14 |
| -version = "1.0" |
15 |
| - |
16 | 16 | # General information about the project.
|
17 | 17 | project = "epics-containers"
|
18 | 18 |
|
| 19 | +# The full version, including alpha/beta/rc tags. |
| 20 | +release = metadata.version(project) |
| 21 | + |
| 22 | +# The short X.Y version. |
| 23 | +if "+" in release: |
| 24 | + # Not on a tag, use branch name |
| 25 | + root = Path(__file__).absolute().parent.parent |
| 26 | + git_branch = check_output("git branch --show-current".split(), cwd=root) |
| 27 | + version = git_branch.decode().strip() |
| 28 | +else: |
| 29 | + version = release |
| 30 | + |
19 | 31 | extensions = [
|
20 | 32 | # Use this for generating API docs
|
21 | 33 | "sphinx.ext.autodoc",
|
|
108 | 120 | html_theme = "pydata_sphinx_theme"
|
109 | 121 | github_repo = "epics-containers.github.io"
|
110 | 122 | github_user = "epics-containers"
|
111 |
| -switcher_json = f"https://{github_user}.github.io/{github_repo}/switcher.json" |
| 123 | +switcher_json = f"https://{github_user}.github.io/switcher.json" |
112 | 124 | switcher_exists = requests.get(switcher_json).ok
|
113 | 125 | if not switcher_exists:
|
114 | 126 | print(
|
|
153 | 165 | # A dictionary of values to pass into the template engine’s context for all pages
|
154 | 166 | html_context = {
|
155 | 167 | "github_user": github_user,
|
156 |
| - "github_repo": project, |
| 168 | + "github_repo": github_repo, |
157 | 169 | "github_version": version,
|
158 | 170 | "doc_path": "docs",
|
159 | 171 | }
|
|
0 commit comments