Skip to content

Commit a672c24

Browse files
author
redjax
committed
lint, format: Run linter & formatter
1 parent 6c5fe65 commit a672c24

File tree

26 files changed

+24
-38
lines changed

26 files changed

+24
-38
lines changed

red_utils/__init__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
import pkgutil
44

55
## Import modules with only stdlib dependencies directly
6-
from .context_managers import DictProtect, ListProtect, SQLiteConnManager
7-
from .context_managers import async_benchmark, benchmark
6+
from .context_managers import (
7+
DictProtect,
8+
ListProtect,
9+
SQLiteConnManager,
10+
async_benchmark,
11+
benchmark,
12+
)
813
from .dict_utils import debug_dict, merge_dicts, update_dict, validate_dict
914
from .file_utils import crawl_dir, default_json_dir, export_json, ts
1015
from .hash_utils import get_hash_from_str
@@ -24,7 +29,6 @@
2429
trim_uuid,
2530
)
2631

27-
2832
## Use pkgutil to only load modules
2933
# if dependencies are met
3034
if pkgutil.find_loader("diskcache"):
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
22

33
from .benchmarks import async_benchmark, benchmark
4+
from .database_managers.sqlite_managers import SQLiteConnManager
45
from .object_managers.protect import DictProtect, ListProtect
5-
from .database_managers.sqlite_managers import SQLiteConnManager

red_utils/context_managers/benchmarks/fn_benchmarks.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from contextlib import asynccontextmanager, contextmanager
44
import time
55

6-
76
@contextmanager
87
def benchmark(description: str = "Unnamed function timer") -> None:
98
"""Time a function call.
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .sqlite_managers import SQLiteConnManager
1+
from __future__ import annotations
2+
3+
from .sqlite_managers import SQLiteConnManager

red_utils/context_managers/database_managers/sqlite_managers.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Context manager utilities for interacting with SQLite databases, using
1+
"""Context manager utilities for interacting with SQLite databases, using
32
the stdlib sqlite3 library.
43
"""
54
from __future__ import annotations
@@ -11,14 +10,14 @@
1110

1211
class SQLiteConnManager:
1312
"""Handle interactions with a SQLite database.
14-
13+
1514
Uses built-in functions to query a database, execute SQL statements,
1615
and gracefully open/close the DB using context managers.
17-
16+
1817
Usage:
1918
Provide a path string to the SQLite database:
2019
sqlite_connection = SQLiteConnManager(path="/path/to/db.sqlite")
21-
20+
2221
Call sqlite3 functions, i.e. "get_tables()":
2322
tables = sqlite_conn.get_tables()
2423
"""

red_utils/context_managers/object_managers/protect.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import inspect
55
import json
66

7-
87
class ListProtect:
98
"""Protect a list during modification by modifying a copy instead of the original.
109

red_utils/dict_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from .validators import validate_dict
66

7-
87
def debug_dict(in_dict: dict = None) -> None:
98
"""Debug print a dict by looping overkeys and printing.
109

red_utils/dict_utils/validators.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
43
def validate_dict(_dict: dict[str, str] = None) -> dict[str, str]:
54
if not _dict:
65
raise ValueError("Missing dict to evaluate")

red_utils/diskcache_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
from diskcache import Cache
3232

33-
3433
def convert_to_seconds(unit: str = None, amount: int = None) -> int:
3534
## Allowed strings for conversion
3635
valid_time_units: list[int] = ["seconds", "hours", "minutes", "days", "weeks"]

red_utils/diskcache_utils/validators.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from diskcache import Cache
1111

12-
1312
def validate_key(key: valid_key_types = None, none_ok: bool = False) -> Union[str, int]:
1413
"""Validate input diskcache key.
1514

red_utils/fastapi_utils/dependencies.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from fastapi import Request
44
from loguru import logger as log
55

6-
76
async def logging_dependency(request: Request) -> None:
87
"""https://stackoverflow.com/a/63413392."""
98
# log.debug(f"{request.method} {request.url}")

red_utils/fastapi_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from fastapi import APIRouter, FastAPI
2424
from fastapi.middleware.cors import CORSMiddleware
2525

