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

Lite: Set the home dir path per appId at each runtime #6432

Merged
merged 6 commits into from Dec 11, 2023

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Nov 15, 2023

Description

Fix the bug introduced in the SharedWorker mode (#6099).

#6099 introduced app-level home dirs (/home/pyodide/<appId>) so each app running on a SharedWorker has separated home dir on the file system.
However, the current directory is not set properly in the Python environment, so file access methods such as open() with relative paths which are assumed to be resolved based on the app-level home dir can fail.
This PR fixes it, by calling os.chdir() and setting `os.environ["HOME"].

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Nov 15, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/b9e76582b7b0168ec4be9b17a6fc629204a1c13b/gradio-4.8.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@b9e76582b7b0168ec4be9b17a6fc629204a1c13b#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Nov 15, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/wasm minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Lite: Set the home dir path per appId at each runtime

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@whitphx whitphx force-pushed the shared-worker-app-home-dir-path-resolution branch from 5b219d5 to c498290 Compare November 15, 2023 15:34
@whitphx whitphx marked this pull request as ready for review November 15, 2023 15:34
@whitphx whitphx added the gradio-lite Related to the @gradio/lite library label Nov 15, 2023
@whitphx whitphx force-pushed the shared-worker-app-home-dir-path-resolution branch from fb89a52 to ab36333 Compare November 17, 2023 10:50
@whitphx
Copy link
Member Author

whitphx commented Dec 8, 2023

Here is an example:

app.py

import gradio as gr

def fn():
    with open("text.txt") as f:
        return f.read()


demo = gr.Interface(fn=fn, inputs=None, outputs="text")

demo.launch()

text.txt

Lorem ipsum
  • text.txt is mounted to FS specified as a relative path, text.txt. It is assumed to be mounted at <app-home-dir>/text.txt.
  • open() tries to read the file with a relative path. It is assumed to read the file from <app-home-dir>/text.txt. Before Lite: SharedWorker mode #6099, it actually worked.
  • However, after Lite: SharedWorker mode #6099, this started to fail. This PR fixes it.

@whitphx
Copy link
Member Author

whitphx commented Dec 8, 2023

I found this branch is not working because it is originally for v3, but the main is now v4 and it's been merged to this branch, then this branch fails to build.
To test this PR, plz rebase to lite-v4 or wait until it's merged.

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

Thanks for clarifying @whitphx, tested and lgtm!

@whitphx
Copy link
Member Author

whitphx commented Dec 11, 2023

Thanks!

@pngwn
Copy link
Member

pngwn commented Dec 11, 2023

@whitphx What is the status of this PR? Is it waiting on the lite v4 branch?

If it isn't currently ready + working can we close it and reopen later?

@whitphx
Copy link
Member Author

whitphx commented Dec 11, 2023

@pngwn Will merge it soon

@whitphx whitphx merged commit bdf81fe into main Dec 11, 2023
13 checks passed
@whitphx whitphx deleted the shared-worker-app-home-dir-path-resolution branch December 11, 2023 14:31
@pngwn pngwn mentioned this pull request Dec 11, 2023
dawoodkhan82 pushed a commit that referenced this pull request Dec 11, 2023
* Set the home dir path per appId at each runtime

* Add a comment

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradio-lite Related to the @gradio/lite library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants