-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Allow overriding constraints with '-o' in constraints file. #11537
Allow overriding constraints with '-o' in constraints file. #11537
Conversation
Did you get the issue number wrong? |
It should have been #8076. I'm baffled by the explanation here, though, @mauritsvanrees. Your example constraints file:
makes no sense to me. Why wouldn't you just replace it with one that says
? Maybe I need to go back and read the extensive debate on the original thread, but I frankly don't have the time or inclination to do so right now. And in any case, this PR will need to include documentation, and that documentation will need to explain what the feature is for, what issues it will address, and how it will work, without expecting the reader to know all of the history on that issue. So why not give a standalone explanation here, so that people can evaluate the PR on its own merits? |
Having now re-read the thread, I think I prefer @notatallshaw's proposal of a completely separate "overrides" file rather than trying to include this in the existing constraints file. I appreciate that a proposal with a PR has a significant advantage over a proposal that no-one has bothered to implement, regardless of any other factors, but I understood the design of the override file proposal pretty much straight away, whereas I find the "override constraint" approach a lot more confusing. I guess you could argue that the two are equivalent, as you can take all the I'm also not convinced that the implementation here would work. At a minimum, please add a test that demonstrates that overriding works as required. |
I'm a bit confused by reading the code of this implementation, does it actually override transitive dependency requirements? |
@pfmoore Sorry, you are right, this PR assumes too much knowledge on the original issue. About my strange example:
This was meant as an easy test to show that the PR works: you have a constraint and you can override it. In practice it would be used to override an upstream constraints file:
Let me show some real world examples of what I want to enable. Example: Plone 5.2 with two newer packagesPlone 5.2 works on both Python 2.7 and Python 3.8. Here we use 3.8.
Both packages have beta versions that only work on Python 3. I want to use them. So I create this constraints file:
Create a virtualenv using a pip clone, on main for now, and try to use the above constraints file to install the smallest of the two packages:
Now try the same with my pip branch and using the new overrides spelling:
Let's try the second package for good measure, which pulls in lots more packages:
Example: editable package from constraintsLet's stick with the same packages. Now I want to use a checkout of
Now with my branch:
I actually need this to work when running tests for these two packages on gh-actions or locally. Currently I am using an extra tool that was created this year by someone in the Plone community to solve this use case:
It would be nice if we don't need to rely on such a tool created in one community, as it makes it harder for new developers to start working on a package. @notatallshaw writes:
That is not my intention, but I think it currently does, so I may need to change this. My intention is to honour any minimum or maximum version requirements in any Some people in the original issue do want to be able to override a version even if |
Ah, that's what I assumed you were trying to do, as that's basically what #8076 is about. For your use case, you should just edit the existing constraints file. I don't think we need a new option just for that, sorry. |
@pfmoore wrote:
There is a warning by @uranusjr that I would summarise as: the parsing of requirements and constraints files is already difficult; if we would add a third type of file the difficulty would even increase. But then, me adding I could have a go at an overrides file. One of my examples above would then become this:
The allowed format within Probably |
The existing constraints file is on an upstream server. So I would need to download it, manually edit it, and store it in git. And do this in every project where I need something similar. Then upstream releases a new version of the constraints file. I need to download it, compare it with the previous original, manually edit it, and store it in git again. Or have a script that downloads it, and use for example And then another developer looks at the project where I did this, and instead of a clear constraints url with two updated pins, she sees a local constraints file of 500 lines (yes, Plone is big), which is probably Plone 5.2.9, but zero, one, or more pins may have been updated, and it is not immediately clear which ones they are. That is not really an option for me. |
Let me put this differently. Regardless of the implementation, I see two options:
I was aiming for number 2, but currently have number 1, which is easier. @pfmoore You prefer number 1 here? I could work with that. |
I personally have no use for any of this, but my understanding of #8076 is that it is solely about telling the resolver to use a specific version of a package, ignoring all other dependency specifications and accepting that the resulting environment will probably fail Being able to override values from a constraints file is, as far as I can tell, an almost entirely accidental side-effect of that requirement. For this PR to be acceptable, I'd want some sort of consensus from the participants in that other issue that it addresses their needs. |
Yes, I agree with @pfmoore here, my understanding of (and definitely my proposal in) #8076 is to give some level of control to the user to outright replace transitive dependency requirements with something other than how they are specified by the downstream projects. My proposal is that just as the primary purpose of a constraints file is to constraint transitive dependencies that an overrides file's primary purpose would be to override transitive dependencies. In my view this gives the user a lot of control that is not easy to replicate with simple scripts. It seems to me that purpose of this PR is that an upstream project has a constraints file but you would like to modify it or merge it with your own constraints. While this seems totally valid to me it also seems not too difficult to implement outside Pip. If I had that problem I would be tempted to make a package that could download multiple constraints files and merge them based on the order which I specified them. But maybe there's something I'm missing here. |
FWIW, if we do go down the route of a overrides file, IMO it shouldn't be a part of the options that requirements or constraints file can take within them, but a separate file entirely. It's reasonable to limit it to only allow |
I am against creating another file. Constraint is a constraint - it must be satisfied no matter what, as the name suggests. Having 2 terms, and 2 files: override and constraint is confusing. The important thing is what |
I think someone should make a new issue for what exactly is being requested here and what problems it solves so the discussion can be focused on if this is a good proposal or not. The merits of the problem that this PR is solving and what #8076 is asking for are very different. E.g.
But in #8076 overrides are not constraints, they are a way to override transitive dependency requirements, not constrain them, they therefore have very different behavior in practice. And I agree with @pradyunsg should be implemented in a very limited fashion and only expanded if legitimate requirements come up for it. This PR though is intended to just deal with constraints, hence the confusion. |
IMO, if this PR isn't intended to address #8076 then I'm -1 on it. |
Quoting @pfmoore who quotes @notatallshaw:
Even though it was not my intention, this PR does currently address it. So I think it could still be considered. But these new possibilities make this a tool that is a bit too sharp for my taste, so I will stop my efforts here. If someone else wants to pick this up, go ahead. I'll close this PR but keep the fork and branch for now. I think the basis works, but the next items are needed to take this to completion:
For my own use case, I was hoping to be able to only override constraints, and not override requirements from
I was trying to avoid needing a separate tool for this. But that goes against your comment, which I can understand. So I will use |
mxdev looks nice, but if it' doesn't enter pip, there is no sustained future on the idea.... |
This is one approach of solving issue #8076, you know, the one with over one hundred comments. I had basically the same idea as @PiotrDabkowski expressed in one of the most recent comments: extend the syntax of what you can say in a constraints file.
Let's show what it can do with a simple package without any dependencies.
So I requested version 3.1.0, then overrode this with version 3.0.0, and the override was installed.
The package is used in Plone, or at least included in the Plone constraints file. Installing an editable version of a package that is pinned in a constraints file, is not possible, see issue #8307. But with this PR we can override it without a version pin:
The implementation is rather easy: a few lines of (perhaps too manual) parsing of a line starting with
-o
or --override, adding
is_overrideto the
InstallRequirementclass and several functions, and then checking
is_override` when getting the constraints of the root requirements.Obviously this needs tests and documentation, which I won't (or shouldn't) have time for soon. But what do you think: would this solve most problems, without giving people a too powerful gun to shoot in their own foot?