-
Notifications
You must be signed in to change notification settings - Fork 13
CFE-4559: cfbs convert, part 2
#276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,11 @@ | ||||||||||||||
| from collections import OrderedDict | ||||||||||||||
| import os | ||||||||||||||
| from typing import Iterable, List | ||||||||||||||
|
|
||||||||||||||
| from cfbs.utils import dict_sorted_by_key, file_sha256 | ||||||||||||||
|
|
||||||||||||||
| Version = str | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider making this a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree, the intention was to make that change separately, though. Especially since other code uses functions using this type. |
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def initialize_vcf(): | ||||||||||||||
| versions_dict = {"versions": {}} | ||||||||||||||
|
|
@@ -141,5 +144,47 @@ def sort_versions(versions: list, reverse: bool = True): | |||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def highest_version(versions): | ||||||||||||||
| def highest_version(versions: Iterable[Version]): | ||||||||||||||
| return max(versions, key=version_as_comparable_list, default=None) | ||||||||||||||
|
Comment on lines
+147
to
148
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ref the asserts and comments below;
Suggested change
And the same for |
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def lowest_version(versions: Iterable[Version]): | ||||||||||||||
| return min(versions, key=version_as_comparable_list, default=None) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def is_lower_version(version_a: Version, version_b: Version): | ||||||||||||||
| """Returns `True` if and only if `version_a` is lower than `version_b`.""" | ||||||||||||||
|
|
||||||||||||||
| return version_as_comparable_list(version_a) < version_as_comparable_list(version_b) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def most_relevant_version( | ||||||||||||||
| other_versions: List[Version], reference_version: Version | ||||||||||||||
| ) -> Version: | ||||||||||||||
| """ | ||||||||||||||
| The most relevant version is the highest version among older other versions, | ||||||||||||||
| or if there are no older other versions, the lowest version among other versions. | ||||||||||||||
|
|
||||||||||||||
| `other_versions` is assumed to be non-empty and not contain `reference_version`.""" | ||||||||||||||
| assert len(other_versions) > 0 | ||||||||||||||
| assert reference_version not in other_versions | ||||||||||||||
|
|
||||||||||||||
| highest_other_version = highest_version(other_versions) | ||||||||||||||
| lowest_other_version = lowest_version(other_versions) | ||||||||||||||
| # Unfortunately, Pyright can not infer that these can't be `None` when `other_versions` is non-empty. | ||||||||||||||
| assert highest_other_version is not None | ||||||||||||||
| assert lowest_other_version is not None | ||||||||||||||
|
Comment on lines
+174
to
+176
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These asserts are repeating, maybe it's more useful if we change |
||||||||||||||
|
|
||||||||||||||
| if is_lower_version(highest_other_version, reference_version): | ||||||||||||||
| # all other versions are older | ||||||||||||||
| return highest_other_version | ||||||||||||||
| if is_lower_version(reference_version, lowest_other_version): | ||||||||||||||
| # all other versions are newer | ||||||||||||||
| return lowest_other_version | ||||||||||||||
| # there are both older and newer versions | ||||||||||||||
| lower_other_versions = [ | ||||||||||||||
| o_v for o_v in other_versions if is_lower_version(o_v, reference_version) | ||||||||||||||
| ] | ||||||||||||||
| highest_lower = highest_version(lower_other_versions) | ||||||||||||||
| assert highest_lower is not None | ||||||||||||||
| return highest_lower | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by arbitrarily-shaped sequence?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that since the list of the multiple other versions might be incontiguous, it can't be displayed as a range, for example. So it's best to simply not display all the versions and instead choose one.