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

Python Fault Handling #22

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -40,7 +39,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.12"

- name: Build
run: |
Expand Down Expand Up @@ -82,4 +81,4 @@ jobs:
./test_updates
./test_updates update
./persistent_test
shell: bash
shell: bash
4 changes: 4 additions & 0 deletions python_bindings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import faulthandler
from .cpp_bindings import *
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is the rexport that makes everything appear under hnswlib?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


faulthandler.enable()
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,9 @@ class BFIndex
}
};

PYBIND11_PLUGIN(hnswlib)
PYBIND11_PLUGIN(cpp_bindings)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this change the name of the module / what does this change do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changes the name of the python bindings package

{
py::module m("hnswlib");
py::module m("cpp_bindings");

py::class_<Index<float>>(m, "Index")
.def(py::init(&Index<float>::createFromParams), py::arg("params"))
Expand Down
1 change: 0 additions & 1 deletion python_bindings/setup.py

This file was deleted.

14 changes: 5 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
include_dirs = [
pybind11.get_include(),
np.get_include(),
"./hnswlib",
]

# compatibility when run in python_bindings
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my understanding - why is this ok to remove?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was additional complexity for if you wanted to run setup.py inside the python_bindings directory - we don't need that.

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 = []
Expand All @@ -31,7 +25,7 @@

ext_modules = [
Extension(
"hnswlib",
"hnswlib.cpp_bindings",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my understanding - is this the module path

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is the module path for the extension module being added here, in this case the cpp bindings are now a submodule of the hnswlib module

source_files,
include_dirs=include_dirs,
libraries=libraries,
Expand Down Expand Up @@ -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"],
)
Loading