Skip to content

Commit da6b568

Browse files
committed
fix linting, lint wasm-preview
1 parent c81c1fb commit da6b568

File tree

5 files changed

+83
-79
lines changed

5 files changed

+83
-79
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DEFAULT_GOAL := all
22
isort = isort pydantic_core tests generate_self_schema.py
3-
black = black pydantic_core tests generate_self_schema.py wasm-preview/upload.py
3+
black = black pydantic_core tests generate_self_schema.py wasm-preview/run_tests.py
44

55
.PHONY: install
66
install:
@@ -63,7 +63,7 @@ format:
6363

6464
.PHONY: lint-python
6565
lint-python:
66-
flake8 --max-line-length 120 pydantic_core tests generate_self_schema.py wasm-preview/upload.py
66+
flake8 --max-line-length 120 pydantic_core tests generate_self_schema.py wasm-preview/run_tests.py
6767
$(isort) --check-only --df
6868
$(black) --check --diff
6969

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
},
1313
"scripts": {
1414
"test": "node tests/emscripten_runner.js",
15-
"format": "prettier --write 'tests/emscripten_runner.js'",
16-
"lint": "prettier --check 'tests/emscripten_runner.js'"
15+
"format": "prettier --write 'tests/emscripten_runner.js' 'wasm-preview/*.{html,js}'",
16+
"lint": "prettier --check 'tests/emscripten_runner.js' 'wasm-preview/*.{html,js}'"
1717
},
1818
"prettier": {
1919
"singleQuote": true,

wasm-preview/index.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<head>
55
<title>pydantic-core unit tests</title>
66
<style>
7-
html, body {
7+
html,
8+
body {
89
height: 100%;
910
background: rgb(30, 31, 46);
1011
color: white;
@@ -35,11 +36,13 @@
3536
text-decoration: none;
3637
}
3738
</style>
38-
</head>
39+
</head>
3940
<body>
4041
<main>
4142
<h1>
42-
<a href="https://github.com/samuelcolvin/pydantic-core/tree/main/wasm-preview">pydantic-core</a> v<span id="version">0.1.0</span> unit tests
43+
<a href="https://github.com/samuelcolvin/pydantic-core/tree/main/wasm-preview">pydantic-core</a>
44+
v<span id="version">0.1.0</span>
45+
unit tests
4346
</h1>
4447
<aside>
4548
pydantic-core is compiled to webassembly and run in the browser using
@@ -52,30 +55,30 @@ <h1>
5255

5356
<script src="https://smokeshow.helpmanual.io/2d1p666q3x5f0j26223o/ansi-to-html.browser.js"></script>
5457
<script>
55-
const output_el = document.getElementById('output')
56-
const decoder = new TextDecoder()
57-
const Convert = require('ansi-to-html')
58-
const ansi_converter = new Convert()
59-
let terminal_output = ''
60-
const version = document.getElementById('version').textContent
58+
const output_el = document.getElementById('output');
59+
const decoder = new TextDecoder();
60+
const Convert = require('ansi-to-html');
61+
const ansi_converter = new Convert();
62+
let terminal_output = '';
63+
const version = document.getElementById('version').textContent;
6164

62-
output_el.innerText = 'Starting worker...'
63-
const worker = new Worker(`./worker.js?v=${Date.now()}`)
65+
output_el.innerText = 'Starting worker...';
66+
const worker = new Worker(`./worker.js?v=${Date.now()}`);
6467
worker.onmessage = ({data}) => {
6568
if (typeof data == 'string') {
66-
terminal_output += data
69+
terminal_output += data;
6770
} else {
6871
for (let chunk of data) {
69-
let arr = new Uint8Array(chunk)
70-
let extra = decoder.decode(arr)
71-
terminal_output += extra
72+
let arr = new Uint8Array(chunk);
73+
let extra = decoder.decode(arr);
74+
terminal_output += extra;
7275
}
7376
}
74-
output_el.innerHTML = ansi_converter.toHtml(terminal_output)
77+
output_el.innerHTML = ansi_converter.toHtml(terminal_output);
7578
// scrolls to the bottom of the div
76-
output_el.scrollIntoView(false)
77-
}
78-
worker.postMessage({version})
79+
output_el.scrollIntoView(false);
80+
};
81+
worker.postMessage({version});
7982
</script>
8083
</body>
8184
</html>

wasm-preview/run_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ async def main(tests_zip: str, version: str):
4343
print('Running tests...')
4444
pytest.main()
4545

46+
4647
try:
47-
await main(tests_zip, version)
48-
except Exception as e:
48+
await main(tests_zip, version) # noqa: F704
49+
except Exception:
4950
traceback.print_exc()
5051
raise

wasm-preview/worker.js

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,99 @@
1-
let chunks = []
2-
let last_post = 0
1+
let chunks = [];
2+
let last_post = 0;
33

44
function print(tty) {
55
if (tty.output && tty.output.length > 0) {
6-
chunks.push(tty.output)
7-
tty.output = []
8-
const now = performance.now()
6+
chunks.push(tty.output);
7+
tty.output = [];
8+
const now = performance.now();
99
if (now - last_post > 100) {
10-
post()
11-
last_post = now
10+
post();
11+
last_post = now;
1212
}
1313
}
1414
}
1515

1616
function post() {
17-
self.postMessage(chunks)
18-
chunks = []
17+
self.postMessage(chunks);
18+
chunks = [];
1919
}
2020

2121
function make_tty_ops() {
2222
return {
2323
put_char(tty, val) {
2424
if (val !== null) {
25-
tty.output.push(val)
25+
tty.output.push(val);
2626
}
2727
if (val === null || val === 10) {
28-
print(tty)
28+
print(tty);
2929
}
3030
},
3131
flush(tty) {
32-
print(tty)
32+
print(tty);
3333
},
34-
}
34+
};
3535
}
3636

