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

Support Python 3.12 #203

Merged
merged 7 commits into from
Oct 2, 2024
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
12 changes: 6 additions & 6 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ jobs:
matrix:
os: [ubuntu-24.04, macos-14]
# Bazel uses hermetic python, these are just placeholders
python-version: ['3_8', '3_9', '3_10', '3_11']
python-version: ['3_8', '3_9', '3_10', '3_11', '3_12']
steps:
- uses: actions/checkout@v4
# configuring python for bazel abi and platform repo rules
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
- name: Python deps
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
matrix:
# Handling boundary conditions of: https://github.com/pypa/manylinux
python-version: ['3.8.0', '3.8.4', '3.9.0']
os: [ubuntu-20.04, macos-12]
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand All @@ -122,15 +122,15 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --upgrade packaging
bazel run -c opt //private_set_intersection/python:wheel.publish -- --verbose --skip-existing
bazel run -c opt //private_set_intersection/python:wheel.publish --@rules_python//python/config_settings:python_version=${{ matrix.python-version }} -- --verbose --skip-existing

Publish-python:
needs: [Core, JS, Go, Python, Rust]
if: ${{ github.event_name == 'release' }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04, macos-14]
steps:
- uses: actions/checkout@v4
Expand All @@ -145,4 +145,4 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --upgrade packaging
bazel run -c opt //private_set_intersection/python:wheel.publish -- --verbose --skip-existing
bazel run -c opt //private_set_intersection/python:wheel.publish --@rules_python//python/config_settings:python_version=${{ matrix.python-version }} -- --verbose --skip-existing
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
- 'private_set_intersection/go/**'
- '.bazelrc'
- '.bazelversion'
- 'MODULE.bazel'
- 'MODULE.bazel.lock'
- 'WORKSPACE'
javascript:
- 'private_set_intersection/javascript/**'
Expand Down Expand Up @@ -122,14 +124,14 @@ jobs:
os:
[ubuntu-24.04, macos-14]
# Bazel uses hermetic python, these are just placeholders
python-version: ['3_8', '3_9', '3_10', '3_11']
python-version: ['3_8', '3_9', '3_10', '3_11', '3_12']
steps:
- uses: actions/checkout@v4
# configuring python for bazel abi and platform repo rules
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
- name: Python deps
run: |
python -m pip install --upgrade pip
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 2.0.5

Feat:

- Add support for python 3.12

# Version 2.0.4

Chore:
Expand Down
11 changes: 5 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "org_openmined_psi",
version = "2.0.4",
version = "2.0.5",
)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand Down Expand Up @@ -29,15 +29,14 @@ bazel_dep(name = "rules_proto_grpc_cpp", version = "5.0.0")
bazel_dep(name = "rules_proto_grpc_go", version = "5.0.0")
bazel_dep(name = "rules_proto_grpc_python", version = "5.0.0")
bazel_dep(name = "rules_python", version = "0.36.0")
bazel_dep(name = "rules_python_gazelle_plugin", version = "0.36.0")
bazel_dep(name = "rules_rust", version = "0.51.0")

## PCJ
http_archive(
name = "private_join_and_compute",
sha256 = "9702d5e1e4deeb111e235952e1e831dc9d9f0127ed8a1a30112b235d11f3e937",
strip_prefix = "private-join-and-compute-2f678958e1b5a1a86adf96830c7c21d9cb2075f3",
url = "https://github.com/s0l0ist/private-join-and-compute/archive/2f678958e1b5a1a86adf96830c7c21d9cb2075f3.zip",
sha256 = "4a2916c42af1d32d3a94799703a81b11e05dbf1d4e0021e25f181d5921f667bf",
strip_prefix = "private-join-and-compute-1225a27f13fb39359242db3da3c090b81d24cced",
url = "https://github.com/s0l0ist/private-join-and-compute/archive/1225a27f13fb39359242db3da3c090b81d24cced.zip",
)

## Python
Expand Down Expand Up @@ -108,7 +107,7 @@ use_repo(python_platform, "python_platform")
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2021",
versions = ["1.80.1"],
versions = ["1.81.0"],
)
use_repo(rust, "rust_toolchains")

