Skip to content

Commit 2a56a5e

Browse files
authored
Type hint and publish to pypi (#131)
* add type hints and ready for pypi * publich by wheels * rename to seal-python * fix build * fix build
1 parent 338f2d2 commit 2a56a5e

14 files changed

Lines changed: 965 additions & 48 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/wheels.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Build and Publish Wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
tags: ["v*"]
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build_wheels:
14+
name: Build wheels on ${{ matrix.os }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- os: ubuntu-latest
21+
- os: windows-latest
22+
- os: macos-14
23+
- os: macos-15
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
submodules: recursive
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.12"
35+
36+
- name: Build wheels
37+
uses: pypa/cibuildwheel@v2.22.0
38+
env:
39+
CIBW_BUILD_VERBOSITY: "1"
40+
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
41+
CIBW_SKIP: "*-musllinux_* pp* cp38-macosx_arm64"
42+
CIBW_ARCHS_LINUX: "x86_64"
43+
CIBW_ARCHS_WINDOWS: "AMD64"
44+
CIBW_ARCHS_MACOS: "auto64"
45+
CIBW_TEST_COMMAND: "python -c \"import seal; print(seal.__version__)\""
46+
CIBW_BEFORE_BUILD: >
47+
python -m pip install --upgrade pip cmake &&
48+
cmake -S SEAL -B SEAL/build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF &&
49+
cmake --build SEAL/build --config Release &&
50+
python -c "import glob; print('SEAL libs:', glob.glob('SEAL/build/**/*.lib', recursive=True)[:50])"
51+
52+
- name: Upload wheel artifacts
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: wheels-${{ matrix.os }}
56+
path: wheelhouse/*.whl
57+
58+
build_sdist:
59+
name: Build sdist
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v4
64+
with:
65+
submodules: recursive
66+
67+
- name: Set up Python
68+
uses: actions/setup-python@v5
69+
with:
70+
python-version: "3.12"
71+
72+
- name: Install build tools
73+
run: python -m pip install --upgrade pip build cmake
74+
75+
- name: Build SEAL static libs
76+
run: |
77+
cmake -S SEAL -B SEAL/build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
78+
cmake --build SEAL/build --config Release
79+
80+
- name: Build source distribution
81+
run: python -m build --sdist
82+
83+
- name: Upload sdist artifact
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: sdist
87+
path: dist/*.tar.gz
88+
89+
publish_pypi:
90+
name: Publish to PyPI
91+
needs: [build_wheels, build_sdist]
92+
runs-on: ubuntu-latest
93+
if: github.event_name == 'release' && github.event.action == 'published'
94+
permissions:
95+
id-token: write
96+
steps:
97+
- name: Download wheel artifacts
98+
uses: actions/download-artifact@v4
99+
with:
100+
path: dist
101+
pattern: wheels-*
102+
merge-multiple: true
103+
104+
- name: Download sdist artifact
105+
uses: actions/download-artifact@v4
106+
with:
107+
path: dist
108+
name: sdist
109+
110+
- name: Publish package distributions to PyPI
111+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ build
4242
temp
4343
.idea
4444
*.bin
45+
dist

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include README.md
2+
include LICENSE
3+
include seal.pyi
4+
include py.typed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ This is a python binding for the Microsoft SEAL library.
1111
## Contents
1212

1313
* [Build](#build)
14+
* [Typing](#typing)
1415
* [Note](#note)
1516
* [Serialize](#serialize)
1617
* [Other](#other)
1718
* [FAQ](#faq)
19+
* [Release](#release)
1820

1921

2022

@@ -163,6 +165,26 @@ This is a python binding for the Microsoft SEAL library.
163165
2. Edit `extra_objects` in setup.py to `*.dylib` or else.
164166

165167

168+
## Typing
169+
170+
This project now ships `seal.pyi` and `py.typed` for Python type checking (PEP 561).
171+
172+
After build/install, editors such as Pylance/Pyright/mypy can use these hints for autocomplete and static analysis.
173+
174+
175+
## Release
176+
177+
Use `RELEASE.md` for the full PyPI release checklist.
178+
179+
Quick commands:
180+
181+
```bash
182+
python3 setup.py sdist bdist_wheel
183+
python3 -m twine check dist/*
184+
python3 -m twine upload dist/*
185+
```
186+
187+
166188

167189
## Contributing
168190

RELEASE.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Release to PyPI
2+
3+
## 1. Build prerequisites
4+
5+
```bash
6+
python3 -m pip install --upgrade pip build twine
7+
git submodule update --init --recursive
8+
cmake -S SEAL -B SEAL/build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
9+
cmake --build SEAL/build
10+
```
11+
12+
## 2. Build wheel and sdist
13+
14+
```bash
15+
python3 setup.py sdist bdist_wheel
16+
```
17+
18+
## 3. Validate artifacts
19+
20+
```bash
21+
python3 -m twine check dist/*
22+
```
23+
24+
## 4. Upload to TestPyPI (recommended first)
25+
26+
```bash
27+
python3 -m twine upload --repository testpypi dist/*
28+
```
29+
30+
## 5. Upload to PyPI
31+
32+
```bash
33+
python3 -m twine upload dist/*
34+
```
35+
36+
## 6. Post-upload smoke test
37+
38+
```bash
39+
python3 -m venv /tmp/seal-publish-test
40+
source /tmp/seal-publish-test/bin/activate
41+
python -m pip install seal-python
42+
python - <<'PY'
43+
import seal
44+
print("seal version:", seal.__version__)
45+
PY
46+
```

py.typed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)