hass-core/homeassistant/util
J. Nick Koston 327edabb64
Fix checking if a package is installed on py3.11 (#88768)
pkg_resources is abandoned and we need to move away
from using it https://github.com/pypa/pkg_resources

In the mean time we need to keep it working. This fixes
a new exception in py3.11 when a module is not installed
which allows proper fallback to pkg_resources.Requirement.parse
when needed

```
2023-02-25 15:46:21.101 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
             ^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/config/config_entries.py", line 148, in post
    return await super().post(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/helpers/data_entry_flow.py", line 71, in post
    result = await self._flow_mgr.async_init(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 826, in async_init
    flow, result = await task
                   ^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 844, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 950, in async_create_flow
    await async_process_deps_reqs(self.hass, self._hass_config, integration)
  File "/Users/bdraco/home-assistant/homeassistant/setup.py", line 384, in async_process_deps_reqs
    await requirements.async_get_integration_with_requirements(
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 52, in async_get_integration_with_requirements
    return await manager.async_get_integration_with_requirements(domain)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 171, in async_get_integration_with_requirements
    await self._async_process_integration(integration, done)
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 186, in _async_process_integration
    await self.async_process_requirements(
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 252, in async_process_requirements
    await self._async_process_requirements(name, missing)
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 284, in _async_process_requirements
    installed, failures = await self.hass.async_add_executor_job(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 113, in _install_requirements_if_missing
    if pkg_util.is_installed(req) or _install_with_retry(req, kwargs):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/util/package.py", line 40, in is_installed
    pkg_resources.get_distribution(package)
  File "/opt/homebrew/lib/python3.11/site-packages/pkg_resources/__init__.py", line 478, in get_distribution
    dist = get_provider(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pkg_resources/__init__.py", line 354, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
``
2023-02-25 22:47:18 -05:00
..
yaml Update Union typing (4) [Py310] (#86427) 2023-01-23 09:04:40 +01:00
__init__.py Stricter pylint message control (#86154) 2023-01-20 13:47:55 +01:00
aiohttp.py Inverse json import logic (#88099) 2023-02-16 11:37:57 +01:00
async_.py Replace fire_coroutine_threadsafe with asyncio.run_coroutine_threadsafe (#88572) 2023-02-21 21:16:18 -05:00
color.py Code styling tweaks to core utils & YAML loader (#85433) 2023-01-08 22:01:55 -08:00
decorator.py Improve typing [util.decorator] (#67087) 2022-02-23 20:58:42 +01:00
distance.py String formatting and max line length - Part 7 (#84532) 2022-12-27 11:18:56 +01:00
dt.py Optimize fetching weekly/monthly/yearly statistics (#87747) 2023-02-09 21:22:32 -05:00
enum.py Cache try_parse_enum (#87911) 2023-02-12 03:57:36 -06:00
executor.py Remove ThreadPoolExecutor shutdown backport (#66735) 2022-02-17 10:39:33 -06:00
file.py Use os.path.dirname() for getting the directory name of a path (#81504) 2022-11-14 15:21:35 +01:00
json.py Add typed helpers and improve type hints in util/json (#88534) 2023-02-22 10:09:28 +01:00
location.py Enable Ruff D212 (#87347) 2023-02-03 23:08:48 +01:00
logging.py Enable Ruff D212 (#87347) 2023-02-03 23:08:48 +01:00
network.py Add is_host_valid util (#76589) 2022-09-11 11:12:04 -05:00
package.py Fix checking if a package is installed on py3.11 (#88768) 2023-02-25 22:47:18 -05:00
percentage.py Fix an extra quote typo in the percentage util (#87161) 2023-02-02 19:59:08 -06:00
pil.py Code styling tweaks to core utils & YAML loader (#85433) 2023-01-08 22:01:55 -08:00
pressure.py Add unitless unit converter (#85694) 2023-01-12 09:20:00 +01:00
process.py Move disallow-any-generics to mypy.ini (#63917) 2022-01-11 13:33:25 -08:00
read_only_dict.py Make TypeVars private (1) (#68205) 2022-03-17 18:52:38 +01:00
speed.py Add unitless unit converter (#85694) 2023-01-12 09:20:00 +01:00
ssl.py Replace deprecated SSLContext constant PROTOCOL_TLS in mqtt (#88214) 2023-02-16 13:01:28 -05:00
temperature.py String formatting and max line length - Part 7 (#84532) 2022-12-27 11:18:56 +01:00
thread.py Ensure shutdown does not deadlock (#49282) 2021-04-18 08:55:51 -10:00
timeout.py Fix danglin task for util.timeout (#88366) 2023-02-18 00:11:35 -05:00
ulid.py Sync event timed_fired and the context ulid time (#71854) 2022-05-14 12:12:08 -07:00
unit_conversion.py Add Mega Joule as valid unit of energy (#86055) 2023-01-25 14:13:42 +01:00
unit_system.py Update unit system unit conversions (#87632) 2023-02-08 10:52:54 +01:00
uuid.py Improve performance of generating non-cryptographically secure uuids (#41314) 2020-10-07 16:37:01 +02:00
variance.py Import ParamSpec from typing [Py310] (#86413) 2023-01-23 07:28:43 +01:00
volume.py String formatting and max line length - Part 7 (#84532) 2022-12-27 11:18:56 +01:00