-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90f5510
commit 2a6f8c8
Showing
7 changed files
with
93 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
build/ | ||
dist/ | ||
clim.spec | ||
clim.json | ||
.coverage | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from codelimit.common.Report import Report | ||
from codelimit.common.Scanner import scan | ||
from codelimit.version import version, release_date | ||
|
||
print('Code Limit') | ||
print(f'Version: {version}, released on: {release_date}') | ||
|
||
report = scan('.') | ||
print(f'Total lines of code: {report.total_lines_of_code}') | ||
measurements = scan('.') | ||
print(f'Total lines of code: {measurements.total_loc()}') | ||
report = Report(measurements) | ||
print(f'Average length (LOC): {report.get_average()}') | ||
print(f'90th percentile: {report.ninetieth_percentile()}') | ||
report.display_risk_category_plot() | ||
report.display_risk_category_plot() | ||
with open('clim.json', 'w') as outfile: | ||
outfile.write(measurements.to_json(True)) | ||
print('Output written to clim.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Measurement: | ||
filename: str | ||
line: int | ||
length: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import dataclasses | ||
import json | ||
|
||
from codelimit.common.Measurement import Measurement | ||
|
||
|
||
class Measurements: | ||
def __init__(self): | ||
self._measurements = [] | ||
|
||
def add(self, measurement: Measurement): | ||
self._measurements.append(measurement) | ||
|
||
def all(self) -> list[Measurement]: | ||
return self._measurements | ||
|
||
def total_loc(self) -> int: | ||
result = 0 | ||
for m in self._measurements: | ||
result += m.length | ||
return result | ||
|
||
def sorted_by_length(self): | ||
return sorted(self._measurements, key=lambda m: m.length) | ||
|
||
def to_json(self, pretty_print=False) -> str: | ||
class EnhancedJSONEncoder(json.JSONEncoder): | ||
def default(self, o): | ||
if dataclasses.is_dataclass(o): | ||
return dataclasses.asdict(o) | ||
return super().default(o) | ||
|
||
if pretty_print: | ||
return json.dumps(self._measurements, cls=EnhancedJSONEncoder, indent=2) | ||
else: | ||
return json.dumps(self._measurements, cls=EnhancedJSONEncoder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from codelimit.common.Measurement import Measurement | ||
from codelimit.common.Measurements import Measurements | ||
|
||
|
||
def test_to_json(): | ||
measurements = Measurements() | ||
m = Measurement('foo.py', 10, 10) | ||
measurements.add(m) | ||
|
||
assert measurements.to_json() == '[{"filename": "foo.py", "line": 10, "length": 10}]' | ||
|
||
|
||
def test_to_json_multiple(): | ||
measurements = Measurements() | ||
m = Measurement('foo.py', 10, 10) | ||
measurements.add(m) | ||
m = Measurement('bar.py', 20, 10) | ||
measurements.add(m) | ||
|
||
assert measurements.to_json() == '[{"filename": "foo.py", "line": 10, "length": 10}' + \ | ||
', {"filename": "bar.py", "line": 20, "length": 10}]' |