• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

livereload/H07-May-2019-921720

livereload.egg-info/H03-May-2022-229153

LICENSEH A D07-May-20191.5 KiB2824

MANIFEST.inH A D07-May-201976 43

PKG-INFOH A D07-May-20198.1 KiB229153

README.rstH A D07-May-20195.3 KiB199124

setup.cfgH A D07-May-2019102 117

setup.pyH A D07-May-20191.9 KiB6353

README.rst

1LiveReload
2==========
3
4This is a brand new LiveReload in version 2.0.0.
5
6`Download on PyPi <https://pypi.python.org/pypi/livereload>`_
7
8Installation
9------------
10
11Python LiveReload is designed for web developers who know Python.
12
13Install Python LiveReload with pip::
14
15    $ pip install livereload
16
17If you don't have pip installed, try easy_install::
18
19    $ easy_install livereload
20
21Command Line Interface
22----------------------
23
24Python LiveReload provides a command line utility, ``livereload``, for starting a server in a directory.
25
26By default, it will listen to port 35729, the common port for `LiveReload browser extensions`_. ::
27
28    $ livereload --help
29    usage: livereload [-h] [-p PORT] [-w WAIT] [directory]
30
31    Start a `livereload` server
32
33    positional arguments:
34      directory             Directory to watch for changes
35
36    optional arguments:
37      -h, --help            show this help message and exit
38      -p PORT, --port PORT  Port to run `livereload` server on
39      -w WAIT, --wait WAIT  Time delay before reloading
40
41.. _`livereload browser extensions`: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-
42
43Older versions of Python LiveReload used a ``Guardfile`` to describe optional additional rules for files to watch and build commands to run on changes.  This conflicted with other tools that used the same file for their configuration and is no longer supported since Python LiveReload version 2.0.0.  Instead of a ``Guardfile`` you can now write a Python script using very similar syntax and run it instead of the command line application.
44
45Script example: Sphinx
46----------------------
47
48Here's a simple example script that rebuilds Sphinx documentation:
49
50.. code:: python
51
52    #!/usr/bin/env python
53    from livereload import Server, shell
54    server = Server()
55    server.watch('docs/*.rst', shell('make html', cwd='docs'))
56    server.serve(root='docs/_build/html')
57
58Run it, then open http://localhost:5500/ and you can see the documentation changes in real time.
59
60Developer Guide
61---------------
62
63The new livereload server is designed for developers. It can power a
64wsgi application now:
65
66.. code:: python
67
68    from livereload import Server, shell
69
70    server = Server(wsgi_app)
71
72    # run a shell command
73    server.watch('static/*.stylus', 'make static')
74
75    # run a function
76    def alert():
77        print('foo')
78    server.watch('foo.txt', alert)
79
80    # output stdout into a file
81    server.watch('style.less', shell('lessc style.less', output='style.css'))
82
83    server.serve()
84
85The ``Server`` class accepts parameters:
86
87- app: a wsgi application
88- watcher: a watcher instance, you don't have to create one
89
90server.watch
91~~~~~~~~~~~~
92
93``server.watch`` can watch a filepath, a directory and a glob pattern::
94
95    server.watch('path/to/file.txt')
96    server.watch('directory/path/')
97    server.watch('glob/*.pattern')
98
99You can also use other library (for example: formic) for more powerful
100file adding::
101
102    for filepath in formic.FileSet(include="**.css"):
103        server.watch(filepath, 'make css')
104
105You can delay a certain seconds to send the reload signal::
106
107    # delay 2 seconds for reloading
108    server.watch('path/to/file', delay=2)
109
110
111server.serve
112~~~~~~~~~~~~
113
114Setup a server with ``server.serve`` method. It can create a static server
115and a livereload server::
116
117    # use default settings
118    server.serve()
119
120    # livereload on another port
121    server.serve(liveport=35729)
122
123    # use custom host and port
124    server.serve(port=8080, host='localhost')
125
126    # open the web browser on startup, based on $BROWSER environment variable
127    server.serve(open_url_delay=5, debug=False)
128
129
130shell
131~~~~~
132
133The powerful ``shell`` function will help you to execute shell commands. You
134can use it with ``server.watch``::
135
136    # you can redirect command output to a file
137    server.watch('style.less', shell('lessc style.less', output='style.css'))
138
139    # commands can be a list
140    server.watch('style.less', shell(['lessc', 'style.less'], output='style.css'))
141
142    # working with Makefile
143    server.watch('assets/*.styl', shell('make assets', cwd='assets'))
144
145
146Frameworks Integration
147----------------------
148
149Livereload can work seamlessly with your favorite framework.
150
151Django
152~~~~~~
153
154For Django there is a management command included.
155
156To use simply
157
158- add ``'livereload'`` to your ``INSTALLED_APPS`` and
159- then run ``./manage.py livereload``.
160
161For available options like host and ports please refer to ``./manage.py livereload -h``.
162
163To automagically serve static files like the native ``runserver`` command you have to use `dj-static <https://github.com/kennethreitz/dj-static>`_. (follow the simple instructions there).
164
165Flask
166~~~~~
167
168Wrap Flask with livereload is much simpler:
169
170.. code:: python
171
172    # app is a Flask object
173    app = create_app()
174
175    # remember to use DEBUG mode for templates auto reload
176    # https://github.com/lepture/python-livereload/issues/144
177    app.debug = True
178
179    server = Server(app.wsgi_app)
180    # server.watch
181    server.serve()
182
183
184Bottle
185~~~~~~
186
187Wrap the ``Bottle`` app with livereload server:
188
189.. code:: python
190
191    # Without this line templates won't auto reload because of caching.
192    # http://bottlepy.org/docs/dev/tutorial.html#templates
193    bottle.debug(True)
194
195    app = Bottle()
196    server = Server(app)
197    # server.watch
198    server.serve()
199