Skip to content

Commit

Permalink
Merge pull request #473 from lona-web-org/fscherf/live-reload
Browse files Browse the repository at this point in the history
setup live reload
  • Loading branch information
fscherf committed Aug 31, 2023
2 parents 2b1fadf + 4c6d63e commit 982df35
Show file tree
Hide file tree
Showing 52 changed files with 209 additions and 170 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pythonic API to write self contained views.
return html
app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080, live_reload=True)
**More information:**
`Getting Started <http://lona-web.org/tutorial/01-getting-started/index.html>`_
Expand Down
3 changes: 2 additions & 1 deletion bin/lona
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import sys

from lona.command_line.handle_command_line import handle_command_line

handle_command_line(sys.argv)
if __name__ == '__main__':
handle_command_line(sys.argv)
31 changes: 1 addition & 30 deletions doc/content/api-reference/frontends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,7 @@ The default frontend template includes ``lona/style.css`` which can be
overridden.

.. code-block:: html

<!-- templates/lona/frontend.html -->
<html>
<head>
<meta charset="utf-8" />
{{ Lona.load_stylesheets() }}
<link href="{{ Lona.load_static_file('lona/style.css') }}" rel="stylesheet">
</head>
<body>
{% include "lona/header.html" %}
<div id="lona"></div>
{% include "lona/footer.html" %}
{{ Lona.load_scripts() }}
<script>
var lona_context = new Lona.LonaContext({
target: '#lona',
title: 'Lona',
update_address_bar: true,
update_title: true,
follow_redirects: true,
follow_http_redirects: true,
});
{% include "lona/frontend.js" %}
lona_context.setup();
</script>
</body>
</html>

:include: ../../../lona/templates/lona/frontend.html


Loading static files
Expand Down
3 changes: 2 additions & 1 deletion doc/content/api-reference/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ python script.
self.sleep(1)
app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
**More information:**
{{ link('api-reference/lona-scripts.rst', 'Lona Scripts') }}
Expand Down
9 changes: 6 additions & 3 deletions doc/content/api-reference/lona-scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ python script.
self.sleep(1)
app.run()
if __name__ == '__main__':
app.run()
Command Line Arguments
Expand Down Expand Up @@ -125,7 +126,8 @@ Views can be added by using the ``LonaApp.route()`` decorator or by setting
return H1('Hello World')
app.run()
if __name__ == '__main__':
app.run()
Setting The Frontend View
Expand Down Expand Up @@ -269,4 +271,5 @@ Custom error views can be set using the decorators ``LonaApp.error_403_view``,
return '500: Internal Error'
app.run()
if __name__ == '__main__':
app.run()
15 changes: 14 additions & 1 deletion doc/content/api-reference/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ Client
:name: CLIENT_DEBUG
:path: lona.default_settings.CLIENT_DEBUG

.. setting::
:name: CLIENT_AUTO_RECONNECT
:path: lona.default_settings.CLIENT_AUTO_RECONNECT

When set to ``True`` the client will try to reconnect to the server
periodically when the websocket connection closes

.. setting::
:name: CLIENT_AUTO_RECONNECT_TIMEOUT
:path: lona.default_settings.CLIENT_AUTO_RECONNECT_TIMEOUT

Auto reconnect timeout in ms

.. setting::
:name: CLIENT_VIEW_START_TIMEOUT
:path: lona.default_settings.CLIENT_VIEW_START_TIMEOUT
Expand Down Expand Up @@ -344,4 +357,4 @@ Feature Flags
When ``settings.USE_FUTURE_NODE_CLASSES`` is set to ``True``:


1. ``lona.html.Select2`` gets used instead of ``lona.html.Select``
1. ``lona.html.Select2`` gets used instead of ``lona.html.Select``
3 changes: 2 additions & 1 deletion doc/content/contrib/chartjs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ your view.
self.show(html)
app.run()
if __name__ == '__main__':
app.run()
57 changes: 0 additions & 57 deletions doc/content/cookbook/auto-reconnect.rst

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ def handle_request(self, request):
return self.html


app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
3 changes: 2 additions & 1 deletion doc/content/demos/channels/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ def on_cleanup(self):
Channel('clock.leave').send()


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/demos/counter/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ def handle_request(self, request):
)


app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
3 changes: 2 additions & 1 deletion doc/content/demos/daemonized-view/daemonized-view.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ def handle_request(self, request):
points.pop(0)


