Fix #284: implement "is compatible with" method#368
Fix #284: implement "is compatible with" method#368tomschr merged 1 commit intopython-semver:masterfrom
Conversation
|
Thanks @Lexicality for your review! Much appreciated! 👍 |
|
Probably worth mentioning in the docstring that this comparison ignores patch versions and giving a couple of examples? |
Yes, also something for the documentation. On my todo list. 🙂 |
c31c53a to
46e5f23
Compare
|
Hi @Lexicality (and to whom who are interested): Thank you very much! |
|
@tomschr great work! Tests comparing a release with a pre-release and major-0 versions (initial development) are missing; |
Thanks. 😊
@rafalkrupinski Ahh yes, right. I'm not completely sure if I understood your sentence. Do you mean something like this: |
8643560 to
edb81ba
Compare
|
Ah, poor grammar, sorry.
|
|
@rafalkrupinski Thanks Raphael for your help. 👍 I've amended your examples in If I read item 9 from the Semver spec correct, the other way around, it should be True, right? Version(1,0,0, 'rc1.').is_compatible(Version(1,0,0))
# returns TrueBecause, |
I think you're referring to this:
That's just ordering, not compatibility.
That's |
37733f3 to
c58e709
Compare
Ok, that's it! Thanks. I've corrected the tests now. Would you go through it and have a final look? |
|
Oh, one thought that just came into my mind: do we want to make the |
Thanks
Yes, that was also my take on this. 😄 Probably I was confused between ordering and compatibility. You've mentioned these two lines:
The tests are okay now. Maybe could you elaborate on the two lines, please? Many thanks! |
|
I don't know how to link comments on code...
|
c58e709 to
2be3b6a
Compare
Well, not really. My intention was to check against incompatible types, as "anything that is not a Version" is incompatible. Of course, a derived class from Version should be allowed. Ahh, you are right, this expression: should be: Not sure why I came up with this nonsense. 😄 I will amend the tests.
Ahh, right. Good catch! It gives back major, minor, and patch. Not the pre-release. Should be Both parts are now added (the first part contains also an additional test case). |
2be3b6a to
3823fbb
Compare
|
@Lexicality, @tlaferriere anything that should be changed or improved from your side? Thanks! |
39ee6b1 to
753771d
Compare
|
@Lexicality, @tlaferriere, @sbrudenell, @rafalkrupinski Thanks for all your help. Could you have a final look at this PR? The changes what I did was mostly about documentation: document the deprecation of Please let me know if you are okay with that. Don't stress yourself, it's fine after the public holidays. 😉 If you don't object I would merge it some time next week. Many thanks! |
|
Not sure about the wording of this section.
Alternatively:
I'm missing instruction on how to use it in real life. E.g.:
Basically document the caller/callee description that we ditched earlier. And BTW, I think this best describes the method and it makes its behaviour clear:
Code examples
# Two different majors:
>>> a = Version(1, 1, 1)
>>> b = Version(2, 0, 0)
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
False
# Two different minors:
>>> a = Version(1, 1, 0)
>>> b = Version(1, 0, 0)
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
True
# The same two majors and minors:
>>> a = Version(1, 1, 1)
>>> b = Version(1, 1, 0)
>>> a.is_compatible(b)
True
>>> b.is_compatible(a)
True
# Release and pre-release:
>>> a = Version(1, 1, 1)
>>> b = Version(1,0,0,'rc1')
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
False
# Different pre-releases:
>>> a = Version(1, 0, 0, 'rc1')
>>> b = Version(1, 0, 0, 'rc2')
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
False
# Identical pre-releases
>>> a = Version(1, 0, 0,'rc1')
>>> b = Version(1, 0, 0,'rc1')
>>> a.is_compatible(b)
True |
753771d to
2c346d4
Compare
|
@rafalkrupinski Thanks a lot Raphael. This is gold! 🥇 You are right with the examples. I used your code and added it there. 👍 Regarding the real-life examples, I agree. I'm still trying to find good a explanation and wording. I will amend it later. I have some questions/comments regarding your description of the
When I apply these changes from above, this would lead to: The expression
I know, it's longer. However, I think, it's clearer. Many thanks and much appreciated your feedback! 👍 |
72f25b6 to
93fdc4e
Compare
Minor parts don't have to be higher than zero to be compatible.
|
😆 Luckily, we don't have to follow Perl. 😉
Ah, I see. Hmn. I think, the term "release" could be mistaken by "pre-release" (as I did). I would like to avoid this. That's why I wrote in all of the documentation about "versions", not "releases".
I know, but for your item ""their majors are equal and higher than 0 and minor versions"" I interpret it as such. 🙂 |
Perhaps you're just so immersed in this project and the lingo, that you've just read what you expected to read ;) Releases and pre-releases have different compatibility rules, so you can't just replace 'release' with 'version', unless you write 'version other than pre-release', but to me it's just indirect way of writing 'release' 🤷🏻. Back to square one.
Missing coma perhaps? Don't let my bad grammar put you off track ;) Hopefully this approach is clearer: #368 (comment) |
|
@rafalkrupinski @Lexicality @tlaferriere Thanks for all your help! |
* Implement Version.is_compatible() method * Update test cases * Update documentation * Rename isvalid method to is_valid to make it consistent with is_compatible The result is True, if either of the following is true: * both versions are equal, or * both majors are equal and higher than 0. Same for both minors. Both pre-releases are equal, or * both majors are equal and higher than 0. The minor of b's minor version is higher then a's. Both pre-releases are equal. The algorithm does *not* check patches! Co-authored-by: Lexi Robinson <lexi@lexi.org.uk> Co-authored-by: Thomas Laferriere <tlaferriere@users.noreply.github.com> Co-authored-by: Raphael Krupinski <rafalkrupinski@users.noreply.github.com>
93fdc4e to
5485b6b
Compare
|
As nobody seemed to object, I'm merging it. Thank you! |
This is a first implementation of
Version.is_compatible.The algorithm checks:
@rafalkrupinski /@sbrudenell / @Lexicality maybe you want to try/review it? 🙂
TODOs