Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Shell autoreload #51

Open
Kazy opened this issue Jan 15, 2013 · 12 comments
Open

Shell autoreload #51

Kazy opened this issue Jan 15, 2013 · 12 comments

Comments

@Kazy
Copy link

Kazy commented Jan 15, 2013

Hi,

Someone has added an auto-reloading functionality to the python REPL (http://benplesser.com/2013/01/10/beefing-up-the-python-shell-to-build-apps-faster-and-dryer/ thanks for his work) allowing an auto-reload of the import, and even to swap already existing objects.
I've already ported it to be used with Flask-Script (https://github.com/Kazy/flask-script), but I would like to know if you're interested to integrate it. It has been set to be activated by default, unless watchdog is not available.

@techniq
Copy link
Collaborator

techniq commented Jan 15, 2013

That looks very interesting. Let me play around with it, but I think it would be a great addition (I know I get frustrated having to reload the shell a lot, especially when playing with my models using SQLAlchemy).

I noticed one of your commits disabled model reloading, and you pass None to model_globals in listen_for_changes(). Does the current state of your branch not support reloading on model changes, and if not, have you found the cause why it's not supported?

@Kazy
Copy link
Author

Kazy commented Jan 15, 2013

It was needed with Django because it caches models, but with (Flask-)SQLAlchemy, since models are usual classes and get no special treatment (or at least none I'm aware of), it is reloaded the same way. I removed the argument, forgot to do it.

@kennethreitz
Copy link
Collaborator

👍

@techniq
Copy link
Collaborator

techniq commented Jan 17, 2013

Some feedback

  • Please remove the additional argh dependency. It's only being used for it's CommandError. Maybe raise InvalidCommand instead? Infact I'm not sure we should check for anything other then _request_ctx_stack.top.app.root_path. PROJECT_ROOT is a Django environment variable I believe, but not really common for Flask. I'm not sure watching the VIRTUAL_ENV is helpful either. Thoughts?
  • How about calling the --no-auto-reload flag --no-reload to match the Server command? Be sure to update the various docs related to the command
  • The line from watchdog.events import FileSystemEventHandler should be inside the try block so not to throw an ImportError for users without watchdog.

Go ahead and send a pull request so we can comment on specific lines of code easier as well. Thanks.

@Kazy
Copy link
Author

Kazy commented Jan 17, 2013

I've committed those changes. About the first point, maybe we should add a way to specify a path, for more exotic configuration (like using a factory to create the app instance, I have no idea how Flask set the root_path variable).

@Kazy Kazy mentioned this issue Jan 17, 2013
@techniq
Copy link
Collaborator

techniq commented Aug 12, 2013

@Kazy Now that Flask-SQLAlchemy has gone back into active development, could you take a look at this and see if its working (or report an issue on Flask-SQLAlchemy)?

@Kazy
Copy link
Author

Kazy commented Aug 13, 2013

@techniq I should be able to do so in a little more than one week !

@techniq
Copy link
Collaborator

techniq commented Aug 13, 2013

Awesome, thanks.

@sibelius
Copy link

The autoreload is not working yet?

@davidism
Copy link

@sibeliusseraphini it looks like they were trying to implement it in #52 but never finished.

@sibelius
Copy link

We can have a Flask autoreload on shell using ipython

Just create the app inside ipython

$ ipython
%autoreload 2
app = create_app()

@takosuke
Copy link

takosuke commented Mar 4, 2016

Bump this - I have autoreload enabled like @sibeliusseraphini in my ipython profile but it gets ignored when using the flask-script shell. Any way I'm not seeing of doing it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants