Skip to content

Commit cd913e6

Browse files
committed
Workaround for issues with conf.py values being ignored
Setting any of the configuration variables is only reflected in the ```app.config._raw_config``` dict * The ```app.config``` object always contains the default values from ```app.add_config_value()``` I have no doubt it's something I did wrong but I haven't been able to find anything yet so for now.... this
1 parent e0cec07 commit cd913e6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

sphinx_github_style/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Dict, Any, Optional, Callable
1111

1212

13-
__version__ = "0.0.1b13"
13+
__version__ = "0.0.1b16"
1414
__author__ = 'Adam Korn <hello@dailykitten.net>'
1515

1616

@@ -40,7 +40,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
4040
setattr(app.config, 'html_context', html_context)
4141

4242
linkcode_url = get_linkcode_url(app)
43-
linkcode_func = getattr(app.config, 'linkcode_resolve', None)
43+
linkcode_func = get_conf_val(app, "linkcode_resolve")
4444

4545
if not callable(linkcode_func):
4646
print(
@@ -74,7 +74,7 @@ def get_linkcode_revision(app: Sphinx) -> str:
7474
* ``last_tag``: links to the most recently tagged commit; if no tags exist, uses ``head``
7575
* ``blob``: links to any blob you want, for example ``"master"`` or ``"v2.0.1"``
7676
"""
77-
blob = getattr(app.config, "linkcode_blob", "head")
77+
blob = get_conf_val(app, "linkcode_blob")
7878
if blob == "head":
7979
return get_head()
8080
if blob == 'last_tag':
@@ -127,8 +127,8 @@ def get_linkcode_url(app: Sphinx) -> str:
127127
128128
Formatted into the final link by ``linkcode_resolve()``
129129
"""
130-
context = getattr(app.config, 'html_context', None)
131-
url = app.config._raw_config.get("linkcode_url", None)
130+
context = get_conf_val(app, "html_context")
131+
url = get_conf_val(app, "linkcode_url")
132132

133133
if url is None:
134134
if context is None or not all(context.get(key) for key in ("github_user", "github_repo")):
@@ -207,4 +207,14 @@ def linkcode_resolve(domain, info):
207207
print(f"Final Link for {fullname}: {final_link}")
208208
return final_link
209209

210-
return linkcode_resolve
210+
return linkcode_resolve
211+
212+
213+
def get_conf_val(app: Sphinx, attr: str, default: Any = None) -> Any:
214+
"""Retrieve values from ``conf.py``
215+
216+
Currently unclear why non-default ``conf.py`` values aren't being updated in the config attributes (?)
217+
So checking for values in the ``_raw_config`` dict first, since they *do* get updated
218+
"""
219+
return app.config._raw_config.get(attr, getattr(app.config, attr, default))
220+

0 commit comments

Comments
 (0)