Pyodide doesn't recognize changes in files using the Emscripten File System API.
See original GitHub issue🐛 Bug
When I’m using pyodide.FS the method writeFile Pyodide doesn’t recognize changes in files.
To Reproduce
- Create a file using FS.writeFile, like this:
const content = `
def hello():
return 'hello v1'
`;
pyodide.FS.writeFile('my_mod.py', content );
- Check the content by FS.readFile
const contentPy = pyodide.FS.readFile('my_mod.py');
const string = new TextDecoder().decode(contentPy);
console.log(string) // print content
- Now, execute code by runPython.
pyodide.runPython(`
import my_mod
print(my_mod.hello())
`);
- Check stdout, show the result:
hello v1
Here all fine!
- But, when I make any change in my_mod.py content with FS.writeFile Pyodide doesn’t recognize the changes. For example:
const newContent= `
def hello():
return 'change'
`;
pyodide.FS.writeFile('my_mod.py', content );
pyodide.runPython(`
import my_mod
print(my_mod.hello())
`);
- Pyodide shows in stdout the old version file, check stdout:
hello v1
hello v1
Expected behavior
Pyodide should recognize changes in files using the Emscripten File System API.
Environment
- Pyodide Version: 0.21.3
Additional context
I create a demo in this stackblitz project to explain the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Accessing files does not work on Pyodide · Issue #2669 - GitHub
Inside the python code file, I access files locally given a directory ... save it to a virtual file system using Emscripten file...
Read more >File System API — Emscripten 3.1.26-git (dev) documentation
Emscripten decides whether to include file system support automatically. Many programs don't need files, and file system support is not negligible in size,...
Read more >Frequently Asked Questions — Version 0.21.3 - Pyodide
Why can't I load files from the local file system? How can I execute code in a custom namespace? How to detect that...
Read more >faq.md.txt - Pyodide
Why can't I load files from the local file system? For security reasons JavaScript ... See {ref}`nativefs-api` for experimental local file system support....
Read more >faq.md.txt - Pyodide
Why can't I load files from the local file system? ... Pyodide ``` More generally you can detect Python built with Emscripten (which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This would probably be another good faq entry.
@hoodmane great!
I tried your approach, which works here in my demo and now I have an idea for not running the 5 steps again.
The next week, I’ll send a PR with improvements in the docs. 🙂