Skip to content

Rework How IDOM Integrates With Servers #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 58 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8a26c2c
initial work to move away from run func
rmorshea Mar 6, 2022
5ef939f
initial work converting to new server interface
rmorshea Mar 17, 2022
b1b8081
finish up flask conversion
rmorshea Mar 17, 2022
c9fc66e
convert tornado + begin reworking test utils
rmorshea Mar 17, 2022
2c5ab44
remove shared dispatchers and rename to serve module
rmorshea Mar 17, 2022
86e54b0
misc fixes
rmorshea Mar 17, 2022
e76104c
start to switch test suite to playwright
rmorshea Mar 18, 2022
1bfbc1a
get basic tests working
rmorshea Mar 19, 2022
6c342e2
get some tests working
rmorshea Mar 19, 2022
3d78eea
slight optimization
rmorshea Mar 19, 2022
8e0d010
misc minor improvements
rmorshea Mar 20, 2022
e15abba
fix test_html
rmorshea Mar 21, 2022
680cf6e
implement test_module
rmorshea Mar 22, 2022
bbc80d5
implement connection context
rmorshea Mar 22, 2022
82a1776
fix playwright install in nox
rmorshea Mar 22, 2022
7dbe32a
add minimal docstrings
rmorshea Mar 22, 2022
3a88e96
remove pytest-playwright
rmorshea Mar 22, 2022
8b09a5d
get suite to run (with failures)
rmorshea Mar 22, 2022
1c422ed
fix log assertion problems
rmorshea Mar 24, 2022
45f4949
misc fixes in order to get reconnect test to work
rmorshea Mar 24, 2022
c3c7cdb
expose use_scope instead of use_connection
rmorshea Mar 26, 2022
fa764f8
fix test common
rmorshea Mar 26, 2022
7ddc2c8
fix test_client
rmorshea Mar 26, 2022
04236f5
test use_scope
rmorshea Mar 26, 2022
56a2134
remove unused imports
rmorshea Mar 26, 2022
89afa71
fix live docs
rmorshea Mar 26, 2022
6b04447
fix typing issues
rmorshea Mar 26, 2022
ee6f625
fix rest of tests
rmorshea Mar 26, 2022
9121436
improve coverage
rmorshea Mar 26, 2022
c8f96b5
import protocol from typing extensions
rmorshea Mar 26, 2022
5726436
fix syntax error
rmorshea Mar 26, 2022
683b1ce
fix docs test
rmorshea Mar 26, 2022
9e9fa81
fix flake8
rmorshea Mar 26, 2022
843cf77
test run function
rmorshea Mar 26, 2022
6d40240
use selector event loop
rmorshea Mar 26, 2022
4ccc523
try to fix loop
rmorshea Mar 26, 2022
c8f393a
only install chromium
rmorshea Mar 26, 2022
5d12ab4
remove unused import
rmorshea Mar 26, 2022
e015ab7
fix shutdown code
rmorshea Mar 26, 2022
fd420a8
skip browser tests on windows
rmorshea Mar 26, 2022
3de5507
fix coverage + reorg testing utils
rmorshea Mar 26, 2022
5cd8f45
minor logging changes
rmorshea Mar 27, 2022
37282bc
fix live docs script
rmorshea Mar 27, 2022
0ea5791
fix log message
rmorshea Mar 27, 2022
a8add30
fix types
rmorshea Mar 27, 2022
e1478a9
documentation updates
rmorshea Mar 27, 2022
89b8825
use dataclasses for options instead of typeddict
rmorshea Mar 27, 2022
f4bb85e
move section
rmorshea Mar 27, 2022
f889d81
add note to changelog
rmorshea Mar 27, 2022
fca1b4d
fix missing refs
rmorshea Mar 27, 2022
90c89be
fix ref
rmorshea Mar 27, 2022
8e77080
fix fastapi alias
rmorshea Mar 27, 2022
6db0f10
fix tornado redirect
rmorshea Mar 27, 2022
420c08f
remove unused imports
rmorshea Mar 27, 2022
2e86b33
changelog entry
rmorshea Mar 28, 2022
70a2b27
fix noxfile tag commit msg
rmorshea Mar 28, 2022
75413cc
improve changelog entry
rmorshea Mar 28, 2022
0f22e77
fix typo in old cl entry
rmorshea Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: nanasess/setup-chromedriver@master
- uses: actions/setup-node@v2
with:
node-version: "14.x"
Expand All @@ -29,7 +28,7 @@ jobs:
run: pip install -r requirements/nox-deps.txt
- name: Run Tests
env: { "CI": "true" }
run: nox -s test_python_suite -- --headless --maxfail=3
run: nox -s test_python_suite -- --maxfail=3
test-python-environments:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -38,7 +37,6 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: nanasess/setup-chromedriver@master
- uses: actions/setup-node@v2
with:
node-version: "14.x"
Expand All @@ -52,7 +50,7 @@ jobs:
run: pip install -r requirements/nox-deps.txt
- name: Run Tests
env: { "CI": "true" }
run: nox -s test_python --stop-on-first-error -- --headless --maxfail=3 --no-cov
run: nox -s test_python --stop-on-first-error -- --maxfail=3 --no-cov
test-docs:
runs-on: ubuntu-latest
steps:
Expand Down
48 changes: 30 additions & 18 deletions docs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from sanic import Sanic, response

