pyodide / micropip

A lightweight Python package installer for Pyodide
https://micropip.pyodide.org
Mozilla Public License 2.0
68 stars 16 forks source link

Download `pyodide-lock.json` with results of micropip.freeze() #68

Open rth opened 1 year ago

rth commented 1 year ago

micropip.freeze() returns the pyodide-lock.json contents, and it would be nice if there was some convenience function that would trigger the download of such pyodide-lock.json.

Maybe something like,

def download_pyodide_lock():
    from js import document, Blob, URL

    blob = Blob.new([micropip.freeze()], {"type": "application/json;charset=utf-8"})
    a = document.createElement("a")
    a.href = URL.createObjectURL(blob)
    a.download = "pyodide-lock.json"
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)

Though it wouldn't work in a web-worker (and JupyterLite)

hoodmane commented 1 year ago

It would be nice if it could detect:

This would be convenient for other things too, maybe adding a small package to Pyodide for this would be nice.

ryanking13 commented 1 year ago

maybe adding a small package to Pyodide for this would be nice.

Making a separate package sounds good to me. People sometimes ask about how they can download files inside the virtual file system, and it would be nice if we can provide some way to do it in Python.

Though it might be reinventing the wheel as there exists a FileSaver.js, but FileSaver.js itself is a small, single file package, so probably we can just reference and rewrite FileSaver.js to work in Pyodide.