From 3897b0d5729dfd9fe2201ea3a383757ba9f76450 Mon Sep 17 00:00:00 2001 From: Valentin Berlier Date: Tue, 20 Feb 2024 09:38:34 +0100 Subject: [PATCH] fix: utf8 everywhere --- beet/contrib/livereload.py | 2 +- beet/core/cache.py | 2 +- beet/core/watch.py | 2 +- beet/toolchain/config.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/beet/contrib/livereload.py b/beet/contrib/livereload.py index 55d62421..7e1a8d26 100644 --- a/beet/contrib/livereload.py +++ b/beet/contrib/livereload.py @@ -161,7 +161,7 @@ def decorator(callback: LogCallback): def target(self, path: FileSystemPath, callback: LogCallback): queue: List[str] = [] - with open(path, "r", errors="ignore") as f: + with open(path, "r", encoding="utf-8", errors="ignore") as f: f.seek(0, 2) while not self.event.is_set(): diff --git a/beet/core/cache.py b/beet/core/cache.py index f4c79466..49be7f4a 100644 --- a/beet/core/cache.py +++ b/beet/core/cache.py @@ -74,7 +74,7 @@ def __init__( self.directory = Path(directory).resolve() self.index_path = self.directory / self.index_file self.index = ( - json.loads(self.index_path.read_text()) + json.loads(self.index_path.read_text("utf-8")) if self.index_path.is_file() else self.get_initial_index() ) diff --git a/beet/core/watch.py b/beet/core/watch.py index ee382bc5..1927a6ab 100644 --- a/beet/core/watch.py +++ b/beet/core/watch.py @@ -46,7 +46,7 @@ def __post_init__(self): if ignore_file.is_file(): self.ignore_patterns += [ pattern - for line in ignore_file.read_text().splitlines() + for line in ignore_file.read_text("utf-8").splitlines() if not line.startswith("#") and (pattern := line.strip()) ] diff --git a/beet/toolchain/config.py b/beet/toolchain/config.py index 9616c457..2e3898ef 100644 --- a/beet/toolchain/config.py +++ b/beet/toolchain/config.py @@ -403,11 +403,11 @@ def load_config( if not path: config: Any = {} elif path.suffix == ".toml": - config = toml.loads(path.read_text()) + config = toml.loads(path.read_text("utf-8")) elif path.suffix in [".yml", ".yaml"]: - config = yaml.safe_load(path.read_text()) + config = yaml.safe_load(path.read_text("utf-8")) else: - config = json.loads(path.read_text()) + config = json.loads(path.read_text("utf-8")) if not config: config = {}