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

Remove unused import with ruff #423

Merged
merged 1 commit into from May 8, 2024
Merged

Conversation

michelletran-codecov
Copy link
Contributor

In particular, I was interested in F401. This should clean up all unused imports in the repo. We have to be careful with celery tasks because they don't get picked up if they are not "imported" anywhere. I've added an annotation on the __init__ files that import these "unused" tasks.

I've also switched to using ruff for "black" linting, which behaves a bit differently.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-qa
Copy link

codecov-qa bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 96.25000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 97.33%. Comparing base (9a02734) to head (ead75d6).

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #423      +/-   ##
==========================================
- Coverage   97.34%   97.33%   -0.01%     
==========================================
  Files         399      399              
  Lines       33758    33629     -129     
==========================================
- Hits        32862    32734     -128     
+ Misses        896      895       -1     
Flag Coverage Δ
integration 97.33% <96.25%> (-0.01%) ⬇️
latest-uploader-overall 97.33% <96.25%> (-0.01%) ⬇️
unit 97.33% <96.25%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.56% <90.62%> (-0.02%) ⬇️
OutsideTasks 97.49% <96.77%> (-0.01%) ⬇️
Files Coverage Δ
app.py 88.88% <ø> (-0.59%) ⬇️
celery_config.py 69.33% <ø> (-0.41%) ⬇️
database/base.py 100.00% <ø> (ø)
database/models/reports.py 99.39% <ø> (-0.01%) ⬇️
database/models/timeseries.py 100.00% <ø> (ø)
database/tests/factories/profiling.py 100.00% <ø> (ø)
database/tests/factories/reports.py 100.00% <ø> (ø)
database/tests/factories/timeseries.py 100.00% <ø> (ø)
database/tests/unit/test_events.py 100.00% <100.00%> (ø)
database/tests/unit/test_model_utils.py 100.00% <ø> (ø)
... and 170 more

Copy link

codecov-public-qa bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 96.20253% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 97.39%. Comparing base (cad2709) to head (6624bbd).

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #423      +/-   ##
==========================================
- Coverage   97.40%   97.39%   -0.02%     
==========================================
  Files         398      398              
  Lines       33575    33444     -131     
==========================================
- Hits        32703    32572     -131     
  Misses        872      872              
Flag Coverage Δ
integration 97.39% <96.20%> (-0.02%) ⬇️
latest-uploader-overall 97.39% <96.20%> (-0.02%) ⬇️
unit 97.39% <96.20%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.70% <90.32%> (-0.03%) ⬇️
OutsideTasks 97.47% <96.77%> (-0.01%) ⬇️
Files Coverage Δ
app.py 88.88% <ø> (-0.59%) ⬇️
celery_config.py 68.05% <ø> (-0.44%) ⬇️
database/base.py 100.00% <ø> (ø)
database/models/reports.py 99.38% <ø> (-0.01%) ⬇️
database/models/timeseries.py 100.00% <ø> (ø)
database/tests/factories/profiling.py 100.00% <ø> (ø)
database/tests/factories/reports.py 100.00% <ø> (ø)
database/tests/factories/timeseries.py 100.00% <ø> (ø)
database/tests/unit/test_events.py 100.00% <100.00%> (ø)
database/tests/unit/test_model_utils.py 100.00% <ø> (ø)
... and 171 more

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 96.25000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 97.36%. Comparing base (9a02734) to head (ead75d6).

Changes have been made to critical files, which contain lines commonly executed in production. Learn more

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #423      +/-   ##
==========================================
- Coverage   97.37%   97.36%   -0.01%     
==========================================
  Files         430      430              
  Lines       34449    34319     -130     
==========================================
- Hits        33544    33415     -129     
+ Misses        905      904       -1     
Flag Coverage Δ
integration 97.33% <96.25%> (-0.01%) ⬇️
latest-uploader-overall 97.33% <96.25%> (-0.01%) ⬇️
unit 97.33% <96.25%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.59% <90.62%> (-0.02%) ⬇️
OutsideTasks 97.49% <96.77%> (-0.01%) ⬇️
Files Coverage Δ
app.py 88.88% <ø> (-0.59%) ⬇️
celery_config.py 69.33% <ø> (-0.41%) ⬇️
database/base.py 100.00% <ø> (ø)
database/models/reports.py 99.39% <ø> (-0.01%) ⬇️
database/models/timeseries.py 100.00% <ø> (ø)
database/tests/factories/profiling.py 100.00% <ø> (ø)
database/tests/factories/reports.py 100.00% <ø> (ø)
database/tests/factories/timeseries.py 100.00% <ø> (ø)
database/tests/unit/test_events.py 100.00% <100.00%> (ø)
database/tests/unit/test_model_utils.py 100.00% <ø> (ø)
... and 170 more
Related Entrypoints
run/app.tasks.notify.Notify
run/app.tasks.pulls.Sync
run/app.tasks.upload.UploadFinisher
run/app.tasks.upload.UploadProcessor
run/app.tasks.upload.ParallelVerification
run/app.tasks.label_analysis.process_request

