Takayuki KONDO avatar Takayuki KONDO committed d5af7e6

change name to 'sphinxcontrib.mercurial'

Comments (0)

Files changed (8)

 This allows you to include a Mercurial extension of your Sphinx documentation
 within the documentation.
 
-How to use
-===========
+Installation
+============
+
+::
+
+   $ pip install sphinxcontrib-mercurial
+
+
+How to setup
+============
 
 Once you enable this extension,
 ::
 
     # Add any Sphinx extension module names here, as strings. They can be extensions
     # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-    extensions = ['sphinxcontrib.hg_changelog']
+    extensions = ['sphinxcontrib.mercurial']
 
-and add
+
+Configulation
+=============
+
+How to use hg_changelog directive
+---------------------------------
+
 ::
 
   .. hg_changelog::
 
 where you want the list of commits to appear.
 
-Options
-=============
+Options of hg_changelog
+-----------------------
 
 repo_root_path
   specify repository root (default: ".")
 
   NOTE: you need to set from repository root.
 
-Example
-===========
+Example of hg_changelog
+-----------------------
 
 ::
 
      :max_commits: 2
      :path: test/rst
 
+
+How to use hg_version directive
+-------------------------------
+
+::
+
+  .. hg_version::
+
+where you want the version to appear,
+
+
+
 Acknowledgement
 ================
 https://github.com/OddBloke/sphinx-git
 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = []
-extensions += ['sphinxcontrib.hg_changelog']
-extensions += ['sphinxcontrib.hg_version']
+extensions += ['sphinxcontrib.mercurial']
 
 
 # Add any paths that contain templates here, relative to this directory.
 [egg_info]
-tag_build = dev
+;tag_build = dev
 ;tag_date = true
 
 [aliases]

sphinxcontrib/hg_changelog.py

-# -*- coding: utf-8-unix -*-
-# Copyright 2012 (C) Takayuki KONDO <tkondou@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-from docutils import nodes
-from docutils.parsers.rst import directives
-from sphinx.util.compat import Directive
-
-from mercurial import ui, hg, util
-
-
-class HgChangeLog(Directive):
-    has_content = True
-    required_arguments = 0
-    optional_arguments = 4
-    final_argument_whitespace = False
-    option_spec = {
-        'max_commits': directives.positive_int,
-        'repo_root_path': directives.unchanged_required,
-        'branch': directives.unchanged_required,
-        'path': directives.unchanged_required
-        }
-
-    def run(self):
-        repo_root_path = "."
-        if 'repo_root_path' in self.options:
-            repo_root_path = self.options['repo_root_path']
-
-        repo = hg.repository(ui.ui(), repo_root_path)
-        l = nodes.bullet_list()
-
-        ctxes = self.get_ctxes(repo, self.options)
-
-        for ctx in ctxes:
-            item = nodes.list_item()
-            item += [nodes.strong(text=ctx.description()),
-                     nodes.inline(text=" by "),
-                     nodes.emphasis(text=ctx.user()),
-                     nodes.inline(text=" at "),
-                     nodes.emphasis(text=util.datestr(ctx.date()))
-                     ]
-            l.append(item)
-        return [l]
-
-    def get_ctxes(self, repo, options):
-        '''get suitable ctxes from commits'''
-        max_commits = 10
-        if 'max_commits' in options:
-            max_commits = options['max_commits']
-        branch = "default"
-        if 'branch' in options:
-            branch = options['branch']
-        path = None
-        if 'path' in options:
-            path = options['path']
-
-        commits = range(repo.changectx("tip").rev() + 1)
-        commits.reverse()
-
-        ret = []
-        for commit in commits:
-            if len(ret) >= max_commits:
-                break
-            ctx = repo.changectx(commit)
-            if ctx.branch() != branch:
-                continue
-            if self.is_file_in_path(ctx.files(), path) is False:
-                continue
-            ret.append(ctx)
-
-        return ret
-
-    def is_file_in_path(self, files, path):
-        '''Check files contain some file in specified path'''
-        if path is None:
-            return True
-        for f in files:
-            print f
-            if f.startswith(path):
-                return True
-        return False
-
-
-def setup(app):
-    app.add_directive('hg_changelog', HgChangeLog)

sphinxcontrib/hg_version.py

-# -*- coding: utf-8-unix -*-
-# Copyright 2012 (C) Takayuki KONDO <tkondou@gmail.com>
-#
-import sys
-import os, subprocess
-
-from docutils import nodes
-from docutils.parsers.rst import directives
-from sphinx.util.compat import Directive
-
-
-if sys.version_info[0] >= 3:
-    def b(s):
-        '''A helper function to emulate 2.6+ bytes literals using string
-        literals.'''
-        return s.encode('latin1')
-else:
-    def b(s):
-        '''A helper function to emulate 2.6+ bytes literals using string
-        literals.'''
-        return s
-
-class HgVersion(Directive):
-
-    def runcmd(self, cmd, env):
-        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE, env=env)
-        out, err = p.communicate()
-        return out, err
-
-    def runhg(self, cmd, env):
-        out, err = self.runcmd(cmd, env)
-
-        err = [e for e in err.splitlines()
-               if not e.startswith(b('Not trusting file')) \
-               and not e.startswith(b('warning: Not importing'))]
-        if err:
-            return ''
-        return out
-
-    def run(self):
-        env = {'LANGUAGE': 'C'}
-        cmd = ['hg', 'log', '-r', '.', '--template', '{tags}\n']
-        numerictags = [t for t in self.runhg(cmd, env).split() if t[0].isdigit()]
-        hgid = self.runhg(['hg', 'id', '-i', '-t'], env).strip()
-
-        version = ''
-
-        if numerictags: # tag(s) found
-            version = numerictags[-1]
-            if hgid.endswith('+'): # propagate the dirty status to the tag
-                version += '+'
-        else: # no tag found
-            cmd = [sys.executable, 'hg', 'parents', '--template',
-                   '{latesttag}+{latesttagdistance}-']
-            version = self.runhg(cmd, env) + hgid
-            if version.endswith('+'):
-                version += time.strftime('%Y%m%d')
-
-        l = nodes.bullet_list()
-        item = nodes.list_item()
-        item += [nodes.inline(text=version)]
-        l.append(item)
-
-        return [l]
-
-def setup(app):
-    app.add_directive('hg_version', HgVersion)

