diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8706c6..7c3ac429 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +- Fixes a bug where some location options did not accept yaml aliases + (#390, thanks for reporting @zany130). + ## v3.2.4 (2024-07-07) - Fixes a bug preventing organize from starting (thanks @feather42). diff --git a/organize/location.py b/organize/location.py index 0bbc64c4..d30beda0 100644 --- a/organize/location.py +++ b/organize/location.py @@ -1,9 +1,9 @@ -from typing import List, Literal, Set, Union +from typing import List, Literal, Union -from pydantic import ConfigDict, Field, field_validator +from pydantic import ConfigDict, Field from pydantic.dataclasses import dataclass -from .validators import FlatList +from .validators import FlatList, FlatSet DEFAULT_SYSTEM_EXCLUDE_FILES = { "thumbs.db", @@ -25,27 +25,14 @@ class Location: min_depth: int = 0 max_depth: Union[Literal["inherit"], int, None] = "inherit" search: Literal["depth", "breadth"] = "breadth" - exclude_files: Set[str] = Field(default_factory=set) - exclude_dirs: Set[str] = Field(default_factory=set) - system_exclude_files: Set[str] = Field( + exclude_files: FlatSet[str] = Field(default_factory=set) + exclude_dirs: FlatSet[str] = Field(default_factory=set) + system_exclude_files: FlatSet[str] = Field( default_factory=lambda: DEFAULT_SYSTEM_EXCLUDE_FILES ) - system_exclude_dirs: Set[str] = Field( + system_exclude_dirs: FlatSet[str] = Field( default_factory=lambda: DEFAULT_SYSTEM_EXCLUDE_DIRS ) filter: Union[List[str], None] = None filter_dirs: Union[List[str], None] = None ignore_errors: bool = False - - @field_validator( - "exclude_files", - "exclude_dirs", - "system_exclude_files", - "system_exclude_dirs", - mode="before", - ) - @classmethod - def ensure_set(cls, value): - if isinstance(value, str): - return set([value]) - return set(value) diff --git a/organize/validators.py b/organize/validators.py index ca4bd74a..258fb8bf 100644 --- a/organize/validators.py +++ b/organize/validators.py @@ -26,3 +26,4 @@ def flatten(x: Any): T = TypeVar("T") FlatList = Annotated[List[T], BeforeValidator(flatten)] +FlatSet = Annotated[List[T], BeforeValidator(flatten)]