Skip to content

Commit 885a4fe

Browse files
authored
ENH: Add python pipeline, integration tests, and CI config (#5)
* CHORE: update vscode config with python stuff * ENH: sdist compatible python build, updated dir structure * TEST: add tests for python dist * REF: rename jsonlogic -> apply; simplify node tests * DOC: add build instructions to README * CHORE: ensure python available in CI * FIX: activeate venv for python tests * CHORE: get windows working in CI (note this is a squash of 33 commits, because holy moly is windows a pain) CHORE: windows does not work with python3.6? CHORE: are windows venv bins in a different directory? CHORE: try another workaround for windows CHORE: pass env vars into cargo test FIX: grab python version from matrix namespace, not runner FIX: variable target for venv creation DEV: add debugging output for windows FIX: quote os name CHORE: more windows debugging CHORE: more windows debugging CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows FIX: variable venv throughout CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows FIX: typo CHORE: try testing the wheel instead since windows is a nightmare CHORE: windows CHORE: windows CHORE: windows CHORE: windows CHORE: windows * CHORE: remove commented code
1 parent a4396c7 commit 885a4fe

20 files changed

+300
-334
lines changed

.github/workflows/ci.yml

+39-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
os: [ubuntu-latest, macos-latest, windows-latest]
10+
python-version: [3.6, 3.7, 3.8]
1011
runs-on: "${{ matrix.os }}"
1112
steps:
1213
# Check out the code
@@ -15,6 +16,18 @@ jobs:
1516
# We need node for some integration tests
1617
- uses: "actions/setup-node@v1"
1718

19+
# Install python
20+
- name: "Set up python"
21+
uses: "actions/setup-python@v2"
22+
with:
23+
python-version: "${{ matrix.python-version }}"
24+
25+
- name: "Get Python Path"
26+
id: get-py-path
27+
shell: bash
28+
run: |
29+
echo "::set-output name=path::$(which python)"
30+
1831
# Set the current month and year (used for cache key)
1932
- name: "Get Date"
2033
id: get-date
@@ -53,7 +66,31 @@ jobs:
5366
# Ensure we're all set up
5467
- name: "Perform Setup"
5568
run: "make setup"
69+
shell: bash
70+
env:
71+
# PY_VER: "${{ matrix.python-version }}"
72+
WINDOWS: "${{ contains(runner.os, 'windows') }}"
73+
PYTHON: ${{ steps.get-py-path.outputs.path }}
5674

57-
# Run the tests
5875
- name: "Run Tests"
59-
run: "make test"
76+
if: "${{ !contains(runner.os, 'windows') }}"
77+
shell: bash
78+
run: "cargo test --all-features"
79+
80+
- name: "Run Tests (Windows)"
81+
if: "${{ contains(runner.os, 'windows') }}"
82+
shell: bash
83+
# Python behaves weirdly with setup.py develop in Windows,
84+
# when it comes to loading DLLs, so on that platform we build and
85+
# install the wheel and run the tests with that.
86+
# Running `cargo test --features=wasm` runs all the regular lib
87+
# tests plus the WASM integration tests, while excluding the
88+
# python integration tests
89+
run: |
90+
cargo test --features=wasm
91+
make develop-py-wheel
92+
pip install dist/*.whl
93+
python tests/test_py.py
94+
env:
95+
WINDOWS: "${{ contains(runner.os, 'windows') }}"
96+
PYTHON: ${{ steps.get-py-path.outputs.path }}

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ Cargo.lock
2121
**/.DS_Store
2222

2323
js/
24+
25+
**/__pycache__/
26+
**/*.egg-info/
27+
build/
28+
dist/
29+
venv/

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
22
"editor.formatOnSave": true,
3+
"python.venvPath": "venv",
4+
"python.pythonPath": "python",
5+
"python.formatting.provider": "black",
6+
"python.linting.enabled": true,
7+
"python.linting.mypyEnabled": true,
8+
"python.linting.flake8Enabled": true,
9+
"python.linting.pylintEnabled": true,
10+
"python.linting.pydocstyleEnabled": true,
311
"rust-analyzer.cargo.allFeatures": true,
412
}

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include src *
2+
include Cargo.toml

Makefile

+47-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
11
# TODO: split sub-language makes into their dirs & call `$(MAKE) -C dir` for them
22

3-
.PHONY: build-js run-js
3+
SHELL = bash
44

5+
ifeq ($(WINDOWS),true)
6+
VENV=venv/Scripts/python.exe
7+
else
8+
VENV=venv/bin/python
9+
endif
10+
11+
ifeq ($(PYTHON),)
12+
PYTHON := python$(PY_VER)
13+
endif
14+
15+
16+
.PHONY: build
517
build:
618
cargo build --release
719

8-
build-wasm:
20+
.PHONY: build-wasm
21+
build-wasm: setup
922
cargo clean -p jsonlogic
1023
rm -rf ./js && wasm-pack build --target nodejs --out-dir js --out-name index --release -- --features wasm
1124

25+
.PHONY: debug-wasm
1226
debug-wasm:
1327
rm -rf ./js && wasm-pack build --target nodejs --out-dir js --out-name index --debug -- --features wasm
1428

15-
run-js:
16-
cd js && npm run-script serve
17-
18-
build-py:
29+
.PHONY: build-py-sdist
30+
build-py-sdist: $(VENV)
1931
cargo clean -p jsonlogic
20-
cd py && source ./venv/bin/activate && python ./setup.py bdist_wheel
32+
$(VENV) setup.py sdist
2133

22-
develop-py:
34+
.PHONY: build-py-wheel
35+
build-py-wheel: $(VENV)
2336
cargo clean -p jsonlogic
24-
cd py && source ./venv/bin/activate && python ./setup.py develop
37+
rm -rf dist/*
38+
$(VENV) setup.py bdist_wheel
39+
40+
.PHONY: develop-py-wheel
41+
develop-py-wheel: $(VENV)
42+
$(VENV) setup.py bdist_wheel
2543

44+
.PHONY: develop-py
45+
develop-py: $(VENV)
46+
$(VENV) setup.py develop
47+
48+
.PHONY: setup
2649
setup:
2750
wasm-pack --version > /dev/null 2>&1 || cargo install wasm-pack
2851

52+
.PHONY: test
2953
test:
30-
cargo test --all-features
54+
PYTHON=$(PYTHON) WINDOWS=$(WINDOWS) cargo test --all-features
55+
56+
.PHONY: test-wasm
57+
test-wasm:
58+
node tests/test_wasm.js
59+
60+
.PHONY: test-py
61+
test-py: $(VENV)
62+
$(VENV) tests/test_py.py
63+
64+
venv: $(VENV)
65+
$(VENV): setup.py pyproject.toml
66+
$(PYTHON) -m venv venv
67+
$(VENV) -m pip install setuptools wheel setuptools-rust

README.md

+75-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,78 @@
11
# json-logic-rs
2-
JSONLogic Implemented for the Rust Language
32

4-
## TODOs
3+
This s an implementation of the [JSONLogic] specification in Rust.
54

6-
- finish last operators
7-
- clean up makefiles
8-
- clean up JS package structure & get rid of example code
9-
- add commands for rust, python, & JS packages
5+
## Building
6+
7+
### Prerequisites
8+
9+
You must have Rust installed and `cargo` available in your `PATH`.
10+
11+
If you would like to build or test the Python distribution, Python 3.6 or
12+
newer must be available in your `PATH`. The `venv` module must be part of the
13+
Python distribution (looking at you, Ubuntu).
14+
15+
If you would like to run tests for the WASM package, `node` 10 or newer must be
16+
available in your `PATH`.
17+
18+
### Rust
19+
20+
To build the Rust library, just run `cargo build`.
21+
22+
You can create a release build with `make build`.
23+
24+
### WebAssembly
25+
26+
You can build a debug WASM release with
27+
28+
```sh
29+
make debug-wasm
30+
```
31+
32+
You can build a production WASM release with
33+
34+
```sh
35+
make build-wasm
36+
```
37+
38+
The built WASM package will be in `js/`. This package is directly importable
39+
from `node`, but needs to be browserified in order to be used in the browser.
40+
41+
### Python
42+
43+
To perform a dev install of the Python package, run:
44+
45+
```sh
46+
make develop-py
47+
```
48+
49+
This will automatically create a virtual environment in `venv/`, install
50+
the necessary packages, and then install `jsonlogic_rs` into that environment.
51+
52+
**Note:** from our CI experiences, this may not work for Python 3.8 on Windows.
53+
If you are running this on a Windows machine and can confirm whether or not
54+
this works, let us know!
55+
56+
To build a production source distribution:
57+
58+
```sh
59+
make build-py-sdist
60+
```
61+
62+
To build a wheel (specific to your current system architecture and python
63+
version):
64+
65+
```sh
66+
make build-py-wheel
67+
```
68+
69+
The python distribution consists both of the C extension generated from the
70+
Rust and a thin wrapper found in `py/jsonlogic_rs/`. `make develop-py` will
71+
compile the C extension and place it in that directory, where it will be
72+
importable by your local venv. When building wheels, the wrapper and the C
73+
extension are all packaged together into the resultant wheel, which will
74+
be found in `dist/`. When building an sdist, the Rust extension is not compiled.
75+
The Rust and Python source are distributed together in a `.tar.gz` file, again
76+
found in `dist/`.
77+
78+
[jsonlogic]: http://jsonlogic.com/

py/.gitignore

-139
This file was deleted.

0 commit comments

Comments
 (0)