Skip to content

Commit 22b8174

Browse files
committed
Ignore phantom directories
1 parent 76ee9d6 commit 22b8174

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

custom_components/patch/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636
)
3737

3838
PATH_VARIABLES = {
39-
"site-packages": next(filter(lambda x: x.endswith("site-packages"), sys.path)),
39+
"site-packages": next(
40+
filter(
41+
lambda x: x.split(os.path.sep)[-1] == "site-packages" and os.path.isdir(x),
42+
sys.path,
43+
)
44+
),
4045
"homeassistant": os.path.dirname(homeassistant.__file__),
4146
}
4247

tests/test_init.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
import os
66
import tempfile
7+
import yaml
78
from unittest.mock import AsyncMock, patch
89

910
import voluptuous as vol
@@ -299,15 +300,15 @@ async def test_expand_path_config(
299300
"""Test configuration with variables."""
300301
await async_setup(
301302
hass,
302-
{
303-
CONF_FILES: [
304-
{
305-
CONF_NAME: "__init__.py",
306-
CONF_BASE: "{site-packages}/aiofiles",
307-
CONF_DESTINATION: "{site-packages}/aiofiles",
308-
CONF_PATCH: "{site-packages}/aiofiles",
309-
}
310-
]
311-
},
303+
yaml.load(
304+
"""
305+
files:
306+
- name: __init__.py
307+
base: "{site-packages}/aiofiles"
308+
destination: "{site-packages}/aiofiles"
309+
patch: "{site-packages}/aiofiles"
310+
""",
311+
Loader=yaml.SafeLoader,
312+
),
312313
)
313314
await async_next_day(hass, freezer)

0 commit comments

Comments
 (0)