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

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

Open
rth opened this issue Jun 23, 2023 · 2 comments
Open

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

rth opened this issue Jun 23, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@rth
Copy link
Member

rth commented Jun 23, 2023

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
Copy link
Member

It would be nice if it could detect:

  • In node use nodefs to write to disk
  • In chrome use nativefs to do a save prompt
  • Otherwise try download

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

@ryanking13
Copy link
Member

ryanking13 commented Jun 25, 2023

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.

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

No branches or pull requests

3 participants