from idom.server.sanic import PerClientStateServer
from idom.widgets import multiview
from idom import component
from idom.core.types import ComponentConstructor
from idom.server.sanic import Options, configure, use_request

from .examples import load_examples

Expand All @@ -22,13 +23,13 @@
def run():
app = make_app()

PerClientStateServer(
make_examples_component(),
{
"redirect_root_to_index": False,
"url_prefix": IDOM_MODEL_SERVER_URL_PREFIX,
},
configure(
app,
Example(),
Options(
redirect_root=False,
url_prefix=IDOM_MODEL_SERVER_URL_PREFIX,
),
)

app.run(
Expand All @@ -39,8 +40,28 @@ def run():
)


@component
def Example():
view_id = use_request().get_args().get("view_id")
return _get_examples()[view_id]()


def _get_examples():
if not _EXAMPLES:
_EXAMPLES.update(load_examples())
return _EXAMPLES


def reload_examples():
_EXAMPLES.clear()
_EXAMPLES.update(load_examples())


_EXAMPLES: dict[str, ComponentConstructor] = {}


def make_app():
app = Sanic(__name__)
app = Sanic("docs_app")

app.static("/docs", str(HERE / "build"))

Expand All @@ -49,12 +70,3 @@ async def forward_to_index(request):
return response.redirect("/docs/index.html")

return app


def make_examples_component():
mount, component = multiview()

for example_name, example_component in load_examples():
mount.add(example_name, example_component)

return component
4 changes: 2 additions & 2 deletions docs/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def load_examples() -> Iterator[tuple[str, Callable[[], ComponentType]]]:
def all_example_names() -> set[str]:
names = set()
for file in _iter_example_files(SOURCE_DIR):
path = file.parent if file.name == "app.py" else file
path = file.parent if file.name == "main.py" else file
names.add("/".join(path.relative_to(SOURCE_DIR).with_suffix("").parts))
return names

Expand All @@ -48,7 +48,7 @@ def get_main_example_file_by_name(
) -> Path:
path = _get_root_example_path_by_name(name, relative_to)
if path.is_dir():
return path / "app.py"
return path / "main.py"
else:
return path.with_suffix(".py")

Expand Down
2 changes: 1 addition & 1 deletion docs/source/_exts/idom_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run(self):
if len(ex_files) == 1:
labeled_tab_items.append(
(
"app.py",
"main.py",
_literal_include(
path=ex_files[0],
linenos=show_linenos,
Expand Down
35 changes: 32 additions & 3 deletions docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,41 @@ Changelog
All notable changes to this project will be recorded in this document. The style of
which is based on `Keep a Changelog <https://keepachangelog.com/>`__. The versioning
scheme for the project adheres to `Semantic Versioning <https://semver.org/>`__. For
more info, see the :ref:`Contributor Guide <Create a Changelog Entry>`.
more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.


.. INSTRUCTIONS FOR CHANGELOG CONTRIBUTORS
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. If you're adding a changelog entry, be sure to read the "Creating a Changelog Entry"
.. section of the documentation before doing so for instructions on how to adhere to the
.. "Keep a Changelog" style guide (https://keepachangelog.com).

Unreleased
----------

Nothing yet...
Changed:

- How IDOM integrates with servers - :pull:`703`

- ``idom.run`` no longer accepts an app instance to discourage use outside of testing
- IDOM's server implementations now provide ``configure()`` functions instead
- ``idom.testing`` has been completely reworked in order to support async web drivers

Added:

- Access to underlying server requests via contexts - :issue:`669`

Removed:

- ``idom.widgets.multiview`` since basic routing view ``use_scope`` is now possible
- All ``SharedClientStateServer`` implementations.
- All ``PerClientStateServer`` implementations have been replaced with ``configure()``

Fixed:

- IDOM's test suite no longer uses sync web drivers - :issue:`591`
- Updated Sanic requirement to ``>=21`` - :issue:`678`
- How we advertise ``idom.run`` - :issue:`657`


0.37.2
Expand All @@ -30,7 +58,8 @@ Changed:

Fixed:

- A typo caused IDOM to use the insecure `ws` web-socket protocol on pages loaded with `https` instead of the secure `wss` protocol - :pull:`716`
- A typo caused IDOM to use the insecure ``ws`` web-socket protocol on pages loaded with
``https`` instead of the secure ``wss`` protocol - :pull:`716`


0.37.1
Expand Down
4 changes: 2 additions & 2 deletions docs/source/about/contributor-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ about how to get started. To make a change to IDOM you'll do the following:
:ref:`equality checks <Code Quality Checks>` and, with any luck, accept your request.
At that point your contribution will be merged into the main codebase!

Create a Changelog Entry
........................
Creating a Changelog Entry
..........................

As part of your pull request, you'll want to edit the `Changelog
<https://github.com/idom-team/idom/blob/main/docs/source/about/changelog.rst>`__ by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ below highlights a line of code where something of interest occurs:

<h2>Initial render</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 2

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

<h2>Initial state declaration</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 3

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

<h2>Define event handler</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 5

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

<h2>Return the view</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 16

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

<h2>User interaction</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 5

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

<h2>New state is set</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 6

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

<h2>Next render begins</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 2

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

<h2>Next state is acquired</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33
:emphasize-lines: 3

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

<h2>Repeat...</h2>

.. literalinclude:: _examples/adding_state_variable/app.py
.. literalinclude:: _examples/adding_state_variable/main.py
:lines: 12-33

From this point on, the steps remain the same. The only difference being the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@component
def App():
return html.h1("Hello, World!")
return html.h1("Hello, world!")


run(App)
23 changes: 23 additions & 0 deletions docs/source/guides/getting-started/_examples/run_fastapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# :lines: 11-

from idom import run
from idom.server import fastapi as fastapi_server


# the run() function is the entry point for examples
fastapi_server.configure = lambda _, cmpt: run(cmpt)


from fastapi import FastAPI

from idom import component, html
from idom.server.fastapi import configure


@component
def HelloWorld():
return html.h1("Hello, world!")


app = FastAPI()
configure(app, HelloWorld)
23 changes: 23 additions & 0 deletions docs/source/guides/getting-started/_examples/run_flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# :lines: 11-

from idom import run
from idom.server import flask as flask_server


# the run() function is the entry point for examples
flask_server.configure = lambda _, cmpt: run(cmpt)


from flask import Flask

from idom import component, html
from idom.server.flask import configure


@component
def HelloWorld():
return html.h1("Hello, world!")


app = Flask(__name__)
configure(app, HelloWorld)
27 changes: 27 additions & 0 deletions docs/source/guides/getting-started/_examples/run_sanic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# :lines: 11-

from idom import run
from idom.server import sanic as sanic_server


# the run() function is the entry point for examples
sanic_server.configure = lambda _, cmpt: run(cmpt)


from sanic import Sanic

from idom import component, html
from idom.server.sanic import configure


@component
def HelloWorld():
return html.h1("Hello, world!")


app = Sanic("MyApp")
configure(app, HelloWorld)


if __name__ == "__main__":
app.run(port=8000)
23 changes: 23 additions & 0 deletions docs/source/guides/getting-started/_examples/run_starlette.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# :lines: 11-

from idom import run
from idom.server import starlette as starlette_server


# the run() function is the entry point for examples
starlette_server.configure = lambda _, cmpt: run(cmpt)


from starlette.applications import Starlette

from idom import component, html
from idom.server.starlette import configure


@component
def HelloWorld():
return html.h1("Hello, world!")


app = Starlette()
configure(app, HelloWorld)
Loading