Merge pull request 're-add 'U' ruff type category' (#615) from Mic92-main into main

This commit is contained in:
clan-bot
2023-12-06 16:18:29 +00:00
8 changed files with 15 additions and 21 deletions

View File

@@ -1,13 +1,12 @@
import argparse import argparse
import json import json
import subprocess import subprocess
from typing import Optional
from ..errors import ClanError from ..errors import ClanError
from ..machines.machines import Machine from ..machines.machines import Machine
def create_backup(machine: Machine, provider: Optional[str] = None) -> None: def create_backup(machine: Machine, provider: str | None = None) -> None:
backup_scripts = json.loads( backup_scripts = json.loads(
machine.eval_nix(f"nixosConfigurations.{machine.name}.config.clanCore.backups") machine.eval_nix(f"nixosConfigurations.{machine.name}.config.clanCore.backups")
) )

View File

@@ -1,13 +1,12 @@
import argparse import argparse
import pprint import pprint
from pathlib import Path from pathlib import Path
from typing import Optional
from ..errors import ClanError from ..errors import ClanError
def list_backups( def list_backups(
flake_dir: Path, machine: str, provider: Optional[str] = None flake_dir: Path, machine: str, provider: str | None = None
) -> dict[str, dict[str, list[dict[str, str]]]]: ) -> dict[str, dict[str, list[dict[str, str]]]]:
dummy_data = { dummy_data = {
"testhostname": { "testhostname": {

View File

@@ -1,6 +1,5 @@
import argparse import argparse
from pathlib import Path from pathlib import Path
from typing import Optional
from ..errors import ClanError from ..errors import ClanError
@@ -10,7 +9,7 @@ def restore_backup(
machine: str, machine: str,
provider: str, provider: str,
backup_id: str, backup_id: str,
service: Optional[str] = None, service: str | None = None,
) -> None: ) -> None:
if service is None: if service is None:
print("would restore backup", machine, provider, backup_id) print("would restore backup", machine, provider, backup_id)

View File

@@ -4,7 +4,7 @@ import urllib.parse
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum, member from enum import Enum, member
from pathlib import Path from pathlib import Path
from typing import Dict, Self from typing import Self
from .errors import ClanError from .errors import ClanError
@@ -52,7 +52,7 @@ class ClanURI:
if uri.startswith("clan://"): if uri.startswith("clan://"):
self._nested_uri = uri[7:] self._nested_uri = uri[7:]
else: else:
raise ClanError("Invalid scheme: expected clan://, got {}".format(uri)) raise ClanError(f"Invalid scheme: expected clan://, got {uri}")
# Parse the URI into components # Parse the URI into components
# scheme://netloc/path;parameters?query#fragment # scheme://netloc/path;parameters?query#fragment
@@ -61,14 +61,12 @@ class ClanURI:
# Parse the query string into a dictionary # Parse the query string into a dictionary
query = urllib.parse.parse_qs(self._components.query) query = urllib.parse.parse_qs(self._components.query)
params: Dict[str, str] = {} params: dict[str, str] = {}
for field in dataclasses.fields(ClanParameters): for field in dataclasses.fields(ClanParameters):
if field.name in query: if field.name in query:
values = query[field.name] values = query[field.name]
if len(values) > 1: if len(values) > 1:
raise ClanError( raise ClanError(f"Multiple values for parameter: {field.name}")
"Multiple values for parameter: {}".format(field.name)
)
params[field.name] = values[0] params[field.name] = values[0]
# Remove the field from the query dictionary # Remove the field from the query dictionary
@@ -89,12 +87,10 @@ class ClanURI:
case "file": case "file":
self.scheme = ClanScheme.FILE.value(Path(self._components.path)) # type: ignore self.scheme = ClanScheme.FILE.value(Path(self._components.path)) # type: ignore
case _: case _:
raise ClanError( raise ClanError(f"Unsupported scheme: {self._components.scheme}")
"Unsupported scheme: {}".format(self._components.scheme)
)
@classmethod @classmethod
def from_path(cls, path: Path, params: ClanParameters) -> Self: # noqa def from_path(cls, path: Path, params: ClanParameters) -> Self: # noqa
urlparams = urllib.parse.urlencode(params.__dict__) urlparams = urllib.parse.urlencode(params.__dict__)
return cls("clan://file://{}?{}".format(path, urlparams)) return cls(f"clan://file://{path}?{urlparams}")

View File

@@ -55,5 +55,5 @@ ignore_missing_imports = true
[tool.ruff] [tool.ruff]
target-version = "py311" target-version = "py311"
line-length = 88 line-length = 88
select = [ "E", "F", "I", "N", "RUF", "ANN", "A" ] select = [ "E", "F", "I", "U", "N", "RUF", "ANN", "A" ]
ignore = ["E501", "E402", "ANN101", "ANN401", "A003"] ignore = ["E501", "E402", "ANN101", "ANN401", "A003"]

View File

@@ -10,7 +10,6 @@
, gobject-introspection , gobject-introspection
, clan-cli , clan-cli
, makeDesktopItem , makeDesktopItem
, mypy
, ipdb , ipdb
}: }:
let let
@@ -35,7 +34,7 @@ python3.pkgs.buildPythonApplication {
]; ];
buildInputs = [ spice-gtk gtk3 gnome.adwaita-icon-theme ]; buildInputs = [ spice-gtk gtk3 gnome.adwaita-icon-theme ];
propagatedBuildInputs = [ mypy ipdb pygobject3 clan-cli ]; propagatedBuildInputs = [ pygobject3 clan-cli ];
# also re-expose dependencies so we test them in CI # also re-expose dependencies so we test them in CI
passthru.tests = { passthru.tests = {

View File

@@ -30,5 +30,5 @@ ignore_missing_imports = true
[tool.ruff] [tool.ruff]
target-version = "py311" target-version = "py311"
line-length = 88 line-length = 88
select = [ "E", "F", "I", "N", "RUF", "ANN", "A" ] select = [ "E", "F", "I", "U", "N", "RUF", "ANN", "A" ]
ignore = ["E501", "E402", "N802", "ANN101", "ANN401", "A003"] ignore = ["E501", "E402", "N802", "ANN101", "ANN401", "A003"]

View File

@@ -1,10 +1,12 @@
{ clan-vm-manager, clan-cli, mkShell, ruff, desktop-file-utils, xdg-utils }: { clan-vm-manager, clan-cli, mkShell, ruff, desktop-file-utils, xdg-utils, mypy, python3Packages }:
mkShell { mkShell {
inherit (clan-vm-manager) propagatedBuildInputs buildInputs; inherit (clan-vm-manager) propagatedBuildInputs buildInputs;
nativeBuildInputs = [ nativeBuildInputs = [
ruff ruff
desktop-file-utils desktop-file-utils
xdg-utils xdg-utils
mypy
python3Packages.ipdb
] ++ clan-vm-manager.nativeBuildInputs; ] ++ clan-vm-manager.nativeBuildInputs;
PYTHONBREAKPOINT = "ipdb.set_trace"; PYTHONBREAKPOINT = "ipdb.set_trace";