Skip to content

Switch to libbz2-rs-sys and finish bz2 impl #5709

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

Merged
merged 3 commits into from
Apr 20, 2025

Conversation

coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Apr 17, 2025

I realized that libbz2-rs-sys exists, by the same folks who make libz-rs-sys - it's a Rust reimplementation of libbz2. This means we can do that same thing as in #5562, and avoid having to cross-compile C. I then realized after I removed the feature flag that we weren't actually running bz2 regrtests in CI, because we weren't passing it as a feature to cargo build, and so something like half of the tests in test_bz2.py were failing. So, I more or less finished up the impl, by making some code in zlib.rs generic over the specific Decompress struct.

@fanninpm
Copy link
Contributor

See also #5605

@arihant2math
Copy link
Collaborator

This one is better than mine ... test_shutil is the only fail (due to 1 new exposed test) and there aren't too many expected failures comparatively. I'll close mine after this is merged.

@youknowone
Copy link
Member

please check #5605 and rebase on it or pick some idea if possible

@coolreader18
Copy link
Member Author

Oh, shoot, sorry - I didn't see that that PR was open.

@@ -12,28 +12,48 @@ mod _bz2 {
object::{PyPayload, PyResult},
types::Constructor,
};
use crate::zlib::{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since there is at-least 1 other decompression module that uses the same format (_lzma). I think this should be moved someplace common.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree - I was planning on doing that in a followup, to reduce the amount of code movement in this pr.

@@ -1001,6 +1005,8 @@ def test_encoding_error_handler(self):
as f:
self.assertEqual(f.read(), "foobar")

# TODO: RUSTPYTHON
@unittest.expectedFailure
Copy link
Member

Choose a reason for hiding this comment

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

@coolreader18 @arihant2math what cause this regression? could this be fixed in future?

Copy link
Collaborator

Choose a reason for hiding this comment

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

A flag probably needs to be added to the decompressor state. I believe the issue is the wt and rt formats. Although I'm not to sure, I suppose looking at the cpython source might help.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason this needed to be flagged now is because the whole test file wasn't running at all before - bz2 was not included in the --features=stdlib,threading,... flag in CI, so the module wasn't even getting compiled or tested at all.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, didn't noticed that. Thanks!

@arihant2math
Copy link
Collaborator

I checkout out of this pr for #5717 so try not to change the trait too much 😄 .

data1: &'a [u8],
data2: &'a [u8],
}
impl<'a> Chunker<'a> {
fn new(data: &'a [u8]) -> Self {
pub(crate) fn new(data: &'a [u8]) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub(crate) fn new(data: &'a [u8]) -> Self {
pub fn new(data: &'a [u8]) -> Self {

When the struct is pub(crate), only pub here is automatically pub(crate)

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I think I'll change that in the follow-up.

@coolreader18 coolreader18 merged commit fbaeecc into RustPython:main Apr 20, 2025
11 checks passed
@coolreader18 coolreader18 deleted the bz2 branch April 20, 2025 22:53
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.

4 participants