Skip to content

Commit

Permalink
Drop remaining Python < 3.8 support (home-assistant#44743)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulus Schoutsen <[email protected]>
Co-authored-by: Franck Nijhof <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2021
1 parent 134db3f commit 4347476
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v2.7.2
hooks:
- id: pyupgrade
args: [--py37-plus]
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build:
image: latest

python:
version: 3.7
version: 3.8
setup_py_install: true

requirements_file: requirements_docs.txt
4 changes: 2 additions & 2 deletions azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ stages:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
displayName: 'Use Python 3.8'
inputs:
versionSpec: '3.7'
versionSpec: '3.8'
- script: pip install twine wheel
displayName: 'Install tools'
- script: python setup.py sdist bdist_wheel
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines-translation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
displayName: 'Use Python 3.8'
inputs:
versionSpec: '3.7'
versionSpec: '3.8'
- script: |
export LOKALISE_TOKEN="$(lokaliseToken)"
export AZURE_BRANCH="$(Build.SourceBranchName)"
Expand Down
10 changes: 4 additions & 6 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,10 @@ def async_enable_logging(
sys.excepthook = lambda *args: logging.getLogger(None).exception(
"Uncaught exception", exc_info=args # type: ignore
)

if sys.version_info[:2] >= (3, 8):
threading.excepthook = lambda args: logging.getLogger(None).exception(
"Uncaught thread exception",
exc_info=(args.exc_type, args.exc_value, args.exc_traceback),
)
threading.excepthook = lambda args: logging.getLogger(None).exception(
"Uncaught thread exception",
exc_info=(args.exc_type, args.exc_value, args.exc_traceback), # type: ignore[arg-type]
)

# Log errors to a file if we have write access to file or config dir
if log_file is None:
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
from homeassistant.util import location, network
from homeassistant.util.async_ import fire_coroutine_threadsafe, run_callback_threadsafe
import homeassistant.util.dt as dt_util
from homeassistant.util.thread import fix_threading_exception_logging
from homeassistant.util.timeout import TimeoutManager
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem
import homeassistant.util.uuid as uuid_util
Expand All @@ -86,7 +85,6 @@


block_async_io.enable()
fix_threading_exception_logging()

T = TypeVar("T")
_UNDEF: dict = {} # Internal; not helpers.typing.UNDEFINED due to circular dependency
Expand Down
1 change: 0 additions & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ emoji==0.5.4
hass-nabucasa==0.39.0
home-assistant-frontend==20201229.0
httpx==0.16.1
importlib-metadata==1.6.0;python_version<'3.8'
jinja2>=2.11.2
netdisco==2.8.2
paho-mqtt==1.5.1
Expand Down
10 changes: 1 addition & 9 deletions homeassistant/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from concurrent.futures import ThreadPoolExecutor
import dataclasses
import logging
import sys
from typing import Any, Dict, Optional

from homeassistant import bootstrap
Expand Down Expand Up @@ -41,14 +40,7 @@ class RuntimeConfig:
open_ui: bool = False


# In Python 3.8+ proactor policy is the default on Windows
if sys.platform == "win32" and sys.version_info[:2] < (3, 8):
PolicyBase = asyncio.WindowsProactorEventLoopPolicy
else:
PolicyBase = asyncio.DefaultEventLoopPolicy


class HassEventLoopPolicy(PolicyBase): # type: ignore
class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy): # type: ignore[valid-type,misc]
"""Event loop policy for Home Assistant."""

def __init__(self, debug: bool) -> None:
Expand Down
12 changes: 1 addition & 11 deletions homeassistant/util/package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Helpers to install PyPi packages."""
import asyncio
from importlib.metadata import PackageNotFoundError, version
import logging
import os
from pathlib import Path
Expand All @@ -10,17 +11,6 @@

import pkg_resources

if sys.version_info[:2] >= (3, 8):
from importlib.metadata import ( # pylint: disable=no-name-in-module,import-error
PackageNotFoundError,
version,
)
else:
from importlib_metadata import ( # pylint: disable=import-error
PackageNotFoundError,
version,
)

_LOGGER = logging.getLogger(__name__)


Expand Down
23 changes: 0 additions & 23 deletions homeassistant/util/thread.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
"""Threading util helpers."""
import ctypes
import inspect
import sys
import threading
from typing import Any


def fix_threading_exception_logging() -> None:
"""Fix threads passing uncaught exceptions to our exception hook.
https://bugs.python.org/issue1230540
Fixed in Python 3.8.
"""
if sys.version_info[:2] >= (3, 8):
return

run_old = threading.Thread.run

def run(*args: Any, **kwargs: Any) -> None:
try:
run_old(*args, **kwargs)
except (KeyboardInterrupt, SystemExit): # pylint: disable=try-except-raise
raise
except Exception: # pylint: disable=broad-except
sys.excepthook(*sys.exc_info())

threading.Thread.run = run # type: ignore


def _async_raise(tid: int, exctype: Any) -> None:
"""Raise an exception in the threads with id tid."""
if not inspect.isclass(exctype):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
target-version = ["py37", "py38"]
target-version = ["py38"]
exclude = 'generated'

[tool.isort]
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ bcrypt==3.1.7
certifi>=2020.12.5
ciso8601==2.1.3
httpx==0.16.1
importlib-metadata==1.6.0;python_version<'3.8'
jinja2>=2.11.2
PyJWT==1.7.1
cryptography==3.2
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ classifier =
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Home Automation

[flake8]
Expand All @@ -31,7 +32,7 @@ ignore =
W504

[mypy]
python_version = 3.7
python_version = 3.8
show_error_codes = true
ignore_errors = true
follow_imports = silent
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"certifi>=2020.12.5",
"ciso8601==2.1.3",
"httpx==0.16.1",
"importlib-metadata==1.6.0;python_version<'3.8'",
"jinja2>=2.11.2",
"PyJWT==1.7.1",
# PyJWT has loose dependency. We want the latest one.
Expand Down
2 changes: 1 addition & 1 deletion tests/components/plex/mock_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def playlist(self, playlist):
"""Mock the playlist lookup method."""
return MockPlexMediaItem(playlist, mediatype="playlist")

@lru_cache()
@lru_cache
def playlists(self):
"""Mock the playlists lookup method with a lazy init."""
return [
Expand Down
9 changes: 2 additions & 7 deletions tests/components/webostv/test_media_player.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The tests for the LG webOS media player platform."""
import sys

from unittest.mock import patch

import pytest

Expand All @@ -25,12 +26,6 @@
)
from homeassistant.setup import async_setup_component

if sys.version_info >= (3, 8, 0):
from unittest.mock import patch
else:
from unittest.mock import patch


NAME = "fake"
ENTITY_ID = f"{media_player.DOMAIN}.{NAME}"

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py37, py38, lint, pylint, typing, cov
envlist = py38, py39, lint, pylint, typing, cov
skip_missing_interpreters = True
ignore_basepython_conflict = True

Expand Down

0 comments on commit 4347476

Please sign in to comment.