Git directive¶
Options¶
The repository directive takes these options.
number_of_revisions: positive integer
Set the number of revision to show commit history. Default is 10.
revision: revision string
Set revision string to show particular commit history.
with_ref_url:
Set as a flag to show commit URL on repository hosting service. It supports github and bitbucket.
include_diff:
Set as a flag to show diff text with commit history. The diff text is hidden with initial state. Clicking around commit message shows the diff text.
Top commit history¶
.. git::
:number_of_revisions: 20
:with_ref_url:
:include_diff:
- update README
by Tetsuya Morimoto at 2019-11-06 02:03:05
0806b703030e8634d97d71c58ed56631f77a8a64
diff --git a/README.md b/README.md index 73e9585..fd8aad4 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ For more information have a look at [the documentation](https://sphinxcontrib-vc ## ChangeLog +### 0.2.2 (2019-11-06) + +* fix packaging issue: cannot import sphinxcontrib.repository + ### 0.2.1 (2019-08-04) * fix wrong Docutils DTD list_item node thanks to amedama41
- fix to be able to import sphinxcontrib.repository
by Tetsuya Morimoto at 2019-11-06 01:56:21
2b2ae4e5f404b3aef281d231203e724abc9a6fa5
diff --git a/setup.py b/setup.py index 9e90796..1ec0c6c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import re from os import path -from setuptools import setup +from setuptools import find_packages, setup version_py = open('sphinxcontrib/vcs.py').read() metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", version_py)) @@ -39,7 +39,7 @@ setup( author_email='tetsuya.morimoto@gmail.com', zip_safe=False, platforms='any', - packages=['sphinxcontrib'], + packages=find_packages(), namespace_packages=['sphinxcontrib'], include_package_data=True, install_requires=[ diff --git a/sphinxcontrib/vcs.py b/sphinxcontrib/vcs.py index d3e7721..98f6517 100644 --- a/sphinxcontrib/vcs.py +++ b/sphinxcontrib/vcs.py @@ -9,7 +9,7 @@ from sphinx.util.osutil import copyfile from .repository import GitRepository -__version__ = '0.2.1' +__version__ = '0.2.2' logger = logging.getLogger(__name__)
- Merge pull request #3 from t2y/dependabot/pip/urllib3-1.24.2
Bump urllib3 from 1.24.1 to 1.24.2 by Tetsuya Morimoto at 2019-11-06 01:31:35
8729d58324940263f5774ddf6150cdb649f5768d
- Bump urllib3 from 1.24.1 to 1.24.2
Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.24.1 to 1.24.2.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/master/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/1.24.1…1.24.2)
Signed-off-by: dependabot[bot] <support@github.com> by dependabot[bot] at 2019-10-21 17:38:12
5580413dacfa8820d15076f06abf96a112868191
diff --git a/requirements.txt b/requirements.txt index 8c7d5a7..b7cef77 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,4 +25,4 @@ sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.2 sphinxcontrib-serializinghtml==1.1.3 sphinxcontrib-vcs==0.2.0 -urllib3==1.24.1 +urllib3==1.24.2
- update version 0.2.1
by Tetsuya Morimoto at 2019-08-04 05:52:37
694004f22607a734ca15f83ff30cbfb6891283d7
diff --git a/README.md b/README.md index 078fada..73e9585 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ For more information have a look at [the documentation](https://sphinxcontrib-vc ## ChangeLog +### 0.2.1 (2019-08-04) + +* fix wrong Docutils DTD list_item node thanks to amedama41 + ### 0.2.0 (2018-11-17) * drop Python 2.7 support and mercurial feature diff --git a/sphinxcontrib/vcs.py b/sphinxcontrib/vcs.py index 86d1d67..d3e7721 100644 --- a/sphinxcontrib/vcs.py +++ b/sphinxcontrib/vcs.py @@ -9,7 +9,7 @@ from sphinx.util.osutil import copyfile from .repository import GitRepository -__version__ = '0.2.0' +__version__ = '0.2.1' logger = logging.getLogger(__name__)
- Merge pull request #2 from amedama41/fix_docutils_tree
fix to generate well-formed docutils document tree by Tetsuya Morimoto at 2019-08-04 05:40:46
33be27e6f95f8470876a66e2365a58e14436ed38
- fix to generate well-formed docutils document tree
by amedama41 at 2019-08-02 13:27:55
f15e49111aae736a06ed97ad3c3140eb97e6e75e
diff --git a/sphinxcontrib/vcs.py b/sphinxcontrib/vcs.py index e809400..86d1d67 100644 --- a/sphinxcontrib/vcs.py +++ b/sphinxcontrib/vcs.py @@ -76,14 +76,17 @@ class GitDirective(BaseDirective): def get_changelog(self, repo, commit): item = nodes.list_item() + para = nodes.paragraph() - item.append(self._make_message_node(commit.message, commit.hexsha)) - item.append(nodes.inline(text=' by ')) - item.append(nodes.emphasis(text=commit.author.name)) - item.append(nodes.inline(text=' at ')) + para.append(self._make_message_node(commit.message, commit.hexsha)) + para.append(nodes.inline(text=' by ')) + para.append(nodes.emphasis(text=commit.author.name)) + para.append(nodes.inline(text=' at ')) commit_date = datetime.fromtimestamp(commit.authored_date) - item.append(nodes.emphasis(text=commit_date)) + para.append(nodes.emphasis(text=commit_date)) + + item.append(para) if OPTION_WITH_REF_URL in self.options: ref_url = repo.get_commit_url(commit.hexsha)
- update tox test environment and drop 3.4 support
by Tetsuya Morimoto at 2019-04-13 03:04:30
d2b208a5576d1012ff0de9ae1b3bb674ea62181f
diff --git a/.travis.yml b/.travis.yml index e39d492..743b766 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,6 @@ language: python matrix: include: - - os: linux - sudo: required - python: 3.4 - env: TOXENV=py34 - os: linux sudo: required python: 3.5 @@ -13,6 +9,10 @@ matrix: sudo: required python: 3.6 env: TOXENV=py36 + - os: linux + sudo: required + python: 3.7 + env: TOXENV=py37 install: pip install docutils tox script: tox diff --git a/setup.py b/setup.py index d3527cc..9e90796 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,6 @@ setup( 'Intended Audience :: Developers', 'Operating System :: OS Independent', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/tox.ini b/tox.ini index 7ed87a0..51a8ca1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,18 @@ [tox] -envlist = py34, py35, py36, py37 +envlist = py35, py36, py37 [testenv] passenv = LANG LC_ALL +; TODO: Sphinx 2.0.x raise No module named 'sphinxcontrib.serializinghtml' deps= nose mock flake8 reportlab sphinx-testing + Sphinx==1.8.5 commands= nosetests -v flake8 setup.py sphinxcontrib/ tests/
- update requirements.txt
by Tetsuya Morimoto at 2019-04-13 02:51:19
f9d252516ddee7f9251f0cdf94cdf8b68b9ee02f
diff --git a/requirements.txt b/requirements.txt index adb4a1e..8c7d5a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,28 @@ alabaster==0.7.12 Babel==2.6.0 -certifi==2018.10.15 +certifi==2019.3.9 chardet==3.0.4 docutils==0.14 gitdb2==2.0.5 GitPython==2.1.11 -idna==2.7 +idna==2.8 imagesize==1.1.0 -Jinja2==2.10 -MarkupSafe==1.1.0 -packaging==18.0 -Pygments==2.2.0 -pyparsing==2.3.0 -pytz==2018.7 -requests==2.20.1 -six==1.11.0 +Jinja2==2.10.1 +MarkupSafe==1.1.1 +packaging==19.0 +Pygments==2.3.1 +pyparsing==2.4.0 +pytz==2019.1 +requests==2.21.0 +six==1.12.0 smmap2==2.0.5 snowballstemmer==1.2.1 -Sphinx==1.8.2 +Sphinx==2.0.1 +sphinxcontrib-applehelp==1.0.1 +sphinxcontrib-devhelp==1.0.1 +sphinxcontrib-htmlhelp==1.0.2 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.2 +sphinxcontrib-serializinghtml==1.1.3 sphinxcontrib-vcs==0.2.0 -sphinxcontrib-websupport==1.1.0 urllib3==1.24.1
- migrate document hosting site to readthedocs.org
by Tetsuya Morimoto at 2018-11-17 13:32:27
776146fc9e456a0733eaa97d0f7679c8eb5d7c5e
diff --git a/README.md b/README.md index 4642e3c..078fada 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Then, repository directives are available as follows. :with_ref_url: :include_diff: -For more information have a look at [the documentation](https://pythonhosted.org/sphinxcontrib-vcs/). +For more information have a look at [the documentation](https://sphinxcontrib-vcs.readthedocs.io/). ## Acknowledgments
- add requirements.txt to build documentation on readthedocs.org
by Tetsuya Morimoto at 2018-11-17 13:26:21
40b6d3e2bd27d675566027131ade069f6989a7e6
diff --git a/.travis.yml b/.travis.yml index b6798eb..e39d492 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,6 @@ matrix: sudo: required python: 3.6 env: TOXENV=py36 - - os: linux - sudo: required - python: 3.7 - env: TOXENV=py37 install: pip install docutils tox script: tox diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..adb4a1e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,23 @@ +alabaster==0.7.12 +Babel==2.6.0 +certifi==2018.10.15 +chardet==3.0.4 +docutils==0.14 +gitdb2==2.0.5 +GitPython==2.1.11 +idna==2.7 +imagesize==1.1.0 +Jinja2==2.10 +MarkupSafe==1.1.0 +packaging==18.0 +Pygments==2.2.0 +pyparsing==2.3.0 +pytz==2018.7 +requests==2.20.1 +six==1.11.0 +smmap2==2.0.5 +snowballstemmer==1.2.1 +Sphinx==1.8.2 +sphinxcontrib-vcs==0.2.0 +sphinxcontrib-websupport==1.1.0 +urllib3==1.24.1
- update travis configuration
by Tetsuya Morimoto at 2018-11-17 13:14:21
7f2a18b7b48e075c7ce5d49ca7d0edeb71fd0dd6
diff --git a/.travis.yml b/.travis.yml index d8ca2cd..b6798eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,22 @@ language: python -python: 3.6 -env: - matrix: - - TOXENV=py34 - - TOXENV=py35 - - TOXENV=py36 - - TOXENV=py37 +matrix: + include: + - os: linux + sudo: required + python: 3.4 + env: TOXENV=py34 + - os: linux + sudo: required + python: 3.5 + env: TOXENV=py35 + - os: linux + sudo: required + python: 3.6 + env: TOXENV=py36 + - os: linux + sudo: required + python: 3.7 + env: TOXENV=py37 install: pip install docutils tox script: tox
- update travis configuration
by Tetsuya Morimoto at 2018-11-17 13:07:22
364870b26c8424fbfbfad426916d3c4e9cca9840
diff --git a/.travis.yml b/.travis.yml index bc36e79..d8ca2cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: python -python: 2.7 +python: 3.6 env: matrix: - - TOXENV=py27 - - TOXENV=py33 - TOXENV=py34 + - TOXENV=py35 + - TOXENV=py36 + - TOXENV=py37 install: pip install docutils tox script: tox
- update version 0.2.0
by Tetsuya Morimoto at 2018-11-17 13:00:55
75e4930ce5932c17ae890151ebd5c3e18fde8c93
diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 6c3c0c1..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,6 +0,0 @@ - -## ChangeLog - -### 0.1.0 (2016-09-06) - -* first release diff --git a/README.md b/README.md index 2738134..4642e3c 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,13 @@ For more information have a look at [the documentation](https://pythonhosted.org *sphinxcontrib-vcs* is inspired from the [sphinx-git](https://github.com/OddBloke/sphinx-git). +## ChangeLog + +### 0.2.0 (2018-11-17) + +* drop Python 2.7 support and mercurial feature +* support internal git repository such as GitHub Enterprise + +### 0.1.0 (2016-09-06) + +* first release diff --git a/setup.cfg b/setup.cfg index 31e9f22..27c1577 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,12 +7,5 @@ formats = gztar [wheel] universal = 1 -[aliases] -release = check -r -s register sdist bdist_wheel upload - -[check] -strict = 1 -restructuredtext = 1 - [upload_sphinx] upload-dir = docs/_build/html diff --git a/setup.py b/setup.py index 298ec4a..d3527cc 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,21 @@ import re +from os import path from setuptools import setup - -try: - import pypandoc - long_description = '\n'.join([ - pypandoc.convert('README.md', 'rst'), - pypandoc.convert('CHANGELOG.md', 'rst'), - ]) -except (IOError, ImportError): - long_description = '' - version_py = open('sphinxcontrib/vcs.py').read() metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", version_py)) desc = 'Sphinx extension to show commit history in version control system' -requires = [ - 'GitPython', - 'Sphinx', -] - +cur_dir = path.abspath(path.dirname(__file__)) +with open(path.join(cur_dir, 'README.md')) as f: + long_description = f.read() setup( name='sphinxcontrib-vcs', version=metadata['version'], description=desc, long_description=long_description, + long_description_content_type='text/markdown', classifiers=[ 'License :: OSI Approved :: BSD License', 'Development Status :: 4 - Beta', @@ -53,7 +43,10 @@ setup( packages=['sphinxcontrib'], namespace_packages=['sphinxcontrib'], include_package_data=True, - install_requires=requires, + install_requires=[ + 'GitPython', + 'Sphinx', + ], tests_require=[ 'flake8', 'mock', 'nose', 'reportlab', 'sphinx-testing', ], diff --git a/sphinxcontrib/vcs.py b/sphinxcontrib/vcs.py index dee234b..e809400 100644 --- a/sphinxcontrib/vcs.py +++ b/sphinxcontrib/vcs.py @@ -9,7 +9,7 @@ from sphinx.util.osutil import copyfile from .repository import GitRepository -__version__ = '0.1.0' +__version__ = '0.2.0' logger = logging.getLogger(__name__)
- support internal git repository like GitHub Enterprise
by Tetsuya Morimoto at 2018-11-17 12:17:31
464ec78d4b4ea7d0373c8b9e426971a9fbd8874b
diff --git a/.gitignore b/.gitignore index db4561e..9be4ee2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +_build/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/sphinxcontrib/repository/_git.py b/sphinxcontrib/repository/_git.py index a4f560f..db40916 100644 --- a/sphinxcontrib/repository/_git.py +++ b/sphinxcontrib/repository/_git.py @@ -12,7 +12,7 @@ class GitRepository(Repo): EMPTY_TREE_SHA = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' URL_PATTERN = re.compile( r""" - git@.*?:(?P<account>.*?)/(?P<repository_name>.*?)\.git + git@(?P<domain>.*?):(?P<account>.*?)/(?P<repository_name>.*?)\.git |https://github.com/(?P<account_>.*?)/(?P<repository_name_>.*?)\.git """, re.VERBOSE ) @@ -78,12 +78,9 @@ class GitRepository(Repo): if len(self._commits) == 0: self.get_commits() + url = self.remotes.origin.url site = find_hosting_site(self.remotes.origin.url) - if site is None: - return '' - - return make_commit_url( - self.URL_PATTERN, self.remotes.origin.url, site, revision) + return make_commit_url(self.URL_PATTERN, url, site, revision) def get_repo(path): diff --git a/sphinxcontrib/repository/utils.py b/sphinxcontrib/repository/utils.py index 0a4dcdf..c7de869 100644 --- a/sphinxcontrib/repository/utils.py +++ b/sphinxcontrib/repository/utils.py @@ -10,6 +10,10 @@ HOSTING_SERVICE = { 'site': 'https://bitbucket.org', 'commit_template': '{site}/{user}/{repository}/commits/{sha}', }, + 'internal': { + 'site': None, + 'commit_template': '{site}/{user}/{repository}/commit/{sha}', + }, } logging.basicConfig( @@ -24,7 +28,7 @@ def find_hosting_site(url): return HOSTING_SERVICE['github'] elif url.find('bitbucket.org') > 0: return HOSTING_SERVICE['bitbucket'] - return None + return HOSTING_SERVICE['internal'] def make_commit_url(pattern, path, site, revision): @@ -33,10 +37,16 @@ def make_commit_url(pattern, path, site, revision): return '' info = m.groupdict() + + _site = site['site'] + if _site is None: + # suppose GitHub Enterprise + _site = 'https://%s' % info.get('domain') + account = info.get('account') or info.get('account_') repository = info.get('repository_name') or info.get('repository_name_') return site['commit_template'].format( - site=site['site'], + site=_site, user=account, repository=repository, sha=revision,
- drop mercurial feature
by Tetsuya Morimoto at 2018-11-17 11:45:34
c3110fa1f0c132f0b1019fe90ca190e495541df6
diff --git a/docs/_options.rst b/docs/_options.rst deleted file mode 100644 index 4889ba3..0000000 --- a/docs/_options.rst +++ /dev/null @@ -1,27 +0,0 @@ -Options -------- - -The repository directive takes these options. - -- **number_of_revisions**: positive integer - - Set the number of revision to show commit history. Default is 10. - -- **revision**: revision string - - Set revision string to show particular commit history. - -- **with_ref_url**: - - Set as a flag to show commit URL on repository hosting service. - It supports github_ and bitbucket_. - -.. _github: https://github.com/ -.. _bitbucket: https://bitbucket.org/ - -- **include_diff**: - - Set as a flag to show diff text with commit history. - The diff text is hidden with initial state. - Clicking around commit message shows the diff text. - diff --git a/docs/git.rst b/docs/git.rst index 4ece3a3..a0d2a29 100644 --- a/docs/git.rst +++ b/docs/git.rst @@ -4,7 +4,32 @@ Git directive .. contents:: contents :local: -.. include:: _options.rst +Options +------- + +The repository directive takes these options. + +- **number_of_revisions**: positive integer + + Set the number of revision to show commit history. Default is 10. + +- **revision**: revision string + + Set revision string to show particular commit history. + +- **with_ref_url**: + + Set as a flag to show commit URL on repository hosting service. + It supports github_ and bitbucket_. + +.. _github: https://github.com/ +.. _bitbucket: https://bitbucket.org/ + +- **include_diff**: + + Set as a flag to show diff text with commit history. + The diff text is hidden with initial state. + Clicking around commit message shows the diff text. Top commit history ------------------ diff --git a/docs/index.rst b/docs/index.rst index cba5231..43db167 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,7 +12,6 @@ Contents: :maxdepth: 2 git - mercurial Acknowledgments diff --git a/docs/mercurial.rst b/docs/mercurial.rst deleted file mode 100644 index 6c277d4..0000000 --- a/docs/mercurial.rst +++ /dev/null @@ -1,33 +0,0 @@ -Mercurial directive -=================== - -.. note:: - - supports Python 2.7 only - -.. contents:: contents - :local: - -.. include:: _options.rst - -Top commit history ------------------- - -:: - - .. mercurial:: - :number_of_revisions: 20 - :with_ref_url: - :include_diff: - - -Particular commit log ---------------------- - -:: - - .. mercurial:: - :revision: 33:g87922kd38d8 - :with_ref_url: - :include_diff: - diff --git a/setup.py b/setup.py index a35595e..298ec4a 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,6 @@ desc = 'Sphinx extension to show commit history in version control system' requires = [ 'GitPython', 'Sphinx', - 'six', ] diff --git a/sphinxcontrib/__init__.py b/sphinxcontrib/__init__.py index 1bfee45..69b0b13 100644 --- a/sphinxcontrib/__init__.py +++ b/sphinxcontrib/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinxcontrib ~~~~~~~~~~~~~ diff --git a/sphinxcontrib/repository/__init__.py b/sphinxcontrib/repository/__init__.py index 77ca293..0b16719 100644 --- a/sphinxcontrib/repository/__init__.py +++ b/sphinxcontrib/repository/__init__.py @@ -1,6 +1 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - from ._git import GitRepository # noqa -from ._mercurial import MercurialRepository # noqa -from .utils import find_repository_top # noqa diff --git a/sphinxcontrib/repository/_git.py b/sphinxcontrib/repository/_git.py index 8d26616..a4f560f 100644 --- a/sphinxcontrib/repository/_git.py +++ b/sphinxcontrib/repository/_git.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - import re import gitdb diff --git a/sphinxcontrib/repository/_mercurial.py b/sphinxcontrib/repository/_mercurial.py deleted file mode 100644 index 15da53b..0000000 --- a/sphinxcontrib/repository/_mercurial.py +++ /dev/null @@ -1,152 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -import os -import re - -try: - from mercurial import ui, hg, commands - from mercurial.error import RepoLookupError -except ImportError: - pass - -from .utils import find_hosting_site, find_repository_top -from .utils import log -from .utils import make_commit_url - - -class MercurialRepository(object): - - LOG_PATTERN = re.compile(r'(?P<type>\w+):[\t\s]+(?P<value>.*)') - URL_PATTERN = re.compile( - r""" - ssh://hg@bitbucket.org/(?P<account>.*?)/(?P<repository_name>.*?)$ - |https://.+?@bitbucket.org/(?P<account_>.*?)/(?P<repository_name_>.*?)$ - """, re.VERBOSE - ) - - def __init__(self, limit, path): - self.limit = limit - self.ui = ui.ui() - self.raw = hg.repository(self.ui, path=path) - self._changeset = {} - self._commits = [] - self.set_default_path(path) - - def set_default_path(self, path): - # FIXME: how to get default path - # for some reason, commands.paths() doesn't return default path - self.default_path = '' - with open(os.path.join(path, '.hg', 'hgrc')) as f: - for line in f: - if line.startswith('default'): - self.default_path = line.split('=')[1].strip() - break - - def read_changeset_lines(self, lines): - is_found, commit = False, {} - for index, line in enumerate(lines, 1): - m = re.match(self.LOG_PATTERN, line) - if m is not None: - log_info = m.groupdict() - type_ = log_info.get('type', None) - value = log_info.get('value', None) - if type_ is not None: - if type_ == 'changeset': - if is_found: - index -= 1 - break - is_found = True - revision, sha = value.split(':') - commit['revision'] = int(revision) - commit['sha'] = sha - commit[type_] = value - return index, commit - - def get_commit(self, revision): - self.ui.pushbuffer() - try: - commands.log(self.ui, self.raw, rev=[str(revision)]) - except RepoLookupError as err: - log.error(err) - log.warn("Not found '%s' in mercurial repository" % revision) - else: - lines = self.ui.popbuffer().decode('utf-8').split('\n') - index, commit = self.read_changeset_lines(lines) - changeset = commit.get('changeset') - if changeset is not None: - self._commits.append(commit) - self._changeset[changeset] = commit - return commit - - def get_commits(self, revision=None, limit=None): - if revision is not None: - self.get_commit(revision) - self.limit = 1 - return self._commits[:self.limit] - - if len(self._commits) == 0 or limit is not None: - self._commits[:] = [] - if limit is not None: - self.limit = limit - - self.ui.pushbuffer() - commands.log(self.ui, self.raw, limit=self.limit + 1) - lines = self.ui.popbuffer().decode('utf-8').split('\n') - - while len(lines) != 0: - index, commit = self.read_changeset_lines(lines) - changeset = commit.get('changeset') - if changeset is not None: - self._commits.append(commit) - self._changeset[changeset] = commit - lines = lines[index:] - - return self._commits[:self.limit] - - def get_commit_url(self, revision): - site = find_hosting_site(self.default_path) - if site is None: - return '' - - return make_commit_url( - self.URL_PATTERN, self.default_path, site, revision) - - def get_diff(self, revision): - self.ui.pushbuffer() - revisions = [revision - 1, revision] - commands.diff(self.ui, self.raw, rev=revisions) - diff_text = self.ui.popbuffer() - try: - diff = diff_text.decode('utf-8') - except UnicodeDecodeError as err: - log.error(err) - msg = 'Supports utf-8 encoding only, '\ - 'so ignore diff text from revisions: %s' % (revisions) - log.warn(msg) - diff = '' - return diff - - -def get_repo(number_of_revisions, path): - repository_path = find_repository_top(path, '.hg') - if repository_path is None: - return None - return MercurialRepository(number_of_revisions, repository_path) - - -def test(): - r = get_repo(10, '.') - - commits = r.get_commits(max_count=3) - print(commits) - - for commit in commits: - print(r.get_diff(commit['revision'])) - - commit_url = r.get_commit_url(commits[0]['sha']) - print(commit_url) - - -if __name__ == '__main__': - test() diff --git a/sphinxcontrib/repository/utils.py b/sphinxcontrib/repository/utils.py index 95c205b..0a4dcdf 100644 --- a/sphinxcontrib/repository/utils.py +++ b/sphinxcontrib/repository/utils.py @@ -1,8 +1,4 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - import logging -import os import re HOSTING_SERVICE = { @@ -31,18 +27,6 @@ def find_hosting_site(url): return None -def find_repository_top(current_dir, conf_dir): - repository_dir = os.path.abspath(os.path.join(current_dir, conf_dir)) - if repository_dir == os.path.abspath(os.sep): - return None - - if os.path.exists(repository_dir) and os.path.isdir(repository_dir): - return os.path.abspath(current_dir) - else: - parent_dir = os.path.join(current_dir, os.path.pardir) - return find_repository_top(parent_dir, conf_dir) - - def make_commit_url(pattern, path, site, revision): m = re.match(pattern, path) if m is None: diff --git a/sphinxcontrib/vcs.py b/sphinxcontrib/vcs.py index a95a0ba..dee234b 100644 --- a/sphinxcontrib/vcs.py +++ b/sphinxcontrib/vcs.py @@ -1,19 +1,18 @@ -# -*- coding: utf-8 -*- import os from datetime import datetime -import six from docutils import nodes from docutils.parsers.rst import Directive from docutils.parsers.rst import directives +from sphinx.util import logging from sphinx.util.osutil import copyfile from .repository import GitRepository -from .repository import MercurialRepository -from .repository import find_repository_top __version__ = '0.1.0' +logger = logging.getLogger(__name__) + CSS_CLASS = { 'diff': ['contrib-vcs-diff', 'toggle-close'], 'directive': ['contrib-vcs'], @@ -43,7 +42,7 @@ class BaseDirective(Directive): } def _make_message_node(self, message, sha): - message, classes = six.text_type(message), [] + message, classes = message, [] if OPTION_INCLUDE_DIFF in self.options: classes = CSS_CLASS['message'] return nodes.strong(ids=[sha], text=message, classes=classes) @@ -79,12 +78,12 @@ class GitDirective(BaseDirective): item = nodes.list_item() item.append(self._make_message_node(commit.message, commit.hexsha)) - item.append(nodes.inline(text=six.text_type(' by '))) - item.append(nodes.emphasis(text=six.text_type(commit.author.name))) - item.append(nodes.inline(text=six.text_type(' at '))) + item.append(nodes.inline(text=' by ')) + item.append(nodes.emphasis(text=commit.author.name)) + item.append(nodes.inline(text=' at ')) commit_date = datetime.fromtimestamp(commit.authored_date) - item.append(nodes.emphasis(text=six.text_type(commit_date))) + item.append(nodes.emphasis(text=commit_date)) if OPTION_WITH_REF_URL in self.options: ref_url = repo.get_commit_url(commit.hexsha) @@ -98,36 +97,6 @@ class GitDirective(BaseDirective): return item -class MercurialDirective(BaseDirective): - - def get_repo(self, number_of_revisions): - env = self.state.document.settings.env - src_dir = find_repository_top(env.srcdir, '.hg') - if src_dir is None: - return None - return MercurialRepository(number_of_revisions, src_dir) - - def get_changelog(self, repo, commit): - item = nodes.list_item() - - item.append(self._make_message_node(commit['summary'], commit['sha'])) - item.append(nodes.inline(text=six.text_type(' by '))) - item.append(nodes.emphasis(text=six.text_type(commit['user']))) - item.append(nodes.inline(text=six.text_type(' at '))) - item.append(nodes.emphasis(text=six.text_type(commit['date']))) - - if OPTION_WITH_REF_URL in self.options: - ref_url = repo.get_commit_url(commit['sha']) - ref = nodes.reference('', commit['sha'], refuri=ref_url) - item.append(nodes.paragraph('', '', ref)) - - if OPTION_INCLUDE_DIFF in self.options: - diff = repo.get_diff(commit['revision']) - item.append(self._make_diff_node(diff, commit['sha'])) - - return item - - CSS_FILES = ['contrib-vcs.css'] JS_FILES = ['contrib-vcs.js'] @@ -149,17 +118,16 @@ def copy_assets(app, exception): current_path = os.path.abspath(os.path.dirname(__file__)) static_path = app.builder.config.html_static_path[0] - app.info('Copying vcs stylesheet/javascript... ', nonl=True) + logger.info('Copying vcs stylesheet/javascript... ', nonl=True) for file_ in CSS_FILES + JS_FILES: dest = os.path.join(app.builder.outdir, static_path, file_) source = os.path.join(current_path, static_path, file_) copyfile(source, dest) - app.info('done') + logger.info('done') def setup(app): app.add_directive('git', GitDirective) - app.add_directive('mercurial', MercurialDirective) # copying css/js to _static app.connect('builder-inited', add_assets)
- drop python 2.7 support (mercurial)
by Tetsuya Morimoto at 2018-11-17 11:20:50
e5f1e488e5a284ec4a1106adba8d7353b3c233f1
diff --git a/README.md b/README.md index ce973b7..2738134 100644 --- a/README.md +++ b/README.md @@ -24,21 +24,8 @@ Then, repository directives are available as follows. :with_ref_url: :include_diff: - -### Mercurial - - .. mercurial:: - :number_of_revisions: 20 - :with_ref_url: - :include_diff: - For more information have a look at [the documentation](https://pythonhosted.org/sphinxcontrib-vcs/). -## Note - -[Mercurial](https://www.mercurial-scm.org/) supports Python 2.x only. -So *sphinxcontrib-vcs* supports the *mercurial* directive on Python 2.7. - ## Acknowledgments *sphinxcontrib-vcs* is inspired from the [sphinx-git](https://github.com/OddBloke/sphinx-git). diff --git a/setup.py b/setup.py index c14fe38..a35595e 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- import re -import sys - -from setuptools import find_packages, setup +from setuptools import setup try: @@ -24,9 +21,6 @@ requires = [ 'six', ] -if sys.version_info < (3, 0): - requires.append('Mercurial') - setup( name='sphinxcontrib-vcs', @@ -38,12 +32,11 @@ setup( 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Topic :: Software Development :: Libraries', 'Environment :: Console', @@ -55,10 +48,10 @@ setup( url='https://github.com/t2y/sphinxcontrib-vcs', license='BSD', author='Tetsuya Morimoto', - author_email='tetsuya dot morimoto at gmail dot com', + author_email='tetsuya.morimoto@gmail.com', zip_safe=False, platforms='any', - packages=find_packages(), + packages=['sphinxcontrib'], namespace_packages=['sphinxcontrib'], include_package_data=True, install_requires=requires, diff --git a/tox.ini b/tox.ini index 952ad09..7ed87a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py33, py34, py35 +envlist = py34, py35, py36, py37 [testenv] passenv =
- fix minor typos
by Tetsuya Morimoto at 2016-09-07 09:30:59
2c8a68d86b3fd4a94c26d83a828873aa3c8037a3
diff --git a/docs/_options.rst b/docs/_options.rst index 5d0ff0c..4889ba3 100644 --- a/docs/_options.rst +++ b/docs/_options.rst @@ -1,7 +1,7 @@ Options ------- -Each repository directive take these options. +The repository directive takes these options. - **number_of_revisions**: positive integer diff --git a/docs/git.rst b/docs/git.rst index 5392cde..4ece3a3 100644 --- a/docs/git.rst +++ b/docs/git.rst @@ -29,7 +29,7 @@ Particular commit log :: .. git:: - :revision: 69ef5f984f8564dceea0e90e8d169b1807247d8a + :revision: 33e6b629ed3d6ed63f64136661642f594b1f4d6f :with_ref_url: :include_diff:
- update to use upload_sphinx command for documentation
by Tetsuya Morimoto at 2016-09-06 05:17:56
c56f2bd20a2266320dfcb50a89a120713c6b940c
diff --git a/setup.cfg b/setup.cfg index 917b7a4..31e9f22 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,3 +13,6 @@ release = check -r -s register sdist bdist_wheel upload [check] strict = 1 restructuredtext = 1 + +[upload_sphinx] +upload-dir = docs/_build/html
- update documentation link in README
by Tetsuya Morimoto at 2016-09-06 05:17:11
d26ac0cac5c00688c334fdbf5c1dd488ae6ce0a7
diff --git a/README.md b/README.md index 0c7ca58..ce973b7 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Then, repository directives are available as follows. :with_ref_url: :include_diff: -For more information have a look at the documentation. +For more information have a look at [the documentation](https://pythonhosted.org/sphinxcontrib-vcs/). ## Note
Particular commit log¶
.. git::
:revision: 33e6b629ed3d6ed63f64136661642f594b1f4d6f
:with_ref_url:
:include_diff:
- initial commit
by Tetsuya Morimoto at 2016-09-02 14:14:28
33e6b629ed3d6ed63f64136661642f594b1f4d6f
diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6f2af0 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Sphinxcontrib-vcs