Skip to content

Commit

Permalink
Cache underlying can_install version checks (#1624)
Browse files Browse the repository at this point in the history
Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
  • Loading branch information
bdraco and ludeeus authored Nov 5, 2020
1 parent b7bb223 commit c17b222
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/hacs/helpers/functions/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Helper functions: misc"""
import re
import semantic_version
from functools import lru_cache

RE_REPOSITORY = re.compile(
r"(?:(?:.*github.com.)|^)([A-Za-z0-9-]+\/[\w.-]+?)(?:(?:\.git)?|(?:[^\w.-].*)?)$"
Expand All @@ -26,6 +27,7 @@ def get_repository_name(repository) -> str:
)


@lru_cache(maxsize=1024)
def version_left_higher_then_right(new: str, old: str) -> bool:
"""Return a bool if source is newer than target, will also be true if identical."""
if not isinstance(new, str) or not isinstance(old, str):
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/misc/test_version_is_newer_than_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def test_wierd_stuff():
assert version_left_higher_then_right("1.0.0", "1.0.0rc0")
assert not version_left_higher_then_right(None, "1.0.0rc0")
assert not version_left_higher_then_right(1.0, "1.0.0rc0")
assert not version_left_higher_then_right({}, "1.0.0rc0")
assert not version_left_higher_then_right("0", "1.0.0rc0")

0 comments on commit c17b222

Please sign in to comment.