File: __init__.py

package info (click to toggle)
python-boto 2.34.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,584 kB
  • ctags: 10,521
  • sloc: python: 78,553; makefile: 123
file content (55 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (12)
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
"""Add github roles to sphinx docs.

Based entirely on Doug Hellmann's bitbucket version, but
adapted for Github.
(https://bitbucket.org/dhellmann/sphinxcontrib-bitbucket/)

"""
from urlparse import urljoin

from docutils import nodes, utils
from docutils.parsers.rst.roles import set_classes


def make_node(rawtext, app, type_, slug, options):
    base_url = app.config.github_project_url
    if base_url is None:
        raise ValueError(
            "Configuration value for 'github_project_url' is not set.")
    relative = '%s/%s' % (type_, slug)
    full_ref = urljoin(base_url, relative)
    set_classes(options)
    if type_ == 'issues':
        type_ = 'issue'
    node = nodes.reference(rawtext, type_ + ' ' + utils.unescape(slug),
                           refuri=full_ref, **options)
    return node


def github_sha(name, rawtext, text, lineno, inliner,
                 options={}, content=[]):
    app = inliner.document.settings.env.app
    node = make_node(rawtext, app, 'commit', text, options)
    return [node], []


def github_issue(name, rawtext, text, lineno, inliner,
                 options={}, content=[]):
    try:
        issue = int(text)
    except ValueError:
        msg = inliner.reporter.error(
            "Invalid Github Issue '%s', must be an integer" % text,
            line=lineno)
        problem = inliner.problematic(rawtext, rawtext, msg)
        return [problem], [msg]
    app = inliner.document.settings.env.app
    node = make_node(rawtext, app, 'issues', str(issue), options)
    return [node], []


def setup(app):
    app.info('Adding github link roles')
    app.add_role('sha', github_sha)
    app.add_role('issue', github_issue)
    app.add_config_value('github_project_url', None, 'env')