Skip to content
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

Implement PEP 685 #526

Closed
5 of 6 tasks
brettcannon opened this issue Mar 22, 2022 · 13 comments
Closed
5 of 6 tasks

Implement PEP 685 #526

brettcannon opened this issue Mar 22, 2022 · 13 comments

Comments

@brettcannon
Copy link
Member

brettcannon commented Mar 22, 2022

https://peps.python.org/pep-0685/

@brettcannon
Copy link
Member Author

brettcannon commented Apr 24, 2022

I think if we update:

def _coerce_parse_result(results: Union[ParseResults, List[Any]]) -> List[Any]:
if isinstance(results, ParseResults):
return [_coerce_parse_result(i) for i in results]
else:
return results

... to coerce extra comparisons immediately after parsing, then that's probably the easiest way to get the value normalized (for printing, writing, etc.). Then we have to worry about comparisons, which may be in:

def _eval_op(lhs: str, op: Op, rhs: str) -> bool:
try:
spec = Specifier("".join([op.serialize(), rhs]))
except InvalidSpecifier:
pass
else:
return spec.contains(lhs, prereleases=True)
oper: Optional[Operator] = _operators.get(op.serialize())
if oper is None:
raise UndefinedComparison(f"Undefined {op!r} on {lhs!r} and {rhs!r}.")
return oper(lhs, rhs)

... or:

elif isinstance(marker, tuple):
lhs, op, rhs = marker
if isinstance(lhs, Variable):
lhs_value = _get_env(environment, lhs.value)
rhs_value = rhs.value
else:
lhs_value = lhs.value
rhs_value = _get_env(environment, rhs.value)
groups[-1].append(_eval_op(lhs_value, op, rhs_value))

There's also separate work for requirements for the self.extras attribute:

self.extras: Set[str] = set(req.extras.asList() if req.extras else [])

@brettcannon
Copy link
Member Author

Thanks to @hroncok we have a PR to normalize the comparison. I have an in-progress PR on my local machine which normalizes for the string representation of markers.

@hroncok
Copy link
Contributor

hroncok commented May 10, 2022

BTW I am sorry for not searching for this issue first. I should have and I have no idea why I haven't :(

@brettcannon
Copy link
Member Author

BTW I am sorry for not searching for this issue first. I should have and I have no idea why I haven't :(

No worries! My in-progress PR isn't wasted regardless since the hardest part in it is normalizing at parse time for __str__().

brettcannon added a commit to brettcannon/packaging that referenced this issue May 12, 2022
This guarantees that getting the string representation of a marker is always normalized for extras.

Part of pypa#526
brettcannon added a commit that referenced this issue May 20, 2022
This guarantees that getting the string representation of a marker is always normalized for extras.

Part of #526
@brettcannon
Copy link
Member Author

Now that markers normalizes everything, I don't think requirements needs an update for extras. Any issues with those fields can (eventually) be handled by metadata.

@ofek
Copy link
Sponsor Contributor

ofek commented Jul 4, 2022

Any update on this?

@brettcannon
Copy link
Member Author

I think we can declare this as done as it's going to be for now. 😁 I just pushed the docs for packaging.utils.NormalizedName and packaging.utils.canonicalize_name(). I don't think this needs to wait for anything in packaging.metadata.

@ofek
Copy link
Sponsor Contributor

ofek commented Jul 4, 2022

Nice! Any ETA for pip to upgrade its bundled copy of this?

@brettcannon
Copy link
Member Author

Nice! Any ETA for pip to upgrade its bundled copy of this?

That's a @pradyunsg question.

@pradyunsg
Copy link
Member

If we cut a packaging release early in this month (say, next week or so) then it'd be in pip 22.2 (due by end of month).

@ofek
Copy link
Sponsor Contributor

ofek commented Jul 23, 2022

22.2 was released

@Julian
Copy link

Julian commented Jul 25, 2022

@ofek not sure if that comment was meant to point this out too but this didn't make it into pip 22.2 right? Ostensibly because this repo needs a release first right @pradyunsg? Or am I misunderstanding still what's left for this one.

@Julian
Copy link

Julian commented Jul 25, 2022

Ah, sorry to double post, but I see #569 is the ticket asking for a release, so this is still "blocked" on that on the pip side if I understand correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants