Skip to content

Commit

Permalink
use FlatSet validator in locations (fixes #390)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Jul 9, 2024
1 parent 126e0ea commit 42c9ac3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
27 changes: 7 additions & 20 deletions organize/location.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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)
1 change: 1 addition & 0 deletions organize/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ def flatten(x: Any):

T = TypeVar("T")
FlatList = Annotated[List[T], BeforeValidator(flatten)]
FlatSet = Annotated[List[T], BeforeValidator(flatten)]

0 comments on commit 42c9ac3

Please sign in to comment.