From 69d079e63a00caf9268575a6ca4789962776761b Mon Sep 17 00:00:00 2001 From: advaithm Date: Wed, 12 May 2021 15:45:45 +0530 Subject: some type hint fixes and a bad catch fix --- .vscode/settings.json | 3 +++ archinstall/lib/disk.py | 5 +++-- archinstall/lib/general.py | 9 +++++---- archinstall/lib/hardware.py | 1 + archinstall/lib/output.py | 2 +- archinstall/lib/profiles.py | 5 +++-- examples/__init__.py | 0 profiles/__init__.py | 0 profiles/applications/__init__.py | 0 setup.py | 2 +- 10 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/__init__.py create mode 100644 profiles/__init__.py create mode 100644 profiles/applications/__init__.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..d2a6c127 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/usr/bin/python" +} \ No newline at end of file diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 44462a21..fd08ea63 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -1,3 +1,4 @@ +from typing import Optional import glob, re, os, json, time, hashlib import pathlib, traceback, logging from collections import OrderedDict @@ -205,7 +206,7 @@ class Partition(): return f'Partition(path={self.path}, size={self.size}, fs={self.filesystem}{mount_repr})' @property - def uuid(self) -> str: + def uuid(self) -> Optional[str]: """ Returns the PARTUUID as returned by lsblk. This is more reliable than relying on /dev/disk/by-partuuid as @@ -214,7 +215,7 @@ class Partition(): lsblk = b''.join(sys_command(f'lsblk -J -o+PARTUUID {self.path}')) for partition in json.loads(lsblk.decode('UTF-8'))['blockdevices']: return partition.get('partuuid', None) - + return None @property def encrypted(self): return self._encrypted diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index eb0c5d14..72f8677f 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -5,6 +5,7 @@ from subprocess import Popen, STDOUT, PIPE, check_output from select import epoll, EPOLLIN, EPOLLHUP from .exceptions import * from .output import log +from typing import Optional, Union def gen_uid(entropy_length=256): return hashlib.sha512(os.urandom(entropy_length)).hexdigest() @@ -160,16 +161,15 @@ class sys_command():#Thread): 'exit_code': self.exit_code } - def peak(self, output :str): + def peak(self, output : Union[str, bytes]) -> bool: if type(output) == bytes: try: output = output.decode('UTF-8') except UnicodeDecodeError: - return None - + return False output = output.strip('\r\n ') if len(output) <= 0: - return None + return False if self.peak_output: from .user_interaction import get_terminal_width @@ -191,6 +191,7 @@ class sys_command():#Thread): # And print the new output we're peaking on: sys.stdout.write(output) sys.stdout.flush() + return True def run(self): self.status = 'running' diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index 185ec1d6..009a3a6c 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -91,6 +91,7 @@ def cpuVendor()-> Optional[str]: if info.get('field',None): if info.get('field',None) == "Vendor ID:": return info.get('data',None) + return None def isVM() -> bool: try: diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 06d99778..d6a197f1 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -19,7 +19,7 @@ class journald(dict): @abc.abstractmethod def log(message, level=logging.DEBUG): try: - import systemd.journal + import systemd.journal # type: ignore except ModuleNotFoundError: return False diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 06237c1c..1feba1cd 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -1,3 +1,4 @@ +from typing import Optional import os, urllib.request, urllib.parse, ssl, json, re import importlib.util, sys, glob, hashlib, logging from collections import OrderedDict @@ -49,7 +50,7 @@ def list_profiles(filter_irrelevant_macs=True, subpath='', filter_top_level_prof except urllib.error.HTTPError as err: print(f'Error: Listing profiles on URL "{profiles_url}" resulted in:', err) return cache - except: + except json.decoder.JSONDecodeError as err: print(f'Error: Could not decode "{profiles_url}" result as JSON:', err) return cache @@ -215,7 +216,7 @@ class Profile(Script): return True @property - def packages(self) -> list: + def packages(self) -> Optional[list]: """ Returns a list of packages baked into the profile definition. If no package definition has been done, .packages() will return None. diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/profiles/__init__.py b/profiles/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/profiles/applications/__init__.py b/profiles/applications/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/setup.py b/setup.py index a4f49f92..8b95d978 100644 --- a/setup.py +++ b/setup.py @@ -1,2 +1,2 @@ -import setuptools +import setuptools # type: ignore setuptools.setup() -- cgit v1.2.3-54-g00ecf From af3d65cc98632042b3b0ef62cfc27553261ec3b0 Mon Sep 17 00:00:00 2001 From: advaithm Date: Wed, 12 May 2021 16:08:49 +0530 Subject: removed .vscode --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d2a6c127..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/usr/bin/python" -} \ No newline at end of file -- cgit v1.2.3-54-g00ecf