-
Notifications
You must be signed in to change notification settings - Fork 85
Add APIs to compare sbt.librarymanagement.VersionNumbers. #218
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
Conversation
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.
hi @tlockney!
thank you for your PR! I've been spending some time on it today. I started reviewing it (1 initial comment) but because I didn't personally know this part of the codebase I spent time getting to know it and cleaning it up, leading to my creating #221 and #222.
having done that I will return to review the work you've done here. I'm happy to rebase your work onto my refactoring if you'd like, just let me know.
def >(o: VersionNumber)(implicit ord: Ordering[VersionNumber]): Boolean = | ||
ord.compare(this, o) > 0 | ||
def >=(o: VersionNumber)(implicit ord: Ordering[VersionNumber]): Boolean = | ||
ord.compare(this, o) >= 0 |
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.
perhaps we can reuse Ordering
's inner Ops
class here?
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.
done 07e9a2d
Hey @dwijnand, I think you meant to tag @tanishiking on this. :-) |
cool, thanks. I'll ping you when (if) they're accepted. |
first off, my interpretation is that in SemVer pre-release identifiers cannot be hyphen-separated, only dot-separated. looking at I'm not sure what we should do to fix this, but I would highlight that pre-release version ordering is pretty niche, not mentioned in sbt/sbt#3710, and in my opinion never going to work anyways because from my experience people (sbt included!) don't dot-separate their prerelease identifiers, e.g sbt version
hehehe I looked the history here and found a comment from me in 2014 :) I agree with you: we should compare case-insensitively. I wonder though whether we should change the implementation of going to review your implementation next |
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 have one more request.
other than that the implementation looks ok.
after we can rebase I'd like to just review the test cases present and missing, and I'm sure we can merge this speedily.
def zero: A = z | ||
} | ||
implicit val StringZero: Zero[String] = Zero[String]("") | ||
implicit val LongZero: Zero[Long] = Zero[Long](0L) |
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 don't think we should introduce such a typeclass universally in sbt.librarymanagement.
Let's move it into VersionNumber, so it's a VersionNumber specific utility only.
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.
done b67a16e
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.
misclicked approve :)
Thank you for reviewing!
Oh, sorry I misunderstood SemVer. After reading https://semver.org/#spec-item-11 again, indeed it is described.
I agree with you! OK, in this PR, I'll leave it :)
Awesome, thanks! Hmm... looking at discussion in semver/semver#176 I think we should change the implementation of |
looking again this PR is introducing an I'm not 100% sure because I don't know what it means to have methods based on and if it needs to be consistent we should enforce that it is (with testing). |
I changed the
Sorry I couldn't catch your feedback. Which do you mean by "consistent"?
|
I think we should just delegate |
def <(o: VersionNumber): Boolean = this < o | ||
def <=(o: VersionNumber): Boolean = this <= o | ||
def >(o: VersionNumber): Boolean = this > o | ||
def >=(o: VersionNumber): Boolean = this >= o |
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.
these definitions are circular
12e7bd7
to
526c3b8
Compare
Thank you for the explanation. I understood!
I agree with you (and tried to implement it e745970) but to do that we have to either
I prefer the latter one. what do you think about this? |
526c3b8
to
e745970
Compare
I'm torn. to add to your list of options there is option 3: don't put the SemVer-honoring in implicit scope, but make it opt-in. we should evaluate in terms of the effect it would be have on the use case presented in #3710 meanwhile my refactoring in #222 is rebased and green. but @eed3si9n is currently on holiday until next week. |
@tanishiking please note that #222 is now merged. |
c08a469
to
a449bd2
Compare
a449bd2
to
63500d9
Compare
Thank you for ping (and sorry for my late reply), rebased. But, after considering the use case presented in sbt/sbt#3710 some days, I came to realize that we should implement an api like semantic version selectors which is given by some package managers like npm (e.g. The reason why implementing VersionNumber's ordering wouldn't be adequate to resolve sbt/sbt#3710 is below.
On the other hand, semantic version selectors realize the use case presented in #3710 without introducing a ordering that is not commonly specified or would breaks symmetry rule. |
@tanishiking I'm sorry for leaving you hanging. In retrospect I realise that I should have forewarned you that I (and Eugene) were going to be busy and afk all of last week. I think you're right and we should go for something like those selectors to avoid conflicting concerns. Please let me know if you need a hand. |
@dwijnand It's no problem :)
OK, I'll try to implement something like that selector and close this PR, thank you for discussing about this! |
Addresses sbt/sbt#3710.
This PR implements APIs to compare
sbt.librarymanagement.VersionNumber
s.Approach
This implementation basically follows https://semver.org/#spec-item-11.
Precedence is determined by the first difference when comparing each of these identifiers from left to right as follows
When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version
identifiers consisting of only digits are compared numerically
identifiers with letters or hyphens are compared lexically in ASCII sort order
Numeric identifiers always have lower precedence than non-numeric identifiers.
A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal.
Questions
VersionNumber#(un)apply
seems not support separation by dots. Is this deliberately? Or should we implement it? (Or am I misunderstanding semantic-versioning?)References