1
0
Fork 0

fix mypy errors

This commit is contained in:
Kim, Jimin 2022-11-14 15:56:59 +09:00
parent 858e76988c
commit 93829c6f96
3 changed files with 29 additions and 20 deletions

2
mypy.ini Normal file
View file

@ -0,0 +1,2 @@
[mypy-inquirer.*]
ignore_missing_imports = True

View file

@ -9,4 +9,4 @@ content_dir = abspath(dirname(dirname(__file__)))
# must be synced with `setup.py`
tmp_dir = "/tmp/com.developomp.setup"
home_dir = environ.get("HOME")
home_dir = environ.get("HOME", "/home/pomp")

View file

@ -1,6 +1,8 @@
from importlib.machinery import SourceFileLoader
from os import system, makedirs, remove
from os.path import dirname, exists
from types import ModuleType
from typing import Optional
from tqdm.auto import tqdm
from pathlib import Path
import requests
@ -62,7 +64,12 @@ def appimage_install(file_url: str, file_name: str) -> None:
remove(download_path)
with requests.get(file_url, stream=True) as r:
total_length = int(r.headers.get("Content-Length"))
total_length = None
try:
total_length = int(r.headers["Content-Length"])
except KeyError:
pass
# show progress bar
with tqdm.wrapattr(r.raw, "read", total=total_length, desc="") as raw:
@ -71,9 +78,8 @@ def appimage_install(file_url: str, file_name: str) -> None:
shutil.copyfileobj(raw, output)
def get_latest_appimage_url_from_github(repo: str) -> str:
return (
re.search(
def get_latest_appimage_url_from_github(repo: str) -> Optional[str]:
matches = re.search(
"(?P<url>https?://[^\s]+)",
[
t
@ -83,10 +89,11 @@ def get_latest_appimage_url_from_github(repo: str) -> str:
if "browser_download" in t and 'AppImage"' in t
][0],
)
.group("url")
.split(".AppImage")[0]
+ ".AppImage"
)
if not matches:
return None
return matches.group("url").split(".AppImage")[0] + ".AppImage"
def smart_mkdir(path: str) -> None:
@ -138,7 +145,7 @@ def copy_file(src_file: str, mode="644", sudo=False) -> None:
system(command)
def copy_directory(src: str, dst: str) -> None:
def copy_directory(src_path: str, dst_path: str) -> None:
"""Copy a directory.
Automatically creates parent directory/directories of dst if it does not exist already
@ -147,7 +154,7 @@ def copy_directory(src: str, dst: str) -> None:
dst: A path-like object or string pointing to a directory.
"""
system(f"cp -R {src.constants.content_dir}{src} {dst}")
system(f"cp -R {src.constants.content_dir}{src_path} {dst_path}")
def load_dconf(file_name: str) -> None:
@ -172,7 +179,7 @@ def unzip(zip_path: str, dst_dir: str) -> None:
zip_ref.extractall(dst_dir)
def import_file(name, path) -> None:
def import_file(name, path) -> ModuleType:
return SourceFileLoader(name, path).load_module()