From ec1d9b8be66b1f09c580d8586e474189902a132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 10 Jan 2017 15:16:56 +0100 Subject: [PATCH] Fixed installation issues --- MANIFEST.in | 2 +- balkian_pre_commit/__init__.py | 27 +++++++++++++++------------ balkian_pre_commit/branchversion.py | 19 +++++++++++-------- hooks.yml => hooks.yaml | 2 +- 4 files changed, 28 insertions(+), 22 deletions(-) rename hooks.yml => hooks.yaml (89%) diff --git a/MANIFEST.in b/MANIFEST.in index e30c575..be921e6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ include requirements.txt include test-requirements.txt include README.md -include balkian-pre-commit/VERSION +include balkian_pre_commit/VERSION diff --git a/balkian_pre_commit/__init__.py b/balkian_pre_commit/__init__.py index fbdf127..1cc216e 100644 --- a/balkian_pre_commit/__init__.py +++ b/balkian_pre_commit/__init__.py @@ -18,18 +18,21 @@ pro-commit hooks for various projects """ from __future__ import print_function -import semver from .version import __version__ -__version_info__ = semver.parse_version_info(__version__) +try: + import semver + __version_info__ = semver.parse_version_info(__version__) -if __version_info__.prerelease: - import logging - logger = logging.getLogger(__name__) - msg = 'WARNING: You are using a pre-release version of {} ({})'.format( - __name__, __version__) - if len(logging.root.handlers) > 0: - logger.info(msg) - else: - import sys - print(msg, file=sys.stderr) + if __version_info__.prerelease: + import logging + logger = logging.getLogger(__name__) + msg = 'WARNING: You are using a pre-release version of {} ({})'.format( + __name__, __version__) + if len(logging.root.handlers) > 0: + logger.info(msg) + else: + import sys + print(msg, file=sys.stderr) +except ImportError: + print('semver not installed, not doing version checking') diff --git a/balkian_pre_commit/branchversion.py b/balkian_pre_commit/branchversion.py index 6fa4d8a..48c1a5a 100644 --- a/balkian_pre_commit/branchversion.py +++ b/balkian_pre_commit/branchversion.py @@ -8,14 +8,17 @@ def main(argv=None): parser.add_argument('filenames', nargs='*') args = parser.parse_args(argv) branch_name = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode() - if branch_name == 'master': - for fn in args.filenames: - if os.path.basename(fn) == 'VERSION': - with open(fn) as f: - version = semver.parse_version_info(f.read()) - if version.prerelease: - return 1 + for fn in args.filenames: + if os.path.basename(fn) == 'VERSION': + with open(fn) as f: + currentcontent = f.read().strip() + prevcontent = check_output(['git', 'show', 'HEAD:{}'.format(fn)]).strip().decode() + current = semver.parse_version_info(currentcontent) + print('Checking versions: {} -> {}'.format(prevcontent, currentcontent)) + if (branch_name == 'master' and current.prerelease) or\ + (semver.compare(currentcontent, prevcontent)<1): + return 1 return 0 - + if __name__ == '__main__': exit(main()) diff --git a/hooks.yml b/hooks.yaml similarity index 89% rename from hooks.yml rename to hooks.yaml index df53e69..031f13f 100644 --- a/hooks.yml +++ b/hooks.yaml @@ -3,4 +3,4 @@ description: This hook avoids commiting a pre-release to a master branch. entry: branchversion language: python - files: VERSION$ \ No newline at end of file + files: "VERSION$"