Skip to content

Commit

Permalink
Merge pull request #5 from finklabs/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
Mark authored Apr 28, 2018
2 parents 3fe5792 + f52897e commit b2533cd
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.0
current_version = 0.3.2

[bumpversion:part:dev]

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

### [0.3.2] - 2018-08-28
#### Added
- added .metrics file contents sample to README

### [0.3.1] - 2018-08-28
#### Changed
- renamed positions to block_positions
- use .gitignore file in globbing

### [0.3.0] - 2018-08-08
#### Added
- positions of functions and classes per file for JS, Go, Python, C++
Expand Down
245 changes: 245 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,251 @@ Please visit the plugin page for details:
* [test coverage](https://github.com/markfink/metrics.pytest-cov)
Sample ".metrics" file results (with plugins installed)
``` json
{
"build": {
"active_branch": "master",
"committed_datetime": "2018-04-28T11:52:37+02:00",
"committed_ts": 1524909157,
"committers": [
"mark"
],
"origin": "[email protected]:markfink/metrics.gitinfo.git",
"sha": "f7ba6f27ee8c34991acd3cd6ef14c8bd6ed9c34e",
"sha_start": "7d04ffd8c2acbbfa24977dc6c7b51f34636e34de",
"summary": "Bump version: 0.0.3 \u2192 0.0.4",
"version": "0.0.4"
},
"files": {
"metrics_gitinfo/__init__.py": {
"age_days": 25.80023148148148,
"block_positions": [],
"change_frequency": 5,
"comments": 1,
"committers_count": 1,
"language": "Python",
"lines_added": [
3
],
"lines_deleted": [
3
],
"mccabe": 0,
"pylint_score": 5.0,
"ratio_comment_to_code": 0.5,
"sloc": 2
},
"metrics_gitinfo/file_info.py": {
"age_days": 0.0008333333333333334,
"block_positions": [
{
"end": 17,
"name": "get_file_info",
"start": 5,
"type": "Function"
}
],
"change_frequency": 1,
"comments": 4,
"committers_count": 1,
"language": "Python",
"mccabe": 1,
"pylint_score": 10.0,
"ratio_comment_to_code": 0.44,
"sloc": 9
},
"metrics_gitinfo/git_diff_muncher.py": {
"age_days": 24.042083333333334,
"block_positions": [
{
"end": 17,
"name": "GitDiffError",
"start": 10,
"type": "Class"
},
{
"end": 81,
"name": "parse_diff_lines",
"start": 18,
"type": "Function"
},
{
"end": 111,
"name": "_parse_hunk_line",
"start": 82,
"type": "Function"
}
],
"change_frequency": 1,
"comments": 50,
"committers_count": 1,
"language": "Python",
"mccabe": 15,
"pylint_score": 9.56,
"ratio_comment_to_code": 1.02,
"sloc": 49
},
"metrics_gitinfo/gitinfo.py": {
"age_days": 25.80023148148148,
"block_positions": [
{
"end": 17,
"name": "get_file_processors",
"start": 13,
"type": "Function"
},
{
"end": 22,
"name": "get_build_processors",
"start": 18,
"type": "Function"
},
{
"end": 113,
"methods": [
{
"end": 35,
"name": "_get_commits_contained",
"start": 31,
"type": "Function"
},
{
"end": 41,
"name": "_get_source_target",
"start": 36,
"type": "Function"
},
{
"end": 56,
"name": "_extract_info",
"start": 52,
"type": "Function"
},
{
"end": 88,
"name": "reset",
"start": 84,
"type": "Function"
},
{
"end": 105,
"name": "process_file",
"start": 89,
"type": "Function"
},
{
"end": 108,
"name": "get_metrics",
"start": 106,
"type": "Function"
},
{
"end": 113,
"name": "get_build_metrics",
"start": 109,
"type": "Function"
}
],
"name": "GitMetric",
"start": 23,
"type": "Class"
}
],
"change_frequency": 6,
"comments": 9,
"committers_count": 1,
"language": "Python",
"lines_added": [
88,
89,
90,
91
],
"lines_deleted": [
10,
64,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
100
],
"mccabe": 8,
"pylint_score": 9.06,
"ratio_comment_to_code": 0.11,
"sloc": 83
},
"tests/__init__.py": {
"age_days": 24.08150462962963,
"block_positions": [
{
"end": 10,
"name": "here",
"start": 9,
"type": "Function"
}
],
"change_frequency": 1,
"comments": 1,
"committers_count": 1,
"language": "Python",
"mccabe": 0,
"pylint_score": 3.33,
"ratio_comment_to_code": 0.17,
"sloc": 6
},
"tests/test_metrics_gitinfo.py": {
"age_days": 22.07342592592593,
"block_positions": [
{
"end": 19,
"name": "tempfolder",
"start": 11,
"type": "Function"
},
{
"end": 29,
"name": "test_metrics_gitinfo_no_git_repo",
"start": 20,
"type": "Function"
},
{
"end": 39,
"name": "test_metrics_gitinfo",
"start": 30,
"type": "Function"
},
{
"end": 47,
"name": "test_metrics_gitinfo_no_lastrun",
"start": 40,
"type": "Function"
}
],
"change_frequency": 1,
"comments": 2,
"committers_count": 1,
"language": "Python",
"mccabe": 6,
"pylint_score": 4.64,
"ratio_comment_to_code": 0.07,
"sloc": 29
}
}
}
```
# Acknowledgements
* codebase originally based on grop.py by Jurgen Hermann (2001)
Expand Down
2 changes: 1 addition & 1 deletion metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
Copyright (c) 2005 by Reg. Charney <[email protected]>
All rights reserved, see LICENSE for details.
"""
__version__ = "0.3.0"
__version__ = "0.3.2"

METRICS_FILENAME = '.metrics'
8 changes: 7 additions & 1 deletion metrics/metrics_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import os.path
import sys
import json
import logging
Expand Down Expand Up @@ -118,7 +119,12 @@ def process_file_metrics(context, file_processors):
file_metrics = OrderedDict()

# TODO make available the includes and excludes feature
in_files = glob_files(context['root_dir'], context['in_file_names'])
gitignore = []
if os.path.isfile('.gitignore'):
with open('.gitignore', 'r') as ifile:
gitignore = ifile.read().splitlines()

in_files = glob_files(context['root_dir'], context['in_file_names'], gitignore=gitignore)
# main loop
for in_file, key in in_files:
# print 'file %i: %s' % (i, in_file)
Expand Down
4 changes: 2 additions & 2 deletions metrics/outputformat_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def format(file_metrics, build_metrics):
def report_header(file_metrics):
values = list(file_metrics.values())[0]
print(values)
values.pop('positions', None)
values.pop('block_positions', None)
return 'filename,' + ','.join(values) + '\n'

def report_metrics(file_metrics):
report = ''
for key, values in file_metrics.items():
report += key + ','
report += ','.join([str(v) for k, v in values.items() if k not in ['positions']])
report += ','.join([str(v) for k, v in values.items() if k not in ['block_positions']])
report += '\n'
return report

Expand Down
2 changes: 1 addition & 1 deletion metrics/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_metrics(self):
for m in p['methods']:
if m['end'] > p['end']:
p['end'] = m['end']
return {'positions': self._positions}
return {'block_positions': self._positions}

metrics = property(get_metrics)

Expand Down
6 changes: 4 additions & 2 deletions metrics/processargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
from optparse import OptionParser, BadOptionError

from . import __version__

usage_str = """python metrics [ options ] pgm1.ex1 [ pgm2.ex2 ... ]
Metrics are computed for the source code files
Expand Down Expand Up @@ -54,7 +56,7 @@ def __init__(self, *pArgs, **pKwds):
del( self.__dict__['pKwds'] ) # remove redundant pKwds in self.__dict__

# set up option parser
parser = MyOptionParser( '', version="%prog 0.8.1" )
parser = MyOptionParser('', version="%prog " + __version__)

parser.add_option("-f", "--files",
dest="in_file_list",
Expand All @@ -69,7 +71,7 @@ def __init__(self, *pArgs, **pKwds):
dest="output_format_str",
default = self.output_format,
choices = ["xml", "csv", "json"],
help="Choose an output format for a parser to read. Valid choices: xml, csv")
help="Choose an output format for a parser to read. Valid choices: xml, csv, json")

