make type checking more strict
This commit is contained in:
@@ -19,8 +19,8 @@ test_driver = ["py.typed"]
|
|||||||
target-version = "py311"
|
target-version = "py311"
|
||||||
line-length = 88
|
line-length = 88
|
||||||
|
|
||||||
select = ["E", "F", "I", "U", "N", "RUF"]
|
select = ["E", "F", "I", "U", "N", "RUF", "ANN"]
|
||||||
ignore = ["E501"]
|
ignore = ["E501", "ANN101", "ANN401"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.11"
|
python_version = "3.11"
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ def retry(fn: Callable, timeout: int = 900) -> None:
|
|||||||
|
|
||||||
|
|
||||||
class Machine:
|
class Machine:
|
||||||
def __init__(self, name: str, toplevel: Path, rootdir: Path, out_dir: str):
|
def __init__(self, name: str, toplevel: Path, rootdir: Path, out_dir: str) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.toplevel = toplevel
|
self.toplevel = toplevel
|
||||||
self.out_dir = out_dir
|
self.out_dir = out_dir
|
||||||
@@ -198,7 +198,7 @@ class Machine:
|
|||||||
timing out.
|
timing out.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def check_active(_: Any) -> bool:
|
def check_active(_: bool) -> bool:
|
||||||
info = self.get_unit_info(unit)
|
info = self.get_unit_info(unit)
|
||||||
state = info["ActiveState"]
|
state = info["ActiveState"]
|
||||||
if state == "failed":
|
if state == "failed":
|
||||||
@@ -247,7 +247,7 @@ def setup_filesystems() -> None:
|
|||||||
|
|
||||||
|
|
||||||
class Driver:
|
class Driver:
|
||||||
def __init__(self, containers: list[Path], testscript: str, out_dir: str):
|
def __init__(self, containers: list[Path], testscript: str, out_dir: str) -> None:
|
||||||
self.containers = containers
|
self.containers = containers
|
||||||
self.testscript = testscript
|
self.testscript = testscript
|
||||||
self.out_dir = out_dir
|
self.out_dir = out_dir
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import socket
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from collections.abc import Iterator
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from typing import Any, Iterator, Optional
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class ClanError(Exception):
|
class ClanError(Exception):
|
||||||
@@ -37,7 +38,7 @@ def try_connect_port(port: int) -> bool:
|
|||||||
return result == 0
|
return result == 0
|
||||||
|
|
||||||
|
|
||||||
def find_free_port() -> Optional[int]:
|
def find_free_port() -> int | None:
|
||||||
"""Find an unused localhost port from 1024-65535 and return it."""
|
"""Find an unused localhost port from 1024-65535 and return it."""
|
||||||
with contextlib.closing(socket.socket(type=socket.SOCK_STREAM)) as sock:
|
with contextlib.closing(socket.socket(type=socket.SOCK_STREAM)) as sock:
|
||||||
sock.bind(("127.0.0.1", 0))
|
sock.bind(("127.0.0.1", 0))
|
||||||
@@ -69,7 +70,7 @@ class ZerotierController:
|
|||||||
path: str,
|
path: str,
|
||||||
method: str = "GET",
|
method: str = "GET",
|
||||||
headers: dict[str, str] = {},
|
headers: dict[str, str] = {},
|
||||||
data: Optional[dict[str, Any]] = None,
|
data: dict[str, Any] | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
body = None
|
body = None
|
||||||
headers = headers.copy()
|
headers = headers.copy()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class ClanHttpError(ClanError):
|
|||||||
status_code: int
|
status_code: int
|
||||||
msg: str
|
msg: str
|
||||||
|
|
||||||
def __init__(self, status_code: int, msg: str):
|
def __init__(self, status_code: int, msg: str) -> None:
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|||||||
@@ -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", "U", "N", "RUF"]
|
select = ["E", "F", "I", "U", "N", "RUF", "ANN"]
|
||||||
ignore = ["E501", "E402"]
|
ignore = ["E501", "E402", "ANN101", "ANN401"]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ from .ui.clan_select_list import ClanSelectPage
|
|||||||
|
|
||||||
|
|
||||||
class VM:
|
class VM:
|
||||||
def __init__(self, url: str, autostart: bool, path: Path):
|
def __init__(self, url: str, autostart: bool, path: Path) -> None:
|
||||||
self.url = url
|
self.url = url
|
||||||
self.autostart = autostart
|
self.autostart = autostart
|
||||||
self.path = path
|
self.path = path
|
||||||
@@ -32,7 +33,7 @@ vms.extend(vms)
|
|||||||
|
|
||||||
|
|
||||||
class ClanJoinPage(Gtk.Box):
|
class ClanJoinPage(Gtk.Box):
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.page = Gtk.Box()
|
self.page = Gtk.Box()
|
||||||
self.set_border_width(10)
|
self.set_border_width(10)
|
||||||
@@ -60,22 +61,22 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
# Must be called AFTER all components were added
|
# Must be called AFTER all components were added
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
def on_quit(self, *args):
|
def on_quit(self, *args: Any) -> None:
|
||||||
Gio.Application.quit(self.get_application())
|
Gio.Application.quit(self.get_application())
|
||||||
|
|
||||||
|
|
||||||
class Application(Gtk.Application):
|
class Application(Gtk.Application):
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
||||||
)
|
)
|
||||||
self.init_style()
|
self.init_style()
|
||||||
|
|
||||||
def do_startup(self):
|
def do_startup(self) -> None:
|
||||||
Gtk.Application.do_startup(self)
|
Gtk.Application.do_startup(self)
|
||||||
Gtk.init(sys.argv)
|
Gtk.init(sys.argv)
|
||||||
|
|
||||||
def do_activate(self):
|
def do_activate(self) -> None:
|
||||||
win = self.props.active_window
|
win = self.props.active_window
|
||||||
if not win:
|
if not win:
|
||||||
# win = SwitchTreeView(application=self)
|
# win = SwitchTreeView(application=self)
|
||||||
@@ -83,7 +84,7 @@ class Application(Gtk.Application):
|
|||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
# TODO: For css styling
|
# TODO: For css styling
|
||||||
def init_style(self):
|
def init_style(self) -> None:
|
||||||
pass
|
pass
|
||||||
# css_provider = Gtk.CssProvider()
|
# css_provider = Gtk.CssProvider()
|
||||||
# css_provider.load_from_resource(constants['RESOURCEID'] + '/style.css')
|
# css_provider.load_from_resource(constants['RESOURCEID'] + '/style.css')
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from ..app import VM
|
||||||
|
|
||||||
|
|
||||||
class ClanSelectPage(Gtk.Box):
|
class ClanSelectPage(Gtk.Box):
|
||||||
def __init__(self, vms):
|
def __init__(self, vms: list["VM"]) -> None:
|
||||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||||
|
|
||||||
self.add(ClanSelectList(vms, self.on_cell_toggled, self.on_select_row))
|
self.add(ClanSelectList(vms, self.on_cell_toggled, self.on_select_row))
|
||||||
@@ -12,16 +18,16 @@ class ClanSelectPage(Gtk.Box):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_start_clicked(self, widget):
|
def on_start_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
print("Start clicked")
|
print("Start clicked")
|
||||||
|
|
||||||
def on_stop_clicked(self, widget):
|
def on_stop_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
print("Stop clicked")
|
print("Stop clicked")
|
||||||
|
|
||||||
def on_backup_clicked(self, widget):
|
def on_backup_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
print("Backup clicked")
|
print("Backup clicked")
|
||||||
|
|
||||||
def on_cell_toggled(self, widget, path):
|
def on_cell_toggled(self, widget: Gtk.Widget, path: str) -> None:
|
||||||
print(f"on_cell_toggled: {path}")
|
print(f"on_cell_toggled: {path}")
|
||||||
# Get the current value from the model
|
# Get the current value from the model
|
||||||
current_value = self.list_store[path][1]
|
current_value = self.list_store[path][1]
|
||||||
@@ -32,14 +38,19 @@ class ClanSelectPage(Gtk.Box):
|
|||||||
# Print the updated value
|
# Print the updated value
|
||||||
print("Switched", path, "to", self.list_store[path][1])
|
print("Switched", path, "to", self.list_store[path][1])
|
||||||
|
|
||||||
def on_select_row(self, selection):
|
def on_select_row(self, selection: Gtk.TreeSelection) -> None:
|
||||||
model, row = selection.get_selected()
|
model, row = selection.get_selected()
|
||||||
if row is not None:
|
if row is not None:
|
||||||
print(f"Selected {model[row][0]}")
|
print(f"Selected {model[row][0]}")
|
||||||
|
|
||||||
|
|
||||||
class ClanSelectButtons(Gtk.Box):
|
class ClanSelectButtons(Gtk.Box):
|
||||||
def __init__(self, on_start_clicked, on_stop_clicked, on_backup_clicked):
|
def __init__(
|
||||||
|
self,
|
||||||
|
on_start_clicked: Callable[[Gtk.Widget], None],
|
||||||
|
on_stop_clicked: Callable[[Gtk.Widget], None],
|
||||||
|
on_backup_clicked: Callable[[Gtk.Widget], None],
|
||||||
|
) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
orientation=Gtk.Orientation.HORIZONTAL, margin_bottom=10, margin_top=10
|
orientation=Gtk.Orientation.HORIZONTAL, margin_bottom=10, margin_top=10
|
||||||
)
|
)
|
||||||
@@ -56,7 +67,12 @@ class ClanSelectButtons(Gtk.Box):
|
|||||||
|
|
||||||
|
|
||||||
class ClanSelectList(Gtk.Box):
|
class ClanSelectList(Gtk.Box):
|
||||||
def __init__(self, vms, on_cell_toggled, on_select_row):
|
def __init__(
|
||||||
|
self,
|
||||||
|
vms: list["VM"],
|
||||||
|
on_cell_toggled: Callable[[Gtk.Widget, str], None],
|
||||||
|
on_select_row: Callable[[Gtk.TreeSelection], None],
|
||||||
|
) -> None:
|
||||||
super().__init__(expand=True)
|
super().__init__(expand=True)
|
||||||
self.vms = vms
|
self.vms = vms
|
||||||
|
|
||||||
|
|||||||
@@ -24,5 +24,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", "U"]
|
select = [ "E", "F", "I", "U", "N", "RUF", "ANN" ]
|
||||||
ignore = ["E501", "E402", "N802"]
|
ignore = ["E501", "E402", "N802", "ANN101", "ANN401"]
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ exclude = "clan_cli.nixpkgs"
|
|||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
line-length = 88
|
line-length = 88
|
||||||
|
target-version = "py311"
|
||||||
select = [ "E", "F", "I", "U", "N"]
|
select = [ "E", "F", "I", "U", "N", "RUF", "ANN" ]
|
||||||
ignore = [ "E501" ]
|
ignore = [ "E501", "ANN101", "ANN401"]
|
||||||
|
|||||||
Reference in New Issue
Block a user