aboutcode-org / deltacode

DeltaCode: compare two codebase scans (from ScanCode) to detect significant changes.
http://www.aboutcode.org/
20 stars 27 forks source link

Refactor 'generate_csv()' #9

Closed johnmhoran closed 6 years ago

johnmhoran commented 6 years ago

I think we might be able to reduce the 38 or so lines used in generate_csv() to construct the .csv tuple down to around 13 lines by using a ternary/conditional expression, e.g.,

new = '' if delta['category'] == 'removed' else delta['new']['path']

Initial testing suggests this works as expected -- all 45 tests pass. The refactoring would be applied here:

https://github.com/nexB/deltacode/blob/551f231b2ad10d683a2af5210883ac8f2fb4558b/src/deltacode/cli.py#L26-L66

steven-esser commented 6 years ago

We should be able to refactor this much more. Your ideas are good, but I am almost certain there is more that we can do.

Right off the bat, the fact that we have to take 12 lines per 'category' to set each variable is very ugly. Also delta['old']['sha1'] is not a great way to reference values either.

Since we are working with the dictionary from to_dict, there is probably an easier way to go from dictionary values to csv.

Give it a try and see what you can do. I can try and write up some examples if you need me too, but you will have to give me some time to dig around and test possible solutions.

johnmhoran commented 6 years ago

Thanks @majurg -- I'll tackle #9 as you suggest and see what I can come up with. :+1:

steven-esser commented 6 years ago

merged, closing this.