archweb icon indicating copy to clipboard operation
archweb copied to clipboard

Add vulture to CI

Open jelly opened this issue 3 years ago • 7 comments

Add vulture (dead code detector to CI)

jelly avatar Jan 17 '22 14:01 jelly

Hello !

I run the following command :

vulture --exclude=*/migrations/*.py --min-confidence 65 devel/**/*.py main/**/*.py mirrors/**/*.py news/**/*.py packages/**/*.py planet/**/*.py public/**/*.py releng/**/*.py todolists/**/*.py visualize/**/*.py

and it gives me the following results :

archweb/devel/management/commands/reporead.py:215: unused variable 'package_sigs' (100% confidence)
archweb/mirrors/admin.py:77: unused variable 'change' (100% confidence)
archweb/mirrors/fields.py:46: unused variable 'expression' (100% confidence)
archweb/packages/tests/test_flag_packages.py:37: unused variable 'denylist' (100% confidence)
archweb/packages/tests/test_search.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:6: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:63: unused variable 'db' (100% confidence)
archweb/planet/tests/test_command.py:17: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:9: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:16: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:29: unused variable 'db' (100% confidence)
archweb/releng/tests/conftest.py:15: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:18: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:26: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:31: unused variable 'db' (100% confidence)

If I don't set the --min-confidence attribute, I get a lot of false positive (models attributes, Meta class, etc) so I raise it just a little bit to have more accurate results, but even there, almost all results are false positive since the unused variable 'db' is always in the tests functions signature.

Do you think it's worth it to find a way to "whitelist" the warnings related to the test files and implement this in a pipeline or we should simply fix the three unused variables and leave it like that?

just1602 avatar Apr 07 '22 04:04 just1602

Hey, I was thinking maybe using vulture in a pre-commit hook would be better than directly adding it to the CI pipeline.

MashyBasker avatar Jan 13 '24 15:01 MashyBasker

Hello !

I run the following command :

vulture --exclude=*/migrations/*.py --min-confidence 65 devel/**/*.py main/**/*.py mirrors/**/*.py news/**/*.py packages/**/*.py planet/**/*.py public/**/*.py releng/**/*.py todolists/**/*.py visualize/**/*.py

and it gives me the following results :

archweb/devel/management/commands/reporead.py:215: unused variable 'package_sigs' (100% confidence)
archweb/mirrors/admin.py:77: unused variable 'change' (100% confidence)
archweb/mirrors/fields.py:46: unused variable 'expression' (100% confidence)
archweb/packages/tests/test_flag_packages.py:37: unused variable 'denylist' (100% confidence)
archweb/packages/tests/test_search.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:6: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:63: unused variable 'db' (100% confidence)
archweb/planet/tests/test_command.py:17: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:9: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:16: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:29: unused variable 'db' (100% confidence)
archweb/releng/tests/conftest.py:15: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:18: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:26: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:31: unused variable 'db' (100% confidence)

If I don't set the --min-confidence attribute, I get a lot of false positive (models attributes, Meta class, etc) so I raise it just a little bit to have more accurate results, but even there, almost all results are false positive since the unused variable 'db' is always in the tests functions signature.

Do you think it's worth it to find a way to "whitelist" the warnings related to the test files and implement this in a pipeline or we should simply fix the three unused variables and leave it like that?

Yes, we should whitelist python fixtures as they are detected as false positives

jelly avatar Jan 21 '24 11:01 jelly

@MashyBasker if you want to go forward and make a PR to run it as a pre-commit hook, go ahead. It has been two years since I comment this issue, and I've change workstation since then, so the work I had for this issue is gone.

If you don't have time, I'll try to get at it when I got some free time ! :)

just1602 avatar Jan 21 '24 16:01 just1602

Thanks! I'll work on creating the pre-commit hook PR.

MashyBasker avatar Jan 21 '24 16:01 MashyBasker

Thanks! I'll work on creating the pre-commit hook PR.

pre-commit hook is the not super interesting. Getting the code to run fine with vulture be a good start.

jelly avatar Jan 22 '24 12:01 jelly

Okay, I'll work on it. @jelly

MashyBasker avatar Jan 23 '24 14:01 MashyBasker