├── lib ├── __init__.py ├── commit_entropy │ ├── __init__.py │ ├── parser │ │ ├── __init__.py │ │ └── git_log_parser.py │ ├── commands │ │ ├── __init__.py │ │ └── csv_printer.py │ ├── settings.py │ └── app.py └── profiler.py ├── tests ├── __init__.py └── parser │ ├── __init__.py │ └── test_git_log_parser.py ├── MANIFEST.in ├── setup.cfg ├── tox.ini ├── docs ├── LICENSE └── README.rst ├── .gitignore ├── setup.py ├── README.md └── LICENSE /lib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/parser/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/commit_entropy/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include docs * -------------------------------------------------------------------------------- /lib/commit_entropy/parser/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 -------------------------------------------------------------------------------- /lib/commit_entropy/commands/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py34 3 | [testenv] 4 | deps=nose 5 | commands=nosetests \ 6 | "--where=tests" 7 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Grip QA 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .coverage.* 40 | .cache 41 | nosetests.xml 42 | coverage.xml 43 | *,cover 44 | 45 | # Translations 46 | *.mo 47 | *.pot 48 | 49 | # Django stuff: 50 | *.log 51 | 52 | # Sphinx documentation 53 | docs/_build/ 54 | 55 | # PyBuilder 56 | target/ 57 | -------------------------------------------------------------------------------- /lib/commit_entropy/settings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | #------------------------------------------------------------------------------ 5 | # Application Name 6 | #------------------------------------------------------------------------------ 7 | app_name = 'entropy' 8 | 9 | #------------------------------------------------------------------------------ 10 | # Version Number 11 | #------------------------------------------------------------------------------ 12 | major_version = "0" 13 | minor_version = "2" 14 | patch_version = "0" 15 | 16 | #------------------------------------------------------------------------------ 17 | # Debug Flag (switch to False for production release code) 18 | #------------------------------------------------------------------------------ 19 | debug = True 20 | 21 | #------------------------------------------------------------------------------ 22 | # Usage String 23 | #------------------------------------------------------------------------------ 24 | usage = '' 25 | 26 | #------------------------------------------------------------------------------ 27 | # Help String 28 | #------------------------------------------------------------------------------ 29 | help = '' 30 | -------------------------------------------------------------------------------- /lib/profiler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import cProfile, pstats, StringIO 5 | 6 | def profile(): 7 | #------------------------------------------------------------------------------ 8 | # Setup a profile 9 | #------------------------------------------------------------------------------ 10 | pr = cProfile.Profile() 11 | #------------------------------------------------------------------------------ 12 | # Enter setup code below 13 | #------------------------------------------------------------------------------ 14 | # Optional: include setup code here 15 | 16 | 17 | #------------------------------------------------------------------------------ 18 | # Start profiler 19 | #------------------------------------------------------------------------------ 20 | pr.enable() 21 | 22 | #------------------------------------------------------------------------------ 23 | # BEGIN profiled code block 24 | #------------------------------------------------------------------------------ 25 | # include profiled code here 26 | 27 | 28 | #------------------------------------------------------------------------------ 29 | # END profiled code block 30 | #------------------------------------------------------------------------------ 31 | pr.disable() 32 | s = StringIO.StringIO() 33 | sortby = 'cumulative' 34 | ps = pstats.Stats(pr, stream=s).sort_stats(sortby) 35 | ps.strip_dirs().sort_stats("time").print_stats() 36 | print(s.getvalue()) 37 | 38 | if __name__ == '__main__': 39 | profile() -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | from setuptools import setup, find_packages 4 | 5 | 6 | def docs_read(fname): 7 | return open(os.path.join(os.path.dirname(__file__), 'docs', fname)).read() 8 | 9 | def version_read(): 10 | settings_file = open(os.path.join(os.path.dirname(__file__), 'lib', 'commit_entropy', 'settings.py')).read() 11 | major_regex = """major_version\s*?=\s*?["']{1}(\d+)["']{1}""" 12 | minor_regex = """minor_version\s*?=\s*?["']{1}(\d+)["']{1}""" 13 | patch_regex = """patch_version\s*?=\s*?["']{1}(\d+)["']{1}""" 14 | major_match = re.search(major_regex, settings_file) 15 | minor_match = re.search(minor_regex, settings_file) 16 | patch_match = re.search(patch_regex, settings_file) 17 | major_version = major_match.group(1) 18 | minor_version = minor_match.group(1) 19 | patch_version = patch_match.group(1) 20 | if len(major_version) == 0: 21 | major_version = 0 22 | if len(minor_version) == 0: 23 | minor_version = 0 24 | if len(patch_version) == 0: 25 | patch_version = 0 26 | return major_version + "." + minor_version + "." + patch_version 27 | 28 | 29 | setup( 30 | name='commit-entropy', 31 | version=version_read(), 32 | description='A tool to measure the entropy of your commit history', 33 | long_description=(docs_read('README.rst')), 34 | url='https://github.com/GripQA/commit-entropy/', 35 | license='apache', 36 | author='Grip QA', 37 | author_email='', 38 | platforms=['any'], 39 | entry_points = { 40 | 'console_scripts': [ 41 | 'commit-entropy = commit_entropy.app:main' 42 | ], 43 | }, 44 | packages=find_packages("lib"), 45 | package_dir={'': 'lib'}, 46 | install_requires=['Naked'], 47 | keywords='', 48 | include_package_data=True, 49 | classifiers=[], 50 | ) 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Commit Entropy 2 | ======= 3 | Commit Entropy is a tool that can be used to calculate the entropy of changes in a source code repository. Entropy for code changes is a measure of how specific each commit was in relation to the entire code base. Very specific commits only affect a small set of files, and thus have a low entropy. Commits that touch a large number of files are much less specific and have a higher entropy as a result. 4 | 5 | The term Entropy in this context is a simplified application of [Shannon Entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29) to commits in a source repository. It's simplified since we only look at the number of files changed each commit, with each file having an equal probability. 6 | 7 | Read more about entropy on our [blog](http://grip.qa/blog/entropy-measuring-software-maturity/). 8 | 9 | Installation 10 | ------------ 11 | Commit Entropy currently supports [Python 3.x](https://www.python.org/downloads/). It can be installed using [pip](https://pip.pypa.io/en/latest/). 12 | 13 | pip install commit-entropy 14 | 15 | This will install the `commit-entropy` executable on your path. 16 | 17 | If you don't have pip, you can install it manually by cloning the code and running the install script: 18 | 19 | git clone git@github.com:GripQA/commit-entropy.git 20 | cd commit-entropy 21 | python setup.py install 22 | 23 | Usage 24 | ----- 25 | Currently we support a single operation: exporting a csv file with the average entropy per day and a 30-day rolling average. From within a git repo: 26 | 27 | commit-entropy csv 28 | 29 | This will output a `entropy.csv` file in the current directory with the average entropy values. 30 | 31 | You can ignore a list of paths by using the `--ignore` option: 32 | 33 | commit-entropy csv --ignore=vendor/*,*.log 34 | 35 | Support 36 | ------- 37 | If you have any questions, problems, or suggestions, please submit an [issue](../../issues) or contact us at support@grip.qa. 38 | -------------------------------------------------------------------------------- /docs/README.rst: -------------------------------------------------------------------------------- 1 | Commit Entropy 2 | ============== 3 | 4 | Commit Entropy is a tool that can be used to calculate the entropy of 5 | changes in a source code repository. Entropy for code changes is a 6 | measure of how specific each commit was in relation to the entire code 7 | base. Very specific commits only affect a small set of files, and thus 8 | have a low entropy. Commits that touch a large number of files are much 9 | less specific and have a higher entropy as a result. 10 | 11 | The term Entropy in this context is a simplified application of `Shannon 12 | Entropy `__ 13 | to commits in a source repository. It's simplified since we only look at 14 | the number of files changed each commit, with each file having an equal 15 | probability. 16 | 17 | Read more about entropy on our 18 | `blog `__. 19 | 20 | Installation 21 | ------------ 22 | 23 | Commit Entropy currently supports `Python 24 | 3.x `__. It can be installed using 25 | `pip `__. 26 | 27 | :: 28 | 29 | pip install commit-entropy 30 | 31 | This will install the ``commit-entropy`` executable on your path. 32 | 33 | If you don't have pip, you can install it manually by cloning the code 34 | and running the install script: 35 | 36 | :: 37 | 38 | git clone git@github.com:GripQA/commit-entropy.git 39 | cd commit-entropy 40 | python setup.py install 41 | 42 | Usage 43 | ----- 44 | 45 | Currently we support a single operation: exporting a csv file with the 46 | average entropy per day and a 30-day rolling average. From within a git 47 | repo: 48 | 49 | :: 50 | 51 | commit-entropy csv 52 | 53 | This will output a ``entropy.csv`` file in the current directory with 54 | the average entropy values. 55 | 56 | You can ignore a list of paths by using the ``--ignore`` option: 57 | 58 | :: 59 | 60 | commit-entropy csv --ignore=vendor/*,*.log 61 | 62 | Support 63 | ------- 64 | 65 | If you have any questions, problems, or suggestions, please submit an 66 | `issue <../../issues>`__ or contact us at support@grip.qa. 67 | -------------------------------------------------------------------------------- /lib/commit_entropy/parser/git_log_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | from datetime import datetime 5 | import re 6 | import math 7 | import fnmatch 8 | from functools import reduce 9 | 10 | class GitLogParser: 11 | COMMIT_REGEXP = r'[a-z0-9]{40}' 12 | AUTHOR_REGEXP = r'Author:\s+(.*)' 13 | DATE_REGEXP = r'Date:\s+(.*)' 14 | FILE_REGEXP = r'(\d+|\-)\s+(\d+|\-)+\s+(.+)' 15 | GIT_DATE_FORMAT = '%a %b %d %H:%M:%S %Y %z' 16 | 17 | def parse_stream(self, input_stream, ignore=[], encoding='utf-8'): 18 | return self.parse(input_stream.decode(encoding), ignore=ignore) 19 | 20 | def parse(self, input_string, ignore=[]): 21 | commit_strings = input_string[7:].split("\n\ncommit ") 22 | commits = [self.parse_commit(commit, ignore=ignore) for commit in commit_strings] 23 | return commits 24 | 25 | def parse_commit(self, commit_string, ignore=[]): 26 | lines = commit_string.split("\n") 27 | commit = reduce((lambda d, l: self.parse_line(d, l, ignore=ignore)), lines, {}) 28 | return commit 29 | 30 | def parse_line(self, commit_dict, line, ignore=[]): 31 | attribute = self.try_fetch_attribute(line, ignore=ignore) 32 | if attribute == None: 33 | return commit_dict 34 | if attribute[0] == 'count': 35 | commit_dict['count'] = commit_dict.get('count', 0) + attribute[1] 36 | else: 37 | commit_dict[attribute[0]] = attribute[1] 38 | return commit_dict 39 | 40 | def try_fetch_attribute(self, commit_line, ignore=[]): 41 | if re.match(self.COMMIT_REGEXP, commit_line): 42 | return ('commit', commit_line) 43 | elif re.match(self.AUTHOR_REGEXP, commit_line): 44 | return ('author', re.match(self.AUTHOR_REGEXP, commit_line).group(1)) 45 | elif re.match(self.DATE_REGEXP, commit_line): 46 | date_str = re.match(self.DATE_REGEXP, commit_line).group(1) 47 | return ('date', datetime.strptime(date_str, self.GIT_DATE_FORMAT)) 48 | elif re.match(self.FILE_REGEXP, commit_line): 49 | filename = re.match(self.FILE_REGEXP, commit_line).group(3) 50 | for pattern in ignore: 51 | if fnmatch.fnmatch(filename, pattern): 52 | return None 53 | return ('count', 1) 54 | return None 55 | 56 | if __name__ == '__main__': 57 | pass 58 | -------------------------------------------------------------------------------- /tests/parser/test_git_log_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | import unittest 5 | from commit_entropy.parser.git_log_parser import GitLogParser 6 | from datetime import datetime, timezone, timedelta 7 | 8 | class GitLogParserTest(unittest.TestCase): 9 | 10 | def setUp(self): 11 | self.commit_line_without_commit_keyword = '9093ace390c4e44910774ebddef403689435f046' 12 | self.author_line = 'Author: Some Author ' 13 | self.date_line = 'Date: Thu Jan 1 12:34:56 2015 +0100' 14 | self.file_line = '1 1 some/file/path.py' 15 | self.ignored_file_line = '1 1 ignored/some/file/path.py' 16 | self.ignored_merge_line = 'Merge: 390c4e4 def4036' 17 | self.ignored_comment_line = ' Some Comment Line' 18 | self.ignored_line = 'Ignored Content' 19 | self.complete_commit = """ 20 | commit 9093ace390c4e44910774ebddef403689435f046 21 | Merge: 390c4e4 def4036 22 | Author: Some Author 23 | Date: Thu Jan 1 12:34:56 2015 +0100 24 | 25 | Some Comment Line 26 | 27 | 1 1 some/file/path.py 28 | 1 0 some/other/path.py 29 | 1 1 ignored/some/file/path.py 30 | 0 1 yet/another/file/path.py 31 | 0 0 yet/another/file/path.py 32 | """.strip() 33 | self.parser = GitLogParser() 34 | 35 | def parse_test(self): 36 | """The correct git commit dicts should be retrieved""" 37 | self.assertEqual( 38 | [ 39 | { 40 | 'commit': '9093ace390c4e44910774ebddef403689435f046', 41 | 'author': 'Some Author ', 42 | 'date': datetime(2015, 1, 1, 12, 34, 56, tzinfo=timezone(timedelta(0, 3600))), 43 | 'count': 4, 44 | }, 45 | ], 46 | self.parser.parse(self.complete_commit, ignore=["ignored/*"]) 47 | ) 48 | 49 | def try_fetch_attribute_test(self): 50 | """The correct attribute k/v pair should be retrieved""" 51 | self.assertEqual( 52 | ('commit', '9093ace390c4e44910774ebddef403689435f046'), 53 | self.parser.try_fetch_attribute(self.commit_line_without_commit_keyword) 54 | ) 55 | self.assertEqual( 56 | ('author', 'Some Author '), 57 | self.parser.try_fetch_attribute(self.author_line) 58 | ) 59 | self.assertEqual( 60 | ('date', datetime(2015, 1, 1, 12, 34, 56, tzinfo=timezone(timedelta(0, 3600)))), 61 | self.parser.try_fetch_attribute(self.date_line) 62 | ) 63 | self.assertEqual( 64 | ('count', 1), 65 | self.parser.try_fetch_attribute(self.file_line) 66 | ) 67 | self.assertEqual( 68 | ('count', 1), 69 | self.parser.try_fetch_attribute(self.ignored_file_line) 70 | ) 71 | self.assertEqual( 72 | None, 73 | self.parser.try_fetch_attribute(self.ignored_file_line, ignore=["ignored/*"]) 74 | ) 75 | self.assertEqual(None, self.parser.try_fetch_attribute(self.ignored_merge_line)) 76 | self.assertEqual(None, self.parser.try_fetch_attribute(self.ignored_comment_line)) 77 | self.assertEqual(None, self.parser.try_fetch_attribute(self.ignored_line)) 78 | -------------------------------------------------------------------------------- /lib/commit_entropy/commands/csv_printer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | from Naked.toolshed.shell import run 5 | from Naked.toolshed.system import exit_fail 6 | from commit_entropy.parser.git_log_parser import GitLogParser 7 | from datetime import datetime 8 | from datetime import timedelta, date 9 | import statistics 10 | import math 11 | import sys 12 | import csv 13 | 14 | def daterange(start_date, end_date): 15 | for n in range(int ((end_date - start_date).days)): 16 | yield start_date + timedelta(n) 17 | 18 | class CsvPrinter: 19 | def run(self, ignore=[]): 20 | self.ensure_git_repo() 21 | log_output = self.get_git_log() 22 | commits = GitLogParser().parse_stream(log_output, ignore=ignore) 23 | for commit in commits: 24 | commit['entropy'] = self.get_entropy(commit) 25 | 26 | daily_commits = self.group_by_day(commits) 27 | daily_entropies = self.get_running_averages(daily_commits, size=1) 28 | monthly_entropies = self.get_running_averages(daily_commits, size=30) 29 | 30 | entropies = [(x[0], x[1], monthly_entropies[i][1]) for i, x in enumerate(daily_entropies)] 31 | 32 | with open('entropy.csv', 'w', newline='') as csvfile: 33 | writer = csv.writer(csvfile) 34 | writer.writerow(['Day','Entropy','30 Day']) 35 | for day in entropies: 36 | writer.writerow(day) 37 | 38 | def ensure_git_repo(self): 39 | status_output = run('git status', suppress_stdout=True, suppress_stderr=True) 40 | if not status_output: 41 | print('Please run this command in a git repository', file=sys.stderr) 42 | exit_fail() 43 | 44 | def get_git_log(self): 45 | log_output = run('git log --numstat --reverse', suppress_stdout=True, suppress_stderr=False) 46 | if not log_output: 47 | print('Error fetching git log', file=sys.stderr) 48 | exit_fail() 49 | return log_output 50 | 51 | def get_entropy(self, commit): 52 | if commit.get('count', 0) == 0: 53 | return None 54 | return math.log(commit['count'], 2) 55 | 56 | def group_by_day(self, commits): 57 | commits_by_day = {} 58 | for commit in commits: 59 | day = commit['date'].strftime('%Y%m%d') 60 | days_commits = commits_by_day.get(day, []) 61 | days_commits.append(commit) 62 | commits_by_day[day] = days_commits 63 | return commits_by_day 64 | 65 | def get_running_averages(self, commits_by_day, size=1): 66 | daily_entropies = [] 67 | start_date = datetime.strptime(min(commits_by_day.keys()), '%Y%m%d') 68 | end_date = datetime.strptime(max(commits_by_day.keys()), '%Y%m%d') 69 | for date in daterange(start_date, end_date + timedelta(1)): 70 | key = date.strftime('%Y%m%d') 71 | if date < start_date + timedelta(size - 1): 72 | daily_entropies.append((key, '')) 73 | continue 74 | commits = [] 75 | for commit_date in daterange(date, date + timedelta(size)): 76 | commits += commits_by_day.get(commit_date.strftime('%Y%m%d'), []) 77 | average = self.get_average_entropy(commits) 78 | if average is not None: 79 | daily_entropies.append((key, average)) 80 | else: 81 | daily_entropies.append((key, '')) 82 | return daily_entropies 83 | 84 | def get_average_entropy(self, commits): 85 | entropies = [c['entropy'] for c in commits if 'entropy' in c and not c['entropy'] == None] 86 | if entropies: 87 | return statistics.mean(entropies) 88 | else: 89 | return None 90 | 91 | if __name__ == '__main__': 92 | pass 93 | -------------------------------------------------------------------------------- /lib/commit_entropy/app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | #------------------------------------------------------------------------------ 5 | # commit_entropy 6 | # Copyright 2015 Grip QA 7 | # apache 8 | #------------------------------------------------------------------------------ 9 | 10 | #------------------------------------------------------------------------------------ 11 | # c.cmd = Primary command (commit-entropy ) 12 | # c.cmd2 = Secondary command (commit-entropy ) 13 | # 14 | # c.arg_to_cmd = first positional argument to the primary command 15 | # c.arg_to_cmd2 = first positional argument to the secondary command 16 | # 17 | # c.option(option_string, [bool argument_required]) = test for option with optional positional argument to option test 18 | # c.option_with_arg(option_string) = test for option and mandatory positional argument to option 19 | # c.flag(flag_string) = test for presence of a "option=argument" style flag 20 | # 21 | # c.arg(arg_string) = returns the next positional argument to the arg_string argument 22 | # c.flag_arg(flag_string) = returns the flag assignment for a "--option=argument" style flag 23 | #------------------------------------------------------------------------------------ 24 | 25 | # Application start 26 | def main(): 27 | import sys 28 | from Naked.commandline import Command 29 | from Naked.toolshed.state import StateObject 30 | 31 | #------------------------------------------------------------------------------------------ 32 | # [ Instantiate command line object ] 33 | # used for all subsequent conditional logic in the CLI application 34 | #------------------------------------------------------------------------------------------ 35 | c = Command(sys.argv[0], sys.argv[1:]) 36 | #------------------------------------------------------------------------------ 37 | # [ Instantiate state object ] 38 | #------------------------------------------------------------------------------ 39 | state = StateObject() 40 | #------------------------------------------------------------------------------------------ 41 | # [ Command Suite Validation ] - early validation of appropriate command syntax 42 | # Test that user entered at least one argument to the executable, print usage if not 43 | #------------------------------------------------------------------------------------------ 44 | if not c.command_suite_validates(): 45 | from commit_entropy.settings import usage as commit_entropy_usage 46 | print(commit_entropy_usage) 47 | sys.exit(1) 48 | #------------------------------------------------------------------------------------------ 49 | # [ NAKED FRAMEWORK COMMANDS ] 50 | # Naked framework provides default help, usage, and version commands for all applications 51 | # --> settings for user messages are assigned in the lib/commit_entropy/settings.py file 52 | #------------------------------------------------------------------------------------------ 53 | if c.help(): # User requested commit-entropy help information 54 | from commit_entropy.settings import help as entropy_help 55 | print(commit_entropy_help) 56 | sys.exit(0) 57 | elif c.usage(): # User requested commit-entropy usage information 58 | from commit_entropy.settings import usage as commit_entropy_usage 59 | print(commit_entropy_usage) 60 | sys.exit(0) 61 | elif c.version(): # User requested commit-entropy version information 62 | from commit_entropy.settings import app_name, major_version, minor_version, patch_version 63 | version_display_string = app_name + ' ' + major_version + '.' + minor_version + '.' + patch_version 64 | print(version_display_string) 65 | sys.exit(0) 66 | #------------------------------------------------------------------------------------------ 67 | # [ PRIMARY COMMAND LOGIC ] 68 | # Enter your command line parsing logic below 69 | #------------------------------------------------------------------------------------------ 70 | 71 | # [[ Example usage ]] ------------------------------->>> 72 | # if c.cmd == 'hello': 73 | # if c.cmd2 = 'world': 74 | # if c.option('--print'): 75 | # print('Hello World!') 76 | # elif c.cmd == 'spam': 77 | # if c.option_with_arg('--with'): 78 | # friend_of_spam = c.arg('--with') # user enters commit-entropy spam --with eggs 79 | # print('spam and ' + friend_of_spam) # prints 'spam and eggs' 80 | # elif c.cmd == 'naked': 81 | # if c.flag("--language"): 82 | # lang = c.flag_arg("--language") # user enters commit-entropy naked --language=python 83 | # print("Naked & " + lang) # prints 'Naked & python' 84 | # End example --------------------------------------->>> 85 | 86 | elif c.cmd == 'csv': 87 | from commit_entropy.commands.csv_printer import CsvPrinter 88 | if c.flag('--ignore'): 89 | ignore = c.flag_arg('--ignore').split(',') 90 | else: 91 | ignore = [] 92 | printer = CsvPrinter() 93 | printer.run(ignore=ignore) 94 | 95 | #------------------------------------------------------------------------------------------ 96 | # [ DEFAULT MESSAGE FOR MATCH FAILURE ] 97 | # Message to provide to the user when all above conditional logic fails to meet a true condition 98 | #------------------------------------------------------------------------------------------ 99 | else: 100 | print("Could not complete the command that you entered. Please try again.") 101 | sys.exit(1) #exit 102 | 103 | if __name__ == '__main__': 104 | main() 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------