-
Notifications
You must be signed in to change notification settings - Fork 2.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
[optimize] early-ignore dependencies not matching chosen markers #4956
base: main
Are you sure you want to change the base?
[optimize] early-ignore dependencies not matching chosen markers #4956
Conversation
This is helpful for many use-cases, where we can narrow the scope environment markers in advance - for example, the code will be developed, tested and deployed only on linux with python 3.8. Consider this example on the environment with linux and python 3.8
As of now poetry prepares several variants which takes 6 overrides. NOTE: the original proposal used CLI to push constraints. The approach below suggested by @radoering seems better. This PR extends the
Then |
I played around a bit. On its own it works fine, but I think there are still some things to think about:
|
Thanks for getting back with valuable comments. Definitely got your point regarding 2) and 3). Note that poetry is already not secured against such cases if downstream packages don't cover environment markers exhaustively (for example, if a package puts only linux markers poetry will match this lock against my windows and will not install anything...). This PR was inspired by use-cases of developers who work on the similar code in similar environments and so can narrow the system combinations. Also, the logic of python constraints is sometimes broken #3444 so this is one more use case. I updated the PR accordingly. Constraints are moved to a dedicated section in the This should mitigate your concerns 2) and 3) I suppose, as the rules would be transparent. In addition:
|
I think this is getting a lot closer to a useful/mergable state. Putting the environment constraints into the pyproject is absolutely the right way to go here. There is a bit more work to be done, and I'm thinking this should go into 1.3 instead of 1.2, but I think this will be a useful addition. |
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.
Looks like this needs a rebase and adjustment for the current state of master. Additionally, I would like to see the docs rewritten to both be more generalize, drop references to this PR, add link to related topics in the docs, and include more examples. It also needs to document the target_env
section in general (with a link to the example usage).
Finally, I'm not convinced the name target_env
is a good one for this section. Something like extra_constraints
might be more descriptive and intuitive.
@@ -67,6 +67,13 @@ class InstallCommand(InstallerCommand): | |||
flag=False, | |||
multiple=True, | |||
), | |||
option( |
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.
This option is dead and should be removed (given the move to using the pyproject.toml).
@@ -37,6 +37,14 @@ def create_poetry( | |||
if io is None: | |||
io = NullIO() | |||
|
|||
# redirect to the extended schema (from poetry, not from poetry-core) |
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.
We should be updating the schema in poetry-core as well, even if the implementation is in poetry only. The intention is to drop all schemas from this repo.
@@ -249,7 +256,21 @@ def _do_install(self, local_repo: Repository) -> int: | |||
self._io, | |||
) | |||
|
|||
ops = solver.solve(use_latest=self._whitelist).calculate_operations() | |||
if ( |
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'm not 100% on if this is the only way to get at the config, but this smells to me. I'm pretty sure you should be able to get at the Config
object from here, or at least create one from a Factory if not.
src/poetry/puzzle/provider.py
Outdated
self._markers_to_filter | ||
): | ||
self.debug( | ||
f"<warning>Removing {dep} due to markers {dep.marker} not matching the target platform</warning>" |
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.
f"<warning>Removing {dep} due to markers {dep.marker} not matching the target platform</warning>" | |
f"<warning>Removing {dep} due to markers ({dep.marker}) not matching the target environment.</warning>" |
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.
Adjusted as per your suggestion.
+1 for this. We have a big project in our team, each time poetry solves the dependencies it already takes more than 10 minutes (each try). However, we know beforehand the version we want as well as the platform, so retries to have a solution that valid everywhere is redundant and a big waste of resources. Currently in our project we have to retries around 20 times, making the whole process super slow, sometimes can be upto 4 hours. |
@neersighted apologizes for the absence—I overlooked the notifications from this topic. If there is still interest in this, I am ready to work on this in upcoming days. |
@maciejskorski This is definitely something worth revisiting now that we have 1.2 out -- though I must say I have limited bandwidth to help get this over the finish line right now. @radoering or @finswimmer might be good maintainers to work with if they are available... (sorry for throwing y'all under the bus!) |
First things first. Let's talk about the representation in pyproject.toml. Current proposal is something like:
It might be useful to support multiple platforms. There are at least two alternatives for that: Lists:
Our (afaik at least partially internal) constraint syntax:
Since our marker handling has improved a lot since this PR was created, an alternative design specifying a PEP 508 compliant environment marker that describes the supported environment, might be possible, e.g.:
This approach is more powerful (but also more verbose). You can define conditions that are not possible with the original (and extended) approach, e.g.
However, I wonder if such use cases even exist. Any thoughts which representation should be chosen? |
I could believe that there are use cases for wanting to express complex top-level markers eg see #6447 in which a user was battling this
As for how this gets written in |
This is something I would be keen to have and implement. However, @radoering, are we absolutely sure that the current marker implementation is mature and correct? Could you advise me on some examples where complex logic (like nested and/or) are tested? |
I'm quite confident in the current implementation. It's possible that very complex expressions are not recognized to be empty, but I think it's good enough for real world use cases. The tests are in poetry-core in test_marker.py, e.g. https://github.com/python-poetry/poetry-core/blob/b0b18230a5eeabe16d0000c67dd40d15a3d8f0e5/tests/version/test_markers.py#L412-L432 |
Just wondering what the status of this was? |
I'd say it is stalled. Maybe, I'll pick this up myself sometime in the future, but at the moment there are many other topics with a higher priority on my list. Thus, nothing to be expected from me here in the next few months. |
Pull Request Check List
Resolves:
#4952
#4670
#6118
#5121