Skip to content

Commit

Permalink
Issue 83: Enable Python bindings for StreamManager and EventWriter. (#…
Browse files Browse the repository at this point in the history
…104)

Enable Python bindings
  • Loading branch information
shrids authored Jun 3, 2020
1 parent fa5239a commit b10c15a
Show file tree
Hide file tree
Showing 29 changed files with 568 additions and 116 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/cibuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}

- name: Install stable toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
components: rustfmt, clippy

Expand Down Expand Up @@ -85,18 +85,17 @@ jobs:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}

- name: Install stable toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace
args: -p pravega-rust-client-channel -p pravega-controller-client -p pravega-rust-client-integration-test -p pravega-rust-client-retry -p pravega-rust-client-shared -p pravega-wire-protocol -p pravega-client-rust

- name: Run code cov
run: |
Expand Down Expand Up @@ -131,10 +130,10 @@ jobs:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}

- name: Install stable toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
components: rustfmt, clippy

Expand Down Expand Up @@ -174,10 +173,10 @@ jobs:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}

- name: Install stable toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
components: rustfmt, clippy

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ pravega-*.tgz
.vscode
/shared/target/
.gradle
*.log

__pycache__/
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2018"
categories = ["Network programming"]
keywords = ["streaming", "client", "pravega"]
readme = "Readme.md"
readme = "README.md"
repository = "https://github.com/pravega/pravega-client-rust"
license = "Apache-2.0"
description = "A Rust client for Pravega. (Pravega.io)"
Expand All @@ -15,7 +15,7 @@ authors = ["Tom Kaitchuck <[email protected]>", "Wenqi Mou <wenqi.mou@dell.

[workspace]
members = [
"controller-client", "shared", "wire_protocol", "retry", "integration_test", "connection_pool", "channel",
"controller-client", "shared", "wire_protocol", "retry", "integration_test", "connection_pool", "channel", "bindings"
]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn mock_connection_no_block(c: &mut Criterion) {
async fn set_up(config: ClientConfig) -> EventStreamWriter {
let scope_name = Scope::new("testWriterPerf".into());
let stream_name = Stream::new("testWriterPerf".into());
let client_factory = ClientFactory::new(config.clone());
let client_factory = ClientFactory::new(config.clone()).await;
let controller_client = client_factory.get_controller_client();
create_scope_stream(controller_client, &scope_name, &stream_name, 1).await;
let scoped_stream = ScopedStream {
Expand Down
44 changes: 44 additions & 0 deletions bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "pravega-rust-client-bindings"
version = "0.1.0"
edition = "2018"
categories = ["Network programming"]
keywords = ["streaming", "client", "pravega"]
readme = "Readme.md"
repository = "https://github.com/pravega/pravega-client-rust"
license = "Apache-2.0"
description = "An internal library used by the Rust client for Pravega to generated language bindings for Python and WASM."
authors = ["Tom Kaitchuck <[email protected]>", "Wenqi Mou <[email protected]>",
"Sandeep Shridhar <[email protected]>", "Wenxiao Zhang <[email protected]>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "pravega_client"
crate-type = ["cdylib"]

[features]
default = ["python_binding"]
javascript_binding = ["wasm-bindgen"]
python_binding = ["pyo3"]

#Run tests for bindings using command cargo test --no-default-features

[dependencies]
log = "0.4"
pravega-client-rust = { path = "../" }
pravega-wire-protocol = { path = "../wire_protocol"}
pravega-controller-client = { path = "../controller-client"}
pravega-rust-client-shared = { path = "../shared"}
pravega-rust-client-retry = {path = "../retry"}
pravega-connection-pool = {path= "../connection_pool"}
tokio = { version = "0.2.13", features = ["full"] }
lazy_static = "1.4.0"
uuid = {version = "0.8", features = ["v4"]}
futures = "0.3.5"
derive-new = "0.5"
#Python bindings
pyo3 = { features = ["extension-module"], optional = true, version = "0.10.1" }
#WASM bindings
wasm-bindgen = { version = "0.2.63", optional = true }
cfg-if = "0.1.10"
3 changes: 3 additions & 0 deletions bindings/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Language Bindings

This provides a way to generate multiple language bindings to interact with Pravega.
3 changes: 3 additions & 0 deletions bindings/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["maturin"]
build-backend = "maturin"
33 changes: 33 additions & 0 deletions bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright (c) Dell Inc., or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//

#[macro_use]
extern crate cfg_if;

mod stream_manager;
mod stream_writer;
cfg_if! {
if #[cfg(feature = "python_binding")] {
use pyo3::prelude::*;
use stream_manager::StreamManager;
#[macro_use]
extern crate derive_new;
use stream_writer::StreamWriter;
}
}

#[cfg(feature = "python_binding")]
#[pymodule]
/// A Python module implemented in Rust.
fn pravega_client(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<StreamManager>()?;
m.add_class::<StreamWriter>()?;
Ok(())
}
36 changes: 36 additions & 0 deletions bindings/src/pravega_client_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright (c) Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#

import unittest
import pravega_client;

class PravegaTest(unittest.TestCase):
def test_writeEvent(self):
print("Creating a Stream Manager, ensure pravega is running")
stream_manager=pravega_client.StreamManager("127.0.0.1:9090")

print("Creating a scope")
scope_result=stream_manager.create_scope("testScope")
self.assertEqual(True, scope_result, "Scope creation status")

print("Creating a stream")
stream_result=stream_manager.create_stream("testScope", "testStream", 1)
self.assertEqual(True, stream_result, "Stream creation status")

print("Creating a writer for Stream")
w1=stream_manager.create_writer("testScope","testStream")

print("Write events")
w1.write_event("test event1")
w1.write_event("test event2")


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit b10c15a

Please sign in to comment.