Skip to content

Commit

Permalink
python, npm, deno, testing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Mar 27, 2023
1 parent 10526c9 commit 52e92d7
Show file tree
Hide file tree
Showing 47 changed files with 1,455 additions and 22 deletions.
204 changes: 186 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,192 @@
on:
push:
tags:
- "*"
on: [push]
name: "test"
jobs:
build:
name: Testing on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
- os: windows-2022
- os: macos-latest
build-linux_x86-extension:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Build + Test
run: |
mkdir -p dist/
make loadable
make test-loadable
- run: make loadable
- uses: actions/upload-artifact@v3
with:
name: sqlite-path-linux_x86
path: dist/path0.so

build-linux_x86-python:
runs-on: ubuntu-20.04
needs: [build-linux_x86-extension]
steps:
- uses: actions/checkout@v3
- name: Download workflow artifacts
uses: actions/download-artifact@v3
with:
name: sqlite-path-linux_x86
path: dist/
- uses: actions/setup-python@v3
- run: pip install wheel
- run: make python
- run: make datasette
- uses: actions/upload-artifact@v3
with:
name: sqlite-path-linux_x86-wheels
path: dist/wheels/*.whl
test-linux_x86:
runs-on: ubuntu-20.04
needs: [build-linux_x86-extension, build-linux_x86-python]
env:
DENO_DIR: deno_cache
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: sqlite-path-linux_x86
path: dist/
- uses: actions/download-artifact@v3
with:
name: sqlite-path-linux_x86-wheels
path: dist/
- run: cp dist/path0.so npm/sqlite-path-linux-x64/lib
- run: pip3 install --find-links dist/ sqlite_path
- run: make test-loadable
- run: make test-python
# for test-npm
- uses: actions/setup-node@v3
with:
cache: "npm"
cache-dependency-path: npm/sqlite-path/package.json
- run: npm install
working-directory: npm/sqlite-path
- run: make test-npm
# for test-deno
- uses: denoland/setup-deno@v1
with:
deno-version: v1.30
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
path: ${{ env.DENO_DIR }}
key: ${{ runner.os }}-${{ hashFiles('deno/deno.lock') }}
- run: make test-deno
env:
DENO_SQLITE_PATH_PATH: ${{ github.workspace }}/dist/path0
build-macos-extension:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- run: make loadable
- uses: actions/upload-artifact@v3
with:
name: sqlite-path-macos
path: dist/path0.dylib
build-macos-python:
runs-on: macos-latest
needs: [build-macos-extension]
steps:
- uses: actions/checkout@v3
- name: Download workflow artifacts
uses: actions/download-artifact@v3
with:
name: sqlite-path-macos
path: dist/
- uses: actions/setup-python@v3
- run: pip install wheel
- run: make python
- run: make datasette
- uses: actions/upload-artifact@v3
with:
name: sqlite-path-macos-wheels
path: dist/wheels/*.whl
test-macos:
runs-on: macos-latest
needs: [build-macos-extension, build-macos-python]
env:
DENO_DIR: deno_cache
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: sqlite-path-macos
path: dist/
- run: cp dist/path0.dylib npm/sqlite-path-darwin-x64/lib
- uses: actions/download-artifact@v3
with:
name: sqlite-path-macos-wheels
path: dist/
- run: brew install python
- run: /usr/local/opt/python@3/libexec/bin/pip install --find-links dist/ sqlite_path
- run: make test-loadable python=/usr/local/opt/python@3/libexec/bin/python
- run: make test-python python=/usr/local/opt/python@3/libexec/bin/python
# for test-npm
- uses: actions/setup-node@v3
with:
cache: "npm"
cache-dependency-path: npm/sqlite-path/package.json
- run: npm install
working-directory: npm/sqlite-path
- run: make test-npm
# for test-deno
- uses: denoland/setup-deno@v1
with:
deno-version: v1.30
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
path: ${{ env.DENO_DIR }}
key: ${{ runner.os }}-${{ hashFiles('deno/deno.lock') }}
- run: make test-deno
env:
DENO_SQLITE_PATH_PATH: ${{ github.workspace }}/dist/path0.dylib
build-windows-extension:
name: Building windows extension
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- run: make loadable
- uses: actions/upload-artifact@v3
with:
name: sqlite-path-windows
path: dist/path0.dll
build-windows-python:
runs-on: windows-latest
needs: [build-windows-extension]
steps:
- uses: actions/checkout@v3
- name: Download workflow artifacts
uses: actions/download-artifact@v3
with:
name: sqlite-path-windows
path: dist/
- uses: actions/setup-python@v3
- run: pip install wheel
- run: make python
- run: make datasette
- uses: actions/upload-artifact@v3
with:
name: sqlite-path-windows-wheels
path: dist/wheels/*.whl
test-windows:
runs-on: windows-2022
needs: [build-windows-extension, build-windows-python]
env:
DENO_DIR: deno_cache
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: sqlite-path-windows
path: dist/
- uses: actions/download-artifact@v3
with:
name: sqlite-path-windows
path: npm/sqlite-path-windows-x64/lib
- uses: actions/download-artifact@v3
with:
name: sqlite-path-windows-wheels
path: dist/
- run: pip install --find-links dist/ sqlite_path
- run: make test-loadable
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
a.out
dist/
bench/
*.dylib
*.so
*.dll
61 changes: 58 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,36 @@ ifdef CONFIG_WINDOWS
LOADABLE_EXTENSION=dll
endif

ifdef python
PYTHON=$(python)
else
PYTHON=python3
endif

DEFINE_SQLITE_PATH_DATE=-DSQLITE_PATH_DATE="\"$(DATE)\""
DEFINE_SQLITE_PATH_VERSION=-DSQLITE_PATH_VERSION="\"$(VERSION)\""
DEFINE_SQLITE_PATH_VERSION=-DSQLITE_PATH_VERSION="\"v$(VERSION)\""
DEFINE_SQLITE_PATH_SOURCE=-DSQLITE_PATH_SOURCE="\"$(COMMIT)\""
DEFINE_SQLITE_PATH_CWALK_VERSION=-DSQLITE_PATH_CWALK_VERSION="\"$(CWALK_VERSION)\""
DEFINE_SQLITE_PATH=$(DEFINE_SQLITE_PATH_DATE) $(DEFINE_SQLITE_PATH_VERSION) $(DEFINE_SQLITE_PATH_SOURCE) $(DEFINE_SQLITE_PATH_CWALK_VERSION)

prefix=dist

TARGET_LOADABLE=dist/path0.$(LOADABLE_EXTENSION)
TARGET_LOADABLE=$(prefix)/path0.$(LOADABLE_EXTENSION)
TARGET_WHEELS=$(prefix)/wheels
TARGET_SQLITE3_EXTRA_C=$(prefix)/sqlite3-extra.c
TARGET_SQLITE3=$(prefix)/sqlite3
TARGET_SQLJS_JS=$(prefix)/sqljs.js
TARGET_SQLJS_WASM=$(prefix)/sqljs.wasm
TARGET_SQLJS=$(TARGET_SQLJS_JS) $(TARGET_SQLJS_WASM)

INTERMEDIATE_PYPACKAGE_EXTENSION=python/sqlite_path/sqlite_path/path0.$(LOADABLE_EXTENSION)

$(prefix):
mkdir -p $(prefix)

$(TARGET_WHEELS): $(prefix)
mkdir -p $(TARGET_WHEELS)

clean:
rm dist/*

Expand All @@ -62,6 +73,37 @@ $(TARGET_LOADABLE): sqlite-path.c
$(DEFINE_SQLITE_PATH) \
$< -o $@ cwalk/src/cwalk.c

python: $(TARGET_WHEELS) $(TARGET_LOADABLE) $(TARGET_WHEELS) scripts/rename-wheels.py $(shell find python/sqlite_path -type f -name '*.py')
cp $(TARGET_LOADABLE) $(INTERMEDIATE_PYPACKAGE_EXTENSION)
rm $(TARGET_WHEELS)/sqlite_path* || true
pip3 wheel python/sqlite_path/ -w $(TARGET_WHEELS)
python3 scripts/rename-wheels.py $(TARGET_WHEELS) $(RENAME_WHEELS_ARGS)
echo "✅ generated python wheel"

python-versions: python/version.py.tmpl
VERSION=$(VERSION) envsubst < python/version.py.tmpl > python/sqlite_path/sqlite_path/version.py
echo "✅ generated python/sqlite_path/sqlite_path/version.py"

VERSION=$(VERSION) envsubst < python/version.py.tmpl > python/datasette_sqlite_path/datasette_sqlite_path/version.py
echo "✅ generated python/datasette_sqlite_path/datasette_sqlite_path/version.py"


datasette: $(TARGET_WHEELS) $(shell find python/datasette_sqlite_path -type f -name '*.py')
rm $(TARGET_WHEELS)/datasette* || true
pip3 wheel python/datasette_sqlite_path/ --no-deps -w $(TARGET_WHEELS)

npm: VERSION npm/platform-package.README.md.tmpl npm/platform-package.package.json.tmpl npm/sqlite-path/package.json.tmpl scripts/npm_generate_platform_packages.sh
scripts/npm_generate_platform_packages.sh

deno: VERSION deno/deno.json.tmpl
scripts/deno_generate_package.sh

version:
make python-versions
make python
make npm
make deno

$(TARGET_SQLITE3): $(prefix) $(TARGET_SQLITE3_EXTRA_C) sqlite/shell.c sqlite-path.c
gcc \
$(DEFINE_SQLITE_PATH) \
Expand All @@ -77,14 +119,26 @@ $(TARGET_SQLITE3_EXTRA_C): sqlite/sqlite3.c core_init.c
test:
make test-format
make test-loadable
make test-python
make test-npm
make test-deno
make test-sqlite3

test-format: SHELL:=/bin/bash
test-format:
diff -u <(cat $(FORMAT_FILES)) <(clang-format $(FORMAT_FILES))

test-loadable: $(TARGET_LOADABLE)
python3 tests/test-loadable.py
$(PYTHON) tests/test-loadable.py

test-python:
$(PYTHON) tests/test-python.py

test-npm:
node npm/sqlite-path/test.js

test-deno:
deno task --config deno/deno.json test

test-loadable-watch: $(TARGET_LOADABLE)
watchexec -w sqlite-path.c -w $(TARGET_LOADABLE) -w tests/test-loadable.py --clear -- make test-loadable
Expand All @@ -99,6 +153,7 @@ test-sqljs: $(TARGET_SQLJS)
python3 -m http.server & open http://localhost:8000/tests/test-sqljs.html

.PHONY: all clean format \
version python python-versions datasette npm deno \
test test-watch test-format \
loadable test-loadable test-loadable-watch

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.0
0.1.0
33 changes: 33 additions & 0 deletions deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--- Generated with the deno_generate_package.sh script, don't edit by hand! -->

# `x/sqlite_path` Deno Module

[![Tags](https://img.shields.io/github/release/asg017/sqlite-path)](https://github.com/asg017/sqlite-path/releases)
[![Doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/sqlite-path@0.1.0/mod.ts)

The [`sqlite-path`](https://github.com/asg017/sqlite-path) SQLite extension is available to Deno developers with the [`x/sqlite_path`](https://deno.land/x/sqlite-path) Deno module. It works with [`x/sqlite3`](https://deno.land/x/sqlite3), the fastest and native Deno SQLite3 module.

```js
import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts";
import * as sqlite_path from "https://deno.land/x/sqlite_path@v0.1.0/mod.ts";

const db = new Database(":memory:");

db.enableLoadExtension = true;
db.loadExtension(sqlite_path.getLoadablePath());

const [version] = db
.prepare("select path_version()")
.value<[string]>()!;

console.log(version);

```

Like `x/sqlite3`, `x/sqlite_path` requires network and filesystem permissions to download and cache the pre-compiled SQLite extension for your machine. Though `x/sqlite3` already requires `--allow-ffi` and `--unstable`, so you might as well use `--allow-all`/`-A`.

```bash
deno run -A --unstable <file>
```

`x/sqlite_path` does not work with [`x/sqlite`](https://deno.land/x/sqlite@v3.7.0), which is a WASM-based Deno SQLite module that does not support loading extensions.
Loading

0 comments on commit 52e92d7

Please sign in to comment.