-
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
Pass Install Extras to Markers #9553
base: main
Are you sure you want to change the base?
Conversation
… with active root extras
I will try to take a closer look at the end of the week. |
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 looks really good. Nice work. 👍
It looks like some of the changes are not tested yet or may be redundant. See separate comments for details.
""" | ||
Marker values, per: | ||
1. marker_env of `self._env` | ||
2. 'extras' will be added to the 'extra' marker if not already present |
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.
- cannot happen, can it?
if "extra" not in result: | ||
result["extra"] = set(extras) | ||
else: | ||
result["extra"] = set(result["extra"]).union(extras) |
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 do not think that it is possible that extra
is already present. This might even be an error. Thus, maybe we just assert "extra" not in result
.
@@ -860,7 +881,7 @@ def _is_relevant_marker( | |||
get_python_constraint_from_marker(marker) | |||
) | |||
and (active_extras is None or marker.validate({"extra": active_extras})) | |||
and (not self._env or marker.validate(self._env.marker_env)) | |||
and (not self._env or marker.validate(self._marker_values(active_extras))) |
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 change should not be necessary because extras are already handled one line above (no matter if self._env
is set or not).
@@ -601,7 +620,9 @@ def complete_package( | |||
|
|||
# For dependency resolution, markers of duplicate dependencies must be | |||
# mutually exclusive. | |||
active_extras = None if package.is_root() else dependency.extras | |||
active_extras = ( | |||
self._active_root_extras if package.is_root() else dependency.extras |
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.
Seems like that is not tested yet. (Tests succeed without this change.) You probably have to add a test similar to test_solver_resolves_duplicate_dependency_in_extra
, which tests this for non root extras.
@@ -541,7 +555,12 @@ def complete_package( | |||
if dep.name in self.UNSAFE_PACKAGES: | |||
continue | |||
|
|||
if self._env and not dep.marker.validate(self._env.marker_env): | |||
active_extras = ( | |||
self._active_root_extras if package.is_root() else dependency.extras |
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.
Seems like the non root part is not tested yet. (Tests succeed when replacing dependency.extras
with None
.) Maybe, this path can be triggered by taking one of your tests and introducing an intermediate package?
and ( | ||
not self._env | ||
or dep.marker.validate( | ||
self._marker_values( | ||
self._active_root_extras | ||
if dependency_package.package.is_root() | ||
else dependency_package.dependency.extras | ||
) | ||
) | ||
) |
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.
It looks like this change is not required by any test. To be honest, I have currently no idea if this change is redundant or if a test is missing...
Thank you so much for the great feedback here! All the comments make sense to me, I'm working through it and will submit updates and responses later this week |
How would this differentiate between the
poetry install -E cuda124 and define the in the package [tool.poetry.extras]
cuda124 = ["torch"] Here your suggestion would add [tool.poetry.dependencies]
python = "^3.10"
torch = [
{ markers = "extra == 'cuda124'", version = "2.4.0+cu124", optional = true},
^^^^^^
poetry add "pandas[aws]" which would show in the [tool.poetry.dependencies]
python = "^3.11"
pandas = {extras = ["aws"], version = "^2.2.2"}
^^^^^ Would the differentiation be made on the following?
If so, I must have misunderstood the docs because I thought these 2 syntaces express the same requirements/constraints |
I apologize for the long delay here, I had to pause this before I managed to finish all the updates. But it hasn't left my mind, and I'll be able to resume the updates in a couple weeks and will push them up and respond to everything in mid-September! Thanks for the patience |
Pull Request Check List
Resolves:
poetry install
, but respected inpip install
#7748This PR exposes the
extras
supplied at install to the 'extra' marker for dependencies, taking up @radoering's offer to create a PR implementing this functionality to allow switching torch installation versions based on acuda
extra.It is a duplicate of the feature in python-poetry/poetry-core#613 but it appears that PR is no longer active, with the last updates in August 2023 and an unanswered question about timeline from March 2024. This PR takes a different approach: I noticed that python-poetry/poetry-core#636 added special handling for the
extras
marker value but that marker isn't populated often, so I opted to populate the value when extras are specified in the installer.See issues and unit tests for more details but the idea is to, among other things, enable exclusive extras like so:
@radoering it looks like you're very familiar with this issue, would you be the right person to review? 🙏
I'm sure I'm missing something here but look forward to iterating!
Edit by @radoering: fix links to poetry-core PRs