Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile pyo3 for normal linux #106

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions shinkai-libs/shinkai-message-pyo3/Cargo.lock

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

6 changes: 3 additions & 3 deletions shinkai-libs/shinkai-message-pyo3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ rand = "0.8"
hex = "=0.4.3"

[dependencies.pyo3]
version = "0.19.2"
features = ["auto-initialize", "extension-module"]
version = "0.20.0"
features = ["extension-module", "abi3-py38"]

[build-dependencies]
maturin = "1.2.3"
maturin = "1.3.0"
13 changes: 13 additions & 0 deletions shinkai-libs/shinkai-message-pyo3/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Create a virtual environment if it doesn't exist
if [ ! -d "./venv" ]
then
python -m venv venv
fi

# Activate your virtual environment
source ./venv/bin/activate

# Run maturin develop and capture its output
maturin build -i python --compatibility linux --strip --release
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct PyEncryptionMethod {
#[pymethods]
impl PyEncryptionMethod {
#[new]
#[args(value = "\"None\"")]
pub fn new(value: &str) -> Self {
pub fn new(value: Option<&str>) -> Self {
let value = value.unwrap_or("None");
let inner = match value {
"None" => EncryptionMethod::None,
// Add other cases here for other possible values of EncryptionMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ impl PyExternalMetadata {
fn set_other(&mut self, other: String) {
self.inner.other = other;
}

#[getter]
fn get_intra_sender(&self) -> PyResult<String> {
Ok(self.inner.intra_sender.clone())
}

#[setter]
fn set_intra_sender(&mut self, intra_sender: String) {
self.inner.intra_sender = intra_sender;
}
}

impl<'source> FromPyObject<'source> for PyExternalMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ use x25519_dalek::{PublicKey as EncryptionPublicKey, StaticSecret as EncryptionS

#[pyclass]
pub struct PyShinkaiMessageBuilder {
// pub inner: ShinkaiMessageBuilder,
pub inner: Option<ShinkaiMessageBuilder>,
}

#[pymethods]
impl PyShinkaiMessageBuilder {
#[new]
#[args(my_encryption_secret_key, my_signature_secret_key, receiver_public_key)]
#[pyo3(text_signature = "(my_encryption_secret_key, my_signature_secret_key, receiver_public_key)")]
fn new(
my_encryption_secret_key: String,
my_signature_secret_key: String,
Expand Down Expand Up @@ -195,6 +194,16 @@ impl PyShinkaiMessageBuilder {
}
}

fn external_metadata_with_intra_sender(&mut self, recipient: String, sender: String, intra_sender: String) -> PyResult<()> {
if let Some(inner) = self.inner.take() {
let new_inner = inner.external_metadata_with_intra_sender(recipient, sender, intra_sender);
self.inner = Some(new_inner);
Ok(())
} else {
Err(PyErr::new::<pyo3::exceptions::PyValueError, _>("inner is None"))
}
}

fn external_metadata_with_other(&mut self, recipient: String, sender: String, other: String) -> PyResult<()> {
if let Some(inner) = self.inner.take() {
let new_inner = inner.external_metadata_with_other(recipient, sender, other);
Expand All @@ -205,6 +214,16 @@ impl PyShinkaiMessageBuilder {
}
}

fn external_metadata_with_other_and_intra_sender(&mut self, recipient: String, sender: String, other: String, intra_sender: String) -> PyResult<()> {
if let Some(inner) = self.inner.take() {
let new_inner = inner.external_metadata_with_other_and_intra_sender(recipient, sender, other, intra_sender);
self.inner = Some(new_inner);
Ok(())
} else {
Err(PyErr::new::<pyo3::exceptions::PyValueError, _>("inner is None"))
}
}

fn external_metadata_with_schedule(
&mut self,
recipient: String,
Expand Down Expand Up @@ -312,7 +331,7 @@ impl PyShinkaiMessageBuilder {
Err(e) => return Err(e),
}

match builder.external_metadata_with_other(recipient, sender, other) {
match builder.external_metadata_with_other_and_intra_sender(recipient, sender, other, sender_subidentity.clone()) {
Ok(_) => (),
Err(e) => return Err(e),
}
Expand Down Expand Up @@ -608,11 +627,11 @@ impl PyShinkaiMessageBuilder {
receiver_public_key: String,
inbox: String,
count: usize,
offset: Option<String>,
sender: String,
sender_subidentity: String,
recipient: String,
recipient_subidentity: String,
offset: Option<String>,
) -> PyResult<String> {
let inbox_name = match InboxName::new(inbox.clone()) {
Ok(name) => name,
Expand Down Expand Up @@ -841,7 +860,7 @@ impl PyShinkaiMessageBuilder {
}
};

let encryption = match Py::new(py, PyEncryptionMethod::new("None")) {
let encryption = match Py::new(py, PyEncryptionMethod::new(Some("None"))) {
Ok(encryption) => encryption,
Err(_) => {
return Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(
Expand Down Expand Up @@ -913,7 +932,7 @@ impl PyShinkaiMessageBuilder {
}
};

let encryption = match Py::new(py, PyEncryptionMethod::new("None")) {
let encryption = match Py::new(py, PyEncryptionMethod::new(Some("None"))) {
Ok(encryption) => encryption,
Err(_) => {
return Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(
Expand Down