From ae0827cec09dedf72bdde756e1a9ba5296d1bdee Mon Sep 17 00:00:00 2001 From: Shamil Date: Fri, 8 May 2026 23:30:09 +0300 Subject: [PATCH] style(env): satisfy ruff (datetime alias, line length, identity check) (#24118) --- backend/open_webui/env.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index e734a2f865..deca6193dd 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -1,21 +1,21 @@ +import datetime as dt import importlib.metadata import json import logging import os import pkgutil -import sys +import re import shutil +import sys import traceback -from datetime import datetime, timezone +from pathlib import Path from typing import Any from uuid import uuid4 -from pathlib import Path -from cryptography.hazmat.primitives import serialization -import re - import markdown from bs4 import BeautifulSoup +from cryptography.hazmat.primitives import serialization + from open_webui.constants import ERROR_MESSAGES #################################### @@ -43,7 +43,8 @@ except ImportError: DOCKER = os.environ.get('DOCKER', 'False').lower() == 'true' -# device type embedding models - "cpu" (default), "cuda" (nvidia gpu required) or "mps" (apple silicon) - choosing this right can lead to better performance +# device type for embedding models - "cpu" (default), "cuda" (nvidia gpu required), or "mps" (apple silicon) +# choosing this correctly can lead to better performance USE_CUDA = os.environ.get('USE_CUDA_DOCKER', 'false') if USE_CUDA.lower() == 'true': @@ -87,7 +88,7 @@ class JSONFormatter(logging.Formatter): def format(self, record: logging.LogRecord) -> str: log_entry: dict[str, Any] = { - 'ts': datetime.fromtimestamp(record.created, tz=timezone.utc).isoformat(timespec='milliseconds'), + 'ts': dt.datetime.fromtimestamp(record.created, tz=dt.UTC).isoformat(timespec='milliseconds'), 'level': _LEVEL_MAP.get(record.levelname, record.levelname.lower()), 'msg': record.getMessage(), 'caller': record.name, @@ -180,7 +181,7 @@ def parse_section(section): try: changelog_path = BASE_DIR / 'CHANGELOG.md' - with open(str(changelog_path.absolute()), 'r', encoding='utf8') as file: + with open(str(changelog_path.absolute()), encoding='utf8') as file: changelog_content = file.read() except Exception: @@ -339,7 +340,7 @@ DATABASE_SCHEMA = os.environ.get('DATABASE_SCHEMA', None) DATABASE_POOL_SIZE = os.environ.get('DATABASE_POOL_SIZE', None) -if DATABASE_POOL_SIZE != None: +if DATABASE_POOL_SIZE is not None: try: DATABASE_POOL_SIZE = int(DATABASE_POOL_SIZE) except Exception: @@ -652,7 +653,7 @@ if LICENSE_PUBLIC_KEY: -----BEGIN PUBLIC KEY----- {LICENSE_PUBLIC_KEY} -----END PUBLIC KEY----- -""".encode('utf-8') +""".encode() )