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

[PP-1216] Zip email reports #1818

Merged
merged 3 commits into from
May 3, 2024
Merged

[PP-1216] Zip email reports #1818

merged 3 commits into from
May 3, 2024

Conversation

dbernstein
Copy link
Contributor

Description

With this update, instead of attaching two csv reports to the email, we are zipping the csvs and attaching the resulting archive to the email.

Motivation and Context

https://ebce-lyrasis.atlassian.net/browse/PP-1216

How Has This Been Tested?

An existing unit test has been modified to account for the change.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

Copy link

codecov bot commented May 1, 2024

Codecov Report

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

Project coverage is 90.03%. Comparing base (c733da5) to head (27dd28a).

Files Patch % Lines
...elery/tasks/generate_inventory_and_hold_reports.py 94.11% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1818      +/-   ##
==========================================
- Coverage   90.03%   90.03%   -0.01%     
==========================================
  Files         299      299              
  Lines       39543    39543              
  Branches     8588     8588              
==========================================
- Hits        35604    35602       -2     
- Misses       2613     2614       +1     
- Partials     1326     1327       +1     
Flag Coverage Δ
manager 89.83% <94.11%> (-0.01%) ⬇️
migration 24.53% <0.00%> (ø)

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

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

@dbernstein dbernstein force-pushed the PP-1216-zip-email-reports branch 2 times, most recently from 7cfb5c8 to a4186d4 Compare May 1, 2024 23:02
@dbernstein dbernstein requested a review from a team May 1, 2024 23:02
Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

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

Whats here looks like it will work, but I made some suggestions to clean it up a bit.

@dbernstein
Copy link
Contributor Author

Thank you for all the great feedback @jonathangreen. I took your advice and reworked the PR. I couldn't use a temp dir because it doesn't support the same delete flag as an file. But as you can see it was possible to do it with temporary files and nested context managers.

@dbernstein dbernstein force-pushed the PP-1216-zip-email-reports branch 2 times, most recently from 8ae7482 to f2061f2 Compare May 3, 2024 06:45
Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

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

The refactoring you did looks great here @dbernstein.

Added one small comment here, the temp files aren't being cleaned up now since delete=False is always set. Once thats fixed this is good to go.

)

def create_temp_file(self) -> _TemporaryFileWrapper[str]:
return tempfile.NamedTemporaryFile("w", delete=False, encoding="utf-8")
Copy link
Member

Choose a reason for hiding this comment

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

Since delete=False is set here, these files are never getting cleaned up right? I think you can completely drop the delete=False here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch.

f"Emailed inventory and holds reports for {library.name}({library.short_name})."
)

def create_temp_file(self) -> _TemporaryFileWrapper[str]:
Copy link
Member

Choose a reason for hiding this comment

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

You can type hint this as the more generic IO[str] to avoid having to use the private _TemporaryFileWrapper object in the hint.

return temp.name
self,
_db: Session,
csv_file: _TemporaryFileWrapper[str],
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, this can be hinted as IO[str]

@dbernstein dbernstein force-pushed the PP-1216-zip-email-reports branch from cdf411a to 27dd28a Compare May 3, 2024 15:59
@dbernstein dbernstein merged commit f3ad4c7 into main May 3, 2024
21 checks passed
@dbernstein dbernstein deleted the PP-1216-zip-email-reports branch May 3, 2024 16:36
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.

2 participants