From 7e7296da790334698bf7d6d6f7930422abb5e73f Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 11 May 2023 19:01:10 +0800 Subject: [PATCH] feat(bindings/python): Enable `abi3` to avoid building on different python version Fixes #2252 Signed-off-by: Frost Ming --- .github/workflows/bindings_python.yml | 6 +++--- Cargo.lock | 2 -- bindings/python/Cargo.toml | 3 +-- bindings/python/python/opendal/layers.pyi | 15 +++++++++++++++ bindings/python/src/layers.rs | 20 ++++++-------------- 5 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 bindings/python/python/opendal/layers.pyi diff --git a/.github/workflows/bindings_python.yml b/.github/workflows/bindings_python.yml index 4ad8f744fb96..d69a90c73017 100644 --- a/.github/workflows/bindings_python.yml +++ b/.github/workflows/bindings_python.yml @@ -67,7 +67,7 @@ jobs: manylinux: auto working-directory: "bindings/python" command: build - args: --release --sdist -o dist --find-interpreter + args: --release --sdist -o dist - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -83,7 +83,7 @@ jobs: with: working-directory: "bindings/python" command: build - args: --release -o dist --find-interpreter + args: --release -o dist - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -99,7 +99,7 @@ jobs: with: working-directory: "bindings/python" command: build - args: --release -o dist --universal2 --find-interpreter + args: --release -o dist --universal2 - name: Upload wheels uses: actions/upload-artifact@v3 with: diff --git a/Cargo.lock b/Cargo.lock index d42a5d021812..8a986e386195 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2711,7 +2711,6 @@ dependencies = [ name = "opendal-python" version = "0.34.0" dependencies = [ - "chrono", "futures", "opendal", "pyo3", @@ -3385,7 +3384,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfb848f80438f926a9ebddf0a539ed6065434fd7aae03a89312a9821f81b8501" dependencies = [ "cfg-if", - "chrono", "indoc", "libc", "memoffset", diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 7b59cbd4d36b..f84b861756bf 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -32,9 +32,8 @@ crate-type = ["cdylib"] doc = false [dependencies] -chrono = { version = "0.4.24", default-features = false, features = ["std"] } futures = "0.3.28" opendal.workspace = true -pyo3 = { version = "0.18", features = ["chrono"] } +pyo3 = { version = "0.18", features = ["abi3-py37"] } pyo3-asyncio = { version = "0.18", features = ["tokio-runtime"] } tokio = "1" diff --git a/bindings/python/python/opendal/layers.pyi b/bindings/python/python/opendal/layers.pyi new file mode 100644 index 000000000000..29fad7cf8328 --- /dev/null +++ b/bindings/python/python/opendal/layers.pyi @@ -0,0 +1,15 @@ +class ConcurrentLimitLayer: + def __init__(self, permits: int) -> None: ... + +class ImmutableIndexLayer: + def insert(self, key: str) -> None: ... + +class RetryLayer: + def __init__( + self, + max_times: int | None = None, + factor: float | None = None, + jitter: bool = False, + max_delay: float | None = None, + min_delay: float | None = None, + ) -> None: ... diff --git a/bindings/python/src/layers.rs b/bindings/python/src/layers.rs index b643315e4914..1e7fe72f6af2 100644 --- a/bindings/python/src/layers.rs +++ b/bindings/python/src/layers.rs @@ -15,9 +15,9 @@ // specific language governing permissions and limitations // under the License. +use std::time::Duration; + use ::opendal as od; -use chrono::Duration; -use pyo3::exceptions::PyOverflowError; use pyo3::prelude::*; #[derive(FromPyObject)] @@ -73,8 +73,8 @@ impl RetryLayer { max_times: Option, factor: Option, jitter: bool, - max_delay: Option, - min_delay: Option, + max_delay: Option, + min_delay: Option, ) -> PyResult { let mut retry = od::layers::RetryLayer::default(); if let Some(max_times) = max_times { @@ -87,18 +87,10 @@ impl RetryLayer { retry = retry.with_jitter(); } if let Some(max_delay) = max_delay { - retry = retry.with_max_delay( - max_delay - .to_std() - .map_err(|err| PyOverflowError::new_err(err.to_string()))?, - ); + retry = retry.with_max_delay(Duration::from_micros((max_delay * 1000000.0) as u64)); } if let Some(min_delay) = min_delay { - retry = retry.with_min_delay( - min_delay - .to_std() - .map_err(|err| PyOverflowError::new_err(err.to_string()))?, - ); + retry = retry.with_min_delay(Duration::from_micros((min_delay * 1000000.0) as u64)); } Ok(Self(retry)) }