app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
3 changes: 2 additions & 1 deletion doc/content/demos/function-plotter/function-plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ def handle_text_input_change(self, input_event):
self.chart.data = CHART_DATA


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/demos/game-of-life/game-of-life.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,5 @@ def handle_request(self, request):
self.enable_controls()


app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
3 changes: 2 additions & 1 deletion doc/content/demos/multi-user-chat/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,5 @@ def handle_request(self, request):
return self.html


app.run()
if __name__ == '__main__':
app.run()
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ def handle_request(self, request):
)


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/deployment/deploying-on-linux.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Lona
return html
app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
Apache2
Expand Down
3 changes: 2 additions & 1 deletion doc/content/deployment/hello-world.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ def handle_request(self, request):
)


app.run(host='0.0.0.0', port=8080)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
20 changes: 0 additions & 20 deletions doc/content/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,3 @@ he had to add ~20 lines of extra Python code.
Web is a very powerful tool for visualization and interaction. Python is a
powerful tool for an unlimited range of tasks. Lona tries to bridge this gap
and is designed to be very accessible and good for rapid prototyping.


Why has Lona no live-reload feature like aiohttp-devtools?
----------------------------------------------------------

**fscherf:** Early versions of Lona had such a feature, but it got removed due
bad user experience: Reloading your view helps when the view is fully self
contained, but when it uses widgets or helper functions from another module,
things become inconsistent.

To make that a reliable feature you would have to maintain a list of all loaded
files and directories and track changes, file removes and addition of new
files. And you would have to maintain this list between restarts, to not miss
events, if files get changed fast after each other, like in a git rebase.

Also people use different editors that save files at different times and
sometimes multiple times and/or periodically.

It's hard to get this right, therefore I focused on making the server fast to
restart and easier to maintain.
3 changes: 2 additions & 1 deletion doc/content/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pythonic API to write self contained views.
return html
app.run(port=8080)
if __name__ == '__main__':
app.run(port=8080)
**More information:**
{{ link('/tutorial/01-getting-started/index.rst', 'Getting Started') }}
Expand Down
4 changes: 3 additions & 1 deletion doc/content/tutorial/01-getting-started/example-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

install_picocss(app, debug=True)

app.run()

if __name__ == '__main__':
app.run(port=8080, live_reload=True)
3 changes: 2 additions & 1 deletion doc/content/tutorial/01-getting-started/example-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def handle_request(self, request):
)


app.run()
if __name__ == '__main__':
app.run(port=8080, live_reload=True)
4 changes: 2 additions & 2 deletions doc/content/tutorial/01-getting-started/example-3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def handle_request(self, request):
)


app.run()

if __name__ == '__main__':
app.run(port=8080, live_reload=True)
6 changes: 4 additions & 2 deletions doc/content/tutorial/01-getting-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ app, like template paths, static directories or routes, will be relative to
this directory.

The last line of the script (``app.run()``), will run the application server,
and block until ``CTRL-C`` was hit.

and block until ``CTRL-C`` was hit.
Run the script using:

.. code-block::
Expand All @@ -105,6 +104,9 @@ If port 8080 is taken by another application, you can set environment
variable ``LONA_DEFAULT_PORT`` to some other port, affecting all examples that
do not set the port explicitly.

When ``live_reload`` is set to ``True`` Lona will watch the scripts project
root and restart the server when a file in it gets written.

The script should print that it opened a webserver on
``http://localhost:8080``. If you navigate your browser there, you should see
this:
Expand Down
3 changes: 2 additions & 1 deletion doc/content/tutorial/02-html/example-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ def handle_request(self, request):
return html


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/02-html/example-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ def handle_request(self, request):
self.sleep(1)


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/02-html/example-3.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ def handle_request(self, request):
current_color += 1


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/03-events/example-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ def handle_request(self, request):
)


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/03-events/example-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ def handle_request(self, request):
)


app.run()
if __name__ == '__main__':
app.run()
4 changes: 3 additions & 1 deletion doc/content/tutorial/03-events/example-3.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ def handle_request(self, request):
P(f'{first_number} + {second_number} = {first_number+second_number}')
)

app.run()

if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/04-user-input/example-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ def handle_request(self, request):
self.show(self.html)


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/05-routing/example-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ def handle_request(self, request):
)


app.run()
if __name__ == '__main__':
app.run()
3 changes: 2 additions & 1 deletion doc/content/tutorial/05-routing/example-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ def handle_request(self, request):
)


app.run()
if __name__ == '__main__':
app.run()
Loading

0 comments on commit 982df35

Please sign in to comment.