mirror of
https://github.com/balkian/pre-commit-hooks.git
synced 2025-09-02 02:52:20 +00:00
First commit
This commit is contained in:
1
balkian_pre_commit/VERSION
Normal file
1
balkian_pre_commit/VERSION
Normal file
@@ -0,0 +1 @@
|
||||
0.0.1
|
35
balkian_pre_commit/__init__.py
Normal file
35
balkian_pre_commit/__init__.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 J. Fernando Sánchez GSI-UPM
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""
|
||||
pro-commit hooks for various projects
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import semver
|
||||
from .version import __version__
|
||||
|
||||
__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)
|
21
balkian_pre_commit/branchversion.py
Normal file
21
balkian_pre_commit/branchversion.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import argparse
|
||||
import semver
|
||||
import os
|
||||
from subprocess import check_output
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
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
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
4
balkian_pre_commit/version.py
Normal file
4
balkian_pre_commit/version.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import os
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), 'VERSION')) as f:
|
||||
__version__ = f.read().strip()
|
Reference in New Issue
Block a user