Skip to content

Commit 8088ad5

Browse files
committed
Clean up import handling
1 parent 52253c2 commit 8088ad5

8 files changed

Lines changed: 12 additions & 51 deletions

File tree

‎scripts/run-tests.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extra=
1111
[ -z "$@" ] && extra="--cov-fail-under=100"
1212

1313
echo "Linting tests..."
14-
mypy --ignore-missing-imports "${testsdir}"
14+
mypy "${testsdir}"
1515

1616
pytest \
1717
--cov=powersensor_local.xlatemsg \

‎src/powersensor_local/devices.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55

66
from datetime import datetime, timezone
77
from enum import Enum
8-
from pathlib import Path
9-
PROJECT_ROOT = str(Path(__file__).parents[1])
10-
if PROJECT_ROOT not in sys.path:
11-
sys.path.append(PROJECT_ROOT)
12-
13-
# pylint: disable=C0413
14-
from powersensor_local.legacy_discovery import LegacyDiscovery
15-
from powersensor_local.plug_api import PlugApi
8+
9+
from .legacy_discovery import LegacyDiscovery
10+
from .plug_api import PlugApi
1611

1712
EXPIRY_CHECK_INTERVAL_S = 30
1813
EXPIRY_TIMEOUT_S = 5 * 60

‎src/powersensor_local/events.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
interface in devices.py rather than parsing the output from this script."""
66
import typing
77
import sys
8-
from pathlib import Path
98

10-
PROJECT_ROOT = str(Path(__file__).parents[1])
11-
if PROJECT_ROOT not in sys.path:
12-
sys.path.append(PROJECT_ROOT)
13-
14-
# pylint: disable=C0413
159
from powersensor_local.devices import PowersensorDevices
1610
from powersensor_local.abstract_event_handler import AbstractEventHandler
1711

‎src/powersensor_local/plug_api.py‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
"""Interface abstraction for Powersensor plugs."""
22
import sys
3-
from pathlib import Path
4-
PROJECT_ROOT = str(Path(__file__).parents[1])
5-
if PROJECT_ROOT not in sys.path:
6-
sys.path.append(PROJECT_ROOT)
7-
8-
# pylint: disable=C0413
9-
from powersensor_local.async_event_emitter import AsyncEventEmitter
10-
from powersensor_local.plug_listener_tcp import PlugListenerTcp
11-
from powersensor_local.plug_listener_udp import PlugListenerUdp
12-
from powersensor_local.xlatemsg import translate_raw_message
3+
4+
from .async_event_emitter import AsyncEventEmitter
5+
from .plug_listener_tcp import PlugListenerTcp
6+
from .plug_listener_udp import PlugListenerUdp
7+
from .xlatemsg import translate_raw_message
138

149
class PlugApi(AsyncEventEmitter):
1510
"""

‎src/powersensor_local/plug_listener_tcp.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
"""Internal helper for accessing the event stream from a Powersensor plug."""
22
import asyncio
33
import json
4-
54
import sys
6-
from pathlib import Path
7-
PROJECT_ROOT = str(Path(__file__).parents[1])
8-
if PROJECT_ROOT not in sys.path:
9-
sys.path.append(PROJECT_ROOT)
105

11-
# pylint: disable=C0413
126
from powersensor_local.async_event_emitter import AsyncEventEmitter
137

148
class PlugListenerTcp(AsyncEventEmitter):

‎src/powersensor_local/plug_listener_udp.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
import socket
55
import sys
66

7-
from pathlib import Path
8-
PROJECT_ROOT = str(Path(__file__).parents[1])
9-
if PROJECT_ROOT not in sys.path:
10-
sys.path.append(PROJECT_ROOT)
11-
12-
# pylint: disable=C0413
137
from powersensor_local.async_event_emitter import AsyncEventEmitter
148

159
# pylint: disable=R0902

‎src/powersensor_local/virtual_household.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
"""Abstraction for producing a household view."""
22

33
import sys
4-
from pathlib import Path
54
from dataclasses import dataclass
65
from typing import Optional
76

8-
PROJECT_ROOT = str(Path(__file__).parents[1])
9-
if PROJECT_ROOT not in sys.path:
10-
sys.path.append(PROJECT_ROOT)
11-
12-
# pylint: disable=C0413
13-
from powersensor_local.async_event_emitter import AsyncEventEmitter
14-
from powersensor_local.event_buffer import EventBuffer
7+
from .async_event_emitter import AsyncEventEmitter
8+
from .event_buffer import EventBuffer
159

1610
KEY_DUR_S = 'duration_s'
1711
KEY_RESET = 'summation_resettime_utc'

‎src/powersensor_local/zeroconf_devices.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,9 @@
5757
import asyncio
5858
import logging
5959
import sys
60-
from pathlib import Path
6160
from typing import Any
6261

63-
PROJECT_ROOT = str(Path(__file__).parents[1])
64-
if PROJECT_ROOT not in sys.path:
65-
sys.path.append(PROJECT_ROOT)
66-
67-
from powersensor_local.devices import _PowersensorDevicesBase, _LogLevel
62+
from .devices import _PowersensorDevicesBase, _LogLevel
6863

6964
_SERVICE_TYPE_UDP = '_powersensor._udp.local.'
7065
_SERVICE_TYPE_TCP = '_powersensor._tcp.local.'

0 commit comments

Comments
 (0)