sphinxcontrib/mercurial/__init__.py

+import hg_changelog
+import hg_version
+
+def setup(app):
+    app.add_directive('hg_changelog', hg_changelog.HgChangeLog)
+    app.add_directive('hg_version', hg_version.HgVersion)

sphinxcontrib/mercurial/hg_changelog.py

+# -*- coding: utf-8-unix -*-
+# Copyright 2012 (C) Takayuki KONDO <tkondou@gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from docutils import nodes
+from docutils.parsers.rst import directives
+from sphinx.util.compat import Directive
+
+from mercurial import ui, hg, util
+
+
+class HgChangeLog(Directive):
+    has_content = True
+    required_arguments = 0
+    optional_arguments = 4
+    final_argument_whitespace = False
+    option_spec = {
+        'max_commits': directives.positive_int,
+        'repo_root_path': directives.unchanged_required,
+        'branch': directives.unchanged_required,
+        'path': directives.unchanged_required
+        }
+
+    def run(self):
+        repo_root_path = "."
+        if 'repo_root_path' in self.options:
+            repo_root_path = self.options['repo_root_path']
+
+        repo = hg.repository(ui.ui(), repo_root_path)
+        l = nodes.bullet_list()
+
+        ctxes = self.get_ctxes(repo, self.options)
+
+        for ctx in ctxes:
+            item = nodes.list_item()
+            item += [nodes.strong(text=ctx.description()),
+                     nodes.inline(text=" by "),
+                     nodes.emphasis(text=ctx.user()),
+                     nodes.inline(text=" at "),
+                     nodes.emphasis(text=util.datestr(ctx.date()))
+                     ]
+            l.append(item)
+        return [l]
+
+    def get_ctxes(self, repo, options):
+        '''get suitable ctxes from commits'''
+        max_commits = 10
+        if 'max_commits' in options:
+            max_commits = options['max_commits']
+        branch = "default"
+        if 'branch' in options:
+            branch = options['branch']
+        path = None
+        if 'path' in options:
+            path = options['path']
+
+        commits = range(repo.changectx("tip").rev() + 1)
+        commits.reverse()
+
+        ret = []
+        for commit in commits:
+            if len(ret) >= max_commits:
+                break
+            ctx = repo.changectx(commit)
+            if ctx.branch() != branch:
+                continue
+            if self.is_file_in_path(ctx.files(), path) is False:
+                continue
+            ret.append(ctx)
+
+        return ret
+
+    def is_file_in_path(self, files, path):
+        '''Check files contain some file in specified path'''
+        if path is None:
+            return True
+        for f in files:
+            print f
+            if f.startswith(path):
+                return True
+        return False
+

sphinxcontrib/mercurial/hg_version.py

+# -*- coding: utf-8-unix -*-
+# Copyright 2012 (C) Takayuki KONDO <tkondou@gmail.com>
+#
+import sys
+import os, subprocess
+
+from docutils import nodes
+from docutils.parsers.rst import directives
+from sphinx.util.compat import Directive
+
+
+if sys.version_info[0] >= 3:
+    def b(s):
+        '''A helper function to emulate 2.6+ bytes literals using string
+        literals.'''
+        return s.encode('latin1')
+else:
+    def b(s):
+        '''A helper function to emulate 2.6+ bytes literals using string
+        literals.'''
+        return s
+
+class HgVersion(Directive):
+
+    def runcmd(self, cmd, env):
+        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE, env=env)
+        out, err = p.communicate()
+        return out, err
+
+    def runhg(self, cmd, env):
+        out, err = self.runcmd(cmd, env)
+
+        err = [e for e in err.splitlines()
+               if not e.startswith(b('Not trusting file')) \
+               and not e.startswith(b('warning: Not importing'))]
+        if err:
+            return ''
+        return out
+
+    def run(self):
+        env = {'LANGUAGE': 'C'}
+        cmd = ['hg', 'log', '-r', '.', '--template', '{tags}\n']
+        numerictags = [t for t in self.runhg(cmd, env).split() if t[0].isdigit()]
+        hgid = self.runhg(['hg', 'id', '-i', '-t'], env).strip()
+
+        version = ''
+
+        if numerictags: # tag(s) found
+            version = numerictags[-1]
+            if hgid.endswith('+'): # propagate the dirty status to the tag
+                version += '+'
+        else: # no tag found
+            cmd = [sys.executable, 'hg', 'parents', '--template',
+                   '{latesttag}+{latesttagdistance}-']
+            version = self.runhg(cmd, env) + hgid
+            if version.endswith('+'):
+                version += time.strftime('%Y%m%d')
+
+        l = nodes.bullet_list()
+        item = nodes.list_item()
+        item += [nodes.inline(text=version)]
+        l.append(item)
+
+        return [l]
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.