Skip to content

Commit 27b94b8

Browse files
authored
feat(#100): python bindings (#101)
* Python bindings * docs * CI issues * Removed license, this is an Apache 2 project and this module doesn't need separate licencing
1 parent d3eb8ae commit 27b94b8

17 files changed

Lines changed: 1839 additions & 15 deletions

File tree

.github/workflows/ci-full.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ on:
1515
# Policy/fixture changes that affect tests
1616
- "fixtures/**"
1717
- "**.rego"
18+
# Python binding changes
19+
- "cupcake-py/**"
1820
workflow_dispatch:
1921

2022
env:
@@ -162,6 +164,95 @@ jobs:
162164
- uses: eqtylab-actions/install-nix-action@v31
163165
- run: nix build .#cupcake-cli -L
164166

167+
test-python:
168+
name: Python Bindings (${{ matrix.os }})
169+
runs-on: ${{ matrix.os }}
170+
strategy:
171+
fail-fast: false
172+
matrix:
173+
os: [cupcake-ubuntu-latest, macos-latest, windows-latest]
174+
steps:
175+
- name: Checkout code
176+
uses: actions/checkout@v4
177+
178+
- name: Setup Rust
179+
uses: dtolnay/rust-toolchain@stable
180+
181+
- name: Setup Rust cache
182+
uses: Swatinem/rust-cache@v2
183+
184+
- name: Setup Python
185+
uses: actions/setup-python@v5
186+
with:
187+
python-version: "3.12"
188+
189+
- name: Install OPA (Unix)
190+
if: runner.os != 'Windows'
191+
run: |
192+
if [[ "$RUNNER_OS" == "Linux" ]]; then
193+
curl -L -o opa https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_linux_amd64_static
194+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
195+
curl -L -o opa https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_darwin_amd64
196+
fi
197+
chmod +x opa
198+
sudo mv opa /usr/local/bin/
199+
opa version
200+
201+
- name: Install OPA (Windows)
202+
if: runner.os == 'Windows'
203+
shell: pwsh
204+
run: |
205+
Invoke-WebRequest -Uri "https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_windows_amd64.exe" -OutFile "opa.exe"
206+
Move-Item opa.exe "C:\Windows\System32\opa.exe" -Force
207+
& opa version
208+
209+
- name: Create virtualenv and install dependencies (Unix)
210+
if: runner.os != 'Windows'
211+
run: |
212+
python -m venv .venv
213+
source .venv/bin/activate
214+
pip install maturin pytest pytest-asyncio
215+
216+
- name: Create virtualenv and install dependencies (Windows)
217+
if: runner.os == 'Windows'
218+
shell: pwsh
219+
run: |
220+
python -m venv .venv
221+
.venv\Scripts\Activate.ps1
222+
pip install maturin pytest pytest-asyncio
223+
224+
- name: Build Python bindings (Unix)
225+
if: runner.os != 'Windows'
226+
run: |
227+
source .venv/bin/activate
228+
cd cupcake-py
229+
maturin develop --release
230+
231+
- name: Build Python bindings (Windows)
232+
if: runner.os == 'Windows'
233+
shell: pwsh
234+
run: |
235+
.venv\Scripts\Activate.ps1
236+
cd cupcake-py
237+
maturin develop --release
238+
239+
- name: Run Python tests (Unix)
240+
if: runner.os != 'Windows'
241+
run: |
242+
source .venv/bin/activate
243+
cd cupcake-py
244+
pytest tests/ -v
245+
246+
- name: Run Python tests (Windows)
247+
if: runner.os == 'Windows'
248+
shell: pwsh
249+
run: |
250+
.venv\Scripts\Activate.ps1
251+
cd cupcake-py
252+
pytest tests/ -v
253+
env:
254+
CI: true
255+
165256
fmt:
166257
name: Format
167258
runs-on: ubuntu-latest

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ on:
1515
# Policy/fixture changes that affect tests
1616
- "fixtures/**"
1717
- "**.rego"
18+
# Python binding changes
19+
- "cupcake-py/**"
1820
workflow_dispatch:
1921

2022
env:
@@ -88,3 +90,50 @@ jobs:
8890
cargo test --doc -j 1 -- --test-threads=1
8991
env:
9092
CI: true
93+
94+
test-python:
95+
name: Python Bindings (Linux)
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout code
99+
uses: actions/checkout@v4
100+
101+
- name: Setup Rust
102+
uses: dtolnay/rust-toolchain@stable
103+
104+
- name: Setup Rust cache
105+
uses: Swatinem/rust-cache@v2
106+
with:
107+
cache-targets: false
108+
109+
- name: Setup Python
110+
uses: actions/setup-python@v5
111+
with:
112+
python-version: "3.12"
113+
114+
- name: Install OPA
115+
run: |
116+
curl -L -o opa https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_linux_amd64_static
117+
chmod +x opa
118+
sudo mv opa /usr/local/bin/
119+
opa version
120+
121+
- name: Create virtualenv and install dependencies
122+
run: |
123+
python -m venv .venv
124+
source .venv/bin/activate
125+
pip install maturin pytest pytest-asyncio
126+
127+
- name: Build Python bindings
128+
run: |
129+
source .venv/bin/activate
130+
cd cupcake-py
131+
maturin develop --release
132+
133+
- name: Run Python tests
134+
run: |
135+
source .venv/bin/activate
136+
cd cupcake-py
137+
pytest tests/ -v
138+
env:
139+
CI: true

0 commit comments

Comments
 (0)