-
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.
feat: ✨ Issue 7 add basic repository browser (#8)
* WIP * Show units in browser * Fixed tests * Add source location * Show code snippet * Very basic report browser
- Loading branch information
1 parent
223a964
commit 9645be2
Showing
31 changed files
with
699 additions
and
307 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,6 +1,6 @@ | ||
build/ | ||
dist/ | ||
clim.spec | ||
main.spec | ||
codelimit.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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
poetry run pyinstaller --specpath dist -n codelimit -F main.py |
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
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,7 +1,11 @@ | ||
from dataclasses import dataclass | ||
|
||
from codelimit.common.SourceLocation import SourceLocation | ||
|
||
|
||
@dataclass | ||
class SourceMeasurement: | ||
start_line: int | ||
unit_name: str | ||
start: SourceLocation | ||
end: SourceLocation | ||
value: 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,26 @@ | ||
import os.path | ||
from pathlib import Path | ||
|
||
from InquirerPy import inquirer | ||
from InquirerPy.base import Choice | ||
|
||
from codelimit.common.report.Report import Report | ||
from codelimit.common.report.ReportUnit import format_report_unit, ReportUnit | ||
from codelimit.common.source_utils import get_location_range | ||
|
||
|
||
class Browser: | ||
def __init__(self, report: Report, path: Path = '.'): | ||
self.report = report | ||
self.path = path | ||
|
||
def show(self): | ||
units = [Choice(value=unit, name=format_report_unit(unit)) for unit in | ||
self.report.all_report_units_sorted_by_length_asc()] | ||
while True: | ||
selected_unit: ReportUnit = inquirer.select(message='Select unit', choices=units).execute() | ||
file_path = os.path.join(self.path, selected_unit['file']) | ||
with open(file_path) as file: | ||
code = file.read() | ||
snippet = get_location_range(code, selected_unit['measurement']['start'], selected_unit['measurement']['end']) | ||
print(snippet) |
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,24 @@ | ||
from json import loads | ||
|
||
from codelimit.common.Codebase import Codebase | ||
from codelimit.common.SourceLocation import SourceLocation | ||
from codelimit.common.report.Report import Report | ||
from codelimit.common.SourceMeasurement import SourceMeasurement | ||
|
||
|
||
class ReportReader: | ||
|
||
@staticmethod | ||
def from_json(json: str) -> Report: | ||
d = loads(json) | ||
codebase = Codebase() | ||
report = Report(codebase) | ||
report.uuid = d['uuid'] | ||
for k, v in d['codebase']['measurements'].items(): | ||
measurements: list[SourceMeasurement] = [] | ||
for m in v: | ||
start_location = SourceLocation(m['start']['line'], m['start']['column']) | ||
end_location = SourceLocation(m['end']['line'], m['end']['column']) | ||
measurements.append(SourceMeasurement(m['unit_name'], start_location, end_location, m['value'])) | ||
codebase.add_file(k, measurements) | ||
return report |
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,16 @@ | ||
from dataclasses import dataclass | ||
|
||
from codelimit.common.SourceMeasurement import SourceMeasurement | ||
|
||
|
||
@dataclass | ||
class ReportUnit: | ||
file: str | ||
measurement: SourceMeasurement | ||
|
||
|
||
def format_report_unit(unit: ReportUnit) -> str: | ||
name = unit.measurement.unit_name | ||
length = unit.measurement.value | ||
prefix = f'[{length:3}]' if length < 61 else '[60+]' | ||
return f'{prefix} {name}' |
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
Empty file.
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
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
Oops, something went wrong.