Closed Thadah closed 7 months ago
Sorry I just realized I was trying to push to main
instead of dev
. Fixed now.
Adding @mtriplett-duality to this PR
Hi @Thadah Thanks so much for the work here! I've run this locally, and everything seems to work perfectly. Unless you have some other modifications to add, we're comfortable merging this in. Just give us the thumbs up!
I found a way of making the pybind11
stubs show in most IDEs, but automating the process is a bit convoluted. It would require to create a wheel
package, then installing it in a development (or virtual) environment, use pybind11-stubgen
to generate the .pyi
files, and generate the package again with the automatically generated pyi
files. A bash script might be the best option.
Another way would be to create the .pyi
files manually and place them in the openfhe/
directory so that they get packaged with the rest of the files. This would require periodic maintenance as they wouldn't be updated automatically and new functions or features would be lost to the IDE.
What approach would you prefer?
I've added a build_package.sh script that should automate the stub creation and packaging automatically, but it will ask for the module to be installed first with pip install e .
I hope this is good enough.
I believe there's nothing else to add for now on my part, so I have no issue for it to be merged. A CI/CD pipeline surely makes a lot more sense than doing workarounds in a setup.py file, but I wanted to provide a stopgap solution in the meantime. Thank you for all the feedback @mtriplett-duality!
Edit: I changed some lines in the shell script because I realized it wasn't working properly when using the project as a submodule and I wasn't looking if pybind11-stubgen was installed before running the script.
Hello!
This PR adds support for PyPI packaging when using the command
python setup.py sdist bdist_wheel
. The purpose is to make easier for developers to create a package of their own and for the openfhe org to be able to publish packages easily.I have created a setup.py that compiles the library with CMake and then creates the sdist
tar.gz
and bdist_wheelwhl
packages with the library inside, allowing for easy installation withpip install
and integration withimport openfhe
.There are some caveats to the approach I followed. Since
build_ext
executes at the end of the setup process, it was creating empty packages and then compiling the library. To work around that I created a customsdist
class that forces abuild_ext
before all the other commands. That introduces the problem of double compilation, which is done in thebdist_wheel
phase. To prevent that, I created the (admittedly not very elegant) solution of passing the compilation if the .so file already exists. That's also why it gets removed during thesdist
phase of the build. There also isn't any docstring for now, which complicated knowing which functions are available and what they do, forcing you to rely on the documentation.If you have any feedback or a better approach to the code, please let me know!
Thank you.