diff --git a/pkgs/clan-cli/clan_cli/debug.py b/pkgs/clan-cli/clan_cli/debug.py index 72bdfc0..6bec665 100644 --- a/pkgs/clan-cli/clan_cli/debug.py +++ b/pkgs/clan-cli/clan_cli/debug.py @@ -1,23 +1,27 @@ -from typing import Dict, Optional, Tuple, Callable, Any, Mapping, List -from pathlib import Path -import ipdb +import logging +import multiprocessing as mp import os +import shlex import stat import subprocess -from .dirs import find_git_repo_root -import multiprocessing as mp -from .types import FlakeName -import logging import sys -import shlex -import time +from pathlib import Path +from typing import Any, Callable, Dict, List, Optional + +import ipdb log = logging.getLogger(__name__) -def command_exec(cmd: List[str], work_dir:Path, env: Dict[str, str]) -> None: + +def command_exec(cmd: List[str], work_dir: Path, env: Dict[str, str]) -> None: subprocess.run(cmd, check=True, env=env, cwd=work_dir.resolve()) -def repro_env_break(work_dir: Path, env: Optional[Dict[str, str]] = None, cmd: Optional[List[str]] = None) -> None: + +def repro_env_break( + work_dir: Path, + env: Optional[Dict[str, str]] = None, + cmd: Optional[List[str]] = None, +) -> None: if env is None: env = os.environ.copy() else: @@ -40,14 +44,16 @@ def repro_env_break(work_dir: Path, env: Optional[Dict[str, str]] = None, cmd: O finally: proc.terminate() -def write_command(command: str, loc:Path) -> None: + +def write_command(command: str, loc: Path) -> None: with open(loc, "w") as f: f.write("#!/usr/bin/env bash\n") f.write(command) st = os.stat(loc) os.chmod(loc, st.st_mode | stat.S_IEXEC) -def spawn_process(func: Callable, **kwargs:Any) -> mp.Process: + +def spawn_process(func: Callable, **kwargs: Any) -> mp.Process: mp.set_start_method(method="spawn") proc = mp.Process(target=func, kwargs=kwargs) proc.start() @@ -59,7 +65,7 @@ def dump_env(env: Dict[str, str], loc: Path) -> None: with open(loc, "w") as f: f.write("#!/usr/bin/env bash\n") for k, v in cenv.items(): - if v.count('\n') > 0 or v.count("\"") > 0 or v.count("'") > 0: + if v.count("\n") > 0 or v.count('"') > 0 or v.count("'") > 0: continue f.write(f"export {k}='{v}'\n") st = os.stat(loc) diff --git a/pkgs/clan-cli/clan_cli/webui/api_inputs.py b/pkgs/clan-cli/clan_cli/webui/api_inputs.py index 94a27b8..70539e7 100644 --- a/pkgs/clan-cli/clan_cli/webui/api_inputs.py +++ b/pkgs/clan-cli/clan_cli/webui/api_inputs.py @@ -3,11 +3,13 @@ from pathlib import Path from typing import Any from pydantic import AnyUrl, BaseModel, validator +from pydantic.tools import parse_obj_as from ..dirs import clan_data_dir, clan_flakes_dir -from ..flakes.create import DEFAULT_URL from ..types import validate_path +DEFAULT_URL = parse_obj_as(AnyUrl, "http://localhost:8000") + log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/webui/api_outputs.py b/pkgs/clan-cli/clan_cli/webui/api_outputs.py index c25a0db..3082b2a 100644 --- a/pkgs/clan-cli/clan_cli/webui/api_outputs.py +++ b/pkgs/clan-cli/clan_cli/webui/api_outputs.py @@ -1,10 +1,6 @@ from enum import Enum -from typing import Dict, List -from pydantic import BaseModel, Field - -from ..async_cmd import CmdOut -from ..task_manager import TaskStatus +from pydantic import BaseModel class Status(Enum): @@ -16,6 +12,3 @@ class Status(Enum): class Machine(BaseModel): name: str status: Status - - - diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index 1205343..88ff380 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -29,7 +29,6 @@ def setup_app() -> FastAPI: app.include_router(health.router) - # Needs to be last in register. Because of wildcard route app.include_router(root.router) app.add_exception_handler(ClanError, clan_error_handler) diff --git a/pkgs/clan-cli/clan_cli/webui/server.py b/pkgs/clan-cli/clan_cli/webui/server.py index a647599..66b0f39 100644 --- a/pkgs/clan-cli/clan_cli/webui/server.py +++ b/pkgs/clan-cli/clan_cli/webui/server.py @@ -13,6 +13,7 @@ from typing import Iterator import uvicorn from pydantic import AnyUrl, IPvAnyAddress from pydantic.tools import parse_obj_as + from clan_cli.errors import ClanError log = logging.getLogger(__name__) @@ -25,9 +26,7 @@ def open_browser(base_url: AnyUrl, sub_url: str) -> None: break except OSError: time.sleep(i) - url = parse_obj_as( - AnyUrl, f"{base_url}/{sub_url.removeprefix('/')}" - ) + url = parse_obj_as(AnyUrl, f"{base_url}/{sub_url.removeprefix('/')}") _open_browser(url) diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index 92d58ce..ab64f5d 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -37,6 +37,10 @@ exclude = "clan_cli.nixpkgs" module = "argcomplete.*" ignore_missing_imports = true +[[tool.mypy.overrides]] +module = "ipdb.*" +ignore_missing_imports = true + [[tool.mypy.overrides]] module = "jsonschema.*" ignore_missing_imports = true @@ -52,7 +56,7 @@ ignore_missing_imports = true [tool.ruff] line-length = 88 -select = [ "E", "F", "I", "U", "N"] +select = [ "E", "F", "I", "N"] ignore = [ "E501" ] [tool.black] diff --git a/pkgs/clan-cli/shell.nix b/pkgs/clan-cli/shell.nix index e651eb8..ac5ee0a 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -22,37 +22,37 @@ mkShell { ]; shellHook = '' - tmp_path=$(realpath ./.direnv) + tmp_path=$(realpath ./.direnv) - repo_root=$(realpath .) - mkdir -p "$tmp_path/python/${pythonWithDeps.sitePackages}" + repo_root=$(realpath .) + mkdir -p "$tmp_path/python/${pythonWithDeps.sitePackages}" - # Install the package in editable mode - # This allows executing `clan` from within the dev-shell using the current - # version of the code and its dependencies. - ${pythonWithDeps.interpreter} -m pip install \ - --quiet \ - --disable-pip-version-check \ - --no-index \ - --no-build-isolation \ - --prefix "$tmp_path/python" \ - --editable $repo_root + # Install the package in editable mode + # This allows executing `clan` from within the dev-shell using the current + # version of the code and its dependencies. + ${pythonWithDeps.interpreter} -m pip install \ + --quiet \ + --disable-pip-version-check \ + --no-index \ + --no-build-isolation \ + --prefix "$tmp_path/python" \ + --editable $repo_root - rm -f clan_cli/nixpkgs clan_cli/webui/assets - ln -sf ${clan-cli.nixpkgs} clan_cli/nixpkgs - ln -sf ${ui-assets} clan_cli/webui/assets + rm -f clan_cli/nixpkgs clan_cli/webui/assets + ln -sf ${clan-cli.nixpkgs} clan_cli/nixpkgs + ln -sf ${ui-assets} clan_cli/webui/assets - export PATH="$tmp_path/python/bin:${checkScript}/bin:$PATH" - export PYTHONPATH="$repo_root:$tmp_path/python/${pythonWithDeps.sitePackages}:" - export PYTHONBREAKPOINT=ipdb.set_trace + export PATH="$tmp_path/python/bin:${checkScript}/bin:$PATH" + export PYTHONPATH="$repo_root:$tmp_path/python/${pythonWithDeps.sitePackages}:" + export PYTHONBREAKPOINT=ipdb.set_trace - export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" - export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}" - mkdir -p \ - $tmp_path/share/fish/vendor_completions.d \ - $tmp_path/share/bash-completion/completions \ - $tmp_path/share/zsh/site-functions - register-python-argcomplete --shell fish clan > $tmp_path/share/fish/vendor_completions.d/clan.fish - register-python-argcomplete --shell bash clan > $tmp_path/share/bash-completion/completions/clan + export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" + export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}" + mkdir -p \ + $tmp_path/share/fish/vendor_completions.d \ + $tmp_path/share/bash-completion/completions \ + $tmp_path/share/zsh/site-functions + register-python-argcomplete --shell fish clan > $tmp_path/share/fish/vendor_completions.d/clan.fish + register-python-argcomplete --shell bash clan > $tmp_path/share/bash-completion/completions/clan ''; } diff --git a/pkgs/ui/nix/pdefs.nix b/pkgs/ui/nix/pdefs.nix index 9bae939..c7a2b74 100644 --- a/pkgs/ui/nix/pdefs.nix +++ b/pkgs/ui/nix/pdefs.nix @@ -18438,4 +18438,4 @@ }; }; }; -} \ No newline at end of file +} diff --git a/pkgs/ui/src/app/layout.tsx b/pkgs/ui/src/app/layout.tsx index de9656c..9b2c52f 100644 --- a/pkgs/ui/src/app/layout.tsx +++ b/pkgs/ui/src/app/layout.tsx @@ -6,7 +6,7 @@ import { CssBaseline, IconButton, ThemeProvider, - useMediaQuery + useMediaQuery, } from "@mui/material"; import { StyledEngineProvider } from "@mui/material/styles"; import axios from "axios";