This commit is contained in:
Johannes Kirschbauer
2024-07-17 13:21:37 +02:00
parent fc7cc74b10
commit fd6d9f5bec
4 changed files with 11 additions and 22 deletions

View File

@@ -1,18 +1 @@
{
stdenv,
python3,
lib,
}:
stdenv.mkDerivation {
name = "classgen";
src = ./.;
buildInputs = [ python3 ];
installPhase = ''
install -Dm755 ${./main.py} $out/bin/classgen
'';
meta = with lib; {
description = "A tool to generate Python dataclasses from JSON Schema definitions";
license = licenses.mit;
};
}
{ writers }: writers.writePython3Bin "classgen" { flakeIgnore = [ "E501" ]; } ./main.py

View File

@@ -129,6 +129,10 @@ def run_gen(args: argparse.Namespace) -> None:
with open(args.output, "w") as f:
f.write(
"""
# DON NOT EDIT THIS FILE MANUALLY. IT IS GENERATED.
# UPDATE:
# ruff: noqa: N815
# ruff: noqa: N806
from dataclasses import dataclass
from typing import Any\n\n
"""

View File

@@ -80,9 +80,9 @@ function createFunctions<K extends OperationNames>(
registry[operationName][id] = fn;
window.clan[operationName] = (s: string) => {
const f = (response: GtkResponse<OperationResponse<K>>) => {
const f = (response: OperationResponse<K>) => {
if (response.op_key === id) {
registry[operationName][id](response.result);
registry[operationName][id](response);
}
};
deserialize(f)(s);
@@ -121,6 +121,7 @@ export const callApi = <K extends OperationNames>(
return new Promise<OperationResponse<K>>((resolve, reject) => {
const id = nanoid();
pyApi[method].receive((response) => {
console.log("Received response: ", { response });
if (response.status === "error") {
reject(response);
}
@@ -132,10 +133,10 @@ export const callApi = <K extends OperationNames>(
};
const deserialize =
<T>(fn: (response: GtkResponse<T>) => void) =>
<T>(fn: (response: T) => void) =>
(str: string) => {
try {
const r = JSON.parse(str) as GtkResponse<T>;
const r = JSON.parse(str) as T;
console.log("Received: ", r);
fn(r);
} catch (e) {

View File

@@ -15,6 +15,7 @@ export const BlockDevicesView: Component = () => {
if (result.status === "error") throw new Error("Failed to fetch data");
return result.data;
},
staleTime: 1000 * 60 * 5,
}));
return (