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

ignore trailing .0 in version comparison #196

Merged
merged 5 commits into from
May 26, 2023
Merged

Conversation

wolfv
Copy link
Contributor

@wolfv wolfv commented May 25, 2023

Not sure if this is the cleanest way of implementing this behavior, but in order to fix #194 we need to ignore trailing 0 when comparing versions for equality.

Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

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

Can this code also be found somewhere in the conda codebase? I followed that pretty closely.

crates/rattler_conda_types/src/version/mod.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

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

Can this code also be found somewhere in the conda codebase? I followed that pretty closely.

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

I can try to find the place in the conda code but this was an issue i observed while debugging resolvelib stuff

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

And this is the code in conda:

    def _eq(self, t1, t2):
        for v1, v2 in zip_longest(t1, t2, fillvalue=[]):
            for c1, c2 in zip_longest(v1, v2, fillvalue=self.fillvalue):
                if c1 != c2:
                    return False
        return True

https://github.com/conda/conda/blob/61edfac743a2461a24fafe48b821a99af61b6bd4/conda/models/version.py#L244-L249

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

Btw. I think we're also missing an compare of the epoch of the two versions.

@baszalmstra
Copy link
Collaborator

Nice!

  • I thinkthe epoch is always included in the components even if not specified. So it is also taken into account.

  • if you can implement the comparison as part of the PartialEq of VersionComponent this should be good. This comparison holds for both the version amd the local.

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

I am confused by the follownig:

    /// The epoch of this version. This is an optional number that can be used to indicate a change
    /// in the versioning scheme.
    norm: String,

The norm doesn't seem to be the epoch but rather the string representation of the version?

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

E.g. this is what I see in debug print:

Version { norm: "1.2.0", version: [[0], [1], [2], [0]], local: [] }
Version { norm: "1!1.2.3", version: [[1], [1], [2], [3]], local: [] }

@wolfv
Copy link
Contributor Author

wolfv commented May 25, 2023

I attempted what you asked but there I am a bit unsure about a couple things.

I had to add #[derive(Eq)] to the Version for some reason.

Also I had to implement a custom hash function. I am now removing all default values (0) from the hash. Clippy was warning that the hash function needs to match the PartialEq function.

@baszalmstra
Copy link
Collaborator

This looks good to me! The warning about the hash is also very correct! Very nice!

The norm is a bit of an odd duck. It represents "sorta" the string it was initially created from. This can be important because (as you've seen with this issue) multiple version representations can represent the exact same version. The norm sorta enables keeping track of that. However, modifications to the Version are also not expressed in the norm which is actually just plain wrong. Maybe we should remove it and implement a proper Display for Version.

@baszalmstra baszalmstra merged commit 200f5df into conda:main May 26, 2023
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.

Double check that libabseil matchspec matches a package
2 participants