diff options
-rw-r--r-- | fietsboek/pages.py | 10 | ||||
-rw-r--r-- | fietsboek/updater/__init__.py | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/fietsboek/pages.py b/fietsboek/pages.py index 5556038..e94a493 100644 --- a/fietsboek/pages.py +++ b/fietsboek/pages.py @@ -1,5 +1,4 @@ """Module containing logic to support "static" pages.""" -import bisect import enum import re @@ -147,7 +146,14 @@ class Pages: page = Page.parse(source) except PageException as exc: raise PageException(f"Error reading `{path}`: {exc}") from None - bisect.insort(self.collection, page, key=lambda page: page.menu_index) + # The following could be done "more efficiently", but bisect.insort + # only supports the key argument starting from Python 3.10. Since we + # assume that the amount of pages is (very) anyway, and the pages are + # loaded at application startup, it is not worth trying to come up with + # clever solutions here. Just do the ovious thing and re-sort the list + # after every insertion. + self.collection.append(page) + self.collection.sort(key=lambda page: page.menu_index) def load_directory(self, path): """Load a directory full of pages. diff --git a/fietsboek/updater/__init__.py b/fietsboek/updater/__init__.py index 7878f8e..a5bcf0e 100644 --- a/fietsboek/updater/__init__.py +++ b/fietsboek/updater/__init__.py @@ -109,7 +109,7 @@ class Updater: :return: The versions, or an empty list if no versions are found. """ try: - versions = self.version_file.read_text().split("\n") + versions = self.version_file.read_text(encoding="utf-8").split("\n") return [version.strip() for version in versions if version.strip()] except FileNotFoundError: return [] @@ -136,7 +136,7 @@ class Updater: :param version: The versions to stamp. :type version: list[str] """ - self.version_file.write_text("\n".join(versions)) + self.version_file.write_text("\n".join(versions), encoding="utf-8") def _pick_updates(self, wanted, applied, dependencies): to_apply = set() |