-
Notifications
You must be signed in to change notification settings - Fork 345
Initial Bazel configuration for Pybind11 and S2Point bindings #524
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Looks like a good start. I'll have a closer look tomorrow. How much are you planning on wrapping? |
Great!
For my purposes I mainly need S2Cell and its dependencies. But I'm happy to do more to get this to whatever you would consider a viable MVP. Open to suggestions there? |
6535f67 to
7b92d38
Compare
src/python/PYBIND_README.md
Outdated
|
|
||
| ## Development | ||
|
|
||
| Bazel can be used for development and testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the CMake / pybind11 story? Say something about that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some explanation about this. Currently CMake only builds the SWIG package. We'll probably need to update CMake to build the wheel for the final distribution but I'll save that for another PR if that's alright with you?
|
|
||
| ``` | ||
| python/ | ||
| ├── bindings/ # Dir for C++ pybind11 bindings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there both bindings/ and s2geometry_pybind/?
It seems like one should do, and everything could probably go directly in python/, but I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we do do need the s2geometry_pybind to match the name of the python package. Open to suggestions on naming there.
The bindings and tests directories are not necessary. We can certainly flatten one or both of those into the python parent if you prefer. Happy to go with whatever layout you prefer here.
| │ └── ... # Bindings for additional classes | ||
| ├── s2geometry_pybind/ # Dir for Python package | ||
| │ └── __init__.py # Package initialization | ||
| ├── tests/ # Dir for Python unit tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/ subdir also seems inconsistent with the rest of the project. Why not keep tests with the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can drop. Just let me know what layout you prefer in the comment above.
src/python/bindings/BUILD.bazel
Outdated
| package(default_visibility = ["//python:__subpackages__"]) | ||
|
|
||
| pybind_extension( | ||
| name = "s2geometry_bindings", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the underscore prefix to indicate it is a private module
|
|
||
| pybind_extension( | ||
| name = "s2geometry_bindings", | ||
| srcs = ["module.cc"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make any sense to have fine-grained targets? In google3, we have fine-grained targets for the S2 library, which really helps compilation and development time. We don't use them for PyClif mostly because the C++ targets were sharded after the pyclif ones were added.
Do we just accept that it's monolithic in Python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could consider adding some submodules. How about if we put the "core" classes directly under the top-level package (e.g. s2geometry.S2Cell), but add submodules for some of the utility classes (e.g. s2geometry.regions.S2CellCovering). Open to suggestions on how to break this up.
Once we align on the python module structure, I think we would then define one pybind_extension rule per module, plus separate pybind_library rules for each class.
|
@jmr, I made most of the changes you suggested. Let me know what you prefer for the directory layout and how to organize the python modules and I'll make those changes as well. |
Initial Bazel configuration for Pybind11 and S2Point bindings.
#522
The S2 Geometry library is transitioning from SWIG-based bindings to pybind11-based bindings.
During this migration:
s2geometry): The current production bindings, built with CMake. Useimport s2geometryto access these.s2geometry_pybind): The new bindings under development, built with Bazel. Useimport s2geometry_pybindto access these.Once the pybind11 bindings are feature-complete and stable, the SWIG bindings will be deprecated and the pybind11 package will be renamed to
s2geometryto become the primary Python API.This PR adds Bazel configuration for building and testing the bindings on the local toolchain. For distribution we'll need to generate a wheel for compatibility with different OS and python versions.