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

Add PackageSpec.from_wheel #18

Merged
merged 2 commits into from
Sep 26, 2023
Merged

Conversation

bollwyvl
Copy link
Contributor

@bollwyvl bollwyvl commented Sep 16, 2023

References

Changes

  • adds PackageSpec.from_wheel
  • build wheel before test in CI (it's used in the test)
  • add [wheel] extra with packaging and pkginfo
  • ignore TYPE_CHECKING blocks in coverage reporting
  • update changelog

Questions

  • is this even the right way to go?
  • while self-testing the wheel is cute, perhaps real fixtures would be better?

@bollwyvl bollwyvl marked this pull request as ready for review September 18, 2023 12:47
Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bollwyvl sorry I missed this PR. Two comments but otherwise LGTM.

pyodide_lock/utils.py Show resolved Hide resolved
raise RuntimeError(f"Could not parse wheel metadata from {path.name}")

return PackageSpec(
name=_normalized_name(metadata.name),
Copy link
Member

@rth rth Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's correct to use normalized names here and in dependencies. I think it should be the package names found in the METADATA file in the wheel?

Copy link
Contributor Author

@bollwyvl bollwyvl Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp... working on various tools, I've had a lot of issues using anything other than the normalized names without having to to assume they need to be re-normalize every single time a comparison/lookup is done.

The wheel artifact name is absolute, of course, and shouldn't be messed with... even though that has now been "standardized" to lowercased _, the vast bulk of them out there aren't.

This APIs on PyPI have long been lowerecase- normalized.

But due to the above baggage, the contents of Requires-Dist in wheels also don't have normalized names, such that in using them verbatim would make it possible to have two packages in the same lockfile that specify the same effective dependency with different cases.

I think as a bespoke lockfile format, normalizing everything on ingest is the right play, and indeed, might consider further tightening the schema with a JSON Schema compatible regex. pip and friends which do have to support all the millions of wheels are already going to have to do normalizing, so even if a lockfile is the input to another process that builds HTML, downstreams will be able to handle pyyaml vs PyYAML just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually gone a bit further, using the already-used packaging.utils.canonicalize_name all over. The tests added in b01b33b show how this might change expectations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I feel like this should go even further, and hoist the various regexen to pattern on name and depends so they make it all the way to #3. pydantic 1.x and 2.x both have constr, but sadly require regex or pattern, respectively, while the likely preferable typing.Annotated route probably doesn't work in 1.x. So probably picking a major version to support would clear things up.

@rth rth mentioned this pull request Sep 25, 2023
Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds good to me. Thanks for the detailed explanation! Also given #20 (comment) let's go forward with it.

@rth rth merged commit 082390b into pyodide:main Sep 26, 2023
3 checks passed
@bollwyvl bollwyvl deleted the gh-9-pkgspec-from-wheel branch September 26, 2023 22:04
@bollwyvl
Copy link
Contributor Author

Cheers, thanks.

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

Successfully merging this pull request may close these issues.

2 participants