mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Avoid keeping config dir in path (#107760)
This commit is contained in:
parent
7fe6fc987b
commit
523352c97e
@ -1177,8 +1177,12 @@ def _async_mount_config_dir(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
Async friendly but not a coroutine.
|
Async friendly but not a coroutine.
|
||||||
"""
|
"""
|
||||||
if hass.config.config_dir not in sys.path:
|
|
||||||
sys.path.insert(0, hass.config.config_dir)
|
sys.path.insert(0, hass.config.config_dir)
|
||||||
|
with suppress(ImportError):
|
||||||
|
import custom_components # pylint: disable=import-outside-toplevel # noqa: F401
|
||||||
|
sys.path.remove(hass.config.config_dir)
|
||||||
|
sys.path_importer_cache.pop(hass.config.config_dir, None)
|
||||||
|
|
||||||
|
|
||||||
def _lookup_path(hass: HomeAssistant) -> list[str]:
|
def _lookup_path(hass: HomeAssistant) -> list[str]:
|
||||||
|
@ -873,3 +873,14 @@ async def test_async_suggest_report_issue(
|
|||||||
)
|
)
|
||||||
== report_issue
|
== report_issue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_config_folder_not_in_path(hass):
|
||||||
|
"""Test that config folder is not in path."""
|
||||||
|
|
||||||
|
# Verify that we are unable to import this file from top level
|
||||||
|
with pytest.raises(ImportError):
|
||||||
|
import check_config_not_in_path # noqa: F401
|
||||||
|
|
||||||
|
# Verify that we are able to load the file with absolute path
|
||||||
|
import tests.testing_config.check_config_not_in_path # noqa: F401
|
||||||
|
1
tests/testing_config/check_config_not_in_path.py
Normal file
1
tests/testing_config/check_config_not_in_path.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""File that should not be possible to import via direct import."""
|
Loading…
x
Reference in New Issue
Block a user