# parse the command line/arguments for this instance
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_code_sample(in_file, fmt, sloc, comments, ratio, mccabe, language):
' <metric name="comments" value="46" />\n' +
' <metric name="ratio_comment_to_code" value="0.03" />\n' +
' <metric name="mccabe" value="169" />\n' +
' <metric name="positions" value="[]" />\n' +
' <metric name="block_positions" value="[]" />\n' +
' </file>\n' +
' </files>\n' +
'</metrics>\n')
Expand All @@ -53,10 +53,10 @@ def test_code_sample(in_file, fmt, sloc, comments, ratio, mccabe, language):
'{\n' +
' "files": {\n' +
' "tests/resources/code_samples/js1.js": {\n' +
' "block_positions": [],\n' +
' "comments": 46,\n' +
' "language": "JavaScript",\n' +
' "mccabe": 169,\n' +
' "positions": [],\n' +
' "ratio_comment_to_code": 0.03,\n' +
' "sloc": 1446\n' +
' }\n' +
Expand Down
2 changes: 1 addition & 1 deletion tests/test_positions_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_lexer_on_cpp_class():
positions.language = 'C++'
for t in tokens:
positions.process_token(t)
assert positions.metrics == {'positions': [{
assert positions.metrics == {'block_positions': [{
'type': 'Class',
'name': 'Rectangle',
'start': 3,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_positions_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_lexer_on_go_code():
positions.language = 'Go'
for t in tokens:
positions.process_token(t)
assert positions.metrics == {'positions': [
assert positions.metrics == {'block_positions': [
{'type': 'Interface', 'name': 'Animal', 'start': 1, 'end': 3},
{'type': 'Struct', 'name': 'Dog', 'start': 5, 'end': 5},
{'type': 'Function', 'name': 'Name', 'start': 7, 'end': 9},
Expand Down
Loading

0 comments on commit b2533cd

Please sign in to comment.