diff --git a/requirements_tests.txt b/requirements_tests.txt index 948ffe898..32536f2f9 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -5,7 +5,7 @@ flake8-docstrings==1.6.0 flake8==3.9.2 pre-commit==2.15.0 pydocstyle==6.1.1 -pylint==2.10.2 +pylint==2.11.1 pytest-aiohttp==0.3.0 pytest-asyncio==0.12.0 # NB!: Versions over 0.12.0 breaks pytest-aiohttp (https://github.com/aio-libs/pytest-aiohttp/issues/16) pytest-cov==2.12.1 diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index d046e8fda..28e577d90 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -530,8 +530,7 @@ class Addon(AddonModel): # Write pulse config try: - with self.path_pulse.open("w") as config_file: - config_file.write(pulse_config) + self.path_pulse.write_text(pulse_config, encoding="utf-8") except OSError as err: _LOGGER.error( "Add-on %s can't write pulse/client.config: %s", self.slug, err diff --git a/supervisor/addons/model.py b/supervisor/addons/model.py index 945b0261c..8f4c990f8 100644 --- a/supervisor/addons/model.py +++ b/supervisor/addons/model.py @@ -184,8 +184,7 @@ class AddonModel(CoreSysAttributes, ABC): return None # Return data - with readme.open("r") as readme_file: - return readme_file.read() + return readme.read_text(encoding="utf-8") @property def repository(self) -> str: diff --git a/supervisor/bootstrap.py b/supervisor/bootstrap.py index d55b78df3..bb08b2d82 100644 --- a/supervisor/bootstrap.py +++ b/supervisor/bootstrap.py @@ -94,7 +94,7 @@ async def initialize_coresys() -> CoreSys: # Set Machine/Host ID if MACHINE_ID.exists(): - coresys.machine_id = MACHINE_ID.read_text().strip() + coresys.machine_id = MACHINE_ID.read_text(encoding="utf-8").strip() # Check if ENV is in development mode if coresys.dev: diff --git a/supervisor/core.py b/supervisor/core.py index 997adc8a2..2c81983a0 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -55,7 +55,7 @@ class Core(CoreSysAttributes): if self._state == new_state: return try: - RUN_SUPERVISOR_STATE.write_text(new_state.value) + RUN_SUPERVISOR_STATE.write_text(new_state.value, encoding="utf-8") except OSError as err: _LOGGER.warning( "Can't update the Supervisor state to %s: %s", new_state, err diff --git a/supervisor/dbus/payloads/generate.py b/supervisor/dbus/payloads/generate.py index b862c3935..500f2d93d 100644 --- a/supervisor/dbus/payloads/generate.py +++ b/supervisor/dbus/payloads/generate.py @@ -32,9 +32,7 @@ def interface_update_payload( def ipv6_to_byte(ip_address: IPv6Address) -> str: """Convert an ipv6 to an byte array.""" - return ( - f'[byte {", ".join("0x{:02x}".format(val) for val in ip_address.packed)}]' - ) + return f'[byte {", ".join(f"0x{val:02x}" for val in ip_address.packed)}]' # Init template env.filters["ipv4_to_int"] = ipv4_to_int diff --git a/supervisor/hardware/disk.py b/supervisor/hardware/disk.py index 5c213b509..3666f74a3 100644 --- a/supervisor/hardware/disk.py +++ b/supervisor/hardware/disk.py @@ -65,7 +65,7 @@ class HwDisk(CoreSysAttributes): return round(free / (1024.0 ** 3), 1) def _get_mountinfo(self, path: str) -> str: - mountinfo = _MOUNTINFO.read_text() + mountinfo = _MOUNTINFO.read_text(encoding="utf-8") for line in mountinfo.splitlines(): mountinfoarr = line.split() if mountinfoarr[4] == path: @@ -92,7 +92,7 @@ class HwDisk(CoreSysAttributes): return None # JEDEC health status DEVICE_LIFE_TIME_EST_TYP_A/B - emmc_life_time = life_time_path.read_text().split() + emmc_life_time = life_time_path.read_text(encoding="utf-8").split() if len(emmc_life_time) < 2: return None diff --git a/supervisor/hardware/helper.py b/supervisor/hardware/helper.py index a10881cdc..f2f70a53d 100644 --- a/supervisor/hardware/helper.py +++ b/supervisor/hardware/helper.py @@ -45,8 +45,7 @@ class HwHelper(CoreSysAttributes): def last_boot(self) -> Optional[str]: """Return last boot time.""" try: - with _PROC_STAT.open("r") as stat_file: - stats: str = stat_file.read() + stats: str = _PROC_STAT.read_text(encoding="utf-8") except OSError as err: _LOGGER.error("Can't read stat data: %s", err) return None diff --git a/supervisor/homeassistant/module.py b/supervisor/homeassistant/module.py index a7ba03f4a..88a37f634 100644 --- a/supervisor/homeassistant/module.py +++ b/supervisor/homeassistant/module.py @@ -114,8 +114,8 @@ class HomeAssistant(FileConfiguration, CoreSysAttributes): @property def api_url(self) -> str: """Return API url to Home Assistant.""" - return "{}://{}:{}".format( - "https" if self.api_ssl else "http", self.ip_address, self.api_port + return ( + f"{'https' if self.api_ssl else 'http'}://{self.ip_address}:{self.api_port}" ) @property @@ -257,8 +257,7 @@ class HomeAssistant(FileConfiguration, CoreSysAttributes): # Write pulse config try: - with self.path_pulse.open("w") as config_file: - config_file.write(pulse_config) + self.path_pulse.write_text(pulse_config, encoding="utf-8") except OSError as err: _LOGGER.error("Home Assistant can't write pulse/client.config: %s", err) else: diff --git a/supervisor/plugins/dns.py b/supervisor/plugins/dns.py index 64cdf6864..f9a024c45 100644 --- a/supervisor/plugins/dns.py +++ b/supervisor/plugins/dns.py @@ -312,7 +312,7 @@ class PluginDns(PluginBase): data = self.hosts_template.render(entries=self._hosts) try: - self.hosts.write_text(data) + self.hosts.write_text(data, encoding="utf-8") except OSError as err: _LOGGER.error("Can't update hosts: %s", err) raise CoreDNSError() from err diff --git a/supervisor/resolution/evaluations/apparmor.py b/supervisor/resolution/evaluations/apparmor.py index 496c59376..a7174accb 100644 --- a/supervisor/resolution/evaluations/apparmor.py +++ b/supervisor/resolution/evaluations/apparmor.py @@ -35,6 +35,6 @@ class EvaluateAppArmor(EvaluateBase): async def evaluate(self) -> None: """Run evaluation.""" try: - return _APPARMOR_KERNEL.read_text().strip().upper() != "Y" + return _APPARMOR_KERNEL.read_text(encoding="utf-8").strip().upper() != "Y" except OSError: return True diff --git a/supervisor/resolution/evaluations/lxc.py b/supervisor/resolution/evaluations/lxc.py index f18ac966a..7343dddfb 100644 --- a/supervisor/resolution/evaluations/lxc.py +++ b/supervisor/resolution/evaluations/lxc.py @@ -34,6 +34,6 @@ class EvaluateLxc(EvaluateBase): async def evaluate(self): """Run evaluation.""" with suppress(OSError): - if "container=lxc" in Path("/proc/1/environ").read_text(): + if "container=lxc" in Path("/proc/1/environ").read_text(encoding="utf-8"): return True return Path("/dev/lxd/sock").exists() diff --git a/supervisor/supervisor.py b/supervisor/supervisor.py index 7944e1ac9..4adb7afac 100644 --- a/supervisor/supervisor.py +++ b/supervisor/supervisor.py @@ -143,7 +143,7 @@ class Supervisor(CoreSysAttributes): with TemporaryDirectory(dir=self.sys_config.path_tmp) as tmp_dir: profile_file = Path(tmp_dir, "apparmor.txt") try: - profile_file.write_text(data) + profile_file.write_text(data, encoding="utf-8") except OSError as err: raise SupervisorAppArmorError( f"Can't write temporary profile: {err!s}", _LOGGER.error diff --git a/tests/common.py b/tests/common.py index a326ab361..2f0149cf3 100644 --- a/tests/common.py +++ b/tests/common.py @@ -6,13 +6,13 @@ from pathlib import Path def load_json_fixture(filename: str) -> dict: """Load a json fixture.""" path = Path(Path(__file__).parent.joinpath("fixtures"), filename) - return json.loads(path.read_text()) + return json.loads(path.read_text(encoding="utf-8")) def load_fixture(filename: str) -> str: """Load a fixture.""" path = Path(Path(__file__).parent.joinpath("fixtures"), filename) - return path.read_text() + return path.read_text(encoding="utf-8") def exists_fixture(filename: str) -> bool: