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

Open
wants to merge 2 commits into
base: dylan/setup-type-checks
Choose a base branch
from

Conversation

dfrankland
Copy link
Member

No description provided.

@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
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.

1 participant