Skip to content

Commit 327881c

Browse files
committed
docs: Fix missing Edit Page button on stable branches
1 parent 07b5a6f commit 327881c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

docs/source/conf.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# -*- coding: utf-8 -*-
2-
#
2+
33
# Mypy documentation build configuration file, created by
44
# sphinx-quickstart on Sun Sep 14 19:50:35 2014.
5-
#
5+
66
# This file is execfile()d with the current directory set to its
77
# containing dir.
8-
#
8+
99
# Note that not all possible configuration values are present in this
1010
# autogenerated file.
11-
#
11+
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

@@ -112,9 +112,27 @@
112112
# a list of builtin themes.
113113
html_theme = "furo"
114114

115+
import os
116+
import subprocess
117+
118+
def get_git_branch():
119+
try:
120+
# Check if running on ReadTheDocs
121+
if os.environ.get("READTHEDOCS") == "True":
122+
return os.environ.get("READTHEDOCS_GIT_IDENTIFIER", "master")
123+
124+
# Otherwise, get the current branch from git locally
125+
return subprocess.check_output(
126+
["git", "rev-parse", "--abbrev-ref", "HEAD"]
127+
).decode("utf-8").strip()
128+
except Exception:
129+
return "master"
130+
131+
current_branch = get_git_branch()
132+
115133
html_theme_options = {
116134
"source_repository": "https://github.com/python/mypy",
117-
"source_branch": "master",
135+
"source_branch": current_branch,
118136
"source_directory": "docs/source",
119137
}
120138

0 commit comments

Comments
 (0)