aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-11-20 00:35:01 +0100
committerDaniel Schadt <kingdread@gmx.de>2022-11-20 00:35:48 +0100
commit97835c471bc10bd20e1253e1bbfd71e5e71b2883 (patch)
tree5dc37408adeae5740f8664b10bb569e40fc9c5c1
parent66487086b5d9e64d67144efe7f34ebbe502f0dd8 (diff)
downloadfietsboek-97835c471bc10bd20e1253e1bbfd71e5e71b2883.tar.gz
fietsboek-97835c471bc10bd20e1253e1bbfd71e5e71b2883.tar.bz2
fietsboek-97835c471bc10bd20e1253e1bbfd71e5e71b2883.zip
remove bisect.insort
This is due to compatibility reasons, such that the code works in Python <3.10.
-rw-r--r--fietsboek/pages.py10
-rw-r--r--fietsboek/updater/__init__.py4
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()