Provide option to return raw metrics by block type (#192
This is a first attempt at implementing a raw_visitor to provide metrics by block type.
It is lightly tested reusing some of the tests from test_raw.py, not all of which are currently passing. Just looking for some feedback @rubik before adding more tests.
ast.get_source_segement was implemented in Python 3.8 which makes it easy to reproduce a segment of the input code from an ast node.
@BlaneG Hi Blane, thanks for the contribution! I was not aware of such addition in Python 3.8, I will check it out. The idea is definitely interesting. It's something I wanted to do from the start, but at the time it wasn't possible in an easy way.
I think the idea is good. Now besides the minor comments I added above, two things are needed mainly:
- enable all the tests and ensure everything is passing
- enable this functionality only on Python versions where it's supported. Currently the tests on Travis are failing for this reason.
Then before merging, we'll have to format the code with black and isort (I added the commands to the Makefile).
Hi @BlaneG, in order to have this PR merged, you need to fix the conflicts and ensure all tests are passing. Are you still working on it?
I came across this open PR when I was searching to see if there was any progress on the topic - is there anything I can do to help?
@miketheman Hi Mike. Sure, I can merge the PR once:
- all conflicts with the master branch are solved
- all tests pass
There's a big showstopper for ast.get_source_segment: it doesn't roundtrip comments, which makes raw metrics wrong.
I'm investigating alternatives that assure a source code roundtrip, hopefully without having to resort to a CST.