From fff41e1895e8f98777452adc8cad16e870c5bf1b Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 30 Apr 2025 00:36:59 +0100 Subject: [PATCH] use SettingsConfigDict add Optional annotations patch bump --- obsws_cli/__about__.py | 2 +- obsws_cli/app.py | 15 ++++++------- obsws_cli/sceneitem.py | 49 ++++++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/obsws_cli/__about__.py b/obsws_cli/__about__.py index d5f6aa1..1fcd12a 100644 --- a/obsws_cli/__about__.py +++ b/obsws_cli/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2025-present onyx-and-iris # # SPDX-License-Identifier: MIT -__version__ = "0.10.0" +__version__ = "0.10.1" diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 405d833..ef037a2 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -1,12 +1,11 @@ """Command line interface for the OBS WebSocket API.""" from pathlib import Path -from typing import Annotated +from typing import Annotated, Optional import obsws_python as obsws import typer -from pydantic import ConfigDict -from pydantic_settings import BaseSettings +from pydantic_settings import BaseSettings, SettingsConfigDict from . import ( group, @@ -27,7 +26,7 @@ from .alias import AliasGroup class Settings(BaseSettings): """Settings for the OBS WebSocket client.""" - model_config = ConfigDict( + model_config = SettingsConfigDict( env_file=( '.env', Path.home() / '.config' / 'obsws-cli' / 'obsws.env', @@ -71,10 +70,10 @@ def version(ctx: typer.Context): @app.callback() def main( ctx: typer.Context, - host: Annotated[str, typer.Option(help='WebSocket host')] = None, - port: Annotated[int, typer.Option(help='WebSocket port')] = None, - password: Annotated[str, typer.Option(help='WebSocket password')] = None, - timeout: Annotated[int, typer.Option(help='WebSocket timeout')] = None, + host: Annotated[Optional[str], typer.Option(help='WebSocket host')] = None, + port: Annotated[Optional[int], typer.Option(help='WebSocket port')] = None, + password: Annotated[Optional[str], typer.Option(help='WebSocket password')] = None, + timeout: Annotated[Optional[int], typer.Option(help='WebSocket timeout')] = None, ): """obsws_cli is a command line interface for the OBS WebSocket API.""" settings = Settings() diff --git a/obsws_cli/sceneitem.py b/obsws_cli/sceneitem.py index 0329683..cbea91f 100644 --- a/obsws_cli/sceneitem.py +++ b/obsws_cli/sceneitem.py @@ -1,7 +1,7 @@ """module containing commands for manipulating items in scenes.""" from collections.abc import Callable -from typing import Annotated +from typing import Annotated, Optional import typer @@ -34,7 +34,10 @@ def _validate_scene_name_and_item_name( """Validate the scene name and item name.""" def wrapper( - ctx: typer.Context, scene_name: str, item_name: str, parent: bool = False + ctx: typer.Context, + scene_name: str, + item_name: str, + parent: Optional[str] = None, ): if not validate.scene_in_scenes(ctx, scene_name): typer.echo(f"Scene '{scene_name}' not found.") @@ -57,7 +60,7 @@ def _validate_scene_name_and_item_name( def _get_scene_name_and_item_id( - ctx: typer.Context, scene_name: str, item_name: str, parent: str + ctx: typer.Context, scene_name: str, item_name: str, parent: Optional[str] = None ): if parent: resp = ctx.obj.get_group_scene_item_list(parent) @@ -82,7 +85,7 @@ def show( ctx: typer.Context, scene_name: str, item_name: str, - parent: Annotated[str, typer.Option(help='Parent group name')] = None, + parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None, ): """Show an item in a scene.""" scene_name, scene_item_id = _get_scene_name_and_item_id( @@ -104,7 +107,7 @@ def hide( ctx: typer.Context, scene_name: str, item_name: str, - parent: Annotated[str, typer.Option(help='Parent group name')] = None, + parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None, ): """Hide an item in a scene.""" scene_name, scene_item_id = _get_scene_name_and_item_id( @@ -126,7 +129,7 @@ def toggle( ctx: typer.Context, scene_name: str, item_name: str, - parent: Annotated[str, typer.Option(help='Parent group name')] = None, + parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None, ): """Toggle an item in a scene.""" if not validate.scene_in_scenes(ctx, scene_name): @@ -169,7 +172,7 @@ def visible( ctx: typer.Context, scene_name: str, item_name: str, - parent: Annotated[str, typer.Option(help='Parent group name')] = None, + parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None, ): """Check if an item in a scene is visible.""" if parent: @@ -211,51 +214,51 @@ def transform( ctx: typer.Context, scene_name: str, item_name: str, - parent: Annotated[str, typer.Option(help='Parent group name')] = None, + parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None, alignment: Annotated[ - int, typer.Option(help='Alignment of the item in the scene') + Optional[int], typer.Option(help='Alignment of the item in the scene') ] = None, bounds_alignment: Annotated[ - int, typer.Option(help='Bounds alignment of the item in the scene') + Optional[int], typer.Option(help='Bounds alignment of the item in the scene') ] = None, bounds_height: Annotated[ - float, typer.Option(help='Height of the item in the scene') + Optional[float], typer.Option(help='Height of the item in the scene') ] = None, bounds_type: Annotated[ - str, typer.Option(help='Type of bounds for the item in the scene') + Optional[str], typer.Option(help='Type of bounds for the item in the scene') ] = None, bounds_width: Annotated[ - float, typer.Option(help='Width of the item in the scene') + Optional[float], typer.Option(help='Width of the item in the scene') ] = None, crop_to_bounds: Annotated[ - bool, typer.Option(help='Crop the item to the bounds') + Optional[bool], typer.Option(help='Crop the item to the bounds') ] = None, crop_bottom: Annotated[ - float, typer.Option(help='Bottom crop of the item in the scene') + Optional[float], typer.Option(help='Bottom crop of the item in the scene') ] = None, crop_left: Annotated[ - float, typer.Option(help='Left crop of the item in the scene') + Optional[float], typer.Option(help='Left crop of the item in the scene') ] = None, crop_right: Annotated[ - float, typer.Option(help='Right crop of the item in the scene') + Optional[float], typer.Option(help='Right crop of the item in the scene') ] = None, crop_top: Annotated[ - float, typer.Option(help='Top crop of the item in the scene') + Optional[float], typer.Option(help='Top crop of the item in the scene') ] = None, position_x: Annotated[ - float, typer.Option(help='X position of the item in the scene') + Optional[float], typer.Option(help='X position of the item in the scene') ] = None, position_y: Annotated[ - float, typer.Option(help='Y position of the item in the scene') + Optional[float], typer.Option(help='Y position of the item in the scene') ] = None, rotation: Annotated[ - float, typer.Option(help='Rotation of the item in the scene') + Optional[float], typer.Option(help='Rotation of the item in the scene') ] = None, scale_x: Annotated[ - float, typer.Option(help='X scale of the item in the scene') + Optional[float], typer.Option(help='X scale of the item in the scene') ] = None, scale_y: Annotated[ - float, typer.Option(help='Y scale of the item in the scene') + Optional[float], typer.Option(help='Y scale of the item in the scene') ] = None, ): """Set the transform of an item in a scene."""