From f2600f30801c849fc1d139386e3ddc3c9eb43e30 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Thu, 10 Feb 2022 14:10:48 -0800 Subject: [PATCH] More cleanup. --- cached/pyproject.toml | 1 + collect/pyproject.toml | 1 + collect/shared_dict.py | 11 ++++++++++- dateparse/dateparse_utils.py | 7 ++++++- dateparse/pyproject.toml | 1 + executors.py | 1 - lockfile.py | 1 - logical_search.py | 1 - ml/pyproject.toml | 1 + ml/quick_label.py | 6 ++---- pyproject.toml | 18 +++++++++++++++++- smart_future.py | 1 - smart_home/cameras.py | 6 +++++- smart_home/chromecasts.py | 8 ++++---- smart_home/device_utils.py | 7 +++---- smart_home/outlets.py | 15 +++++++++++++-- smart_home/pyproject.toml | 1 + smart_home/thermometers.py | 12 +++++++++--- string_utils.py | 12 +++++++++++- tests/pyproject.toml | 1 + tests/shared_dict_test.py | 2 +- type/pyproject.toml | 1 + 22 files changed, 88 insertions(+), 27 deletions(-) create mode 120000 cached/pyproject.toml create mode 120000 collect/pyproject.toml create mode 120000 dateparse/pyproject.toml create mode 120000 ml/pyproject.toml create mode 120000 smart_home/pyproject.toml create mode 120000 tests/pyproject.toml create mode 120000 type/pyproject.toml diff --git a/cached/pyproject.toml b/cached/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/cached/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file diff --git a/collect/pyproject.toml b/collect/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/collect/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file diff --git a/collect/shared_dict.py b/collect/shared_dict.py index e0a42f2..f4ec914 100644 --- a/collect/shared_dict.py +++ b/collect/shared_dict.py @@ -31,7 +31,16 @@ import pickle from contextlib import contextmanager from functools import wraps from multiprocessing import RLock, shared_memory -from typing import Any, Dict, Generator, ItemsView, Iterator, KeysView, Optional, ValuesView +from typing import ( + Any, + Dict, + Generator, + ItemsView, + Iterator, + KeysView, + Optional, + ValuesView, +) from decorator_utils import synchronized diff --git a/dateparse/dateparse_utils.py b/dateparse/dateparse_utils.py index 79ce8a3..6ba647c 100755 --- a/dateparse/dateparse_utils.py +++ b/dateparse/dateparse_utils.py @@ -25,7 +25,12 @@ import decorator_utils from dateparse.dateparse_utilsLexer import dateparse_utilsLexer # type: ignore from dateparse.dateparse_utilsListener import dateparse_utilsListener # type: ignore from dateparse.dateparse_utilsParser import dateparse_utilsParser # type: ignore -from datetime_utils import TimeUnit, date_to_datetime, datetime_to_date, n_timeunits_from_base +from datetime_utils import ( + TimeUnit, + date_to_datetime, + datetime_to_date, + n_timeunits_from_base, +) logger = logging.getLogger(__name__) diff --git a/dateparse/pyproject.toml b/dateparse/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/dateparse/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file diff --git a/executors.py b/executors.py index 60bd166..1077667 100644 --- a/executors.py +++ b/executors.py @@ -10,7 +10,6 @@ Also defines DefaultExecutors which is a container for references to global executors / worker pools with automatic shutdown semantics.""" from __future__ import annotations - import concurrent.futures as fut import logging import os diff --git a/lockfile.py b/lockfile.py index 10fe10d..f64a2c3 100644 --- a/lockfile.py +++ b/lockfile.py @@ -3,7 +3,6 @@ """File-based locking helper.""" from __future__ import annotations - import contextlib import datetime import json diff --git a/logical_search.py b/logical_search.py index c85b262..ef55a2b 100644 --- a/logical_search.py +++ b/logical_search.py @@ -5,7 +5,6 @@ corpus of documents. The corpus is held in memory for fast searching.""" from __future__ import annotations - import enum import sys from collections import defaultdict diff --git a/ml/pyproject.toml b/ml/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/ml/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file diff --git a/ml/quick_label.py b/ml/quick_label.py index 120ff5f..7e0a6bf 100644 --- a/ml/quick_label.py +++ b/ml/quick_label.py @@ -3,8 +3,8 @@ import glob import logging import os -from typing import Callable, List, NamedTuple, Optional, Set import warnings +from typing import Callable, List, NamedTuple, Optional, Set import argparse_utils import config @@ -80,9 +80,7 @@ def label(in_spec: InputSpec) -> None: elif in_spec.image_file_prepopulated_list is not None: images += in_spec.image_file_prepopulated_list else: - raise ValueError( - 'One of image_file_glob or image_file_prepopulated_list is required' - ) + raise ValueError('One of image_file_glob or image_file_prepopulated_list is required') skip_list = read_skip_list() for image in images: diff --git a/pyproject.toml b/pyproject.toml index e8a7162..b10ec47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,22 @@ line-length=100 profile="black" sections="FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER" no_lines_before="STDLIB" +known_first_party = [ + "acl", "ansi", "argparse_utils", "arper", "base_presence", "bootstrap", "camera_utils", + "config", "constants", "conversion_utils", "datetime_utils", "decorator_utils", "deferred_operand", + "dict_utils", "directory_filter", "exceptions", "exec_utils", "executors", "file_utils", + "function_utils", "google_assistant", "histogram", "id_generator", "input_utils", "letter_compress", + "list_utils", "lockfile", "logging_utils", "logical_search", "math_utils", "misc_utils", + "orb_utils", "parallelize", "persistent", "profanity_filter", "remote_worker", "scott_secrets", + "site_config", "smart_future", "state_tracker", "stopwatch", "string_utils", "text_utils", + "thread_utils", "type_utils", "unittest_utils", "unscrambler", "waitable_presence", + "smart_home.cameras", "smart_home.chromecasts", "smart_home.device_utils", "smart_home.device", + "smart_home.lights", "smart_home.outlets", "smart_home.registry", "smart_home.thermometers", + "cached.weather_data", "cached.weather_forecast", "collect.bidict", "collect.bst", + "collect.shared_dict", "collect.trie", "dateparse.dateparse_utils", "ml.model_trainer", + "ml.quick_label", "type.centcount", "type.locations", "type.money", "type.people", + "type.rate", +] [tool.pylint] [tool.pylint.MASTER] @@ -100,7 +116,7 @@ unsafe-load-any-extension="no" # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use "--disable=all --enable=classes # --disable=W". -disable="invalid-name, missing-function-docstring, useless-object-inheritance, unspecified-encoding, import-outside-toplevel, raw-checker-failed, bad-inline-option, locally-disabled, line-too-long, too-few-public-methods, file-ignored, suppressed-message, useless-suppression, no-else-return, no-else-raise, no-else-break, deprecated-pragma, unnecessary-pass, use-symbolic-message-instead, broad-except" +disable="invalid-name, missing-function-docstring, useless-object-inheritance, unspecified-encoding, import-outside-toplevel, raw-checker-failed, bad-inline-option, locally-disabled, line-too-long, too-few-public-methods, file-ignored, suppressed-message, useless-suppression, no-else-return, no-else-raise, no-else-break, deprecated-pragma, unnecessary-pass, use-symbolic-message-instead, broad-except, wrong-import-order" # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/smart_future.py b/smart_future.py index 9aa68f3..a1f6d97 100644 --- a/smart_future.py +++ b/smart_future.py @@ -6,7 +6,6 @@ value is not yet available, it will block until it becomes available.""" from __future__ import annotations - import concurrent import concurrent.futures as fut import logging diff --git a/smart_home/cameras.py b/smart_home/cameras.py index 712d73f..f77ddc6 100644 --- a/smart_home/cameras.py +++ b/smart_home/cameras.py @@ -10,6 +10,8 @@ logger = logging.getLogger(__name__) class BaseCamera(dev.Device): + """A base class for a webcam device.""" + camera_mapping = { 'cabin_drivewaycam': 'cabin_driveway', 'outside_backyard_camera': 'backyard', @@ -30,4 +32,6 @@ class BaseCamera(dev.Device): if name == 'driveway': return 'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mjpeg/GKlT2FfiSQ/driveway' else: - return f'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mp4/GKlT2FfiSQ/{name}/s.mp4' + return ( + f'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mp4/GKlT2FfiSQ/{name}/s.mp4' + ) diff --git a/smart_home/chromecasts.py b/smart_home/chromecasts.py index bec8461..dd6d217 100644 --- a/smart_home/chromecasts.py +++ b/smart_home/chromecasts.py @@ -17,6 +17,8 @@ logger = logging.getLogger(__name__) class BaseChromecast(dev.Device): + """A base class to represent a Google Chromecase device.""" + ccasts: List[Any] = [] refresh_ts = None browser = None @@ -45,13 +47,11 @@ class BaseChromecast(dev.Device): self.cast = None for cc in BaseChromecast.ccasts: if cc.cast_info.host == ip and cc.cast_info.cast_type != 'group': - logger.debug(f'Found chromecast at {ip}: {cc}') + logger.debug('Found chromecast at %s: %s', ip, cc) self.cast = cc self.cast.wait(timeout=1.0) if self.cast is None: - raise Exception( - f'Can\'t find ccast device at {ip}, is that really a ccast device?' - ) + raise Exception(f'Can\'t find ccast device at {ip}, is that really a ccast device?') def is_idle(self): return self.cast.is_idle diff --git a/smart_home/device_utils.py b/smart_home/device_utils.py index f79c734..40a7b70 100644 --- a/smart_home/device_utils.py +++ b/smart_home/device_utils.py @@ -1,12 +1,11 @@ #!/usr/bin/env python3 +"""General utility functions involving smart home devices.""" + import logging from typing import Any -import smart_home.cameras as cameras -import smart_home.chromecasts as chromecasts -import smart_home.lights as lights -import smart_home.outlets as outlets +from smart_home import cameras, chromecasts, lights, outlets logger = logging.getLogger(__name__) diff --git a/smart_home/outlets.py b/smart_home/outlets.py index a7f6f47..60b98a6 100644 --- a/smart_home/outlets.py +++ b/smart_home/outlets.py @@ -58,11 +58,13 @@ def tplink_outlet_command(command: str) -> bool: logger.warning(msg) logging_utils.hlog(msg) return False - logger.debug(f'{command} succeeded.') + logger.debug('%s succeeded.', command) return True class BaseOutlet(dev.Device): + """An abstract base class for smart outlets.""" + def __init__(self, name: str, mac: str, keywords: str = "") -> None: super().__init__(name.strip(), mac.strip(), keywords) @@ -84,6 +86,8 @@ class BaseOutlet(dev.Device): class TPLinkOutlet(BaseOutlet): + """A TPLink smart outlet.""" + def __init__(self, name: str, mac: str, keywords: str = '') -> None: super().__init__(name, mac, keywords) self.info: Optional[Dict] = None @@ -150,6 +154,9 @@ class TPLinkOutlet(BaseOutlet): class TPLinkOutletWithChildren(TPLinkOutlet): + """A TPLink outlet where the top and bottom plus are individually + controllable.""" + def __init__(self, name: str, mac: str, keywords: str = "") -> None: super().__init__(name, mac, keywords) self.children: List[str] = [] @@ -178,7 +185,7 @@ class TPLinkOutletWithChildren(TPLinkOutlet): cmd = self.get_cmdline(child) + f"-c {cmd}" if extra_args is not None: cmd += f" {extra_args}" - logger.debug(f'About to execute {cmd}') + logger.debug('About to execute: %s', cmd) return tplink_outlet_command(cmd) def get_children(self) -> List[str]: @@ -208,6 +215,8 @@ class TPLinkOutletWithChildren(TPLinkOutlet): class GoogleOutlet(BaseOutlet): + """A smart outlet controlled via Google Assistant.""" + def __init__(self, name: str, mac: str, keywords: str = "") -> None: super().__init__(name.strip(), mac.strip(), keywords) self.info = None @@ -285,6 +294,8 @@ class MerossWrapper(object): class MerossOutlet(BaseOutlet): + """A Meross smart outlet class.""" + def __init__(self, name: str, mac: str, keywords: str = '') -> None: super().__init__(name, mac, keywords) self.meross_wrapper: Optional[MerossWrapper] = None diff --git a/smart_home/pyproject.toml b/smart_home/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/smart_home/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file diff --git a/smart_home/thermometers.py b/smart_home/thermometers.py index dff84f6..90199b9 100644 --- a/smart_home/thermometers.py +++ b/smart_home/thermometers.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +"""Code involving querying various smart home thermometers.""" + import logging import urllib.request from typing import Optional @@ -8,6 +10,8 @@ logger = logging.getLogger() class ThermometerRegistry(object): + """A registry of thermometer hosts / names and how to talk with them.""" + def __init__(self): self.thermometers = { 'house_outside': ('10.0.0.75', 'outside_temp'), @@ -25,11 +29,13 @@ class ThermometerRegistry(object): record = self.thermometers.get(location, None) if record is None: logger.error( - f'Location {location} is not known. Valid locations are {self.thermometers.keys()}.' + 'Location %s is not known. Valid locations are %s.', + location, + self.thermometers.keys(), ) return None url = f'http://{record[0]}/~pi/{record[1]}' - logger.debug(f'Constructed URL: {url}') + logger.debug('Constructed URL: %s', url) try: www = urllib.request.urlopen(url, timeout=3) temp = www.read().decode('utf-8') @@ -40,7 +46,7 @@ class ThermometerRegistry(object): temp = round(temp) except Exception as e: logger.exception(e) - logger.error(f'Failed to read temperature at URL: {url}') + logger.error('Failed to read temperature at URL: %s', url) temp = None finally: if www is not None: diff --git a/string_utils.py b/string_utils.py index adfb149..4bec031 100644 --- a/string_utils.py +++ b/string_utils.py @@ -40,7 +40,17 @@ import string import unicodedata import warnings from itertools import zip_longest -from typing import Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple +from typing import ( + Any, + Callable, + Dict, + Iterable, + List, + Literal, + Optional, + Sequence, + Tuple, +) from uuid import uuid4 import list_utils diff --git a/tests/pyproject.toml b/tests/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/tests/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file diff --git a/tests/shared_dict_test.py b/tests/shared_dict_test.py index c8294c5..0b73a45 100755 --- a/tests/shared_dict_test.py +++ b/tests/shared_dict_test.py @@ -2,10 +2,10 @@ import unittest -from collect.shared_dict import SharedDict import parallelize as p import smart_future import unittest_utils +from collect.shared_dict import SharedDict class SharedDictTest(unittest.TestCase): diff --git a/type/pyproject.toml b/type/pyproject.toml new file mode 120000 index 0000000..1e11d78 --- /dev/null +++ b/type/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file -- 2.47.1