Skip to content

Commit e1478a9

Browse files
committed
documentation updates
1 parent a8add30 commit e1478a9

File tree

28 files changed

+283
-218
lines changed

28 files changed

+283
-218
lines changed

docs/examples.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def load_examples() -> Iterator[tuple[str, Callable[[], ComponentType]]]:
2323
def all_example_names() -> set[str]:
2424
names = set()
2525
for file in _iter_example_files(SOURCE_DIR):
26-
path = file.parent if file.name == "app.py" else file
26+
path = file.parent if file.name == "main.py" else file
2727
names.add("/".join(path.relative_to(SOURCE_DIR).with_suffix("").parts))
2828
return names
2929

@@ -48,7 +48,7 @@ def get_main_example_file_by_name(
4848
) -> Path:
4949
path = _get_root_example_path_by_name(name, relative_to)
5050
if path.is_dir():
51-
return path / "app.py"
51+
return path / "main.py"
5252
else:
5353
return path.with_suffix(".py")
5454

docs/source/_exts/idom_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run(self):
5151
if len(ex_files) == 1:
5252
labeled_tab_items.append(
5353
(
54-
"app.py",
54+
"main.py",
5555
_literal_include(
5656
path=ex_files[0],
5757
linenos=show_linenos,

docs/source/guides/adding-interactivity/components-with-state/index.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ below highlights a line of code where something of interest occurs:
151151

152152
<h2>Initial render</h2>
153153

154-
.. literalinclude:: _examples/adding_state_variable/app.py
154+
.. literalinclude:: _examples/adding_state_variable/main.py
155155
:lines: 12-33
156156
:emphasize-lines: 2
157157

@@ -165,7 +165,7 @@ below highlights a line of code where something of interest occurs:
165165

166166
<h2>Initial state declaration</h2>
167167

168-
.. literalinclude:: _examples/adding_state_variable/app.py
168+
.. literalinclude:: _examples/adding_state_variable/main.py
169169
:lines: 12-33
170170
:emphasize-lines: 3
171171

@@ -181,7 +181,7 @@ below highlights a line of code where something of interest occurs:
181181

182182
<h2>Define event handler</h2>
183183

184-
.. literalinclude:: _examples/adding_state_variable/app.py
184+
.. literalinclude:: _examples/adding_state_variable/main.py
185185
:lines: 12-33
186186
:emphasize-lines: 5
187187

@@ -196,7 +196,7 @@ below highlights a line of code where something of interest occurs:
196196

197197
<h2>Return the view</h2>
198198

199-
.. literalinclude:: _examples/adding_state_variable/app.py
199+
.. literalinclude:: _examples/adding_state_variable/main.py
200200
:lines: 12-33
201201
:emphasize-lines: 16
202202

@@ -212,7 +212,7 @@ below highlights a line of code where something of interest occurs:
212212

213213
<h2>User interaction</h2>
214214

215-
.. literalinclude:: _examples/adding_state_variable/app.py
215+
.. literalinclude:: _examples/adding_state_variable/main.py
216216
:lines: 12-33
217217
:emphasize-lines: 5
218218

@@ -226,7 +226,7 @@ below highlights a line of code where something of interest occurs:
226226

227227
<h2>New state is set</h2>
228228

229-
.. literalinclude:: _examples/adding_state_variable/app.py
229+
.. literalinclude:: _examples/adding_state_variable/main.py
230230
:lines: 12-33
231231
:emphasize-lines: 6
232232

@@ -242,7 +242,7 @@ below highlights a line of code where something of interest occurs:
242242

243243
<h2>Next render begins</h2>
244244

245-
.. literalinclude:: _examples/adding_state_variable/app.py
245+
.. literalinclude:: _examples/adding_state_variable/main.py
246246
:lines: 12-33
247247
:emphasize-lines: 2
248248

@@ -256,7 +256,7 @@ below highlights a line of code where something of interest occurs:
256256

257257
<h2>Next state is acquired</h2>
258258

259-
.. literalinclude:: _examples/adding_state_variable/app.py
259+
.. literalinclude:: _examples/adding_state_variable/main.py
260260
:lines: 12-33
261261
:emphasize-lines: 3
262262

@@ -272,7 +272,7 @@ below highlights a line of code where something of interest occurs:
272272

273273
<h2>Repeat...</h2>
274274

275-
.. literalinclude:: _examples/adding_state_variable/app.py
275+
.. literalinclude:: _examples/adding_state_variable/main.py
276276
:lines: 12-33
277277

278278
From this point on, the steps remain the same. The only difference being the

docs/source/guides/getting-started/_examples/hello_world.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@component
55
def App():
6-
return html.h1("Hello, World!")
6+
return html.h1("Hello, world!")
77

88

99
run(App)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# :lines: 11-
2+
3+
from idom import run
4+
from idom.server import fastapi as fastapi_server
5+
6+
7+
# the run() function is the entry point for examples
8+
fastapi_server.configure = lambda _, cmpt: run(cmpt)
9+
10+
11+
from fastapi import FastAPI
12+
13+
from idom import component, html
14+
from idom.server.fastapi import configure
15+
16+
17+
@component
18+
def HelloWorld():
19+
return html.h1("Hello, world!")
20+
21+
22+
app = FastAPI()
23+
configure(app, HelloWorld)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# :lines: 11-
2+
3+
from idom import run
4+
from idom.server import flask as flask_server
5+
6+
7+
# the run() function is the entry point for examples
8+
flask_server.configure = lambda _, cmpt: run(cmpt)
9+
10+
11+
from flask import Flask
12+
13+
from idom import component, html
14+
from idom.server.flask import configure
15+
16+
17+
@component
18+
def HelloWorld():
19+
return html.h1("Hello, world!")
20+
21+
22+
app = Flask(__name__)
23+
configure(app, HelloWorld)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# :lines: 11-
2+
3+
from idom import run
4+
from idom.server import sanic as sanic_server
5+
6+
7+
# the run() function is the entry point for examples
8+
sanic_server.configure = lambda _, cmpt: run(cmpt)
9+
10+
11+
from sanic import Sanic
12+
13+
from idom import component, html
14+
from idom.server.sanic import configure
15+
16+
17+
@component
18+
def HelloWorld():
19+
return html.h1("Hello, world!")
20+
21+
22+
app = Sanic("MyApp")
23+
configure(app, HelloWorld)
24+
25+
26+
if __name__ == "__main__":
27+
app.run(port=8000)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# :lines: 11-
2+
3+
from idom import run
4+
from idom.server import starlette as starlette_server
5+
6+
7+
# the run() function is the entry point for examples
8+
starlette_server.configure = lambda _, cmpt: run(cmpt)
9+
10+
11+
from starlette.applications import Starlette
12+
13+
from idom import component, html
14+
from idom.server.starlette import configure
15+
16+
17+
@component
18+
def HelloWorld():
19+
return html.h1("Hello, world!")
20+
21+
22+
app = Starlette()
23+
configure(app, HelloWorld)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# :lines: 11-
2+
3+
from idom import run
4+
from idom.server import tornado as tornado_server
5+
6+
7+
# the run() function is the entry point for examples
8+
tornado_server.configure = lambda _, cmpt: run(cmpt)
9+
10+
11+
import tornado.ioloop
12+
import tornado.web
13+
14+
from idom import component, html
15+
from idom.server.tornado import configure
16+
17+
18+
@component
19+
def HelloWorld():
20+
return html.h1("Hello, world!")
21+
22+
23+
def make_app():
24+
app = tornado.web.Application()
25+
configure(app, HelloWorld)
26+
return app
27+
28+
29+
if __name__ == "__main__":
30+
app = make_app()
31+
app.listen(8000)
32+
tornado.ioloop.IOLoop.current().start()
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import idom
22

33

4-
idom.run(idom.sample.App)
4+
idom.run(idom.sample.SampleApp)

docs/source/guides/getting-started/_static/embed-idom-view/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from sanic.response import file
33

44
from idom import component, html
5-
from idom.server.sanic import Config, PerClientStateServer
5+
from idom.server.sanic import Options, configure
66

77

8-
app = Sanic(__name__)
8+
app = Sanic("MyApp")
99

1010

1111
@app.route("/")
@@ -18,6 +18,6 @@ def IdomView():
1818
return html.code("This text came from an IDOM App")
1919

2020

21-
PerClientStateServer(IdomView, app=app, config=Config(url_prefix="/_idom"))
21+
configure(app, IdomView, Options(url_prefix="/_idom"))
2222

2323
app.run(host="127.0.0.1", port=5000)

docs/source/guides/getting-started/index.rst

+22-7
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,35 @@ notebook linked below will demonstrate how to do this:
4646
Section 1: Installing IDOM
4747
--------------------------
4848

49-
The next fastest option is to install IDOM with ``pip``:
49+
The next fastest option is to install IDOM along with a supported server (like
50+
``starlette``) with ``pip``:
5051

5152
.. code-block:: bash
5253
53-
pip install "idom[stable]"
54+
pip install "idom[starlette]"
5455
5556
To check that everything is working you can run the sample application:
5657

5758
.. code-block:: bash
5859
59-
python -c "import idom; idom.run(idom.sample.App, open_browser=True)"
60+
python -c "import idom; idom.run(idom.sample.SampleApp)"
6061
61-
This should automatically open up a browser window to a page that looks like this:
62+
.. note::
63+
64+
This launches a simple development server which is good enough for testing, but
65+
probably not what you want to use in production. When deploying in production,
66+
there's a number of different ways of :ref:`running IDOM <Section 2: Running IDOM>`.
67+
68+
You should then see a few log messages:
69+
70+
.. code-block:: text
71+
72+
2022-03-27T11:58:59-0700 | WARNING | You are running a development server. Change this before deploying in production!
73+
2022-03-27T11:58:59-0700 | INFO | Running with 'Starlette' at http://127.0.0.1:8000
74+
75+
The second log message includes a URL indicating where you should go to view the app.
76+
That will usually be http://127.0.0.1:8000. Once you go to that URL you should see
77+
something like this:
6278

6379
.. card::
6480

@@ -70,9 +86,8 @@ If you get a ``RuntimeError`` similar to the following:
7086
7187
Found none of the following builtin server implementations...
7288
73-
Then be sure you installed ``"idom[stable]"`` and not just ``idom``.
74-
75-
For anything else, report your issue in IDOM's :discussion-type:`discussion forum
89+
Then be sure you run ``pip install "idom[starlette]"`` instead of just ``idom``. For
90+
anything else, report your issue in IDOM's :discussion-type:`discussion forum
7691
<problem>`.
7792

7893
.. card::

docs/source/guides/getting-started/installing-idom.rst

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
Installing IDOM
22
===============
33

4-
The easiest way to ``pip`` install idom is to do so using the ``stable`` option:
4+
Installing IDOM with ``pip`` will generally require doing so alongside a supported
5+
server implementation. This can be done by specifying an installation extra using square
6+
brackets. For example, if we want to run IDOM using `Starlette
7+
<https://www.starlette.io/>`__ we would run:
58

69
.. code-block:: bash
710
8-
pip install "idom[stable]"
11+
pip install "idom[starlette]"
912
10-
This includes a set of default dependencies for one of the builtin web server
11-
implementation. If you want to install IDOM without these dependencies you may simply
12-
``pip install idom``.
13+
If you want to install a "pure" version of IDOM without a server implementation you can
14+
do so without any installation extras. You might do this if you wanted to user a server
15+
which is not officially supported or if you wanted to manually pin your dependencies:
16+
17+
.. code-block:: bash
18+
19+
pip install idom
1320
1421
15-
Installing Other Servers
16-
------------------------
22+
Officially Supported Servers
23+
----------------------------
1724

1825
IDOM includes built-in support for a variety web server implementations. To install the
19-
required dependencies for each you should substitute ``stable`` from the ``pip install``
20-
command above with one of the options below:
26+
required dependencies for each you should substitute ``starlette`` from the ``pip
27+
install`` command above with one of the options below:
2128

2229
- ``fastapi`` - https://fastapi.tiangolo.com
2330
- ``flask`` - https://palletsprojects.com/p/flask/
2431
- ``sanic`` - https://sanicframework.org
32+
- ``starlette`` - https://www.starlette.io/
2533
- ``tornado`` - https://www.tornadoweb.org/en/stable/
2634

2735
If you need to, you can install more than one option by separating them with commas:
2836

2937
.. code-block:: bash
3038
31-
pip install idom[fastapi,flask,sanic,tornado]
39+
pip install "idom[fastapi,flask,sanic,starlette,tornado]"
3240
3341
Once this is complete you should be able to :ref:`run IDOM <Running IDOM>` with your
3442
:ref:`chosen server implementation <choosing a server implementation>`.
@@ -40,7 +48,7 @@ Installing In Other Frameworks
4048
While IDOM can run in a variety of contexts, sometimes web frameworks require extra work
4149
in order to integrate with them. In these cases, the IDOM team distributes bindings for
4250
various frameworks as separate Python packages. For documentation on how to install and
43-
run IDOM in the supported frameworks, follow the links below:
51+
run IDOM in these supported frameworks, follow the links below:
4452

4553
.. raw:: html
4654

0 commit comments

Comments
 (0)