-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: dylan/setup-type-checks
Are you sure you want to change the base?
parse_meta_from_tarball python bindings #176
Conversation
54eba5c
to
1251bff
Compare
ef5b7aa
to
c7483d4
Compare
c7483d4
to
65c56a5
Compare
raw_stream = StreamingBody( | ||
io.BytesIO(meta_tarball_compressed), len(meta_tarball_compressed) | ||
) |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
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()))?; |
There was a problem hiding this comment.
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
#[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, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using gen_stub_pymethods
doesn'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
No description provided.