Skip to content
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

Fix/delegate __lt__ to PackageVersionLike #448

Merged

Conversation

Karrenbelt
Copy link

@Karrenbelt Karrenbelt commented Nov 17, 2022

Proposed changes

Delegate comparison operations to PackageVersionLike._version in custom __lt__ methods on custom data types: PackageVersion, PublicId and PackageId.

Fixes

If it fixes a bug or resolves a feature request, be sure to link to that issue.

Types of changes

What types of changes does your code introduce to agents-aea?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING doc
  • I am making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Lint and unit tests pass locally with my changes and CI passes too
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that code coverage does not decrease.
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Comment on lines -1008 to 1009
v3 = PackageVersion("latest")
v3 = PackageVersion("0.12.0")
assert v1 < v2 < v3
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work otherwise, test was not proper since relied on string comparison ("0" < "l" == True)

Copy link
Author

@Karrenbelt Karrenbelt Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: we do not delegate to semver.VersionInfo to maintain the ability to use "latest" and "any", however we cannot compare PackageVersion("1.0.0") < PackageVersion("latest"), which will raise ValueError: latest is not valid SemVer string due to the deflection. See Version.__lt__ and Version.compare

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this change does not make sense at all, the latest version should always be the superior when comparing to other versions.

Copy link
Author

@Karrenbelt Karrenbelt Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Au contraire mon ami.

  • This change would have made the original implementation fail.
  • Comparing "latest" should not always return True, in case latest is equal to current version being compared to. In this sense "latest" is a property.
  • We also have this "any" which poses another issue.

Hence, additional tests are required to cover these cases, for which I can stack a PR later this week. Prior to that, however, we need to decide how to deal with these. As I stated in my base PR (#428) we should reconsider whether we want to maintain "any" and "latest".

put a #428 (comment) in base PR to address later so we can merge #445, #447 and #448 into it.

Comment on lines -115 to 121
sorted_expected = list(map(str, sorted(self.expected_dependencies)))
sorted_missing = list(map(str, sorted(self.missing_dependencies)))
expected = list(map(str, self.expected_dependencies))
missing = list(map(str, self.missing_dependencies))
print("=" * 50)
print(f"Package {self.configuration_file}:")
print(f"Expected: {pprint.pformat(sorted_expected)}")
print(f"Missing: {pprint.pformat(sorted_missing)}")
print(f"Expected: {pprint.pformat(expected)}")
print(f"Missing: {pprint.pformat(missing)}")
print("=" * 50)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sortable when author and name differ

Comment on lines -249 to +252
flat_tree.append(
sorted(
{package for package in tree_level if package not in dirty_packages}
)
)
flat_tree.append([])
for package in tree_level:
if package not in dirty_packages and package not in flat_tree[-1]:
flat_tree[-1].append(package)
Copy link
Author

@Karrenbelt Karrenbelt Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sortable, this way we obtain a unique set that maintains a deterministic ordering

@Karrenbelt Karrenbelt changed the title Fix/delegate __lt__ to PackageVersionLike [1.25.0] Fix/delegate __lt__ to PackageVersionLike Nov 17, 2022
@Karrenbelt Karrenbelt changed the title [1.25.0] Fix/delegate __lt__ to PackageVersionLike [WIP - 1.25.0] Fix/delegate __lt__ to PackageVersionLike Nov 17, 2022
@Karrenbelt Karrenbelt changed the title [WIP - 1.25.0] Fix/delegate __lt__ to PackageVersionLike [WIP] Fix/delegate __lt__ to PackageVersionLike Nov 28, 2022
@angrybayblade angrybayblade marked this pull request as draft December 14, 2022 14:27
@Karrenbelt Karrenbelt force-pushed the fix/delegate_to_PackageVersionLike branch from 2ec503d to 4784ac1 Compare December 17, 2022 18:26
@Karrenbelt Karrenbelt force-pushed the fix/delegate_to_PackageVersionLike branch from f6889df to 779c951 Compare December 17, 2022 18:39
@codecov-commenter
Copy link

codecov-commenter commented Dec 18, 2022

Codecov Report

Base: 97.31% // Head: 97.30% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (f4aea8d) compared to base (f269b13).
Patch coverage: 92.30% of modified lines in pull request are covered.

Additional details and impacted files
@@                   Coverage Diff                    @@
##           fix/data_types__lt__     #448      +/-   ##
========================================================
- Coverage                 97.31%   97.30%   -0.01%     
========================================================
  Files                       221      221              
  Lines                     19543    19548       +5     
========================================================
+ Hits                      19018    19022       +4     
- Misses                      525      526       +1     
Flag Coverage Δ
unittests 97.30% <92.30%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aea/configurations/data_types.py 99.16% <75.00%> (-0.28%) ⬇️
aea/cli/check_packages.py 96.81% <100.00%> (ø)
aea/helpers/base.py 100.00% <100.00%> (ø)
aea/helpers/dependency_tree.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

aea/helpers/base.py Outdated Show resolved Hide resolved
@Karrenbelt Karrenbelt marked this pull request as ready for review December 18, 2022 16:38
queue.extendleft(sorted(roots)) # type: ignore
queue.extendleft(sorted(roots, key=str)) # type: ignore
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this guarantees the ordering of root nodes is deterministic, and hence the returned List[T] of find_topological_order will be as well.

@Karrenbelt Karrenbelt changed the title [WIP] Fix/delegate __lt__ to PackageVersionLike Fix/delegate __lt__ to PackageVersionLike Dec 19, 2022
@DavidMinarsch DavidMinarsch merged commit 9276d3a into fix/data_types__lt__ Dec 19, 2022
@DavidMinarsch DavidMinarsch deleted the fix/delegate_to_PackageVersionLike branch December 22, 2022 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants