Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line numbers for metrics in Cyclomatic and Halstead operators #218

Merged
merged 11 commits into from
Sep 25, 2023

Conversation

devdanzin
Copy link
Collaborator

As a first step to address #217, allowing wily to generate annotated source listings with inline visualization of code metrics, we need to record line numbers for code blocks when building the cache.

Radon already supplies line numbers (lineno and endline) for Cyclomatic Complexity, so we just record those in the detailed metrics.

For Halstead line numbers, we need to customize visitor, harvester and some other pieces. PRs and issues upstreaming this work have already started being submitted to radon.

This PR is necessary regardless of whether the annotate feature lands as a command or is kept as a separate tool.

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.09% 🎉

Comparison is base (dbe9172) 95.76% compared to head (fd71462) 95.86%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #218      +/-   ##
==========================================
+ Coverage   95.76%   95.86%   +0.09%     
==========================================
  Files          25       25              
  Lines        1370     1403      +33     
  Branches      293      296       +3     
==========================================
+ Hits         1312     1345      +33     
  Misses         33       33              
  Partials       25       25              
Files Changed Coverage Δ
src/wily/operators/cyclomatic.py 100.00% <ø> (ø)
src/wily/operators/halstead.py 95.58% <100.00%> (+4.15%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@devdanzin devdanzin added the enhancement New feature or request label Sep 2, 2023
@tonybaloney
Copy link
Owner

Please update one of the tests to verify this behaviour

@devdanzin
Copy link
Collaborator Author

Thanks for reviewing this!

I couldn't find a test that covered similar behavior, so I created on that checks all metric fields and values from the cache. I'm not sure it's in the best place, maybe it'd be better as a separated test file?

Writing the test uncovered two issues:

  • The code adding line numbers doesn't work with Python 3.7 (disabled on 3.7).
  • The typing of HalsteadOperator._report_to_dict() was wrong (fixed).

@tonybaloney tonybaloney merged commit a0d70df into tonybaloney:master Sep 25, 2023
18 checks passed
@devdanzin devdanzin deleted the add_line_numbers branch September 25, 2023 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants