##// END OF EJS Templates
add github extension for easy links to issues/pulls....
MinRK -
Show More
@@ -0,0 +1,155 b''
1 """Define text roles for GitHub
2
3 * ghissue - Issue
4 * ghpull - Pull Request
5 * ghuser - User
6
7 Adapted from bitbucket example here:
8 https://bitbucket.org/birkenfeld/sphinx-contrib/src/tip/bitbucket/sphinxcontrib/bitbucket.py
9
10 Authors
11 -------
12
13 * Doug Hellmann
14 * Min RK
15 """
16 #
17 # Original Copyright (c) 2010 Doug Hellmann. All rights reserved.
18 #
19
20 from docutils import nodes, utils
21 from docutils.parsers.rst.roles import set_classes
22
23 def make_link_node(rawtext, app, type, slug, options):
24 """Create a link to a github resource.
25
26 :param rawtext: Text being replaced with link node.
27 :param app: Sphinx application context
28 :param type: Link type (issue, changeset, etc.)
29 :param slug: ID of the thing to link to
30 :param options: Options dictionary passed to role func.
31 """
32
33 try:
34 base = app.config.github_project_url
35 if not base:
36 raise AttributeError
37 if not base.endswith('/'):
38 base += '/'
39 except AttributeError, err:
40 raise ValueError('github_project_url configuration value is not set (%s)' % str(err))
41
42 ref = base + type + '/' + slug + '/'
43 set_classes(options)
44 prefix = "#"
45 if type == 'pull':
46 prefix = "PR " + prefix
47 node = nodes.reference(rawtext, prefix + utils.unescape(slug), refuri=ref,
48 **options)
49 return node
50
51 def ghissue_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
52 """Link to a GitHub issue.
53
54 Returns 2 part tuple containing list of nodes to insert into the
55 document and a list of system messages. Both are allowed to be
56 empty.
57
58 :param name: The role name used in the document.
59 :param rawtext: The entire markup snippet, with role.
60 :param text: The text marked with the role.
61 :param lineno: The line number where rawtext appears in the input.
62 :param inliner: The inliner instance that called us.
63 :param options: Directive options for customization.
64 :param content: The directive content for customization.
65 """
66
67 try:
68 issue_num = int(text)
69 if issue_num <= 0:
70 raise ValueError
71 except ValueError:
72 msg = inliner.reporter.error(
73 'GitHub issue number must be a number greater than or equal to 1; '
74 '"%s" is invalid.' % text, line=lineno)
75 prb = inliner.problematic(rawtext, rawtext, msg)
76 return [prb], [msg]
77 app = inliner.document.settings.env.app
78 #app.info('issue %r' % text)
79 if 'pull' in name.lower():
80 category = 'pull'
81 elif 'issue' in name.lower():
82 category = 'issue'
83 else:
84 msg = inliner.reporter.error(
85 'GitHub roles include "ghpull" and "ghissue", '
86 '"%s" is invalid.' % name, line=lineno)
87 prb = inliner.problematic(rawtext, rawtext, msg)
88 return [prb], [msg]
89 node = make_link_node(rawtext, app, category, str(issue_num), options)
90 return [node], []
91
92 def ghuser_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
93 """Link to a GitHub user.
94
95 Returns 2 part tuple containing list of nodes to insert into the
96 document and a list of system messages. Both are allowed to be
97 empty.
98
99 :param name: The role name used in the document.
100 :param rawtext: The entire markup snippet, with role.
101 :param text: The text marked with the role.
102 :param lineno: The line number where rawtext appears in the input.
103 :param inliner: The inliner instance that called us.
104 :param options: Directive options for customization.
105 :param content: The directive content for customization.
106 """
107 app = inliner.document.settings.env.app
108 #app.info('user link %r' % text)
109 ref = 'https://www.github.com/' + text
110 node = nodes.reference(rawtext, text, refuri=ref, **options)
111 return [node], []
112
113 def ghcommit_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
114 """Link to a GitHub commit.
115
116 Returns 2 part tuple containing list of nodes to insert into the
117 document and a list of system messages. Both are allowed to be
118 empty.
119
120 :param name: The role name used in the document.
121 :param rawtext: The entire markup snippet, with role.
122 :param text: The text marked with the role.
123 :param lineno: The line number where rawtext appears in the input.
124 :param inliner: The inliner instance that called us.
125 :param options: Directive options for customization.
126 :param content: The directive content for customization.
127 """
128 app = inliner.document.settings.env.app
129 #app.info('user link %r' % text)
130 try:
131 base = app.config.github_project_url
132 if not base:
133 raise AttributeError
134 if not base.endswith('/'):
135 base += '/'
136 except AttributeError, err:
137 raise ValueError('github_project_url configuration value is not set (%s)' % str(err))
138
139 ref = base + text
140 node = nodes.reference(rawtext, text[:6], refuri=ref, **options)
141 return [node], []
142
143
144 def setup(app):
145 """Install the plugin.
146
147 :param app: Sphinx application context.
148 """
149 app.info('Initializing GitHub plugin')
150 app.add_role('ghissue', ghissue_role)
151 app.add_role('ghpull', ghissue_role)
152 app.add_role('ghuser', ghuser_role)
153 app.add_role('ghcommit', ghcommit_role)
154 app.add_config_value('github_project_url', None, 'env')
155 return
@@ -1,195 +1,199 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 #
2 #
3 # IPython documentation build configuration file.
3 # IPython documentation build configuration file.
4
4
5 # NOTE: This file has been edited manually from the auto-generated one from
5 # NOTE: This file has been edited manually from the auto-generated one from
6 # sphinx. Do NOT delete and re-generate. If any changes from sphinx are
6 # sphinx. Do NOT delete and re-generate. If any changes from sphinx are
7 # needed, generate a scratch one and merge by hand any new fields needed.
7 # needed, generate a scratch one and merge by hand any new fields needed.
8
8
9 #
9 #
10 # This file is execfile()d with the current directory set to its containing dir.
10 # This file is execfile()d with the current directory set to its containing dir.
11 #
11 #
12 # The contents of this file are pickled, so don't put values in the namespace
12 # The contents of this file are pickled, so don't put values in the namespace
13 # that aren't pickleable (module imports are okay, they're removed automatically).
13 # that aren't pickleable (module imports are okay, they're removed automatically).
14 #
14 #
15 # All configuration values have a default value; values that are commented out
15 # All configuration values have a default value; values that are commented out
16 # serve to show the default value.
16 # serve to show the default value.
17
17
18 import sys, os
18 import sys, os
19
19
20 # If your extensions are in another directory, add it here. If the directory
20 # If your extensions are in another directory, add it here. If the directory
21 # is relative to the documentation root, use os.path.abspath to make it
21 # is relative to the documentation root, use os.path.abspath to make it
22 # absolute, like shown here.
22 # absolute, like shown here.
23 sys.path.insert(0, os.path.abspath('../sphinxext'))
23 sys.path.insert(0, os.path.abspath('../sphinxext'))
24
24
25 # Import support for ipython console session syntax highlighting (lives
25 # Import support for ipython console session syntax highlighting (lives
26 # in the sphinxext directory defined above)
26 # in the sphinxext directory defined above)
27 import ipython_console_highlighting
27 import ipython_console_highlighting
28
28
29 # We load the ipython release info into a dict by explicit execution
29 # We load the ipython release info into a dict by explicit execution
30 iprelease = {}
30 iprelease = {}
31 execfile('../../IPython/core/release.py',iprelease)
31 execfile('../../IPython/core/release.py',iprelease)
32
32
33 # General configuration
33 # General configuration
34 # ---------------------
34 # ---------------------
35
35
36 # Add any Sphinx extension module names here, as strings. They can be extensions
36 # Add any Sphinx extension module names here, as strings. They can be extensions
37 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
37 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
38 extensions = [
38 extensions = [
39 # 'matplotlib.sphinxext.mathmpl',
39 # 'matplotlib.sphinxext.mathmpl',
40 'matplotlib.sphinxext.only_directives',
40 'matplotlib.sphinxext.only_directives',
41 # 'matplotlib.sphinxext.plot_directive',
41 # 'matplotlib.sphinxext.plot_directive',
42 'sphinx.ext.autodoc',
42 'sphinx.ext.autodoc',
43 'sphinx.ext.doctest',
43 'sphinx.ext.doctest',
44 'inheritance_diagram',
44 'inheritance_diagram',
45 'ipython_console_highlighting',
45 'ipython_console_highlighting',
46 'numpydoc', # to preprocess docstrings
46 'numpydoc', # to preprocess docstrings
47 'github', # for easy GitHub links
47 ]
48 ]
48
49
49 # Add any paths that contain templates here, relative to this directory.
50 # Add any paths that contain templates here, relative to this directory.
50 templates_path = ['_templates']
51 templates_path = ['_templates']
51
52
52 # The suffix of source filenames.
53 # The suffix of source filenames.
53 source_suffix = '.txt'
54 source_suffix = '.txt'
54
55
55 # The master toctree document.
56 # The master toctree document.
56 master_doc = 'index'
57 master_doc = 'index'
57
58
58 # General substitutions.
59 # General substitutions.
59 project = 'IPython'
60 project = 'IPython'
60 copyright = '2008, The IPython Development Team'
61 copyright = '2008, The IPython Development Team'
61
62
63 # ghissue config
64 github_project_url = "https://github.com/ipython/ipython"
65
62 # The default replacements for |version| and |release|, also used in various
66 # The default replacements for |version| and |release|, also used in various
63 # other places throughout the built documents.
67 # other places throughout the built documents.
64 #
68 #
65 # The full version, including alpha/beta/rc tags.
69 # The full version, including alpha/beta/rc tags.
66 release = iprelease['version']
70 release = iprelease['version']
67 # The short X.Y version.
71 # The short X.Y version.
68 version = '.'.join(release.split('.',2)[:2])
72 version = '.'.join(release.split('.',2)[:2])
69
73
70
74
71 # There are two options for replacing |today|: either, you set today to some
75 # There are two options for replacing |today|: either, you set today to some
72 # non-false value, then it is used:
76 # non-false value, then it is used:
73 #today = ''
77 #today = ''
74 # Else, today_fmt is used as the format for a strftime call.
78 # Else, today_fmt is used as the format for a strftime call.
75 today_fmt = '%B %d, %Y'
79 today_fmt = '%B %d, %Y'
76
80
77 # List of documents that shouldn't be included in the build.
81 # List of documents that shouldn't be included in the build.
78 #unused_docs = []
82 #unused_docs = []
79
83
80 # List of directories, relative to source directories, that shouldn't be searched
84 # List of directories, relative to source directories, that shouldn't be searched
81 # for source files.
85 # for source files.
82 exclude_dirs = ['attic']
86 exclude_dirs = ['attic']
83
87
84 # If true, '()' will be appended to :func: etc. cross-reference text.
88 # If true, '()' will be appended to :func: etc. cross-reference text.
85 #add_function_parentheses = True
89 #add_function_parentheses = True
86
90
87 # If true, the current module name will be prepended to all description
91 # If true, the current module name will be prepended to all description
88 # unit titles (such as .. function::).
92 # unit titles (such as .. function::).
89 #add_module_names = True
93 #add_module_names = True
90
94
91 # If true, sectionauthor and moduleauthor directives will be shown in the
95 # If true, sectionauthor and moduleauthor directives will be shown in the
92 # output. They are ignored by default.
96 # output. They are ignored by default.
93 #show_authors = False
97 #show_authors = False
94
98
95 # The name of the Pygments (syntax highlighting) style to use.
99 # The name of the Pygments (syntax highlighting) style to use.
96 pygments_style = 'sphinx'
100 pygments_style = 'sphinx'
97
101
98
102
99 # Options for HTML output
103 # Options for HTML output
100 # -----------------------
104 # -----------------------
101
105
102 # The style sheet to use for HTML and HTML Help pages. A file of that name
106 # The style sheet to use for HTML and HTML Help pages. A file of that name
103 # must exist either in Sphinx' static/ path, or in one of the custom paths
107 # must exist either in Sphinx' static/ path, or in one of the custom paths
104 # given in html_static_path.
108 # given in html_static_path.
105 html_style = 'default.css'
109 html_style = 'default.css'
106
110
107 # The name for this set of Sphinx documents. If None, it defaults to
111 # The name for this set of Sphinx documents. If None, it defaults to
108 # "<project> v<release> documentation".
112 # "<project> v<release> documentation".
109 #html_title = None
113 #html_title = None
110
114
111 # The name of an image file (within the static path) to place at the top of
115 # The name of an image file (within the static path) to place at the top of
112 # the sidebar.
116 # the sidebar.
113 #html_logo = None
117 #html_logo = None
114
118
115 # Add any paths that contain custom static files (such as style sheets) here,
119 # Add any paths that contain custom static files (such as style sheets) here,
116 # relative to this directory. They are copied after the builtin static files,
120 # relative to this directory. They are copied after the builtin static files,
117 # so a file named "default.css" will overwrite the builtin "default.css".
121 # so a file named "default.css" will overwrite the builtin "default.css".
118 html_static_path = ['_static']
122 html_static_path = ['_static']
119
123
120 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
124 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
121 # using the given strftime format.
125 # using the given strftime format.
122 html_last_updated_fmt = '%b %d, %Y'
126 html_last_updated_fmt = '%b %d, %Y'
123
127
124 # If true, SmartyPants will be used to convert quotes and dashes to
128 # If true, SmartyPants will be used to convert quotes and dashes to
125 # typographically correct entities.
129 # typographically correct entities.
126 #html_use_smartypants = True
130 #html_use_smartypants = True
127
131
128 # Custom sidebar templates, maps document names to template names.
132 # Custom sidebar templates, maps document names to template names.
129 #html_sidebars = {}
133 #html_sidebars = {}
130
134
131 # Additional templates that should be rendered to pages, maps page names to
135 # Additional templates that should be rendered to pages, maps page names to
132 # template names.
136 # template names.
133 #html_additional_pages = {}
137 #html_additional_pages = {}
134
138
135 # If false, no module index is generated.
139 # If false, no module index is generated.
136 #html_use_modindex = True
140 #html_use_modindex = True
137
141
138 # If true, the reST sources are included in the HTML build as _sources/<name>.
142 # If true, the reST sources are included in the HTML build as _sources/<name>.
139 #html_copy_source = True
143 #html_copy_source = True
140
144
141 # If true, an OpenSearch description file will be output, and all pages will
145 # If true, an OpenSearch description file will be output, and all pages will
142 # contain a <link> tag referring to it. The value of this option must be the
146 # contain a <link> tag referring to it. The value of this option must be the
143 # base URL from which the finished HTML is served.
147 # base URL from which the finished HTML is served.
144 #html_use_opensearch = ''
148 #html_use_opensearch = ''
145
149
146 # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
150 # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
147 #html_file_suffix = ''
151 #html_file_suffix = ''
148
152
149 # Output file base name for HTML help builder.
153 # Output file base name for HTML help builder.
150 htmlhelp_basename = 'ipythondoc'
154 htmlhelp_basename = 'ipythondoc'
151
155
152
156
153 # Options for LaTeX output
157 # Options for LaTeX output
154 # ------------------------
158 # ------------------------
155
159
156 # The paper size ('letter' or 'a4').
160 # The paper size ('letter' or 'a4').
157 latex_paper_size = 'letter'
161 latex_paper_size = 'letter'
158
162
159 # The font size ('10pt', '11pt' or '12pt').
163 # The font size ('10pt', '11pt' or '12pt').
160 latex_font_size = '11pt'
164 latex_font_size = '11pt'
161
165
162 # Grouping the document tree into LaTeX files. List of tuples
166 # Grouping the document tree into LaTeX files. List of tuples
163 # (source start file, target name, title, author, document class [howto/manual]).
167 # (source start file, target name, title, author, document class [howto/manual]).
164
168
165 latex_documents = [
169 latex_documents = [
166 ('index', 'ipython.tex', 'IPython Documentation',
170 ('index', 'ipython.tex', 'IPython Documentation',
167 ur"""The IPython Development Team""", 'manual', True),
171 ur"""The IPython Development Team""", 'manual', True),
168 ('parallel/winhpc_index', 'winhpc_whitepaper.tex',
172 ('parallel/winhpc_index', 'winhpc_whitepaper.tex',
169 'Using IPython on Windows HPC Server 2008',
173 'Using IPython on Windows HPC Server 2008',
170 ur"Brian E. Granger", 'manual', True)
174 ur"Brian E. Granger", 'manual', True)
171 ]
175 ]
172
176
173 # The name of an image file (relative to this directory) to place at the top of
177 # The name of an image file (relative to this directory) to place at the top of
174 # the title page.
178 # the title page.
175 #latex_logo = None
179 #latex_logo = None
176
180
177 # For "manual" documents, if this is true, then toplevel headings are parts,
181 # For "manual" documents, if this is true, then toplevel headings are parts,
178 # not chapters.
182 # not chapters.
179 #latex_use_parts = False
183 #latex_use_parts = False
180
184
181 # Additional stuff for the LaTeX preamble.
185 # Additional stuff for the LaTeX preamble.
182 #latex_preamble = ''
186 #latex_preamble = ''
183
187
184 # Documents to append as an appendix to all manuals.
188 # Documents to append as an appendix to all manuals.
185 #latex_appendices = []
189 #latex_appendices = []
186
190
187 # If false, no module index is generated.
191 # If false, no module index is generated.
188 latex_use_modindex = True
192 latex_use_modindex = True
189
193
190
194
191 # Cleanup
195 # Cleanup
192 # -------
196 # -------
193 # delete release info to avoid pickling errors from sphinx
197 # delete release info to avoid pickling errors from sphinx
194
198
195 del iprelease
199 del iprelease
General Comments 0
You need to be logged in to leave comments. Login now