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

parse_meta_from_tarball python bindings #176

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

dfrankland
Copy link
Member

@dfrankland dfrankland commented Nov 25, 2024

Depends on #181

Will be used to filter bundles without completely downloading them

@dfrankland dfrankland force-pushed the dylan/parse_meta_from_tarball-python-bindings branch from 54eba5c to 1251bff Compare November 25, 2024 07:06
Copy link

trunk-staging-io bot commented Nov 25, 2024

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@dfrankland dfrankland force-pushed the dylan/parse_meta_from_tarball-python-bindings branch 2 times, most recently from ef5b7aa to c7483d4 Compare November 26, 2024 06:41
@dfrankland dfrankland changed the base branch from main to dylan/setup-type-checks November 26, 2024 06:41
@dfrankland dfrankland force-pushed the dylan/parse_meta_from_tarball-python-bindings branch from c7483d4 to 65c56a5 Compare November 26, 2024 06:42
Comment on lines 374 to 376
raw_stream = StreamingBody(
io.BytesIO(meta_tarball_compressed), len(meta_tarball_compressed)
)
Copy link
Member Author

Choose a reason for hiding this comment

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

StreamingBody is the type returned by S3 when fetching an object

inner: py_bytes_reader,
content_length,
content_length_read: 0,
inner_buffer: Vec::with_capacity(0),
Copy link
Member Author

Choose a reason for hiding this comment

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

fun fact: there's no allocation when a Vec is created with 0 capacity 👍

}

impl<'py> PyBytesReader<'py> {
const DEFAULT_CHUNK_SIZE: usize = 1024;
Copy link
Member Author

Choose a reason for hiding this comment

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

This matches StreamingBody's default chunk size

Comment on lines +90 to +95
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
let versioned_bundle = rt
.block_on(parse_tarball(py_bytes_reader))
.map_err(|err| PyTypeError::new_err(err.to_string()))?;
Copy link
Member Author

Choose a reason for hiding this comment

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

Even though this is not async, reading bytes still happens as needed

Comment on lines +96 to +124
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[cfg(feature = "pyo3")]
#[gen_stub_pyclass]
#[pyclass]
pub struct BindingsVersionedBundle(pub VersionedBundle);

#[cfg(feature = "pyo3")]
#[gen_stub_pymethods]
#[pymethods]
impl BindingsVersionedBundle {
pub fn get_v0_5_29(&self) -> Option<BundleMetaV0_5_29> {
match &self.0 {
VersionedBundle::V0_5_29(bundle_meta) => Some(bundle_meta.clone()),
_ => None,
}
}
pub fn get_v0_5_34(&self) -> Option<BundleMetaV0_5_34> {
match &self.0 {
VersionedBundle::V0_5_34(bundle_meta) => Some(bundle_meta.clone()),
_ => None,
}
}
pub fn get_v0_6_2(&self) -> Option<BundleMetaV0_6_2> {
match &self.0 {
VersionedBundle::V0_6_2(bundle_meta) => Some(bundle_meta.clone()),
_ => None,
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Using gen_stub_pymethodsdoesn't seem to work on enums yet:
Jij-Inc/pyo3-stub-gen#69

All that's needed is a new type here to get around it

Also, the Python bindings aren't using serde, so VersionedBundle doesn't end up creating a nice dict—we can just use methods to get the meta.json values

@dfrankland dfrankland marked this pull request as ready for review November 26, 2024 06:59
@dfrankland dfrankland changed the base branch from dylan/setup-type-checks to main November 26, 2024 17:49
Copy link
Collaborator

@TylerJang27 TylerJang27 left a comment

Choose a reason for hiding this comment

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

Nicenice

@@ -276,3 +276,113 @@ def test_repo_validate():
assert repo_validation.max_level() == RepoValidationLevel.Valid, "\n" + "\n".join(
[issue.error_message for issue in repo_validation.issues_flat()]
)


def test_parse_meta_from_tarball():
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit/optional: I made this a separate ts test file just to make these more digestible. Would be better to do that here too for consistency imo

Copy link
Member Author

Choose a reason for hiding this comment

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

Can do no problemlo

@dfrankland dfrankland force-pushed the dylan/parse_meta_from_tarball-python-bindings branch from cc4c675 to ca88274 Compare November 26, 2024 17:51
@dfrankland dfrankland merged commit 5348e44 into main Nov 26, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants