add config option to point to the cgit browser
Add a configuration option to let projects set the URL to the cgit browser for their source. Still try to guess at the location based on our git URL. Change-Id: I11455f8a137a029c28a864eb555f69f6c282840b
This commit is contained in:
parent
cd2674bb95
commit
c383e0026a
@ -26,6 +26,8 @@ extensions = [
|
|||||||
'oslosphinx'
|
'oslosphinx'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
oslosphinx_cgit_link = 'http://git.openstack.org/cgit/openstack/oslosphinx'
|
||||||
|
|
||||||
# autodoc generation is a bit aggressive and a nuisance when doing heavy
|
# autodoc generation is a bit aggressive and a nuisance when doing heavy
|
||||||
# text edit cycles.
|
# text edit cycles.
|
||||||
# execute "export SPHINX_DEBUG=1" in your terminal to disable
|
# execute "export SPHINX_DEBUG=1" in your terminal to disable
|
||||||
|
@ -13,3 +13,14 @@ If you are an incubating project, set::
|
|||||||
html_theme_options = {'incubating': True}
|
html_theme_options = {'incubating': True}
|
||||||
|
|
||||||
in your conf.py as well, to enable the Incubation theme.
|
in your conf.py as well, to enable the Incubation theme.
|
||||||
|
|
||||||
|
Linking to a Source Repository
|
||||||
|
==============================
|
||||||
|
|
||||||
|
``oslosphinx`` defines a configuration option ``oslosphinx_cgit_link``
|
||||||
|
which should be the URL to the git repository browser for the project
|
||||||
|
being documented. The default is a guess, and will be right for a lot
|
||||||
|
of projects, but to ensure that it is correct in all situations it is
|
||||||
|
best to set the value in conf.py::
|
||||||
|
|
||||||
|
oslosphinx_cgit_link = 'http://git.openstack.org/cgit/openstack/oslosphinx'
|
||||||
|
@ -18,22 +18,24 @@ import subprocess
|
|||||||
|
|
||||||
|
|
||||||
CGIT_BASE = 'http://git.openstack.org/cgit/'
|
CGIT_BASE = 'http://git.openstack.org/cgit/'
|
||||||
_cgit_link = None
|
|
||||||
|
|
||||||
|
|
||||||
def _html_page_context(app, pagename, templatename, context, doctree):
|
def _guess_cgit_link():
|
||||||
global _cgit_link
|
|
||||||
if _cgit_link is None:
|
|
||||||
try:
|
try:
|
||||||
git_remote = subprocess.check_output(
|
git_remote = subprocess.check_output(
|
||||||
['git', 'config', '--local', '--get', 'remote.origin.url']
|
['git', 'config', '--local', '--get', 'remote.origin.url']
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
_cgit_link = 'unknown'
|
return None
|
||||||
else:
|
else:
|
||||||
parsed = parse.urlparse(git_remote)
|
parsed = parse.urlparse(git_remote)
|
||||||
_cgit_link = CGIT_BASE + parsed.path.lstrip('/')
|
return CGIT_BASE + parsed.path.lstrip('/')
|
||||||
context['cgit_link'] = _cgit_link
|
|
||||||
|
|
||||||
|
def _html_page_context(app, pagename, templatename, context, doctree):
|
||||||
|
# Insert the cgit link into the template context.
|
||||||
|
context['cgit_link'] = app.config.oslosphinx_cgit_link
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
def builder_inited(app):
|
def builder_inited(app):
|
||||||
@ -60,3 +62,7 @@ def builder_inited(app):
|
|||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.connect('builder-inited', builder_inited)
|
app.connect('builder-inited', builder_inited)
|
||||||
|
# Try to guess at the default value for where the cgit repository
|
||||||
|
# is.
|
||||||
|
cgit_link = _guess_cgit_link()
|
||||||
|
app.add_config_value('oslosphinx_cgit_link', cgit_link, 'env')
|
||||||
|
Loading…
Reference in New Issue
Block a user