From 8d2d76ff1ed5ba0e5a89fc879e9ca30fd9b0913b Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Fri, 19 Jul 2024 09:04:18 +0000 Subject: [PATCH] Extend the test --- .github/workflows/ci.yml | 6 +- .gitignore | 1 + Cargo.lock | 218 ----------------------------- Cargo.toml | 3 +- crates/numcodecs-python/Cargo.toml | 1 + crates/numcodecs-python/src/lib.rs | 62 +++++--- 6 files changed, 53 insertions(+), 238 deletions(-) delete mode 100644 Cargo.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5eb4f089..7158d94c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - rust: ["1.76", stable, nightly] + rust: ["1.65", stable, nightly] steps: - name: Checkout the Repository @@ -48,7 +48,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - rust: ["1.76", stable, nightly] + rust: ["1.65", stable, nightly] python: ["3.10", "3.11", "3.12"] steps: @@ -103,7 +103,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - rust: ["1.76", stable] + rust: ["1.65", stable] steps: - name: Checkout the Repository diff --git a/.gitignore b/.gitignore index ea8c4bf7..4fffb2f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/Cargo.lock diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index a60846d5..00000000 --- a/Cargo.lock +++ /dev/null @@ -1,218 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "numcodecs" -version = "0.0.0-reserve.0" - -[[package]] -name = "numcodecs-python" -version = "0.1.0" -dependencies = [ - "pyo3", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - -[[package]] -name = "portable-atomic" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" - -[[package]] -name = "pyo3" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" -dependencies = [ - "cfg-if", - "libc", - "memoffset", - "parking_lot", - "portable-atomic", - "pyo3-build-config", - "pyo3-ffi", -] - -[[package]] -name = "pyo3-build-config" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" -dependencies = [ - "once_cell", - "target-lexicon", -] - -[[package]] -name = "pyo3-ffi" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" -dependencies = [ - "libc", - "pyo3-build-config", -] - -[[package]] -name = "redox_syscall" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" -dependencies = [ - "bitflags", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "target-lexicon" -version = "0.12.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 0392f722..292200ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,13 +10,14 @@ edition = "2021" authors = ["Juniper Tyree "] repository = "https://github.com/juntyr/numcodecs-rs" license = "MPL-2.0" -rust-version = "1.57" +rust-version = "1.65" [workspace.dependencies] # workspace-internal crates numcodecs = { path = "crates/numcodecs-python", default-features = false } # crates.io third-party dependencies +numpy = { version = "0.21", default-features = false } pyo3 = { version = "0.21", default-features = false } [workspace.lints.rust] diff --git a/crates/numcodecs-python/Cargo.toml b/crates/numcodecs-python/Cargo.toml index 4f94f074..abebf41c 100644 --- a/crates/numcodecs-python/Cargo.toml +++ b/crates/numcodecs-python/Cargo.toml @@ -18,6 +18,7 @@ keywords = ["numcodecs", "compression", "encoding", "python", "pyo3"] pyo3 = { workspace = true } [dev-dependencies] +numpy = { workspace = true } pyo3 = { workspace = true, features = ["auto-initialize"] } [lints] diff --git a/crates/numcodecs-python/src/lib.rs b/crates/numcodecs-python/src/lib.rs index cfe5b007..9d4042e3 100644 --- a/crates/numcodecs-python/src/lib.rs +++ b/crates/numcodecs-python/src/lib.rs @@ -27,20 +27,6 @@ impl Registry { /// /// Errors if no codec with a matching `id` has been registered, or if /// constructing the codec fails. - /// - /// # Examples - /// - /// ``` - /// # use pyo3::{prelude::*, types::PyDict}; - /// # use numcodecs_python::Registry; - /// - /// Python::with_gil(|py| { - /// let config = PyDict::new_bound(py); - /// config.set_item("id", "crc32"); - /// - /// let codec = Registry::get_codec(config.as_borrowed()).unwrap(); - /// }); - /// ``` pub fn get_codec<'py>(config: Borrowed<'_, 'py, PyDict>) -> Result, PyErr> { static GET_CODEC: GILOnceCell> = GILOnceCell::new(); @@ -96,7 +82,7 @@ impl Registry { /// [`numcodecs.abc.Codec`]: https://numcodecs.readthedocs.io/en/stable/abc.html#module-numcodecs.abc #[repr(transparent)] pub struct Codec { - codec: PyAny, + _codec: PyAny, } /// Methods implemented for [`Codec`]s. @@ -230,7 +216,7 @@ unsafe impl PyTypeInfo for Codec { /// [`numcodecs.abc.Codec`]: https://numcodecs.readthedocs.io/en/stable/abc.html#module-numcodecs.abc #[repr(transparent)] pub struct CodecClass { - class: PyType, + _class: PyType, } /// Methods implemented for [`CodecClass`]es. @@ -314,3 +300,47 @@ unsafe impl PyTypeInfo for CodecClass { mod sealed { pub trait Sealed {} } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn crc32() -> Result<(), PyErr> { + Python::with_gil(|py| { + let config = PyDict::new_bound(py); + config.set_item("id", "crc32")?; + + let codec = Registry::get_codec(config.as_borrowed())?; + assert_eq!(codec.class().codec_id()?, "crc32"); + + let data = &[1, 2, 3, 4]; + + let encoded = codec.encode( + numpy::PyArray1::from_slice_bound(py, data) + .as_any() + .as_borrowed(), + )?; + let decoded = codec.decode(encoded.as_borrowed(), None)?; + + let encoded: Vec = encoded.extract()?; + let decoded: Vec = decoded.extract()?; + + assert_eq!(encoded, [123]); + assert_eq!(decoded, data); + + let config = codec.get_config()?; + assert_eq!(config.len(), 1); + assert_eq!( + config + .get_item("id")? + .map(|i| i.extract::()) + .transpose()? + .as_deref(), + Some("crc32") + ); + + Ok(()) + }) + } +}