This is a WIP/MVP. SS was created in tandem with a Flask web app. The need to refresh the browser automatically brought this about. It is just viable enough to install and run. It will need to be manually configured through the the source, for now.
- Command line arg folder targets
- Custom API call
- Upload to PyPI
- Tests
- Better install documentation
- Command line control over using the .gitfile
This module uses watchdog to watch project folders and files for changes and passively alert the browser a change has occurred and will cause it to refresh the page. Flask already can restart itself on a change of python code, so this module uses that as well as its own watchdog to alert the browser of other file changes and provides the functionality to refresh.
This requires running a flask app or something similar. Below are docs for flask. Any server or framework can work as all you need to do is import the watchFolders module, add a route, and insert the code below.
The command sneak-snek
will be added your $PATH so just run it like that.
Import:
from sneaky_snek import watchFolders
handler = watchFolders.Handler()
Also requires "request" imported from flask
from flask import request
Place a route to the handle_request() function:
#watchFolders dumby route used by refresher.js on an HTTP request to the flask app
@app.route("/check_changes", methods=["GET", 'POST'])
def check_changes():
return handler.handle_request(bytes.decode(request.data))
At the end of your flask app startup code, place:
handler.update_change_time()
Every time the flask server using watchdog detects a change, it will also trigger the browser to refresh.
Load up a second terminal to your project directory and activate your venv. Run sneaky-snek.
Make sure to send the decoded data as plain text.
- Better filter. Ignores anything in .gitignore. Custom ignore patterns can be added as well.
- Cleaned up the directory.
- Created a __main__.py file.
- Refactored out some hard coded variables.
- Better OS support for hardcoded DIRs to watch.
- Initial load refreshes an extra time.