From b3421cf72767196cd80c1bc4ff4c1cc5d6ee5163 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 13 Jan 2022 20:41:11 +0100 Subject: [PATCH] Remove Windows workarounds (#64068) --- homeassistant/__main__.py | 14 ------ homeassistant/config.py | 4 +- homeassistant/helpers/signal.py | 74 +++++++++------------------- homeassistant/helpers/system_info.py | 4 +- homeassistant/util/package.py | 7 ++- 5 files changed, 29 insertions(+), 74 deletions(-) diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 1a129686a8f..4833b81637d 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -5,7 +5,6 @@ import argparse import faulthandler import os import platform -import subprocess import sys import threading @@ -265,19 +264,6 @@ def main() -> int: """Start Home Assistant.""" validate_python() - # Run a simple daemon runner process on Windows to handle restarts - if os.name == "nt" and "--runner" not in sys.argv: - nt_args = cmdline() + ["--runner"] - while True: - try: - subprocess.check_call(nt_args) - sys.exit(0) - except KeyboardInterrupt: - sys.exit(0) - except subprocess.CalledProcessError as exc: - if exc.returncode != RESTART_EXIT_CODE: - sys.exit(exc.returncode) - args = get_arguments() if args.script is not None: diff --git a/homeassistant/config.py b/homeassistant/config.py index 8e6c4657f39..74a8055e971 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -260,8 +260,8 @@ CORE_CONFIG_SCHEMA = vol.All( def get_default_config_dir() -> str: """Put together the default configuration directory based on the OS.""" - data_dir = os.getenv("APPDATA") if os.name == "nt" else os.path.expanduser("~") - return os.path.join(data_dir, CONFIG_DIR_NAME) # type: ignore + data_dir = os.path.expanduser("~") + return os.path.join(data_dir, CONFIG_DIR_NAME) async def async_ensure_config_exists(hass: HomeAssistant) -> bool: diff --git a/homeassistant/helpers/signal.py b/homeassistant/helpers/signal.py index 53802a2a119..9fd643a7757 100644 --- a/homeassistant/helpers/signal.py +++ b/homeassistant/helpers/signal.py @@ -1,8 +1,6 @@ """Signal handling related helpers.""" import logging import signal -import sys -from types import FrameType from homeassistant.const import RESTART_EXIT_CODE from homeassistant.core import HomeAssistant, callback @@ -15,57 +13,31 @@ _LOGGER = logging.getLogger(__name__) @bind_hass def async_register_signal_handling(hass: HomeAssistant) -> None: """Register system signal handler for core.""" - if sys.platform != "win32": - @callback - def async_signal_handle(exit_code: int) -> None: - """Wrap signal handling. + @callback + def async_signal_handle(exit_code: int) -> None: + """Wrap signal handling. - * queue call to shutdown task - * re-instate default handler - """ - hass.loop.remove_signal_handler(signal.SIGTERM) - hass.loop.remove_signal_handler(signal.SIGINT) - hass.async_create_task(hass.async_stop(exit_code)) + * queue call to shutdown task + * re-instate default handler + """ + hass.loop.remove_signal_handler(signal.SIGTERM) + hass.loop.remove_signal_handler(signal.SIGINT) + hass.async_create_task(hass.async_stop(exit_code)) - try: - hass.loop.add_signal_handler(signal.SIGTERM, async_signal_handle, 0) - except ValueError: - _LOGGER.warning("Could not bind to SIGTERM") + try: + hass.loop.add_signal_handler(signal.SIGTERM, async_signal_handle, 0) + except ValueError: + _LOGGER.warning("Could not bind to SIGTERM") - try: - hass.loop.add_signal_handler(signal.SIGINT, async_signal_handle, 0) - except ValueError: - _LOGGER.warning("Could not bind to SIGINT") + try: + hass.loop.add_signal_handler(signal.SIGINT, async_signal_handle, 0) + except ValueError: + _LOGGER.warning("Could not bind to SIGINT") - try: - hass.loop.add_signal_handler( - signal.SIGHUP, async_signal_handle, RESTART_EXIT_CODE - ) - except ValueError: - _LOGGER.warning("Could not bind to SIGHUP") - - else: - old_sigterm = None - old_sigint = None - - @callback - def async_signal_handle(exit_code: int, frame: FrameType) -> None: - """Wrap signal handling. - - * queue call to shutdown task - * re-instate default handler - """ - signal.signal(signal.SIGTERM, old_sigterm) - signal.signal(signal.SIGINT, old_sigint) - hass.async_create_task(hass.async_stop(exit_code)) - - try: - old_sigterm = signal.signal(signal.SIGTERM, async_signal_handle) - except ValueError: - _LOGGER.warning("Could not bind to SIGTERM") - - try: - old_sigint = signal.signal(signal.SIGINT, async_signal_handle) - except ValueError: - _LOGGER.warning("Could not bind to SIGINT") + try: + hass.loop.add_signal_handler( + signal.SIGHUP, async_signal_handle, RESTART_EXIT_CODE + ) + except ValueError: + _LOGGER.warning("Could not bind to SIGHUP") diff --git a/homeassistant/helpers/system_info.py b/homeassistant/helpers/system_info.py index 7e65ab858ad..e137d0f673e 100644 --- a/homeassistant/helpers/system_info.py +++ b/homeassistant/helpers/system_info.py @@ -34,9 +34,7 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]: except KeyError: info_object["user"] = None - if platform.system() == "Windows": - info_object["os_version"] = platform.win32_ver()[0] - elif platform.system() == "Darwin": + if platform.system() == "Darwin": info_object["os_version"] = platform.mac_ver()[0] elif platform.system() == "Linux": info_object["docker"] = os.path.isfile("/.dockerenv") diff --git a/homeassistant/util/package.py b/homeassistant/util/package.py index a0b5c2832ad..a1ee2b9f584 100644 --- a/homeassistant/util/package.py +++ b/homeassistant/util/package.py @@ -89,10 +89,9 @@ def install_package( # This only works if not running in venv args += ["--user"] env["PYTHONUSERBASE"] = os.path.abspath(target) - if sys.platform != "win32": - # Workaround for incompatible prefix setting - # See http://stackoverflow.com/a/4495175 - args += ["--prefix="] + # Workaround for incompatible prefix setting + # See http://stackoverflow.com/a/4495175 + args += ["--prefix="] _LOGGER.debug("Running pip command: args=%s", args) with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) as process: _, stderr = process.communicate()