3737
function setupStreams(FS, TTY) {
38-
let mytty = FS.makedev(FS.createDevice.major++, 0)
39-
let myttyerr = FS.makedev(FS.createDevice.major++, 0)
40-
TTY.register(mytty, make_tty_ops())
41-
TTY.register(myttyerr, make_tty_ops())
42-
FS.mkdev('/dev/mytty', mytty)
43-
FS.mkdev('/dev/myttyerr', myttyerr)
44-
FS.unlink('/dev/stdin')
45-
FS.unlink('/dev/stdout')
46-
FS.unlink('/dev/stderr')
47-
FS.symlink('/dev/mytty', '/dev/stdin')
48-
FS.symlink('/dev/mytty', '/dev/stdout')
49-
FS.symlink('/dev/myttyerr', '/dev/stderr')
50-
FS.closeStream(0)
51-
FS.closeStream(1)
52-
FS.closeStream(2)
53-
FS.open('/dev/stdin', 0)
54-
FS.open('/dev/stdout', 1)
55-
FS.open('/dev/stderr', 1)
38+
let mytty = FS.makedev(FS.createDevice.major++, 0);
39+
let myttyerr = FS.makedev(FS.createDevice.major++, 0);
40+
TTY.register(mytty, make_tty_ops());
41+
TTY.register(myttyerr, make_tty_ops());
42+
FS.mkdev('/dev/mytty', mytty);
43+
FS.mkdev('/dev/myttyerr', myttyerr);
44+
FS.unlink('/dev/stdin');
45+
FS.unlink('/dev/stdout');
46+
FS.unlink('/dev/stderr');
47+
FS.symlink('/dev/mytty', '/dev/stdin');
48+
FS.symlink('/dev/mytty', '/dev/stdout');
49+
FS.symlink('/dev/myttyerr', '/dev/stderr');
50+
FS.closeStream(0);
51+
FS.closeStream(1);
52+
FS.closeStream(2);
53+
FS.open('/dev/stdin', 0);
54+
FS.open('/dev/stdout', 1);
55+
FS.open('/dev/stderr', 1);
5656
}
5757

5858
async function get(url, mode) {
59-
const r = await fetch(url)
59+
const r = await fetch(url);
6060
if (r.ok) {
6161
if (mode === 'text') {
62-
return await r.text()
62+
return await r.text();
6363
} else {
6464
const blob = await r.blob();
6565
let buffer = await blob.arrayBuffer();
66-
return btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), ''))
66+
return btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), ''));
6767
}
6868
} else {
69-
let text = await r.text()
70-
console.error('unexpected response', r, text)
71-
throw new Error(`${r.status}: ${text}`)
69+
let text = await r.text();
70+
console.error('unexpected response', r, text);
71+
throw new Error(`${r.status}: ${text}`);
7272
}
7373
}
7474

7575
self.onmessage = async ({data}) => {
76-
const {version} = data
77-
self.postMessage(`Downloading repo v${version} archive to get tests...\n`)
78-
const zip_url = `https://githubproxy.samuelcolvin.workers.dev/samuelcolvin/pydantic-core/archive/refs/tags/v${version}.zip`
76+
const {version} = data;
77+
self.postMessage(`Downloading repo v${version} archive to get tests...\n`);
78+
const zip_url = `https://githubproxy.samuelcolvin.workers.dev/samuelcolvin/pydantic-core/archive/refs/tags/v${version}.zip`;
7979
try {
80-
const [python_code, tests_zip,] = await Promise.all([
80+
const [python_code, tests_zip] = await Promise.all([
8181
get(`./run_tests.py?v=${Date.now()}`, 'text'),
8282
// e4cf2e2 commit matches the pydantic-core wheel being used, so tests should pass
8383
get(zip_url, 'blob'),
84-
importScripts('https://cdn.jsdelivr.net/pyodide/v0.21.0a3/full/pyodide.js')
85-
])
84+
importScripts('https://cdn.jsdelivr.net/pyodide/v0.21.0a3/full/pyodide.js'),
85+
]);
8686

87-
const pyodide = await loadPyodide()
88-
const {FS} = pyodide
89-
setupStreams(FS, pyodide._module.TTY)
90-
FS.mkdir('/test_dir')
91-
FS.chdir('/test_dir')
92-
await pyodide.loadPackage(['micropip', 'pytest', 'pytz'])
93-
await pyodide.runPythonAsync(python_code, {globals: pyodide.toPy({version, tests_zip})})
94-
post()
87+
const pyodide = await loadPyodide();
88+
const {FS} = pyodide;
89+
setupStreams(FS, pyodide._module.TTY);
90+
FS.mkdir('/test_dir');
91+
FS.chdir('/test_dir');
92+
await pyodide.loadPackage(['micropip', 'pytest', 'pytz']);
93+
await pyodide.runPythonAsync(python_code, {globals: pyodide.toPy({version, tests_zip})});
94+
post();
9595
} catch (err) {
96-
console.error(err)
97-
self.postMessage(`Error: ${err}\n`)
96+
console.error(err);
97+
self.postMessage(`Error: ${err}\n`);
9898
}
99-
}
99+
};

0 commit comments

Comments
 (0)