-
Notifications
You must be signed in to change notification settings - Fork 267
feat(markers): support 'extras' and 'dependency_groups' markers #888
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
Conversation
Signed-off-by: Frost Ming <me@frostming.com>
Signed-off-by: Frost Ming <me@frostming.com>
5af59cc
to
200c455
Compare
Signed-off-by: Frost Ming <me@frostming.com>
The PR LGTM (and thanks, @frostming !), but since @pradyunsg wrote most of the code being changed I want to give him a chance to do a review if he has the time. If not I will merge this in about a week. |
src/packaging/markers.py
Outdated
@@ -308,7 +318,7 @@ def evaluate(self, environment: dict[str, str] | None = None) -> bool: | |||
The environment is determined from the current Python process. | |||
""" | |||
current_environment = cast("dict[str, str]", default_environment()) | |||
current_environment["extra"] = "" | |||
current_environment.update(extra="", extras=set(), dependency_groups=set()) |
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 not be setting these in the evaluation environments unconditionally, since that would allow packages to use the extras
and dependency_groups
marker variables in regular dependency declarations (outside of the context of a lockfile).
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 would make it ~impossible for downstream tools to implement the following behaviour from PEP 751's specification update:
Outside of the context of lock files, these two variables should result in an error like all other unknown variables.
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 would be good to add an explicit test for the unknown variable error case that this pertains to.
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.
Outside of the context of lock files, these two variables should result in an error like all other unknown variables.
But other unknown markers are thrown as InvalidMarker
errors during the parse phase. Should we, and can we keep consistent for extras
? That may require a different version of parsing function, possibly with a flag
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 made it a "should" statement for a reason. We could add a flag to evaluate()
to specify the context and also clean things up for extra
while we are at it, otherwise there's precedent of this code being sloppy/permissive in what it accepts.
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.
@brettcannon thanks for the clarification, not sure if I interpret your feedback correctly
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.
What I was thinking was instead of a for_lock
argument, we have a context
argument. That would take an enum that specified under what context the marker was being evaluated. We could have metadata
which matches what it does now where extra
is always set (and would be the default). We could have lock_file
which doesn't have extra
but has extras
and dependency_groups
always set. And then we could have requirement
which has none of extra
, extras
, or dependency_groups
automatically set.
FYI I'm not attached to any of these names.
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.
@pradyunsg does the approach Frost took work for you (it does for me)?
Signed-off-by: Frost Ming <me@frostming.com>
Signed-off-by: Frost Ming <me@frostming.com>
8fbf371
to
28a9c05
Compare
Signed-off-by: Frost Ming <me@frostming.com>
28a9c05
to
6f37ebf
Compare
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.
Just a docstring change and docs will need updating.
Co-authored-by: Brett Cannon <brett@python.org>
Signed-off-by: Frost Ming <me@frostming.com>
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 think
Lines 61 to 74 in e624d8e
.. method:: evaluate(environment=None) | |
Evaluate the marker given the context of the current Python process. | |
:param dict environment: A dictionary containing keys and values to | |
override the detected environment. | |
:raises: UndefinedComparison: If the marker uses a comparison on strings | |
which are not valid versions per the | |
:ref:`specification of version specifiers | |
<pypug:version-specifiers>`. | |
:raises: UndefinedEnvironmentName: If the marker accesses a value that | |
isn't present inside of the environment | |
dictionary. | |
:rtype: bool |
FYI linting failed. |
Signed-off-by: Frost Ming <me@frostming.com>
LGTM! We will give @pradyunsg until next week to weigh in, else I will merge this. |
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.
Let's do this! Thanks @frostming!
Signed-off-by: Frost Ming me@frostming.com
Resolve #885