1
1
from __future__ import annotations
2
2
3
+ import hashlib
3
4
import os
4
5
import pathlib
5
6
import typing
6
7
7
8
import nox
9
+ import yaml
8
10
from nox import options
9
11
10
12
if typing .TYPE_CHECKING :
11
13
import collections .abc
12
14
13
- PATH_TO_PROJECT = pathlib .Path (__name__ ).parent
15
+ PATH_TO_PROJECT = pathlib .Path (__name__ ).parent . absolute ()
14
16
SCRIPT_PATHS = ["noxfile.py" , PATH_TO_PROJECT / "scripts" , PATH_TO_PROJECT / "test" ]
17
+ TESTS_PATH = PATH_TO_PROJECT / "test"
15
18
16
19
DRIVER_PATHS = {
17
- "asyncpg" : PATH_TO_PROJECT / "test" / "driver_asyncpg" ,
18
- "aiosqlite" : PATH_TO_PROJECT / "test" / "driver_aiosqlite" ,
19
- "sqlite3" : PATH_TO_PROJECT / "test" / "driver_sqlite3" ,
20
+ "asyncpg" : TESTS_PATH / "driver_asyncpg" ,
21
+ "aiosqlite" : TESTS_PATH / "driver_aiosqlite" ,
22
+ "sqlite3" : TESTS_PATH / "driver_sqlite3" ,
20
23
}
21
24
22
25
SQLC_CONFIGS = ["sqlc.yaml" ]
@@ -84,6 +87,49 @@ def sqlc_check(session: nox.Session, driver: str) -> None:
84
87
85
88
86
89
@nox .session (reuse_venv = True )
90
+ def update_test_plugin (session : nox .Session ) -> None :
91
+ # Build the plugin
92
+ wasm_path = TESTS_PATH / "sqlc-gen-better-python.wasm"
93
+
94
+ with session .chdir ("plugin" ):
95
+ session .run (
96
+ "go" ,
97
+ "build" ,
98
+ "-o" ,
99
+ str (wasm_path ),
100
+ env = {"GOOS" : "wasip1" , "GOARCH" : "wasm" },
101
+ external = True ,
102
+ )
103
+
104
+ # Calculate the SHA256 hash
105
+ sha256_hasher = hashlib .sha256 ()
106
+ with wasm_path .open ("rb" ) as fp :
107
+ while True :
108
+ data = fp .read (65536 ) # 64kb chunks
109
+ if not data :
110
+ break
111
+
112
+ sha256_hasher .update (data )
113
+
114
+ plugin_hash = sha256_hasher .hexdigest ()
115
+
116
+ # Update the SHA256 in the config files
117
+ for driver_name , driver_path in DRIVER_PATHS .items ():
118
+ for config_filename in SQLC_CONFIGS :
119
+ config_path = driver_path / config_filename
120
+
121
+ with config_path .open () as fp :
122
+ config = yaml .safe_load (fp )
123
+
124
+ config ["plugins" ][0 ]["wasm" ]["sha256" ] = plugin_hash
125
+
126
+ with config_path .open ("w" ) as fp :
127
+ yaml .safe_dump (config , fp )
128
+
129
+ sqlc_generate (session , driver_name )
130
+
131
+
132
+ @nox .session (reuse_venv = True , requires = ["update_test_plugin" ])
87
133
def sqlite3 (session : nox .Session ) -> None :
88
134
uv_sync (session , include_self = True , groups = ["pyright" , "ruff" ])
89
135
@@ -92,7 +138,7 @@ def sqlite3(session: nox.Session) -> None:
92
138
session .run ("ruff" , "check" , * session .posargs , DRIVER_PATHS ["sqlite3" ])
93
139
94
140
95
- @nox .session (reuse_venv = True )
141
+ @nox .session (reuse_venv = True , requires = [ "update_test_plugin" ] )
96
142
def sqlite3_check (session : nox .Session ) -> None :
97
143
uv_sync (session , include_self = True , groups = ["pyright" , "ruff" ])
98
144
@@ -101,7 +147,7 @@ def sqlite3_check(session: nox.Session) -> None:
101
147
session .run ("ruff" , "check" , * session .posargs , DRIVER_PATHS ["sqlite3" ])
102
148
103
149
104
- @nox .session (reuse_venv = True )
150
+ @nox .session (reuse_venv = True , requires = [ "update_test_plugin" ] )
105
151
def aiosqlite (session : nox .Session ) -> None :
106
152
uv_sync (session , include_self = True , groups = ["pyright" , "ruff" ])
107
153
0 commit comments