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

new python bindings: SqliteReportBuilder.from_pyreport() #36

Merged
merged 3 commits into from
Sep 16, 2024

Conversation

matt-codecov
Copy link
Collaborator

fixes codecov/engineering-team#2315

commit titles describe the changes. the result is python bindings like:

from codecov_rs.report import SqliteReportBuilder

# Create a new database file in a temp dir
report_builder = SqliteReportBuilder.from_pyreport("report_json.json", "chunks.txt")
print(report_builder.filepath())
# /var/folders/96/92bch5jn5llfz6gcvvchfy100000gn/T/codecov-W5jDQymDQHNKitVH

# Use a specified filepath
report_builder = SqliteReportBuilder.from_pyreport("report_json.json", "chunks.txt", "db.sqlite")
print(report_builder.filepath())
# /Users/matt/dev/codecov/codecov-rs/db.sqlite

immediate next steps:

  • review and then flip the repo to public
  • CI glue to publish to pypi

there is some awkwardness to sort out due to python expecting to access SqliteReportBuilder functionality (db inserts) and SqliteReport functionality (.totals(), .merge(), converting back to pyreport) through a single handle. this PR punts that issue down the line but i am thinking about it

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 92.50000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 98.53%. Comparing base (dc4903d) to head (72e3eac).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
bindings/src/error.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
- Coverage   98.62%   98.53%   -0.09%     
==========================================
  Files          21       22       +1     
  Lines        6751     6776      +25     
==========================================
+ Hits         6658     6677      +19     
- Misses         93       99       +6     
Components Coverage Δ
core 98.61% <100.00%> (-0.01%) ⬇️
bindings 79.31% <76.00%> (-20.69%) ⬇️
python 100.00% <100.00%> (ø)

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

Copy link
Contributor

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

lgtm, though this brings up an interesting question:

should the output path/file be the full responsibility of the caller?
In the sense that the API does not have the new fallback, and always requires the caller to provide a file handle?

related to that, I believe the rust tests are currently leaking temporary files, as it does not look like you are using the tempfile crate thus far.

core/src/report/sqlite/mod.rs Outdated Show resolved Hide resolved
@matt-codecov
Copy link
Collaborator Author

should the output path/file be the full responsibility of the caller?

is there a reason to force the responsibility to one side or the other? why not allow the caller to supply a file if they want to manage it and fall back to a tempfile created by the library if they don't care?

related to that, I believe the rust tests are currently leaking temporary files, as it does not look like you are using the tempfile crate thus far

i think all of the tests use tempfiles/tempdirs. python uses NamedTemporaryFile and rust uses tempfile::TempDir (example) which delete themselves on drop

the ::new() constructor will leak temp files though, which is somewhat intentional but i am torn. it feels a little strong for our library to say "we will create a file but if you want to keep it you either need to keep us in scope forever or copy it" but a little weak to say "we're fine throwing potentially gigabytes of garbage in your temp dir". what do you think @Swatinem?

@Swatinem
Copy link
Contributor

Thats why I would suggest delegating that responsibility to the caller. That "resolves" that question, along with slimming down the API surface and the potential for surprises.

@matt-codecov
Copy link
Collaborator Author

@Swatinem i've removed ::new() for now and made an outpath required. if that proves tedious i'll revisit

@matt-codecov matt-codecov merged commit 739da11 into main Sep 16, 2024
6 of 7 checks passed
@matt-codecov matt-codecov deleted the matt/initial-pyreport-bindings branch September 16, 2024 16:25
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.

[codecov-rs/rust] Set up maturin + write first Python binding: Rust+SQLite constructor
2 participants