diff --git a/pre-commit b/pre-commit index 083d44e7..3bf202d7 100755 --- a/pre-commit +++ b/pre-commit @@ -15,17 +15,18 @@ Copy this file to .git/hooks/ """ import os -import sys -import string import re - +import string +import sys from subprocess import call, check_output + try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse from fileinput import FileInput + # https://github.com/python/cpython/commit/6cb7b659#diff-78790b53ff259619377058acd4f74672 if sys.version_info[0] < 3: class FileInputCtx(FileInput): @@ -35,6 +36,7 @@ if sys.version_info[0] < 3: def __exit__(self, type, value, traceback): self.close() + FileInput = FileInputCtx @@ -91,15 +93,15 @@ def espurna_get_version(base, version_h="code/espurna/config/version.h"): TEMPLATES = { "![travis]": "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" - "(https://travis-ci.org/{USER}/{REPO})\n", - "![version]": "[![version](https://img.shields.io/badge/version-{VERSION:escape_hyphen}-brightgreen.svg)](CHANGELOG.md)\n", + "(https://travis-ci.org/{USER}/{REPO})\n", + "![version]": "[![version](https://img.shields.io/badge/version-{VERSION:escape_hyphen}-brightgreen.svg)]" + "(CHANGELOG.md)\n", "![branch]": "[![branch](https://img.shields.io/badge/branch-{BRANCH:escape_hyphen}-orange.svg)]" - "(https://github.com/{USER}/{REPO}/tree/{BRANCH}/)\n", + "(https://github.com/{USER}/{REPO}/tree/{BRANCH}/)\n", } README = "README.md" - if __name__ == "__main__": base = os.getcwd() @@ -117,6 +119,7 @@ if __name__ == "__main__": for k, tmpl in TEMPLATES.items() ] + def fmt_line(line): for match, tmpl in templates: if match in line: @@ -124,6 +127,7 @@ if __name__ == "__main__": return line + path = os.path.join(base, README) with FileInput(path, inplace=True) as readme: