|
13 | 13 |
|
14 | 14 | import sys, os |
15 | 15 |
|
16 | | -building_web = int(os.environ.get('BUILDING_WEB', '0')) |
17 | | - |
18 | 16 | # If extensions (or modules to document with autodoc) are in another directory, |
19 | 17 | # add these directories to sys.path here. If the directory is relative to the |
20 | 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
|
24 | 22 |
|
25 | 23 | # Add any Sphinx extension module names here, as strings. They can be extensions |
26 | 24 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. |
27 | | -extensions = [ ] |
| 25 | +extensions = [ 'sphinxcontrib.bitbucket' ] |
28 | 26 |
|
29 | 27 | bitbucket_project_url = 'http://bitbucket.org/dhellmann/virtualenvwrapper/' |
30 | 28 |
|
|
196 | 194 |
|
197 | 195 | # If false, no module index is generated. |
198 | 196 | #latex_use_modindex = True |
199 | | - |
200 | | -from docutils import nodes, utils |
201 | | -from docutils.parsers.rst.roles import set_classes |
202 | | - |
203 | | -def make_link_node(rawtext, app, type, slug, options): |
204 | | - """Create a link to a BitBucket resource. |
205 | | -
|
206 | | - :param rawtext: Text being replaced with link node. |
207 | | - :param app: Sphinx application context |
208 | | - :param type: Link type (issue, changeset, etc.) |
209 | | - :param slug: ID of the thing to link to |
210 | | - :param options: Options dictionary passed to role func. |
211 | | - """ |
212 | | - # |
213 | | - try: |
214 | | - base = app.config.bitbucket_project_url |
215 | | - if not base: |
216 | | - raise AttributeError |
217 | | - except AttributeError, err: |
218 | | - raise ValueError('bitbucket_project_url configuration value is not set (%s)' % str(err)) |
219 | | - # |
220 | | - slash = '/' if base[-1] != '/' else '' |
221 | | - ref = base + slash + type + '/' + slug + '/' |
222 | | - set_classes(options) |
223 | | - node = nodes.reference(rawtext, type + ' ' + utils.unescape(slug), refuri=ref, |
224 | | - **options) |
225 | | - return node |
226 | | - |
227 | | - |
228 | | -def bbissue_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
229 | | - """Link to a BitBucket issue. |
230 | | -
|
231 | | - Returns 2 part tuple containing list of nodes to insert into the |
232 | | - document and a list of system messages. Both are allowed to be |
233 | | - empty. |
234 | | -
|
235 | | - :param name: The role name used in the document. |
236 | | - :param rawtext: The entire markup snippet, with role. |
237 | | - :param text: The text marked with the role. |
238 | | - :param lineno: The line number where rawtext appears in the input. |
239 | | - :param inliner: The inliner instance that called us. |
240 | | - :param options: Directive options for customization. |
241 | | - :param content: The directive content for customization. |
242 | | - """ |
243 | | - try: |
244 | | - issue_num = int(text) |
245 | | - if issue_num <= 0: |
246 | | - raise ValueError |
247 | | - except ValueError: |
248 | | - msg = inliner.reporter.error( |
249 | | - 'BitBucket issue number must be a number greater than or equal to 1; ' |
250 | | - '"%s" is invalid.' % text, line=lineno) |
251 | | - prb = inliner.problematic(rawtext, rawtext, msg) |
252 | | - return [prb], [msg] |
253 | | - app = inliner.document.settings.env.app |
254 | | - node = make_link_node(rawtext, app, 'issue', str(issue_num), options) |
255 | | - return [node], [] |
256 | | - |
257 | | -def bbchangeset_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
258 | | - """Link to a BitBucket changeset. |
259 | | -
|
260 | | - Returns 2 part tuple containing list of nodes to insert into the |
261 | | - document and a list of system messages. Both are allowed to be |
262 | | - empty. |
263 | | -
|
264 | | - :param name: The role name used in the document. |
265 | | - :param rawtext: The entire markup snippet, with role. |
266 | | - :param text: The text marked with the role. |
267 | | - :param lineno: The line number where rawtext appears in the input. |
268 | | - :param inliner: The inliner instance that called us. |
269 | | - :param options: Directive options for customization. |
270 | | - :param content: The directive content for customization. |
271 | | - """ |
272 | | - app = inliner.document.settings.env.app |
273 | | - node = make_link_node(rawtext, app, 'changeset', text, options) |
274 | | - return [node], [] |
275 | | - |
276 | | - |
277 | | -def setup(app): |
278 | | - """Install the plugin. |
279 | | - |
280 | | - :param app: Sphinx application context. |
281 | | - """ |
282 | | - app.add_role('bbissue', bbissue_role) |
283 | | - app.add_role('bbchangeset', bbchangeset_role) |
284 | | - app.add_config_value('bitbucket_project_url', None, 'env') |
285 | | - return |
0 commit comments