Set strict mypy, add types for do_install

This commit is contained in:
flyingscorpio@arch-desktop 2020-04-23 14:55:59 +02:00
parent 7f04bd92d1
commit f914135142
2 changed files with 17 additions and 9 deletions

View file

@ -89,8 +89,7 @@ filetype plugin indent on " required
" PLUGIN OPTIONS {{{ " PLUGIN OPTIONS {{{
" uncomment to set strict mypy checking let g:ale_python_mypy_options = '--strict --strict-optional'
"let g:ale_python_mypy_options = '--strict --strict-optional'
let g:ycm_extra_conf_globlist = ['!~/*'] " is overwritten in autogroups for c let g:ycm_extra_conf_globlist = ['!~/*'] " is overwritten in autogroups for c
let g:ycm_autoclose_preview_window_after_insertion = 1 let g:ycm_autoclose_preview_window_after_insertion = 1

View file

@ -7,19 +7,20 @@ Shamelessly copied from https://github.com/dmerejkowsky/dotfiles.
import argparse import argparse
import subprocess import subprocess
from typing import Dict, List, Optional, Tuple from typing import List, Optional
from urllib.request import urlretrieve from urllib.request import urlretrieve
import cli_ui as ui # type: ignore import cli_ui as ui # type: ignore
from path import Path # type: ignore from path import Path # type: ignore
import ruamel.yaml from ruamel.yaml import YAML
class Installer: class Installer:
"""Regroups all the installation methods listed in the yaml conf file.""" """Regroups all the installation methods listed in the yaml conf file."""
def __init__(self, force: bool = False, update: bool = False): def __init__(self, force: bool = False, update: bool = False):
self.conf = ruamel.yaml.safe_load(Path("configs.yml").text()) yaml = YAML(typ='safe')
self.conf = yaml.load(Path("configs.yml").text())
self.base_dir = Path.getcwd() self.base_dir = Path.getcwd()
self.home = Path("~").expanduser() self.home = Path("~").expanduser()
self.operating_system = define_os() self.operating_system = define_os()
@ -105,16 +106,22 @@ class Installer:
if executable: if executable:
p_dest.chmod(0o755) p_dest.chmod(0o755)
def do_install(self, *packages, **os_specific_packages) -> None: def do_install(
self, *packages: str, **os_specific_packages: List[str]
) -> None:
"""Install packages with OS-specific package manager. """Install packages with OS-specific package manager.
Packages can either be in a tuple for non OS-specific packages, or in a Packages can either be in a tuple for non OS-specific packages, or in a
dict for OS-specific packages. dict for OS-specific packages.
""" """
if not packages: # we got the dict, make a list out of it if not packages:
try: try:
packages = os_specific_packages[self.operating_system] + os_specific_packages["both"] packages = tuple(
os_specific_packages[self.operating_system]
+ os_specific_packages["both"]
)
except KeyError: except KeyError:
ui.fatal("Operating System not understood.") ui.fatal("Operating System not understood.")
return return
@ -281,7 +288,9 @@ def define_os() -> str:
if operating_system in ("arch", "debian"): if operating_system in ("arch", "debian"):
return operating_system + " based" return operating_system + " based"
return ui.fatal("I only support Arch and Debian based distros.") ui.fatal("I only support Arch and Debian based distros.")
return "Unsupported OS"
def main() -> None: def main() -> None: