Skip to content

Commit 262fd66

Browse files
Thadahgpujana
authored andcommitted
Generate stubbed package with shell script
1 parent ef72a57 commit 262fd66

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ docs/
1313
demoData/
1414
dist/
1515
openfhe/openfhe.so
16-
openfhe.egg-info/
16+
openfhe/*.pyi
17+
openfhe.egg-info/
18+
stubs/
19+
.venv/

build_package.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Exit on any error
3+
set -e
4+
5+
# Find the venv directory
6+
if [ -d ".venv" ]; then
7+
VENV_DIR=".venv"
8+
elif [ -d "../.venv" ]; then
9+
VENV_DIR="../.venv"
10+
else
11+
echo "The virtual environment does not exist. Please run 'python -m venv .venv' to create it." >&2
12+
exit 1
13+
fi
14+
15+
# Activate the virtual environment
16+
source $VENV_DIR/bin/activate
17+
18+
# Install pybind11-stubgen
19+
if ! pip show pybind11-stubgen > /dev/null; then
20+
pip install pybind11-stubgen
21+
fi
22+
23+
# Check if the virtual environment has the openfhe package installed
24+
if ! pip show openfhe > /dev/null; then
25+
echo "The openfhe package is not installed in the virtual environment. Please run 'pip install -e .' to install it." >&2
26+
exit 1
27+
fi
28+
29+
# Generate stub files using pybind11-stubgen
30+
echo "Generating stub files..."
31+
pybind11-stubgen openfhe
32+
33+
# Check if stub generation was successful
34+
if [ $? -eq 0 ]; then
35+
echo "Stub files generated successfully."
36+
else
37+
echo "Stub generation failed." >&2
38+
exit 1
39+
fi
40+
41+
# Move the generated stub files to the openfhe package directory
42+
echo "Moving the generated stub files to the openfhe package directory..."
43+
mv stubs/openfhe/* openfhe/
44+
rm -r -d stubs
45+
46+
# Build the source distribution and wheel distribution
47+
echo "Building the sdist and bdist_wheel..."
48+
python setup.py sdist bdist_wheel
49+
50+
# Indicate where the distributions were saved
51+
echo "The distributions have been built and are located in the 'dist' directory. You can install the package using 'pip install dist/<distribution_file>'."

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ def run(self):
6666
url='https://github.com/openfheorg/openfhe-python',
6767
license='BSD-2-Clause',
6868
packages=['openfhe'],
69-
package_data={'openfhe': ['*.so']},
69+
package_data={'openfhe': ['*.so', '*.pyi']},
7070
ext_modules=[CMakeExtension('openfhe', sourcedir='')],
7171
cmdclass={
7272
'build_ext': CMakeBuild,
7373
'sdist': SDist
7474
},
7575
include_package_data=True,
7676
python_requires=">=3.6",
77-
install_requires=['pybind11', 'pybind11-global']
77+
install_requires=['pybind11', 'pybind11-global', 'pybind11-stubgen']
7878
)

0 commit comments

Comments
 (0)