Repository navigation
rip does not follow spec for handling of pre-releases #118
Description
Currently rip does not accept a pre-release if there are no other packages, but the documentation states the follow: https://packaging.python.org/en/latest/specifications/version-specifiers/#handling-of-pre-releases
By default, dependency resolution tools SHOULD: ... accept remotely available pre-releases for version specifiers where there is no final or post release that satisfies the version specifier
But rip excludes all pre-releases even if nothing else is available:
e.g. cargo r -- opentelemetry-exporter-prometheus rusults in:
× Could not solve for the requested requirements:
│ The following packages are incompatible
│ |-- opentelemetry-exporter-prometheus * cannot be installed because there are no viable options:
│ |-- opentelemetry-exporter-prometheus 1.12.0rc1 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 1.10a0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.42b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.41b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.40b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.39b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.38b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.37b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.36b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.35b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.34b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.33b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.32b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.30b1 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.30b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.29b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.17b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.16b1 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.16b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.15b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.14b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.13b0 is excluded because prereleases are not allowed
│ |-- opentelemetry-exporter-prometheus 0.12b0 is excluded because prereleases are not allowed
In my opinion there should be an option to force exclude pre release packages and keep this behavior, but this does come up in the Python ecosystem naturally: #74 (comment)
By the way, my understanding is Pip's behavior is to do this when collecting packages, but not when backtracking transitive dependencies, I have a question on the Python board if this is really following the spec: https://discuss.python.org/t/handeling-of-pre-releases-when-backtracking/40505
Activity
[-]rip does not follow spec for handeling packages with only pre-releases[/-][+]rip does not follow spec for handling of pre-releases[/+]notatallshaw commentedon Dec 7, 2023
FYI, the discussion on the thread questions the behavior I have described for Pip: https://discuss.python.org/t/handling-of-pre-releases-when-backtracking/40505/4
I will try and reproduce, but I will do this seperarelty from rip and file a Pip bug if I find the behavior does not match the comment I linked in all cases.
tdejager commentedon Dec 14, 2023
Yes we should fix this definitely we just have not come around to it yet!
notatallshaw commentedon Jan 10, 2024
Some updates on the Python discussion board: https://discuss.python.org/t/handling-of-pre-releases-when-backtracking/40505/10
It's clear to me now that what Pip does here "selects a pre-release if all releases are pre-releases" and what the spec says are different.
@wolfv if any RIP maintainers would like to provide any feedback there on any changes they would like to see here (Pip documentation on what they do, update spec to Pip or something different, change in Pip behavior to the spec, etc.) I'm sure input would be appreciated.
wolfv commentedon Jan 10, 2024
Thanks @notatallshaw for pointing this out. To be honest, what
pipimplements would be quite straightforward to implement for us, too. So we might start out with that :)The
--preflag to get all possible pre-releases would also continue to work.notatallshaw commentedon Jan 10, 2024
Sounds good to me, and sounds like the spec should be updated. Although, when I get a chance, I will check what Poetry does.
I would still strongly prefer there be an option to exclude all pre-releases. I would really like to not be surprised in prod that a pre-release slipped in. But maybe this use case is too niche.
wolfv commentedon Jan 10, 2024
We have that as an option in the
enum:It might be the better default ... although, as you noted, will prevent some packages from resolving.
baszalmstra commentedon Jan 10, 2024
Hey @notatallshaw ! Thanks for pitching and for the link! I would also be very interested in what Poetry does!
notatallshaw commentedon Jan 11, 2024
As best as I can tell, Poetry appears to follow the spec for direct dependencies, but struggles when resolving transative dependencies: https://discuss.python.org/t/handling-of-pre-releases-when-backtracking/40505/11
tdejager commentedon Jan 11, 2024
So if we want to follow pip's rules, which rules should we follow? I'm getting a bit lost in the details here. I initially wrote down: #4 but not sure where I got that idea from anymore.
Then there's @pradyun comment:
Which seem quite reasonable.
But @notatallshaw you've also noted in: https://discuss.python.org/t/handling-of-pre-releases-when-backtracking/40505/11 that pip either does or does not use pre-releases when backtracking? Which kind-of comes back to #4. But also does not make a whole lot of sense to me. Although poetry does not consider transitive pre-release dependencies?
Maybe @wolfv @notatallshaw could clearly lay out the rules that pip follows in this thread or in the linked one so that we have a written down reference to follow, instead of just code :)
wolfv commentedon Jan 11, 2024
I would like to follow what Pradyun laid out.
jupyterlab==4.1.0b0then use the pre-release. Ortoml>=4.0.1b0. This is easy for us to implement because this means just a "local" check in the comparison operator.Although there will be some trickery involved in implementing the first rule while also implementing the second rule, so let's see (since we cannot just filter out the pre-releases anymore).
tdejager commentedon Jan 11, 2024
So what we discussed what we could do is to change the
containsof thePyPiVersionSetto have global information regarding if pre-releases are allowed for thatVersionSeteither by the consequence of there only being pre-releases for that package version, allowing all pre-releases by the user, or by being explicitely selected e.g.>1.0a0.Note that the the
pep440_rscrate includes the matching of pre-releases by default so:So take care when implementing this :)
E.g if you have 2 packages
Adepends onfoo==1.0a0Bdepends onfoo>=0.9If we first process
Aand the pre-releases are added forfoo, and we subsequently processBif we naively match, it would be totally fine using1.0.a0because according pep440_rs the versionset contains this version. This might not be what we want, at least that's the gist I get from your last comment @wolfv .If you have a lot of problems with this you can always implement
containsfor thepep440_rs::Versionyourself, and explicitely exclude pre-releases.tdejager commentedon Jan 11, 2024
@notatallshaw The final point of unclarity for me remains in the comment in the python discourse thread w.r.t backtracking and transitive dependencies, including the poetry comment. Hoping you can clarify :)!
So in my head there are two cases:
a 1.0 -> b 1.0 -> c 1.0aBut I suppose in both cases you should just look at which candidates would match the
VersionSet, so I don't really see why one would make a difference to how that works when compared to direct dependencies.That is if the direct dependency
foo >= 1.0.0does not select pre-releases (disregarding the case for this example when there are only pre-releases) thena -> foowherefoo >= 1.0.0Should also not select pre-releases. Alternatively, if it does select them for direct dependencies it should also do so for both case 1 and 2.However, if I read your posts correctly it seems that:
Am I correct in my reading of this?
notatallshaw commentedon Jan 11, 2024
I'm a bit confused by the different questions, let me outline the scenario I was thinking about when I originally started that thread:
a == 1.0, b == 1.0- For simplicity these are the only versions availablea -> c != 1.0b -> c != 2.01.0,2.0, and3.0a1I thought this case was special for Pip when I opened the thread because I thought Pip followed the spec. But now I think (but haven't tested) that this case is not special for Pip because for Pip this is no different than normal, Pip see's C as having non-prerelease versions and none of the requirements involve a pre-release specifier so Pip will not choose
3.0a1. So this is exactly in-line with Pip's expectations.I think Poetry also doesn't choose
3.0a1for C but considers it a bug, but I haven't tested, I'm just going off from what I read on their issue tracker. Possibly it's far more nuanced.I still don't think Pip is consistent in how it handles this, the real world motivation for me initially thinking about this was a user reported an issue to Pip that they were gets a
ResolutionImpossibleerror. They were on Apple Silicon and if they installedtensorflowdirectly it worked with a pre-release version (the only version available in that environment), but when tensorflow was a transitive dependency they got theResolutionImpossibleerror. If someone is interested and has an Apple Silicon machine, they can use PyPI timemachine to reproduce: pypa/pip#12049Finally, and I think your questions are getting at this (?), I have not even thought about the scenario where one or both of the specifiers include a pre-release:
a == 1.0, b == 1.0- For simplicity this is the only versions availablea -> c > 2.0a1b -> c != 2.01.0,2.0, and3.0a1I would suspect Pip's behavior is the same as to whether it is a transitive dependency or not and depends on the order it is checking the specifiers.
pandas>2.1.4 pandas>=2.1.5rc0pandas>=2.1.5rc01 pandas>2.1.4And which specifier operators are being used:
pandas>2.1.5rc01pandas>=2.1.5rc01Off to report more issues to the Pip tracker.
tdejager commentedon Jan 11, 2024
Wow, I would expect that in both the cases
pandas>2.1.4 pandas>=2.1.5rc0andpandas>=2.1.5rc01 pandas>2.1.4it should not have a solution. Is that also what you would expect?Also, the second example with the specifier caught me off-guard as well.
notatallshaw commentedon Jan 11, 2024
I thought both of them should have a solution, but either way I would prefer consistency.
Some further discussion on Pip's state of affairs on one of the issues I raised: pypa/pip#12471 (comment)
IMO Pip's situation is the following:
But, as per the discussion I link to, this is all likely because the logic was implemented before there was a spec, and there hasn't been a significant interest in working on this aspect of requirement resolution.
Fow now I think RIP is going to need to make it's own choices, document it's own intended behavior, and take a pragmatical approach of what works in the Python ecosystem.
pfmoore commentedon Jan 11, 2024
Pip maintainer here - I disagree with this explanation.
IMO, pip isn't following the spec, but it should be. That's a bug in pip. That's all. It's not a bug we'll be able to fix quickly (so if rip follows the spec, it will behave differently than pip in some edge cases, probably for some time) but it is "just" a bug.
Talk of pip's "intended behaviour" basically comes down to a couple of pip maintainers (one of whom was me) having mentioned what they thought pip did as part of a discussion. It was a statement of what we think the code does, not a claim that it's intentional (much less that it's intentionally different to the spec!)
notatallshaw commentedon Jan 11, 2024
Apologies, it seems I misinterpreted some statements.
I have been confused on this point over the course of this conversation, because of you saying that the spec says SHOULD and MAY that Pip could be interpreted as not violating the spec (which, in some sense, I am taking to have an equivelence as "following the spec").
I think this, with an outlining of behavior of what the code in Pip does, and the highlighting that Pip may have implemented this behavior before there was a spec, is what led to my mistaken assumption of Pip's "intended" behavior.
tdejager commentedon Jan 12, 2024
Nice to see a fruitful discussion coming out of this. Also both @notatallshaw and @pfmoore, thank you for all the hard work you are doing, I've really learned a lot about the pypa/pypi packaging space these last month, and all of your help has been invaluable. 🙏 😃
I think for now we will be going with an implementation that is close to pip, and disregards some of the spec, of course we would rather follow it, but I have the feeling it might change in the coming time. @wolfv is working on an implementation already: #141