@michelletran-codecov michelletran-codecov force-pushed the remove_unused_imports branch 3 times, most recently from d73c59b to d82ec54 Compare April 30, 2024 21:10
@michelletran-codecov michelletran-codecov requested a review from a team April 30, 2024 21:16
@thomasrockhu-codecov
Copy link
Contributor

Ooo, never herad of ruff. Looks pretty cool

@michelletran-codecov michelletran-codecov force-pushed the remove_unused_imports branch 2 times, most recently from d82ec54 to 6624bbd Compare May 2, 2024 14:30
@codecov-notifications
Copy link

codecov-notifications bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 96.20253% with 3 lines in your changes are missing coverage. Please review.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #423   +/-   ##
=======================================
  Coverage        ?   97.39%           
=======================================
  Files           ?      398           
  Lines           ?    33444           
  Branches        ?        0           
=======================================
  Hits            ?    32572           
  Misses          ?      872           
  Partials        ?        0           
Flag Coverage Δ
integration 97.39% <96.20%> (?)
latest-uploader-overall 97.39% <96.20%> (?)
unit 97.39% <96.20%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.70% <90.32%> (?)
OutsideTasks 97.47% <96.77%> (?)
Files Coverage Δ
app.py 88.88% <ø> (ø)
celery_config.py 68.05% <ø> (ø)
database/base.py 100.00% <ø> (ø)
database/models/reports.py 99.38% <ø> (ø)
database/models/timeseries.py 100.00% <ø> (ø)
database/tests/factories/profiling.py 100.00% <ø> (ø)
database/tests/factories/reports.py 100.00% <ø> (ø)
database/tests/factories/timeseries.py 100.00% <ø> (ø)
database/tests/unit/test_events.py 100.00% <100.00%> (ø)
database/tests/unit/test_model_utils.py 100.00% <ø> (ø)
... and 171 more

@michelletran-codecov
Copy link
Contributor Author

I've tested this in staging and was able go through the following workflow:

  • GitHub re-sync
  • create commit, create report and upload report (from command line)

Are there any other workflows that would be useful to check? I will probably do a quick check before merging again.

@adrian-codecov
Copy link
Contributor

@michelletran-codecov those are good flows! I think by virtue of the change living in staging for some time (a day or two?) we can notice any error trickle in. I'd just check sentry every now and then and ensure nothing is off. But should be good!

import pytest

import database.events
import database.events # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soo, I searched this up and this F401 is an unused imported module, https://www.flake8rules.com/rules/F401.html#:~:text=A%20module%20has%20been%20imported,the%20import%20should%20be%20removed. Do we want to get rid of this line as part of running ruff? Or do we just want to signal it?

(I think we should remove it, maybe it was missed?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this was actually removed, and the test started failing. :p So I added it back. Admittedly, I'm not entirely sure why it's required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting.. that's werid haha, I guess ruff can tell? Maybe there's methods from database.events that are silently used, but ya that's odd

@@ -1,3 +1,4 @@
# ruff: noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about F401

@@ -1,3 +1,4 @@
# ruff: noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, but now wondering if this should be treated differently for init.py for imports, so this one seems okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was trying to be conservative (especially with these imports in __init__). I'll try removing some of these and see how it goes.🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... these paths are being imported elsewhere in the code. I would have to update the downstream references if we want to get rid of them here. Since this provides a shorter import path for code importing these modules, so I don't think there's any harm leaving them as is.

adrian-codecov
adrian-codecov previously approved these changes May 2, 2024
Copy link
Contributor

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick questions on the imports question but otherwise lgtm!

In particular, I was interested in F401. This should clean up all unused imports in the repo.
We have to be careful with celery tasks because they don't get picked up if they are not "imported" anywhere.
I've added an annotation on the `__init__` files that import these "unused" tasks.
@michelletran-codecov michelletran-codecov added this pull request to the merge queue May 8, 2024
Merged via the queue into main with commit f2ce06f May 8, 2024
27 of 33 checks passed
@michelletran-codecov michelletran-codecov deleted the remove_unused_imports branch May 8, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants