-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Plugin that configures line endings before writing out files.""" | ||
|
||
|
||
__all__ = [ | ||
"LineEndingsOptions", | ||
"line_endings", | ||
] | ||
|
||
|
||
from typing import Any, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from beet import Context, ListOption, TextFileBase, configurable | ||
|
||
|
||
class LineEndingsOptions(BaseModel): | ||
extensions: ListOption[str] = ListOption() | ||
newline: Optional[str] = None | ||
|
||
|
||
def beet_default(ctx: Context): | ||
ctx.require(line_endings) | ||
|
||
|
||
@configurable(validator=LineEndingsOptions) | ||
def line_endings(ctx: Context, opts: LineEndingsOptions): | ||
"""Plugin that configures line endings before writing out files.""" | ||
for pack in ctx.packs: | ||
for _, text_file in pack.list_files( | ||
*opts.extensions.entries(), | ||
extend=TextFileBase[Any], | ||
): | ||
text_file.newline = opts.newline |