Remove Windows workarounds (#64068)

This commit is contained in:
Erik Montnemery 2022-01-13 20:41:11 +01:00 committed by GitHub
parent be628a7c4d
commit b3421cf727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 74 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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,7 +13,6 @@ _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:
@ -44,28 +41,3 @@ def async_register_signal_handling(hass: HomeAssistant) -> None:
)
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")

View File

@ -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")

View File

@ -89,7 +89,6 @@ 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="]