nix fmt
This commit is contained in:
@@ -40,6 +40,7 @@ def create(args: argparse.Namespace) -> None:
|
||||
print(line, end="")
|
||||
print("")
|
||||
|
||||
|
||||
def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument("machine", type=str)
|
||||
parser.set_defaults(func=create)
|
||||
|
||||
@@ -5,7 +5,6 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.routing import APIRoute
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
|
||||
from .assets import asset_path
|
||||
from .routers import flake, health, machines, root, utils, vms
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import functools
|
||||
from pathlib import Path
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_hash(string: str) -> str:
|
||||
"""
|
||||
This function takes a string like '/nix/store/kkvk20b8zh8aafdnfjp6dnf062x19732-source'
|
||||
and returns the hash part 'kkvk20b8zh8aafdnfjp6dnf062x19732' after '/nix/store/' and before '-source'.
|
||||
"""
|
||||
# Split the string by '/' and get the last element
|
||||
last_element = string.split('/')[-1]
|
||||
last_element = string.split("/")[-1]
|
||||
# Split the last element by '-' and get the first element
|
||||
hash_part = last_element.split('-')[0]
|
||||
hash_part = last_element.split("-")[0]
|
||||
# Return the hash part
|
||||
return hash_part
|
||||
|
||||
@@ -30,7 +31,6 @@ def check_divergence(path: Path) -> None:
|
||||
log.debug(f"Serving webui asset with hash {gh}")
|
||||
|
||||
|
||||
|
||||
@functools.cache
|
||||
def asset_path() -> Path:
|
||||
path = Path(__file__).parent / "assets"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import logging
|
||||
import os
|
||||
from mimetypes import guess_type
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Response
|
||||
|
||||
from ..assets import asset_path
|
||||
|
||||
@@ -5,15 +5,13 @@ from pathlib import Path
|
||||
from typing import Annotated, Iterator
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Body
|
||||
from fastapi import APIRouter, BackgroundTasks, Body, status
|
||||
from fastapi import APIRouter, Body, status
|
||||
from fastapi.exceptions import HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from ...nix import nix_build, nix_eval, nix_shell
|
||||
from clan_cli.webui.routers.flake import get_attrs
|
||||
|
||||
from ...nix import nix_build, nix_eval
|
||||
from ...nix import nix_build, nix_eval, nix_shell
|
||||
from ..schemas import VmConfig, VmCreateResponse, VmInspectResponse, VmStatusResponse
|
||||
from ..task_manager import BaseTask, CmdState, get_task, register_task
|
||||
from .utils import run_cmd
|
||||
@@ -163,9 +161,7 @@ async def get_vm_logs(uuid: UUID) -> StreamingResponse:
|
||||
|
||||
|
||||
@router.post("/api/vms/create")
|
||||
async def create_vm(
|
||||
vm: Annotated[VmConfig, Body()]
|
||||
) -> VmCreateResponse:
|
||||
async def create_vm(vm: Annotated[VmConfig, Body()]) -> VmCreateResponse:
|
||||
flake_attrs = await get_attrs(vm.flake_url)
|
||||
if vm.flake_attr not in flake_attrs:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -54,7 +54,7 @@ class CmdState:
|
||||
line = line.strip("\n")
|
||||
self.stderr.append(line)
|
||||
self.log.debug("stderr: %s", line)
|
||||
self._output.put(line + '\n')
|
||||
self._output.put(line + "\n")
|
||||
|
||||
if self.p.stdout in rlist:
|
||||
assert self.p.stdout is not None
|
||||
@@ -63,7 +63,7 @@ class CmdState:
|
||||
line = line.strip("\n")
|
||||
self.stdout.append(line)
|
||||
self.log.debug("stdout: %s", line)
|
||||
self._output.put(line + '\n')
|
||||
self._output.put(line + "\n")
|
||||
|
||||
if self.p.returncode != 0:
|
||||
raise RuntimeError(f"Failed to run command: {shlex.join(cmd)}")
|
||||
@@ -109,9 +109,9 @@ class BaseTask(threading.Thread):
|
||||
break
|
||||
if proc.done:
|
||||
for line in proc.stderr:
|
||||
yield line + '\n'
|
||||
yield line + "\n"
|
||||
for line in proc.stdout:
|
||||
yield line + '\n'
|
||||
yield line + "\n"
|
||||
continue
|
||||
while True:
|
||||
out = proc._output
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import json
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from api import TestClient
|
||||
|
||||
@@ -31,7 +31,6 @@ def test_inspect_err(api: TestClient) -> None:
|
||||
assert data.get("detail")
|
||||
|
||||
|
||||
|
||||
@pytest.mark.impure
|
||||
def test_inspect_flake(api: TestClient, test_flake_with_core: Path) -> None:
|
||||
params = {"url": str(test_flake_with_core)}
|
||||
|
||||
Reference in New Issue
Block a user