Skip to content

Commit

Permalink
Merge branch 'master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 authored Jan 11, 2025
2 parents 863e545 + e7f2a8c commit 0413d9a
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Just another guided/automated [Arch Linux](https://wiki.archlinux.org/index.php/
The installer also doubles as a python library to install Arch Linux and manage services, packages, and other things inside the installed system *(Usually from a live medium)*.

* archinstall [discord](https://discord.gg/aDeMffrxNg) server
* archinstall [matrix.org](https://app.element.io/#/room/#archinstall:matrix.org) channel
* archinstall [#archinstall:matrix.org](https://matrix.to/#/#archinstall:matrix.org) Matrix channel
* archinstall [#[email protected]:6697](https://web.libera.chat/?channel=#archinstall)
* archinstall [documentation](https://archinstall.archlinux.page/)

Expand Down
4 changes: 2 additions & 2 deletions archinstall/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import importlib
import pathlib
import sys
from pathlib import Path

# Load .git version before the builtin version
if pathlib.Path('./archinstall/__init__.py').absolute().exists():
if Path('./archinstall/__init__.py').absolute().exists():
spec = importlib.util.spec_from_file_location("archinstall", "./archinstall/__init__.py")

if spec is None or spec.loader is None:
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _read_file(self, path: Path) -> str:

return path.read_text()

def _cleanup_config(self, config: Namespace | dict) -> dict[str, Any]:
def _cleanup_config(self, config: Namespace | dict[str, Any]) -> dict[str, Any]:
clean_args = {}
for key, val in config.items():
if isinstance(val, dict):
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class ConfigurationOutput:
def __init__(self, config: dict):
def __init__(self, config: dict[str, Any]):
"""
Configuration output handler to parse the existing configuration data structure and prepare for output on the
console and for saving it to configuration files
Expand Down
10 changes: 8 additions & 2 deletions archinstall/lib/disk/device_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,17 @@ def __le__(self, other: Size) -> bool:
return self._normalize() <= other._normalize()

@override
def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Size):
return NotImplemented

return self._normalize() == other._normalize()

@override
def __ne__(self, other) -> bool:
def __ne__(self, other: object) -> bool:
if not isinstance(other, Size):
return NotImplemented

return self._normalize() != other._normalize()

def __gt__(self, other: Size) -> bool:
Expand Down
14 changes: 7 additions & 7 deletions archinstall/lib/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import os
import pathlib
import re
import secrets
import shlex
Expand All @@ -16,6 +15,7 @@
from collections.abc import Callable, Iterator
from datetime import date, datetime
from enum import Enum
from pathlib import Path
from select import EPOLLHUP, EPOLLIN, epoll
from shutil import which
from typing import TYPE_CHECKING, Any, override
Expand Down Expand Up @@ -73,7 +73,7 @@ def jsonify(obj: Any, safe: bool = True) -> Any:
return obj.isoformat()
if isinstance(obj, list | set | tuple):
return [jsonify(item, safe) for item in obj]
if isinstance(obj, pathlib.Path):
if isinstance(obj, Path):
return str(obj)
if hasattr(obj, "__dict__"):
return vars(obj)
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(
cmd = shlex.split(cmd)

if cmd:
if cmd[0][0] != '/' and cmd[0][:2] != './': # pathlib.Path does not work well
if cmd[0][0] != '/' and cmd[0][:2] != './': # Path() does not work well
cmd[0] = locate_binary(cmd[0])

self.cmd = cmd
Expand Down Expand Up @@ -245,7 +245,7 @@ def peak(self, output: str | bytes) -> bool:
except UnicodeDecodeError:
return False

peak_logfile = pathlib.Path(f"{storage['LOG_PATH']}/cmd_output.txt")
peak_logfile = Path(f"{storage['LOG_PATH']}/cmd_output.txt")

change_perm = False
if peak_logfile.exists() is False:
Expand Down Expand Up @@ -304,7 +304,7 @@ def execute(self) -> bool:

# https://stackoverflow.com/questions/4022600/python-pty-fork-how-does-it-work
if not self.pid:
history_logfile = pathlib.Path(f"{storage['LOG_PATH']}/cmd_history.txt")
history_logfile = Path(f"{storage['LOG_PATH']}/cmd_history.txt")

change_perm = False
if history_logfile.exists() is False:
Expand Down Expand Up @@ -477,7 +477,7 @@ def run_custom_user_commands(commands: list[str], installation: Installer) -> No
os.unlink(chroot_path)


def json_stream_to_structure(configuration_identifier: str, stream: str, target: dict) -> bool:
def json_stream_to_structure(configuration_identifier: str, stream: str, target: dict[str, Any]) -> bool:
"""
Load a JSON encoded dictionary from a stream and merge it into an existing dictionary.
A stream can be a filepath, a URL or a raw JSON string.
Expand All @@ -496,7 +496,7 @@ def json_stream_to_structure(configuration_identifier: str, stream: str, target:
return False

# Try using the stream as a filepath that should be read
if raw is None and (path := pathlib.Path(stream)).exists():
if raw is None and (path := Path(stream)).exists():
try:
raw = path.read_text()
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
if accessibility_tools_in_use():
self._base_packages.extend(__accessibility_packages__)

self.post_base_install: list[Callable] = []
self.post_base_install: list[Callable] = [] # type: ignore[type-arg]

# TODO: Figure out which one of these two we'll use.. But currently we're mixing them..
storage['session'] = self
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/interactions/general_conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import pathlib
from pathlib import Path
from typing import TYPE_CHECKING

from archinstall.tui import Alignment, EditMenu, FrameProperties, MenuItem, MenuItemGroup, Orientation, ResultType, SelectMenu, Tui
Expand Down Expand Up @@ -243,7 +243,7 @@ def validator(s: str) -> str | None:
case ResultType.Selection:
downloads: int = int(result.text())

pacman_conf_path = pathlib.Path("/etc/pacman.conf")
pacman_conf_path = Path("/etc/pacman.conf")
with pacman_conf_path.open() as f:
pacman_conf = f.read().split("\n")

Expand Down
10 changes: 8 additions & 2 deletions archinstall/lib/models/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def pkg_version(self) -> str:
return self.pkgver

@override
def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, PackageSearchResult):
return NotImplemented

return self.pkg_version == other.pkg_version

def __lt__(self, other: 'PackageSearchResult') -> bool:
Expand Down Expand Up @@ -99,7 +102,10 @@ def pkg_version(self) -> str:
return self.version

@override
def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, LocalPackage):
return NotImplemented

return self.pkg_version == other.pkg_version

def __lt__(self, other: 'LocalPackage') -> bool:
Expand Down
1 change: 1 addition & 0 deletions archinstall/lib/models/mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def speed(self) -> float:
with urllib.request.urlopen(req, None, 5) as handle, DownloadTimer(timeout=5) as timer:
size = len(handle.read())

assert timer.time is not None
self._speed = size / timer.time
debug(f" speed: {self._speed} ({int(self._speed / 1024 / 1024 * 100) / 100}MiB/s)")
# Do not retry error
Expand Down
6 changes: 3 additions & 3 deletions archinstall/lib/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _parse(cls, config_users: list[dict[str, Any]]) -> list['User']:
return users

@classmethod
def _parse_backwards_compatible(cls, config_users: dict, sudo: bool) -> list['User']:
def _parse_backwards_compatible(cls, config_users: dict[str, dict[str, str]], sudo: bool) -> list['User']:
if len(config_users.keys()) > 0:
username = list(config_users.keys())[0]
password = config_users[username]['!password']
Expand All @@ -153,8 +153,8 @@ def _parse_backwards_compatible(cls, config_users: dict, sudo: bool) -> list['Us
@classmethod
def parse_arguments(
cls,
config_users: list[dict[str, str]] | dict[str, str],
config_superusers: list[dict[str, str]] | dict[str, str]
config_users: list[dict[str, str]] | dict[str, dict[str, str]],
config_superusers: list[dict[str, str]] | dict[str, dict[str, str]]
) -> list['User']:
users = []

Expand Down
10 changes: 5 additions & 5 deletions archinstall/lib/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import ssl
import struct
import time
from types import FrameType
from typing import Any
from types import FrameType, TracebackType
from typing import Any, Self
from urllib.error import URLError
from urllib.parse import urlencode
from urllib.request import urlopen
Expand Down Expand Up @@ -40,15 +40,15 @@ def raise_timeout(self, signl: int, frame: FrameType | None) -> None:
'''
raise DownloadTimeout(f'Download timed out after {self.timeout} second(s).')

def __enter__(self):
def __enter__(self) -> Self:
if self.timeout > 0:
self.previous_handler = signal.signal(signal.SIGALRM, self.raise_timeout) # type: ignore[assignment]
self.previous_timer = signal.alarm(self.timeout)

self.start_time = time.time()
return self

def __exit__(self, typ, value, traceback) -> None:
def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None:
if self.start_time:
time_delta = time.time() - self.start_time
signal.alarm(0)
Expand Down Expand Up @@ -164,7 +164,7 @@ def build_icmp(payload: bytes) -> bytes:
return struct.pack('!BBHHH', 8, 0, checksum, 0, 1) + payload


def ping(hostname, timeout=5) -> int:
def ping(hostname, timeout: int = 5) -> int:
watchdog = select.epoll()
started = time.time()
random_identifier = f'archinstall-{random.randint(1000, 9999)}'.encode()
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FormattedOutput:
def _get_values(
cls,
o: 'DataclassInstance',
class_formatter: str | Callable | None = None,
class_formatter: str | Callable | None = None, # type: ignore[type-arg]
filter_list: list[str] = []
) -> dict[str, Any]:
"""
Expand Down Expand Up @@ -52,7 +52,7 @@ def _get_values(
def as_table(
cls,
obj: list[Any],
class_formatter: str | Callable | None = None,
class_formatter: str | Callable | None = None, # type: ignore[type-arg]
filter_list: list[str] = [],
capitalize: bool = False
) -> str:
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/pacman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(args: str, default_cmd: str = 'pacman') -> SysCommand:

return SysCommand(f'{default_cmd} {args}')

def ask(self, error_message: str, bail_message: str, func: Callable, *args, **kwargs) -> None:
def ask(self, error_message: str, bail_message: str, func: Callable, *args, **kwargs) -> None: # type: ignore[type-arg]
while True:
try:
func(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions archinstall/scripts/list.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import glob
import pathlib
from pathlib import Path

print("The following are viable --script options:")

for script in [pathlib.Path(x) for x in glob.glob(f"{pathlib.Path(__file__).parent}/*.py")]:
for script in [Path(x) for x in glob.glob(f"{Path(__file__).parent}/*.py")]:
if script.stem in ['__init__', 'list']:
continue

Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dev = [
"mypy==1.14.1",
"flake8==7.1.1",
"pre-commit==4.0.1",
"ruff==0.9.0",
"ruff==0.9.1",
"pylint==3.3.3",
"pylint-pydantic==0.3.5",
"pytest==8.3.4",
Expand Down Expand Up @@ -96,13 +96,16 @@ disallow_any_explicit = true

[[tool.mypy.overrides]]
module = "archinstall.lib.*"
disallow_any_generics = false
disallow_any_unimported = false
disallow_incomplete_defs = false
disallow_untyped_defs = false
warn_return_any = false
warn_unreachable = false

[[tool.mypy.overrides]]
module = "archinstall.lib.disk.*"
# 'Any' imports are allowed because pyparted doesn't have type hints
disallow_any_unimported = false

[[tool.mypy.overrides]]
module = "archinstall.lib.packages"
disallow_any_explicit = true
Expand Down

0 comments on commit 0413d9a

Please sign in to comment.