Expand Down
472 changes: 57 additions & 415 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmined/psi.js",
"version": "2.0.4",
"version": "2.0.5",
"description": "Private Set Intersection for JavaScript",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions private_set_intersection/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bazel test --test_output=all //private_set_intersection/python:test_3_8
bazel test --test_output=all //private_set_intersection/python:test_3_9
bazel test --test_output=all //private_set_intersection/python:test_3_10
bazel test --test_output=all //private_set_intersection/python:test_3_11
bazel test --test_output=all //private_set_intersection/python:test_3_12
...
```

Expand All @@ -28,6 +29,7 @@ bazel run -c opt --test_output=all //private_set_intersection/python:benchmark_3
bazel run -c opt --test_output=all //private_set_intersection/python:benchmark_3_9
bazel run -c opt --test_output=all //private_set_intersection/python:benchmark_3_10
bazel run -c opt --test_output=all //private_set_intersection/python:benchmark_3_11
bazel run -c opt --test_output=all //private_set_intersection/python:benchmark_3_12
...
```

Expand All @@ -40,6 +42,7 @@ bazel run //private_set_intersection/python/requirements:requirements_3_8.update
bazel run //private_set_intersection/python/requirements:requirements_3_9.update
bazel run //private_set_intersection/python/requirements:requirements_3_10.update
bazel run //private_set_intersection/python/requirements:requirements_3_11.update
bazel run //private_set_intersection/python/requirements:requirements_3_12.update
...
```

Expand Down
103 changes: 65 additions & 38 deletions private_set_intersection/python/psi_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ namespace py = pybind11;

template <class T>
T throwOrReturn(const absl::StatusOr<T>& in) {
if (!in.ok()) throw std::runtime_error(std::string(in.status().message()));
if (!in.ok()) {
py::gil_scoped_acquire acquire;
throw std::runtime_error(std::string(in.status().message()));
}
return *in;
}

Expand All @@ -29,6 +32,7 @@ auto saveProto(const T& obj) {
template <class T>
auto loadProto(T& obj, const py::bytes& data) {
if (!obj.ParseFromString(data)) {
py::gil_scoped_acquire acquire;
throw std::invalid_argument("failed to parse proto data");
}
}
Expand All @@ -47,44 +51,67 @@ void bind(pybind11::module& m) {

py::class_<psi_proto::ServerSetup>(m, "cpp_proto_server_setup")
.def(py::init<>())
.def("load", [](psi_proto::ServerSetup& obj,
const py::bytes& data) { return loadProto(obj, data); })
.def(
"load",
[](psi_proto::ServerSetup& obj, const py::bytes& data) {
return loadProto(obj, data);
},
py::call_guard<py::gil_scoped_release>())
.def("save",
[](const psi_proto::ServerSetup& obj) { return saveProto(obj); })
.def_static("Load", [](const py::bytes& data) {
psi_proto::ServerSetup obj;
loadProto(obj, data);
return obj;
});
.def_static(
"Load",
[](const py::bytes& data) {
psi_proto::ServerSetup obj;
loadProto(obj, data);
return obj;
},
py::call_guard<py::gil_scoped_release>());
py::class_<psi_proto::Request>(m, "cpp_proto_request")
.def(py::init<>())
.def("load", [](psi_proto::Request& obj,
const py::bytes& data) { return loadProto(obj, data); })
.def(
"load",
[](psi_proto::Request& obj, const py::bytes& data) {
return loadProto(obj, data);
},
py::call_guard<py::gil_scoped_release>())
.def("save", [](const psi_proto::Request& obj) { return saveProto(obj); })
.def_static("Load", [](const py::bytes& data) {
psi_proto::Request obj;
loadProto(obj, data);
return obj;
});
.def_static(
"Load",
[](const py::bytes& data) {
psi_proto::Request obj;
loadProto(obj, data);
return obj;
},
py::call_guard<py::gil_scoped_release>());
py::class_<psi_proto::Response>(m, "cpp_proto_response")
.def(py::init<>())
.def("load", [](psi_proto::Response& obj,
const py::bytes& data) { return loadProto(obj, data); })
.def(
"load",
[](psi_proto::Response& obj, const py::bytes& data) {
return loadProto(obj, data);
},
py::call_guard<py::gil_scoped_release>())
.def("save",
[](const psi_proto::Response& obj) { return saveProto(obj); })
.def_static("Load", [](const py::bytes& data) {
psi_proto::Response obj;
loadProto(obj, data);
return obj;
});
.def_static(
"Load",
[](const py::bytes& data) {
psi_proto::Response obj;
loadProto(obj, data);
return obj;
},
py::call_guard<py::gil_scoped_release>());

py::class_<psi::PsiClient>(m, "cpp_client")
.def_static(
"CreateWithNewKey",
[](bool reveal_intersection) {
auto client = psi::PsiClient::CreateWithNewKey(reveal_intersection);
if (!client.ok())
if (!client.ok()) {
py::gil_scoped_acquire acquire;
throw std::runtime_error(std::string(client.status().message()));
}
return std::move(*client);
},
py::call_guard<py::gil_scoped_release>())
Expand All @@ -93,8 +120,10 @@ void bind(pybind11::module& m) {
[](const std::string& key_bytes, bool reveal_intersection) {
auto client =
psi::PsiClient::CreateFromKey(key_bytes, reveal_intersection);
if (!client.ok())
if (!client.ok()) {
py::gil_scoped_acquire acquire;
throw std::runtime_error(std::string(client.status().message()));
}
return std::move(*client);
},
py::call_guard<py::gil_scoped_release>())
Expand Down Expand Up @@ -123,20 +152,19 @@ void bind(pybind11::module& m) {
obj.GetIntersectionSize(server_setup, server_response));
},
py::call_guard<py::gil_scoped_release>())
.def(
"GetPrivateKeyBytes",
[](const psi::PsiClient& obj) {
return py::bytes(obj.GetPrivateKeyBytes());
},
py::call_guard<py::gil_scoped_release>());
.def("GetPrivateKeyBytes", [](const psi::PsiClient& obj) {
return py::bytes(obj.GetPrivateKeyBytes());
});

py::class_<psi::PsiServer>(m, "cpp_server")
.def_static(
"CreateWithNewKey",
[](bool reveal_intersection) {
auto server = psi::PsiServer::CreateWithNewKey(reveal_intersection);
if (!server.ok())
if (!server.ok()) {
py::gil_scoped_acquire acquire;
throw std::runtime_error(std::string(server.status().message()));
}
return std::move(*server);
},
py::call_guard<py::gil_scoped_release>())
Expand All @@ -145,8 +173,10 @@ void bind(pybind11::module& m) {
[](const std::string& key_bytes, bool reveal_intersection) {
auto server =
psi::PsiServer::CreateFromKey(key_bytes, reveal_intersection);
if (!server.ok())
if (!server.ok()) {
py::gil_scoped_acquire acquire;
throw std::runtime_error(std::string(server.status().message()));
}
return std::move(*server);
},
py::call_guard<py::gil_scoped_release>())
Expand All @@ -165,12 +195,9 @@ void bind(pybind11::module& m) {
return throwOrReturn(obj.ProcessRequest(client_request));
},
py::call_guard<py::gil_scoped_release>())
.def(
"GetPrivateKeyBytes",
[](const psi::PsiServer& obj) {
return py::bytes(obj.GetPrivateKeyBytes());
},
py::call_guard<py::gil_scoped_release>());
.def("GetPrivateKeyBytes", [](const psi::PsiServer& obj) {
return py::bytes(obj.GetPrivateKeyBytes());
});
}

PYBIND11_MODULE(openmined_psi, m) { bind(m); }
Expand Down
2 changes: 1 addition & 1 deletion tools/package.bzl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" Version of the current release """
VERSION_LABEL = "2.0.4"
VERSION_LABEL = "2.0.5"
Loading