Open mdsitton opened 9 years ago
That sounds really good, it might be worth looking at using the ast
module, and meta.decompiler http://meta.readthedocs.org/en/latest/_modules/meta/decompiler.html to recompile the functions as it could help simplify things even further (for instance you get line numbers in the ast).
There are a couple of things that would enable building 'livecoding' like I have in shoebot in this https://www.youtube.com/watch?v=foxzx0JFU5g (were unsaved modified code is sent from the editor to the executor)
It would be great to get something like
def substitute_content(filename, new_content):
"""
Substitute the real file content with new_content
"""
pass
def substitute_source(filename, substitute_file):
Substitute filename with substitute_file, this is useful for
apps that want to share temporary state, possibly in /tmp
pass
I'm thinking of implementing a couple of things + probably pushing the code to here so IDE can use common code.
If you do go with AST it might be possible to do other modifications using it ... one I'd really like is to be able to change filenames that are passed to 'open' with that + the networked bit, I could build 'live editing' on my livecoding tool - this would be plugins for inkscape / gedit - that saved intermediate state to files in /tmp.
Scenario1:
pyhotreload API is called, e.g. 'substitute_file('panda.svg', '/tmp/panda_1234.svg') pyhotreload reloads the files that opened 'panda.svg' (and any that referenced them).
I might could use the ast module in the future, but currently with how the code is i think the inspect module looks more useful. Looked into it a bit and it seems possible to do a substitution function like that, i guess ill implement it at some point. It wouldn't be that difficult to monkey patch the built-ins with a wrapper around open to implement the image loading thing you mention. However it seems like a problem that's out of the scope of this project. A VFS implementation in your code seems more logical to me.
Now I've slept on it, monkey patching the builtins is definitely is out of scope for this project. :)
VFS would be nice, but since it's something I want to make work for arbitrary code then I'll need to work out something more sneaky, and money patching might be the way, though of course I can do that before I send the new code to pyhotreload.
I started the redesign branch around a year ago right before i stopped working on hotreload for a while. Thought it would be a good idea to mention my plans for the branch.
What i'm planning to do with the branch is to make the code smarter about what it replaces. Currently it just replaces most everything without checking if things have actually changed or not. What i'm planning on doing for this branch is actually check if something has been changed before doing the reload. I'm thinking that doing this should simplify the reload code quite a bit.