Permalink
Browse files

Add the github stats tool from IPython

  • Loading branch information...
mdboom committed Sep 7, 2012
1 parent be22cba commit 820985ad65be943568512dc20ae3eca4a3a0f273
Showing with 798 additions and 1 deletion.
  1. +5 −1 doc/conf.py
  2. +155 −0 doc/sphinxext/github.py
  3. +442 −0 doc/users/github_stats.rst
  4. +3 −0 doc/users/whats_new.rst
  5. +193 −0 tools/github_stats.py
View
@@ -27,7 +27,7 @@
'sphinx.ext.autodoc', 'matplotlib.sphinxext.only_directives',
'matplotlib.sphinxext.plot_directive', 'sphinx.ext.inheritance_diagram',
'gen_gallery', 'gen_rst',
- 'matplotlib.sphinxext.ipython_console_highlighting']
+ 'matplotlib.sphinxext.ipython_console_highlighting', 'github']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -81,6 +81,10 @@
plot_formats = [('png', 80), ('hires.png', 200), ('pdf', 50)]
+# Github extension
+
+github_project_url = "http://github.com/matplotlib/matplotlib/"
+
# Options for HTML output
# -----------------------
View
@@ -0,0 +1,155 @@
+"""Define text roles for GitHub
+
+* ghissue - Issue
+* ghpull - Pull Request
+* ghuser - User
+
+Adapted from bitbucket example here:
+https://bitbucket.org/birkenfeld/sphinx-contrib/src/tip/bitbucket/sphinxcontrib/bitbucket.py
+
+Authors
+-------
+
+* Doug Hellmann
+* Min RK
+"""
+#
+# Original Copyright (c) 2010 Doug Hellmann. All rights reserved.
+#
+
+from docutils import nodes, utils
+from docutils.parsers.rst.roles import set_classes
+
+def make_link_node(rawtext, app, type, slug, options):
+ """Create a link to a github resource.
+
+ :param rawtext: Text being replaced with link node.
+ :param app: Sphinx application context
+ :param type: Link type (issues, changeset, etc.)
+ :param slug: ID of the thing to link to
+ :param options: Options dictionary passed to role func.
+ """
+
+ try:
+ base = app.config.github_project_url
+ if not base:
+ raise AttributeError
+ if not base.endswith('/'):
+ base += '/'
+ except AttributeError as err:
+ raise ValueError('github_project_url configuration value is not set (%s)' % str(err))
+
+ ref = base + type + '/' + slug + '/'
+ set_classes(options)
+ prefix = "#"
+ if type == 'pull':
+ prefix = "PR " + prefix
+ node = nodes.reference(rawtext, prefix + utils.unescape(slug), refuri=ref,
+ **options)
+ return node
+
+def ghissue_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
+ """Link to a GitHub issue.
+
+ Returns 2 part tuple containing list of nodes to insert into the
+ document and a list of system messages. Both are allowed to be
+ empty.
+
+ :param name: The role name used in the document.
+ :param rawtext: The entire markup snippet, with role.
+ :param text: The text marked with the role.
+ :param lineno: The line number where rawtext appears in the input.
+ :param inliner: The inliner instance that called us.
+ :param options: Directive options for customization.
+ :param content: The directive content for customization.
+ """
+
+ try:
+ issue_num = int(text)
+ if issue_num <= 0:
+ raise ValueError
+ except ValueError:
+ msg = inliner.reporter.error(
+ 'GitHub issue number must be a number greater than or equal to 1; '
+ '"%s" is invalid.' % text, line=lineno)
+ prb = inliner.problematic(rawtext, rawtext, msg)
+ return [prb], [msg]
+ app = inliner.document.settings.env.app
+ #app.info('issue %r' % text)
+ if 'pull' in name.lower():
+ category = 'pull'
+ elif 'issue' in name.lower():
+ category = 'issues'
+ else:
+ msg = inliner.reporter.error(
+ 'GitHub roles include "ghpull" and "ghissue", '
+ '"%s" is invalid.' % name, line=lineno)
+ prb = inliner.problematic(rawtext, rawtext, msg)
+ return [prb], [msg]
+ node = make_link_node(rawtext, app, category, str(issue_num), options)
+ return [node], []
+
+def ghuser_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
+ """Link to a GitHub user.
+
+ Returns 2 part tuple containing list of nodes to insert into the
+ document and a list of system messages. Both are allowed to be
+ empty.
+
+ :param name: The role name used in the document.
+ :param rawtext: The entire markup snippet, with role.
+ :param text: The text marked with the role.
+ :param lineno: The line number where rawtext appears in the input.
+ :param inliner: The inliner instance that called us.
+ :param options: Directive options for customization.
+ :param content: The directive content for customization.
+ """
+ app = inliner.document.settings.env.app
+ #app.info('user link %r' % text)
+ ref = 'https://www.github.com/' + text
+ node = nodes.reference(rawtext, text, refuri=ref, **options)
+ return [node], []
+
+def ghcommit_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
+ """Link to a GitHub commit.
+
+ Returns 2 part tuple containing list of nodes to insert into the
+ document and a list of system messages. Both are allowed to be
+ empty.
+
+ :param name: The role name used in the document.
+ :param rawtext: The entire markup snippet, with role.
+ :param text: The text marked with the role.
+ :param lineno: The line number where rawtext appears in the input.
+ :param inliner: The inliner instance that called us.
+ :param options: Directive options for customization.
+ :param content: The directive content for customization.
+ """
+ app = inliner.document.settings.env.app
+ #app.info('user link %r' % text)
+ try:
+ base = app.config.github_project_url
+ if not base:
+ raise AttributeError
+ if not base.endswith('/'):
+ base += '/'
+ except AttributeError as err:
+ raise ValueError('github_project_url configuration value is not set (%s)' % str(err))
+
+ ref = base + text
+ node = nodes.reference(rawtext, text[:6], refuri=ref, **options)
+ return [node], []
+
+
+def setup(app):
+ """Install the plugin.
+
+ :param app: Sphinx application context.
+ """
+ app.info('Initializing GitHub plugin')
+ app.add_role('ghissue', ghissue_role)
+ app.add_role('ghpull', ghissue_role)
+ app.add_role('ghuser', ghuser_role)
+ app.add_role('ghcommit', ghcommit_role)
+ app.add_config_value('github_project_url', None, 'env')
+ return
Oops, something went wrong.

0 comments on commit 820985a

Please sign in to comment.