Strict mypy - Phase 1 (#2533)

* Strict mypy for examples/
This commit is contained in:
Daniel Girtler 2024-06-14 05:35:54 +10:00 committed by GitHub
parent 9c5a66b145
commit aa87fb1db5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 55 additions and 120 deletions

View File

@ -7,8 +7,17 @@ jobs:
image: archlinux/archlinux:latest
steps:
- uses: actions/checkout@v4
- run: pacman --noconfirm -Syu python python-pip
- name: Prepare arch
run: |
pacman-key --init
pacman --noconfirm -Sy archlinux-keyring
pacman --noconfirm -Syyu
pacman --noconfirm -Sy python-pip python-pyparted python-simple-term-menu pkgconfig gcc
- run: pip install --break-system-packages --upgrade pip
- run: pip install --break-system-packages flake8
# this will install the exact version of mypy that is in the pyproject.toml file
- name: Install archinstall dependencies
run: pip install --break-system-packages .[dev]
- run: python --version
- run: flake8 --version
- name: Lint with flake8
run: flake8

View File

@ -7,12 +7,19 @@ jobs:
image: archlinux/archlinux:latest
steps:
- uses: actions/checkout@v4
- run: pacman --noconfirm -Syu python mypy python-pip
- name: Prepare arch
run: |
pacman-key --init
pacman --noconfirm -Sy archlinux-keyring
pacman --noconfirm -Syyu
pacman --noconfirm -Sy python-pip python-pyparted python-simple-term-menu pkgconfig gcc
- run: pip install --break-system-packages --upgrade pip
- run: pip install --break-system-packages fastapi pydantic
# this will install the exact version of mypy that is in the pyproject.toml file
- name: Install archinstall dependencies
run: pip install --break-system-packages .[dev]
- run: python --version
- run: mypy --version
# one day this will be enabled
# run: mypy --strict --module archinstall || exit 0
- name: run mypy
run: mypy --config-file pyproject.toml
- name: run mypy strict
run: mypy --config-file mypy.ini

View File

@ -13,7 +13,7 @@ repos:
require_serial: true
fail_fast: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# general hooks:
- id: check-added-large-files # Prevent giant files from being committed

View File

@ -7,7 +7,7 @@ if TYPE_CHECKING:
class MinimalProfile(Profile):
def __init__(self):
def __init__(self) -> None:
super().__init__(
'Minimal',
ProfileType.Minimal,

View File

@ -195,11 +195,11 @@ class Installer:
f'Please resize it to at least 200MiB and re-run the installation.'
)
def sanity_check(self):
def sanity_check(self) -> None:
# self._verify_boot_part()
self._verify_service_stop()
def mount_ordered_layout(self):
def mount_ordered_layout(self) -> None:
debug('Mounting ordered layout')
luks_handlers: Dict[Any, Luks2] = {}
@ -353,7 +353,7 @@ class Installer:
mount_options = mount_options + [f'subvol={subvol.name}']
disk.device_handler.mount(dev_path, mountpoint, options=mount_options)
def generate_key_files(self):
def generate_key_files(self) -> None:
match self._disk_encryption.encryption_type:
case disk.EncryptionType.Luks:
self._generate_key_files_partitions()

View File

@ -15,7 +15,7 @@ if TYPE_CHECKING:
_: Any
def ask_user_questions():
def ask_user_questions() -> None:
global_menu = archinstall.GlobalMenu(data_store=archinstall.arguments)
global_menu.enable('archinstall-language')
@ -76,7 +76,7 @@ def ask_user_questions():
global_menu.run()
def perform_installation(mountpoint: Path):
def perform_installation(mountpoint: Path) -> None:
"""
Performs the installation steps on a block device.
Only requirement is that the block devices are

View File

@ -13,7 +13,7 @@ if TYPE_CHECKING:
_: Any
def perform_installation(mountpoint: Path):
def perform_installation(mountpoint: Path) -> None:
disk_config: disk.DiskLayoutConfiguration = archinstall.arguments['disk_config']
disk_encryption: disk.DiskEncryption = archinstall.arguments.get('disk_encryption', None)
@ -42,7 +42,7 @@ def perform_installation(mountpoint: Path):
installation.create_users(user)
def prompt_disk_layout():
def prompt_disk_layout() -> None:
fs_type = None
if filesystem := archinstall.arguments.get('filesystem', None):
fs_type = disk.FilesystemType(filesystem)
@ -56,7 +56,7 @@ def prompt_disk_layout():
)
def parse_disk_encryption():
def parse_disk_encryption() -> None:
if enc_password := archinstall.arguments.get('!encryption-password', None):
modification: List[disk.DeviceModification] = archinstall.arguments['disk_config']
partitions: List[disk.PartitionModification] = []

View File

@ -4,7 +4,7 @@ import archinstall
from archinstall import Installer, disk, debug
def ask_user_questions():
def ask_user_questions() -> None:
global_menu = archinstall.GlobalMenu(data_store=archinstall.arguments)
global_menu.enable('archinstall-language')
@ -20,7 +20,7 @@ def ask_user_questions():
global_menu.run()
def perform_installation(mountpoint: Path):
def perform_installation(mountpoint: Path) -> None:
"""
Performs the installation steps on a block device.
Only requirement is that the block devices are

View File

@ -1,102 +0,0 @@
[mypy]
python_version = 3.10
follow_imports = silent
exclude = (?x)(
| ^archinstall/lib/configuration\.py$
| ^archinstall/lib/disk/btrfs/btrfssubvolumeinfo\.py$
| ^archinstall/lib/disk/helpers\.py$
| ^archinstall/lib/hsm/fido\.py$
| ^archinstall/lib/menu/list_manager\.py$
| ^archinstall/lib/menu/menu\.py$
| ^archinstall/lib/menu/simple_menu\.py$
| ^archinstall/lib/menu/text_input\.py$
| ^archinstall/lib/models/dataclasses\.py$
| ^archinstall/lib/models/network_configuration\.py$
| ^archinstall/lib/models/password_strength\.py$
| ^archinstall/lib/models/pydantic\.py$
| ^archinstall/lib/models/subvolume\.py$
| ^archinstall/lib/models/users\.py$
| ^archinstall/lib/output\.py$
| ^archinstall/lib/plugins\.py$
| ^archinstall/examples/guided\.py$
| ^archinstall/examples/minimal\.py$
| ^archinstall/examples/only_hd\.py$
| ^archinstall/examples/swiss\.py$
| ^archinstall/__init__\.py$
| ^archinstall/lib/disk/blockdevice\.py$
| ^archinstall/lib/disk/btrfs/btrfs_helpers\.py$
| ^archinstall/lib/disk/btrfs/btrfspartition\.py$
| ^archinstall/lib/disk/dmcryptdev\.py$
| ^archinstall/lib/disk/filesystem\.py$
| ^archinstall/lib/disk/mapperdev\.py$
| ^archinstall/lib/disk/partition\.py$
| ^archinstall/lib/disk/user_guides\.py$
| ^archinstall/lib/general\.py$
| ^archinstall/lib/hardware\.py$
| ^archinstall/lib/installer\.py$
| ^archinstall/lib/locale_helpers\.py$
| ^archinstall/lib/luks\.py$
| ^archinstall/lib/menu/global_menu\.py$
| ^archinstall/lib/menu/selection_menu\.py$
| ^archinstall/lib/mirrors\.py$
| ^archinstall/lib/networking\.py$
| ^archinstall/lib/packages/packages\.py$
| ^archinstall/lib/pacman\.py$
| ^archinstall/lib/profiles\.py$
| ^archinstall/lib/systemd\.py$
| ^archinstall/lib/translation\.py$
| ^archinstall/lib/user_interaction/backwards_compatible_conf\.py$
| ^archinstall/lib/user_interaction/disk_conf\.py$
| ^archinstall/lib/user_interaction/general_conf\.py$
| ^archinstall/lib/user_interaction/locale_conf\.py$
| ^archinstall/lib/user_interaction/manage_users_conf\.py$
| ^archinstall/lib/user_interaction/network_conf\.py$
| ^archinstall/lib/user_interaction/partitioning_conf\.py$
| ^archinstall/lib/user_interaction/save_conf\.py$
| ^archinstall/lib/user_interaction/system_conf\.py$
| ^archinstall/lib/user_interaction/utils\.py$
| ^archinstall/profiles/applications/pipewire\.py$
| ^archinstall/profiles/awesome\.py$
| ^archinstall/profiles/bspwm\.py$
| ^archinstall/profiles/budgie\.py$
| ^archinstall/profiles/cinnamon\.py$
| ^archinstall/profiles/cutefish\.py$
| ^archinstall/profiles/deepin\.py$
| ^archinstall/profiles/desktop\.py$
| ^archinstall/profiles/enlightenment\.py$
| ^archinstall/profiles/gnome\.py$
| ^archinstall/profiles/i3\.py$
| ^archinstall/profiles/lxqt\.py$
| ^archinstall/profiles/mate\.py$
| ^archinstall/profiles/minimal\.py$
| ^archinstall/profiles/plasma\.py$
| ^archinstall/profiles/qtile\.py$
| ^archinstall/profiles/server\.py$
| ^archinstall/profiles/sway\.py$
| ^archinstall/profiles/xfce4\.py$
| ^archinstall/profiles/xorg\.py$
| ^profiles/applications/pipewire\.py$
| ^profiles/awesome\.py$
| ^profiles/bspwm\.py$
| ^profiles/budgie\.py$
| ^profiles/cinnamon\.py$
| ^profiles/cutefish\.py$
| ^profiles/deepin\.py$
| ^profiles/desktop\.py$
| ^profiles/enlightenment\.py$
| ^profiles/gnome\.py$
| ^profiles/i3\.py$
| ^profiles/lxqt\.py$
| ^profiles/mate\.py$
| ^profiles/minimal\.py$
| ^profiles/plasma\.py$
| ^profiles/qtile\.py$
| ^profiles/server\.py$
| ^profiles/sway\.py$
| ^profiles/xfce4\.py$
| ^profiles/xorg\.py$
| ^examples/guided\.py$
| ^examples/only_hd\.py$
| ^examples/minimal\.py$
| ^examples/swiss\.py$)
files = archinstall/, profiles/, examples/

20
mypy.ini Normal file
View File

@ -0,0 +1,20 @@
[mypy]
python_version = 3.11
follow_imports = silent
check_untyped_defs = True
strict_equality = True
warn_unused_configs = True
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
warn_unreachable = True
extra_checks = True
files = examples/
exclude = (?x)(
^archinstall)

View File

@ -31,6 +31,7 @@ Source = "https://github.com/archlinux/archinstall"
log = ["systemd_python==235"]
dev = [
"mypy==1.10.0",
"flake8==7.0.0",
"pre-commit==3.7.1",
]
doc = ["sphinx"]