From 256bcc71a0f29147a884e466d03251bc7223aa17 Mon Sep 17 00:00:00 2001 From: atroyn Date: Tue, 20 Aug 2024 18:07:04 -0700 Subject: [PATCH 1/6] Release and tests --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 56c93ef7..37c1136c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,7 @@ jobs: CIBW_ENVIRONMENT: HNSWLIB_NO_NATIVE=true CIBW_ENVIRONMENT_PASS_LINUX: HNSWLIB_NO_NATIVE CIBW_PROJECT_REQUIRES_PYTHON: ">=3.7" - CIBW_SKIP: "pp* *musllinux* cp312-win*" + CIBW_SKIP: "pp* *musllinux*" CIBW_ARCHS_MACOS: "x86_64 arm64" CIBW_ARCHS_WINDOWS: "AMD64" CIBW_ARCHS_LINUX: "x86_64 aarch64" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9674abb7..fbae72c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -40,7 +40,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.12" - name: Build run: | From 559b5eca4d3d9d906e9f23d1cf4adbd934715a3d Mon Sep 17 00:00:00 2001 From: atroyn Date: Wed, 21 Aug 2024 14:49:04 -0700 Subject: [PATCH 2/6] Refactor installation & add fault handler to init --- python_bindings/__init__.py | 4 ++++ python_bindings/{ => cpp_bindings}/bindings.cpp | 4 ++-- python_bindings/setup.py | 1 - setup.py | 14 +++++--------- 4 files changed, 11 insertions(+), 12 deletions(-) rename python_bindings/{ => cpp_bindings}/bindings.cpp (99%) delete mode 120000 python_bindings/setup.py diff --git a/python_bindings/__init__.py b/python_bindings/__init__.py index e69de29b..522e3a99 100644 --- a/python_bindings/__init__.py +++ b/python_bindings/__init__.py @@ -0,0 +1,4 @@ +import faulthandler +from .cpp_bindings import * + +faulthandler.enable() diff --git a/python_bindings/bindings.cpp b/python_bindings/cpp_bindings/bindings.cpp similarity index 99% rename from python_bindings/bindings.cpp rename to python_bindings/cpp_bindings/bindings.cpp index cad2f7b9..ec08f9f6 100644 --- a/python_bindings/bindings.cpp +++ b/python_bindings/cpp_bindings/bindings.cpp @@ -952,9 +952,9 @@ class BFIndex } }; -PYBIND11_PLUGIN(hnswlib) +PYBIND11_PLUGIN(cpp_bindings) { - py::module m("hnswlib"); + py::module m("cpp_bindings"); py::class_>(m, "Index") .def(py::init(&Index::createFromParams), py::arg("params")) diff --git a/python_bindings/setup.py b/python_bindings/setup.py deleted file mode 120000 index f8f80fc2..00000000 --- a/python_bindings/setup.py +++ /dev/null @@ -1 +0,0 @@ -../setup.py \ No newline at end of file diff --git a/setup.py b/setup.py index e9543baa..a8c799b9 100644 --- a/setup.py +++ b/setup.py @@ -13,16 +13,10 @@ include_dirs = [ pybind11.get_include(), np.get_include(), + "./hnswlib", ] -# compatibility when run in python_bindings -bindings_dir = "python_bindings" -if bindings_dir in os.path.basename(os.getcwd()): - source_files = ["./bindings.cpp"] - include_dirs.extend(["../hnswlib/"]) -else: - source_files = ["./python_bindings/bindings.cpp"] - include_dirs.extend(["./hnswlib/"]) +source_files = ["./python_bindings/cpp_bindings/bindings.cpp"] libraries = [] @@ -31,7 +25,7 @@ ext_modules = [ Extension( - "hnswlib", + "hnswlib.cpp_bindings", source_files, include_dirs=include_dirs, libraries=libraries, @@ -127,4 +121,6 @@ def build_extensions(self): install_requires=["numpy"], cmdclass={"build_ext": BuildExt}, zip_safe=False, + package_dir={"hnswlib": "python_bindings"}, + packages=["hnswlib"], ) From 6ede4f5eb973618a13623ab11c04ffbedea3b944 Mon Sep 17 00:00:00 2001 From: atroyn Date: Wed, 21 Aug 2024 16:33:01 -0700 Subject: [PATCH 3/6] causing problems on purpose --- python_bindings/cpp_bindings/bindings.cpp | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/python_bindings/cpp_bindings/bindings.cpp b/python_bindings/cpp_bindings/bindings.cpp index ec08f9f6..f164547f 100644 --- a/python_bindings/cpp_bindings/bindings.cpp +++ b/python_bindings/cpp_bindings/bindings.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include + namespace py = pybind11; using namespace pybind11::literals; // needed to bring in _a literal @@ -952,10 +955,31 @@ class BFIndex } }; +void raise_signal(int signal_number) +{ + if (std::raise(signal_number) != 0) + { + throw std::runtime_error("Failed to raise signal"); + } +} + +// Example function to raise SIGSEGV +void raise_segv() +{ + raise_signal(SIGSEGV); +} + +// Example function to raise SIGABRT +void raise_abort() +{ + raise_signal(SIGABRT); +} + PYBIND11_PLUGIN(cpp_bindings) { py::module m("cpp_bindings"); - + m.def("raise_segv", &raise_segv); + m.def("raise_abort", &raise_abort); py::class_>(m, "Index") .def(py::init(&Index::createFromParams), py::arg("params")) /* WARNING: Index::createFromIndex is not thread-safe with Index::addItems */ From b9c1ba9b8e93f0534673c2fea7082e9630494d90 Mon Sep 17 00:00:00 2001 From: atroyn Date: Wed, 21 Aug 2024 19:39:04 -0700 Subject: [PATCH 4/6] Revert "causing problems on purpose" This reverts commit 6ede4f5eb973618a13623ab11c04ffbedea3b944. --- python_bindings/cpp_bindings/bindings.cpp | 26 +---------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/python_bindings/cpp_bindings/bindings.cpp b/python_bindings/cpp_bindings/bindings.cpp index f164547f..ec08f9f6 100644 --- a/python_bindings/cpp_bindings/bindings.cpp +++ b/python_bindings/cpp_bindings/bindings.cpp @@ -9,9 +9,6 @@ #include #include -#include -#include - namespace py = pybind11; using namespace pybind11::literals; // needed to bring in _a literal @@ -955,31 +952,10 @@ class BFIndex } }; -void raise_signal(int signal_number) -{ - if (std::raise(signal_number) != 0) - { - throw std::runtime_error("Failed to raise signal"); - } -} - -// Example function to raise SIGSEGV -void raise_segv() -{ - raise_signal(SIGSEGV); -} - -// Example function to raise SIGABRT -void raise_abort() -{ - raise_signal(SIGABRT); -} - PYBIND11_PLUGIN(cpp_bindings) { py::module m("cpp_bindings"); - m.def("raise_segv", &raise_segv); - m.def("raise_abort", &raise_abort); + py::class_>(m, "Index") .def(py::init(&Index::createFromParams), py::arg("params")) /* WARNING: Index::createFromIndex is not thread-safe with Index::addItems */ From d3bf4f14450a7b19768ce738a16c717ec580495c Mon Sep 17 00:00:00 2001 From: atroyn Date: Wed, 21 Aug 2024 19:57:01 -0700 Subject: [PATCH 5/6] Remove examples from tests --- test.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test.json diff --git a/test.json b/test.json new file mode 100644 index 00000000..7cd0a16a --- /dev/null +++ b/test.json @@ -0,0 +1,13 @@ +{ + "config": { + "name": "test", + "version": "1.0.0", + "description": "test", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "test", + "license": "ISC" + }, +} \ No newline at end of file From 7e6c6fb341439fd34274cf31280950143d515149 Mon Sep 17 00:00:00 2001 From: atroyn Date: Wed, 21 Aug 2024 20:00:04 -0700 Subject: [PATCH 6/6] Remove examples from tests --- .github/workflows/test.yml | 3 +-- test.json | 13 ------------- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 test.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fbae72c9..8b69605f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,6 @@ jobs: - name: Test timeout-minutes: 15 run: | - python -m unittest discover -v --start-directory examples/python --pattern "example*.py" python -m unittest discover -v --start-directory tests/python --pattern "bindings_test*.py" test_cpp: @@ -82,4 +81,4 @@ jobs: ./test_updates ./test_updates update ./persistent_test - shell: bash + shell: bash \ No newline at end of file diff --git a/test.json b/test.json deleted file mode 100644 index 7cd0a16a..00000000 --- a/test.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "config": { - "name": "test", - "version": "1.0.0", - "description": "test", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "test", - "license": "ISC" - }, -} \ No newline at end of file