Conversation
|
The CI failures could be fixed by extracting a function from the kinda duplicated code that prints the table or JSON, something like below: def print_result(as_json, console_format, data, headers, path):
if as_json:
json_data = [{headers[x]: d[x] for x in range(len(headers))} for d in data]
for entry in json_data:
entry["Filename"] = path
print(json.dumps(json_data, indent=2))
else:
print(
tabulate.tabulate(
headers=headers, tabular_data=data, tablefmt=console_format
)
)However, it's not clear to me where such a function should live. Maybe in a new module in |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #194 +/- ##
==========================================
- Coverage 95.86% 95.83% -0.03%
==========================================
Files 25 26 +1
Lines 1403 1442 +39
Branches 296 315 +19
==========================================
+ Hits 1345 1382 +37
- Misses 33 34 +1
- Partials 25 26 +1
☔ View full report in Codecov by Sentry. |
|
This feature could be really useful, do you need help on something ? |
|
Yes, thank you, I'd love to get some validation on the chosen output format/entries. I'll update this PR this week and show what the output currently looks like. |
|
I've updated the PR and added some tests. I'm open to all suggestions: if you see ways to improve the output or the code, please let me know. Here's some sample output for report: [
{
"Revision": "d0ad384",
"Message": "Add some more typing (#221)\n\n* Update typing info ",
"Author": "devdanzin",
"Date": "2023-09-22",
"Cyclomatic Complexity": "23 (0)",
"Unique Operands": "6 (0)",
"Maintainability Index": "62.7366 (-0.30257)",
"Lines of Code": "176 (1)",
"Filename": "src\\wily\\commands\\graph.py"
},
{
"Revision": "bdc825f",
"Message": "Standalone plotly.min.js for graph (fix #189) (#20",
"Author": "devdanzin",
"Date": "2023-09-22",
"Cyclomatic Complexity": "23 (0)",
"Unique Operands": "6 (0)",
"Maintainability Index": "63.0391 (0.624665)",
"Lines of Code": "175 (3)",
"Filename": "src\\wily\\commands\\graph.py"
},
{
"Revision": "6f5cd5d",
"Message": "Restore displaying graph markers. (#215)\n\n",
"Author": "devdanzin",
"Date": "2023-09-04",
"Cyclomatic Complexity": "23 (0)",
"Unique Operands": "6 (0)",
"Maintainability Index": "62.4145 (0.0997117)",
"Lines of Code": "172 (0)",
"Filename": "src\\wily\\commands\\graph.py"
},
{
"Revision": "07fc855",
"Message": "Allow passing multiple file names to graph, to get",
"Author": "devdanzin",
"Date": "2023-08-25",
"Cyclomatic Complexity": "23 (3)",
"Unique Operands": "6 (1)",
"Maintainability Index": "62.3148 (-2.57913)",
"Lines of Code": "172 (15)",
"Filename": "src\\wily\\commands\\graph.py"
}
]Here's sample output for report, diff, rank and index (only the JSON goes to stdout): Output for wily report --jsonwily report src\wily\commands\graph.py -c -m --json
Using default metrics ['raw.loc', 'maintainability.mi', 'halstead.h1', 'cyclomatic.complexity']
-----------History for ['cyclomatic.complexity', 'halstead.h1', 'maintainability.mi', 'raw.loc']------------
[
{
"Revision": "d0ad384",
"Message": "Add some more typing (#221)\n\n* Update typing info ",
"Author": "devdanzin",
"Date": "2023-09-22",
"Cyclomatic Complexity": "23 (0)",
"Unique Operands": "6 (0)",
"Maintainability Index": "62.7366 (-0.30257)",
"Lines of Code": "176 (1)",
"Filename": "src\\wily\\commands\\graph.py"
},
{
"Revision": "bdc825f",
"Message": "Standalone plotly.min.js for graph (fix #189) (#20",
"Author": "devdanzin",
"Date": "2023-09-22",
"Cyclomatic Complexity": "23 (0)",
"Unique Operands": "6 (0)",
"Maintainability Index": "63.0391 (0.624665)",
"Lines of Code": "175 (3)",
"Filename": "src\\wily\\commands\\graph.py"
},
{
"Revision": "6f5cd5d",
"Message": "Restore displaying graph markers. (#215)\n\n",
"Author": "devdanzin",
"Date": "2023-09-04",
"Cyclomatic Complexity": "23 (0)",
"Unique Operands": "6 (0)",
"Maintainability Index": "62.4145 (0.0997117)",
"Lines of Code": "172 (0)",
"Filename": "src\\wily\\commands\\graph.py"
},
{
"Revision": "07fc855",
"Message": "Allow passing multiple file names to graph, to get",
"Author": "devdanzin",
"Date": "2023-08-25",
"Cyclomatic Complexity": "23 (3)",
"Unique Operands": "6 (1)",
"Maintainability Index": "62.3148 (-2.57913)",
"Lines of Code": "172 (15)",
"Filename": "src\\wily\\commands\\graph.py"
}
]
Output of wily diff --jsonwily diff src\wily\commands\report.py -r bdc825f --json
Using default metrics ['raw.loc', 'maintainability.mi', 'halstead.h1', 'cyclomatic.complexity']
Comparing current with bdc825f by devdanzin on 2023-09-22.
[
{
"File": "src\\wily\\commands\\report.py",
"Lines of Code": "216 -> 222",
"Maintainability Index": "52.2582 -> 51.1045",
"Unique Operands": "10 -> 10",
"Cyclomatic Complexity": "27 -> 29"
},
{
"File": "src\\wily\\commands\\report.py:report",
"Lines of Code": "-",
"Maintainability Index": "-",
"Unique Operands": "10 -> 10",
"Cyclomatic Complexity": "27 -> 29"
},
{
"File": "src\\wily\\commands\\report.py:report",
"Lines of Code": "-",
"Maintainability Index": "-",
"Unique Operands": "10 -> 10",
"Cyclomatic Complexity": "27 -> 29"
}
]
Output for wily rank --jsonwily rank --json
-----------Rank for Maintainability Index for f57006e by devdanzin on 2023-10-28.------------
[
{
"File": "test\\unit\\test_report_unit.py",
"Maintainability Index": 32.32190502991561
},
{
"File": "src\\wily\\__main__.py",
"Maintainability Index": 34.30472174464306
},
[...]
{
"File": "test",
"Maintainability Index": 53.8019265092112
},
{
"File": "src\\wily\\commands\\diff.py",
"Maintainability Index": 54.453194689759016
},
{
"File": "test\\unit\\test_cache.py",
"Maintainability Index": 56.010024060239985
},
{
"File": "test\\integration\\test_archiver.py",
"Maintainability Index": 56.92174441952554
},
{
"File": "test\\integration",
"Maintainability Index": 58.06125906375679
},
{
"File": "test\\unit\\test_operators.py",
"Maintainability Index": 58.341013499953924
},
{
"File": "src\\wily\\operators\\__init__.py",
"Maintainability Index": 58.88435086943125
},
{
"File": "test\\integration\\test_all_operators.py",
"Maintainability Index": 60.037337074043776
},
{
"File": "src\\wily\\commands\\build.py",
"Maintainability Index": 61.21595278201455
},
{
"File": "test\\unit\\test_list_metrics_unit.py",
"Maintainability Index": 61.88150602294518
},
{
"File": "src\\wily\\cache.py",
"Maintainability Index": 62.37760644177526
},
{
"File": "src\\wily\\commands\\graph.py",
"Maintainability Index": 62.736559310518224
},
{
"File": "src\\wily\\state.py",
"Maintainability Index": 62.91391505052898
},
{
"File": "src\\wily\\archivers\\git.py",
"Maintainability Index": 64.88920153537751
},
{
"File": "",
"Maintainability Index": 66.68375918601492
},
[...]
"File": "docs",
"Maintainability Index": 100.0
},
{
"File": "docs\\source",
"Maintainability Index": 100.0
},
{
"File": "Total",
"Maintainability Index": 68.52496920011775
}
]
Output of wily index --jsonwily index -m --json
--------Configuration---------
Path: ~\PycharmProjects\wily
Archiver: git
Operators: {'cyclomatic', 'raw', 'maintainability', 'halstead'}
|
separated columns in report() JSON output.
…ain to allow report() to pass.
This proof of concept adds a
--jsonoption to diff, index, rank and report, allowing to generate output in JSON format.Example output (excerpt from
wily report -n 11 --json src\wily\commands\report.py):[ { "Revision": "f1e8225", "Author": "Anthony Shaw", "Date": "2023-03-12", "Cyclomatic Complexity": "24 (0)", "Unique Operands": "8 (0)", "Maintainability Index": "56.8982 (0.0)", "Lines of Code": "206 (0)" }, { "Revision": "e9921dd", "Author": "Christian Clauss", "Date": "2023-03-11", "Cyclomatic Complexity": "24 (0)", "Unique Operands": "8 (0)", "Maintainability Index": "56.8982 (0)", "Lines of Code": "206 (0)" } ]Pasting this here I just realized it might be a good idea to add file name to each JSON entry. Oh well, back to the drawing board.
Still needs tests and docstring updates.
Fixes part of #92.