Skip to content

Commit

Permalink
Issue #6. Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ksenia-vazhdaeva committed Aug 23, 2024
1 parent a36fe68 commit 9349c97
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 47 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand All @@ -54,7 +54,7 @@ jobs:
--directory build/html -cvf artifact.tar .
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: github-pages
path: docs/artifact.tar
Expand All @@ -70,9 +70,8 @@ jobs:

steps:
- name: Setup Pages
uses: actions/configure-pages@v1
uses: actions/configure-pages@v5

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

uses: actions/deploy-pages@v4
20 changes: 10 additions & 10 deletions .github/workflows/rocksq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ jobs:
- self-hosted
- ${{ matrix.runner }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up docker buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Build docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
file: ${{ matrix.docker_file }}
platforms: ${{ matrix.arch }}
Expand All @@ -61,9 +61,9 @@ jobs:
run: docker run --rm -v $(pwd)/distfiles:/tmp rocksq cp -R /opt/dist /tmp

- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: wheels
name: wheels-${{ matrix.runner }}
path: distfiles/dist

- name: Publish to PyPI
Expand All @@ -82,8 +82,8 @@ jobs:
target: [x64]
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
architecture: ${{ matrix.target }}
Expand All @@ -95,9 +95,9 @@ jobs:
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: wheels
name: wheels-${{ matrix.python }}
path: queue_py/dist
- name: Publish to PyPI
if: "startsWith(github.ref, 'refs/tags/')"
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.manylinux_2_28_ARM64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/insight-platform/manylinux_2_28_arm64:v0.0.3 as chef
FROM ghcr.io/insight-platform/manylinux_2_28_arm64:v0.0.4 as chef

FROM chef as planner

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.manylinux_2_28_X64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/insight-platform/manylinux_2_28_x64:v0.0.3 as chef
FROM ghcr.io/insight-platform/manylinux_2_28_x64:v0.0.4 as chef

FROM chef as planner

Expand Down
6 changes: 3 additions & 3 deletions queue_py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ crate-type = ["cdylib", "lib"]
queue_rs = { path = "../queue_rs" }

[dependencies.pyo3]
version = "0.20"
version = "0.22.2"

[dev-dependencies]
serial_test = "3"

[build-dependencies]
pyo3-build-config = "0.19"
cbindgen = "0.24"
pyo3-build-config = "0.22.2"
cbindgen = "0.27.0"

[package.metadata.maturin]
python-source = "python"
Expand Down
18 changes: 10 additions & 8 deletions queue_py/src/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::StartPosition;
use crate::{pylist_to_vec_of_byte_vec, value_as_slice, StartPosition};
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use pyo3::types::{PyBytes, PyList};
use queue_rs::mpmc;
use rocksdb::Options;
use std::time::Duration;
Expand Down Expand Up @@ -60,8 +60,9 @@ impl PersistentQueueWithCapacity {
/// None
///
#[pyo3(signature = (items, no_gil = true))]
fn push(&self, items: Vec<&PyBytes>, no_gil: bool) -> PyResult<()> {
let data = items.iter().map(|e| e.as_bytes()).collect::<Vec<&[u8]>>();
fn push(&self, items: &Bound<'_, PyList>, no_gil: bool) -> PyResult<()> {
let items = pylist_to_vec_of_byte_vec(items);
let data = value_as_slice(&items);
Python::with_gil(|py| {
let f = || {
self.0
Expand Down Expand Up @@ -110,7 +111,7 @@ impl PersistentQueueWithCapacity {
results
.into_iter()
.map(|r| {
PyBytes::new_with(py, r.len(), |b: &mut [u8]| {
PyBytes::new_bound_with(py, r.len(), |b: &mut [u8]| {
b.copy_from_slice(&r);
Ok(())
})
Expand Down Expand Up @@ -232,8 +233,9 @@ impl MpmcQueue {
/// None
///
#[pyo3(signature = (items, no_gil = true))]
fn add(&self, items: Vec<&PyBytes>, no_gil: bool) -> PyResult<()> {
let data = items.iter().map(|e| e.as_bytes()).collect::<Vec<&[u8]>>();
fn add(&self, items: &Bound<'_, PyList>, no_gil: bool) -> PyResult<()> {
let items = pylist_to_vec_of_byte_vec(items);
let data = value_as_slice(&items);
Python::with_gil(|py| {
let f = || {
self.0
Expand Down Expand Up @@ -301,7 +303,7 @@ impl MpmcQueue {
results
.into_iter()
.map(|r| {
PyBytes::new_with(py, r.len(), |b: &mut [u8]| {
PyBytes::new_bound_with(py, r.len(), |b: &mut [u8]| {
b.copy_from_slice(&r);
Ok(())
})
Expand Down
30 changes: 21 additions & 9 deletions queue_py/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::PyDict;
use pyo3::types::{PyDict, PyList};
use pyo3::wrap_pymodule;

mod blocking;
Expand Down Expand Up @@ -54,22 +54,22 @@ fn remove_mpmc_queue(path: &str) -> PyResult<()> {
.map_err(|e| PyRuntimeError::new_err(format!("Failed to remove mpmc queue: {}", e)))
}

#[pyclass]
#[pyclass(eq, eq_int)]
#[derive(PartialEq, Copy, Clone)]
enum StartPosition {
Oldest,
Newest,
Oldest = 0,
Newest = 1,
}

#[pymodule]
fn rocksq_blocking(_: Python, m: &PyModule) -> PyResult<()> {
fn rocksq_blocking(_: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<blocking::PersistentQueueWithCapacity>()?;
m.add_class::<blocking::MpmcQueue>()?;
Ok(())
}

#[pymodule]
fn rocksq_nonblocking(_: Python, m: &PyModule) -> PyResult<()> {
fn rocksq_nonblocking(_: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<nonblocking::ResponseVariant>()?;
m.add_class::<nonblocking::Response>()?;
m.add_class::<nonblocking::PersistentQueueWithCapacity>()?;
Expand All @@ -82,7 +82,7 @@ fn rocksq_nonblocking(_: Python, m: &PyModule) -> PyResult<()> {
}

#[pymodule]
fn rocksq(py: Python, m: &PyModule) -> PyResult<()> {
fn rocksq(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(version, m)?)?;
m.add_function(wrap_pyfunction!(remove_queue, m)?)?;
m.add_function(wrap_pyfunction!(remove_mpmc_queue, m)?)?;
Expand All @@ -92,11 +92,23 @@ fn rocksq(py: Python, m: &PyModule) -> PyResult<()> {

m.add_class::<StartPosition>()?;

let sys = PyModule::import(py, "sys")?;
let sys_modules: &PyDict = sys.getattr("modules")?.downcast()?;
let sys = PyModule::import_bound(py, "sys")?;
let attr_modules = sys.getattr("modules")?;
let sys_modules: &Bound<'_, PyDict> = attr_modules.downcast::<PyDict>()?;

sys_modules.set_item("rocksq.blocking", m.getattr("rocksq_blocking")?)?;
sys_modules.set_item("rocksq.nonblocking", m.getattr("rocksq_nonblocking")?)?;

Ok(())
}

fn pylist_to_vec_of_byte_vec(items: &Bound<'_, PyList>) -> Vec<Vec<u8>> {
items
.iter()
.map(|e| e.extract::<Vec<u8>>().unwrap())
.collect::<Vec<_>>()
}

fn value_as_slice<T>(items: &[Vec<T>]) -> Vec<&[T]> {
items.iter().map(|e| e.as_slice()).collect::<Vec<_>>()
}
18 changes: 10 additions & 8 deletions queue_py/src/nonblocking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::StartPosition;
use crate::{pylist_to_vec_of_byte_vec, value_as_slice, StartPosition};
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use pyo3::types::{PyBytes, PyList};
use queue_rs::mpmc;
use rocksdb::Options;
use std::time::Duration;
Expand Down Expand Up @@ -38,7 +38,7 @@ impl ResponseVariant {
results
.iter()
.map(|r| {
PyBytes::new_with(py, r.len(), |b: &mut [u8]| {
PyBytes::new_bound_with(py, r.len(), |b: &mut [u8]| {
b.copy_from_slice(r);
Ok(())
})
Expand Down Expand Up @@ -227,8 +227,9 @@ impl PersistentQueueWithCapacity {
/// the response object is only useful to call for `is_ready()`.
///
#[pyo3(signature = (items, no_gil = true))]
fn push(&self, items: Vec<&PyBytes>, no_gil: bool) -> PyResult<Response> {
let data = items.iter().map(|e| e.as_bytes()).collect::<Vec<&[u8]>>();
fn push(&self, items: &Bound<'_, PyList>, no_gil: bool) -> PyResult<Response> {
let items = pylist_to_vec_of_byte_vec(items);
let data = value_as_slice(&items);
Python::with_gil(|py| {
let f = || {
self.0
Expand Down Expand Up @@ -380,7 +381,7 @@ impl MpmcResponseVariant {
results
.iter()
.map(|r| {
PyBytes::new_with(py, r.len(), |b: &mut [u8]| {
PyBytes::new_bound_with(py, r.len(), |b: &mut [u8]| {
b.copy_from_slice(r);
Ok(())
})
Expand Down Expand Up @@ -617,8 +618,9 @@ impl MpmcQueue {
/// the response object is only useful to call for `is_ready()`.
///
#[pyo3(signature = (items, no_gil = true))]
fn add(&self, items: Vec<&PyBytes>, no_gil: bool) -> PyResult<MpmcResponse> {
let data = items.iter().map(|e| e.as_bytes()).collect::<Vec<&[u8]>>();
fn add(&self, items: &Bound<'_, PyList>, no_gil: bool) -> PyResult<MpmcResponse> {
let items = pylist_to_vec_of_byte_vec(items);
let data = value_as_slice(&items);
Python::with_gil(|py| {
let f = || {
self.0
Expand Down
2 changes: 1 addition & 1 deletion queue_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
anyhow = "1"
parking_lot = "0.12"
crossbeam-channel = "0.5.8"
crossbeam-channel = "0.5.13"
bincode = "2.0.0-rc.3"
chrono = "0.4.38"

Expand Down

0 comments on commit 9349c97

Please sign in to comment.