Skip to content

Commit

Permalink
feat(bindings/python): Enable abi3 to avoid building on different p…
Browse files Browse the repository at this point in the history
…ython version (#2255)

Fixes #2252

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed May 11, 2023
1 parent 5552c97 commit 8ef38ac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/bindings_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 15 additions & 0 deletions bindings/python/python/opendal/layers.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
20 changes: 6 additions & 14 deletions bindings/python/src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -73,8 +73,8 @@ impl RetryLayer {
max_times: Option<usize>,
factor: Option<f32>,
jitter: bool,
max_delay: Option<Duration>,
min_delay: Option<Duration>,
max_delay: Option<f64>,
min_delay: Option<f64>,
) -> PyResult<Self> {
let mut retry = od::layers::RetryLayer::default();
if let Some(max_times) = max_times {
Expand All @@ -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))
}
Expand Down

0 comments on commit 8ef38ac

Please sign in to comment.