26-
2726
def fix_api_docs(app: FastAPI = None):
2827
"""Fix error loading /docs when a root_path is set.
2928

red_utils/fastapi_utils/validators.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from fastapi import APIRouter
66

7-
87
def is_str(input: str = None) -> str:
98
if not input:
109
raise ValueError("Missing input to evaluate")

red_utils/file_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from .constants import default_json_dir, ts
1111

12-
1312
def export_json(
1413
input: Union[str, list[list, dict], dict[str, Any]] = None,
1514
output_dir: str = default_json_dir,

red_utils/hash_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import hashlib
44

5-
65
def get_hash_from_str(input_str: str = None, encoding: str = "utf-8") -> str:
76
if not input_str:
87
raise ValueError("Missing input string")

red_utils/httpx_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from httpx import Client
1212

13-
1413
def merge_headers(
1514
original_headers: dict[str, str] = default_headers,
1615
update_vals: dict[str, str] = None,

red_utils/httpx_utils/validators.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from httpx import AsyncClient, Client
88

9-
109
def validate_client(
1110
client: Union[Client, AsyncClient] = None
1211
) -> Union[Client, AsyncClient]:

red_utils/loguru_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
from loguru import logger
2424

25-
2625
def add_sink(
2726
_logger: logger = None,
2827
sink: Union[str, Path, io.TextIOWrapper, Handler, Callable, Coroutine] = None,

red_utils/loguru_utils/validators.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from loguru import logger
1919

20-
2120
def validate_logger(_logger: logger = None, none_ok: bool = False) -> logger:
2221
"""Validate a loguru.Logger object."""
2322
if none_ok:

red_utils/msgpack_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import msgpack
1010

11-
1211
def ensure_path(dir: Union[str, Path] = None) -> bool:
1312
"""Ensure a directory path exists.
1413

red_utils/sqlalchemy_utils/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"""
2323
from __future__ import annotations
2424

25+
from . import custom_types
26+
2527
## Import SQLAlchemy dependencies
2628
## Import SQLAlchemy DeclarativeBase object
2729
from .base import Base
@@ -36,6 +38,7 @@
3638

3739
## Import constants
3840
from .constants import valid_db_types
41+
from .custom_types import CompatibleUUID
3942

4043
## Import custom SQLAlchemy utils
4144
from .utils import (
@@ -54,6 +57,3 @@
5457
orm as sa_orm,
5558
)
5659
from sqlalchemy.orm import Session, scoped_session, sessionmaker
57-
58-
from . import custom_types
59-
from .custom_types import CompatibleUUID

red_utils/sqlalchemy_utils/connection_models.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import sqlalchemy as sa
77

8-
98
@dataclass
109
class saConnectionBase:
1110
"""Base class for SQLAlchemy connection models.

red_utils/sqlalchemy_utils/custom_types.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Define custom type classes for SQLAlchemy.
1+
"""Define custom type classes for SQLAlchemy.
32
43
- [SQLAlchemy docs: Custom Types](https://docs.sqlalchemy.org/en/20/core/custom_types.html#custom-types)
54
@@ -16,13 +15,15 @@ class SomeModel(Base):
1615
## Tell this model to convert uuid.UUID Python types to custom CompatibleUUID class
1716
type_annotation_map = {uuid.UUID: CompatibleUUID}
1817
"""
18+
from __future__ import annotations
19+
1920
from typing import Any
2021
import uuid
22+
2123
from sqlalchemy import BINARY
22-
from sqlalchemy.types import TypeDecorator, CHAR
23-
from sqlalchemy.engine.interfaces import Dialect
2424
from sqlalchemy.dialects.postgresql import UUID
25-
25+
from sqlalchemy.engine.interfaces import Dialect
26+
from sqlalchemy.types import CHAR, TypeDecorator
2627

2728
class CompatibleUUID(TypeDecorator):
2829
"""Define a custom UUID, overriding SQLAlchemy's UUId type.

red_utils/sqlalchemy_utils/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from sqlalchemy.orm import Session, sessionmaker
2323
from sqlalchemy.schema import CreateTable
2424

25-
2625
def debug_metadata_obj(metadata_obj: sa.MetaData = None) -> None:
2726
"""Debug-print a SQLAlchemy MetaData object.
2827

red_utils/time_utils/operations.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from .constants import default_format, twelve_hour_format
1212

13-
1413
def datetime_as_str(ts: dt = None, format: str = default_format) -> str:
1514
"""Convert a datetime.datetime object to a string.
1615

red_utils/uuid_utils/classes.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from dataclasses import dataclass
44

5-
65
@dataclass
76
class UUIDLength:
87
"""Simple dataclass to store UUID string lengths."""

0 commit comments

Comments
 (0)