pypa / packaging

Core utilities for Python packages
https://packaging.pypa.io/
Other
620 stars 248 forks source link

Make it possible to check/validate requirements and versions online #670

Open pradyunsg opened 1 year ago

pradyunsg commented 1 year ago

I'm imagining this would help users hit by #631 and friends. Pyodide seems like the right tool for the job.

/cc @rth in case he has thoughts on how we could use packaging from the current-latest PyPI release.

brettcannon commented 1 year ago

So you're basically looking to create a web page where you can feed in something like a pyproject.toml and have it validate it?

And this is probably a good use of https://pyscript.net/ to build a quick-and-easy web UI wrapping some Python code.

rth commented 1 year ago

Yes it could be done with Pyscript, or plain HTML/JS with a bit of Pyodide. Here is a very basic version https://jsfiddle.net/z9bkhq6c/2/ (which does only version checking, not parsing of pyproject.toml)

how we could use packaging from the current-latest PyPI release.

Yes, so right now it doesn't seem possible to install a different version of packaging than the one we ship https://github.com/pyodide/micropip/issues/51 (because it's already loaded as a dependency of micropip) but that should probably be fixed.

A simpler solution is to load the wheel by URL using pyodide_js.loadPackage

>>> import pyodide_js
>>> await pyodide_js.loadPackage('https://files.pythonhosted.org/packages/ed/35/a31aed2993e398f6b09a790a181a7927eb1
4610ee8bbf02dc14d31677f1c/packaging-23.0-py3-none-any.whl'
... )
>>> import packaging
>>> packaging.__version__
'23.0'

which should work both in Pyodide and Pyscript.