Skip to content

Commit f96538c

Browse files
authored
rename proto modules to types (#701)
* rename proto modules to types * sphinx ignore __all__ * changelog entry * fix doc issue not sure why this was not caught earlier
1 parent d73b79f commit f96538c

28 files changed

+111
-64
lines changed

docs/examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Callable, Iterator
77

88
import idom
9-
from idom import ComponentType
9+
from idom.types import ComponentType
1010

1111

1212
HERE = Path(__file__)

docs/source/_custom_js/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/_exts/autogen_api_docs.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
AUTODOC_TEMPLATE_WITH_MEMBERS = """\
2323
.. automodule:: {module}
2424
:members:
25+
:ignore-module-all:
2526
"""
2627

2728
AUTODOC_TEMPLATE_WITHOUT_MEMBERS = """\
2829
.. automodule:: {module}
30+
:ignore-module-all:
2931
"""
3032

3133
TITLE = """\

docs/source/about/changelog.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ Changelog
1010

1111
All notable changes to this project will be recorded in this document. The style of
1212
which is based on `Keep a Changelog <https://keepachangelog.com/>`__. The versioning
13-
scheme for the project adheres to `Semantic Versioning <https://semver.org/>`__.
13+
scheme for the project adheres to `Semantic Versioning <https://semver.org/>`__. For
14+
more info, see the :ref:`Contributor Guide <Create a Changelog Entry>`.
1415

1516

1617
Unreleased
1718
----------
1819

19-
Nothing yet...
20+
Changed:
21+
22+
- The name of ``proto`` modules to ``types`` and added a top level ``idom.types`` module
23+
- :pull:`701`
2024

2125

2226
0.37.1

docs/source/about/contributor-guide.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ about how to get started. To make a change to IDOM you'll do the following:
6969
Create a Changelog Entry
7070
........................
7171

72-
As part of your pull request, you'll want to edit the :ref:`Changelog` by adding an
73-
entry describing what you've changed or improved. You should write an entry in the style
74-
of `Keep a Changelog <https://keepachangelog.com/>`__ that falls under one of the
75-
following categories, and add it to the :ref:`Unreleased` section of the changelog:
72+
As part of your pull request, you'll want to edit the `Changelog
73+
<https://github.com/idom-team/idom/blob/main/docs/source/about/changelog.rst>`__ by
74+
adding an entry describing what you've changed or improved. You should write an entry in
75+
the style of `Keep a Changelog <https://keepachangelog.com/>`__ that falls under one of
76+
the following categories, and add it to the :ref:`Unreleased` section of the changelog:
7677

7778
- **Added** - for new features.
7879
- **Changed** - for changes in existing functionality.

src/idom/__init__.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from . import config, html, log, web
1+
from . import config, html, log, types, web
22
from .core import hooks
3-
from .core.component import Component, component
3+
from .core.component import component
44
from .core.dispatcher import Stop
5-
from .core.events import EventHandler, event
5+
from .core.events import event
66
from .core.hooks import (
77
create_context,
88
use_callback,
@@ -14,7 +14,6 @@
1414
use_state,
1515
)
1616
from .core.layout import Layout
17-
from .core.proto import ComponentType, VdomDict
1817
from .core.vdom import vdom
1918
from .sample import run_sample_app
2019
from .server.prefab import run
@@ -27,12 +26,9 @@
2726

2827
__all__ = [
2928
"component",
30-
"Component",
31-
"ComponentType",
3229
"config",
3330
"create_context",
3431
"event",
35-
"EventHandler",
3632
"hooks",
3733
"hotswap",
3834
"html_to_vdom",
@@ -44,6 +40,7 @@
4440
"run_sample_app",
4541
"run",
4642
"Stop",
43+
"types",
4744
"use_callback",
4845
"use_context",
4946
"use_effect",
@@ -52,6 +49,5 @@
5249
"use_ref",
5350
"use_state",
5451
"vdom",
55-
"VdomDict",
5652
"web",
5753
]

src/idom/core/component.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from functools import wraps
55
from typing import Any, Callable, Dict, Optional, Tuple, Union
66

7-
from .proto import ComponentType, VdomDict
7+
from .types import ComponentType, VdomDict
88

99

1010
def component(

src/idom/core/dispatcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from ._fixed_jsonpatch import apply_patch, make_patch # type: ignore
2626
from .layout import LayoutEvent, LayoutUpdate
27-
from .proto import LayoutType, VdomJson
27+
from .types import LayoutType, VdomJson
2828

2929

3030
logger = getLogger(__name__)

src/idom/core/events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from anyio import create_task_group
77
from typing_extensions import Literal
88

9-
from idom.core.proto import EventHandlerFunc, EventHandlerType
9+
from idom.core.types import EventHandlerFunc, EventHandlerType
1010

1111

1212
@overload

src/idom/core/hooks.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from idom.utils import Ref
2828

2929
from ._thread_local import ThreadLocal
30-
from .proto import Key, VdomDict
30+
from .types import Key, VdomDict
3131
from .vdom import vdom
3232

3333

@@ -561,15 +561,19 @@ class LifeCycleHook:
561561
562562
.. testcode::
563563
564-
from idom.core.hooks import LifeCycleHook, DID_RENDER_EFFECT
564+
from idom.core.hooks import (
565+
current_hook,
566+
LifeCycleHook,
567+
COMPONENT_DID_RENDER_EFFECT,
568+
)
565569
566570
567571
# this function will come from a layout implementation
568572
schedule_render = lambda: ...
569573
570574
# --- start life cycle ---
571575
572-
hook = hooks.LifeCycle(schedule_render)
576+
hook = LifeCycleHook(schedule_render)
573577
574578
# --- start render cycle ---
575579
@@ -582,11 +586,11 @@ class LifeCycleHook:
582586
...
583587
584588
# the component may access the current hook
585-
assert hooks.current_hook() is hook
589+
assert current_hook() is hook
586590
587591
# and save state or add effects
588592
current_hook().use_state(lambda: ...)
589-
current_hook().use_effect(DID_RENDER_EFFECT, lambda: ...)
593+
current_hook().add_effect(COMPONENT_DID_RENDER_EFFECT, lambda: ...)
590594
finally:
591595
hook.unset_current()
592596

src/idom/core/layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from ._event_proxy import _wrap_in_warning_event_proxies
3434
from .hooks import LifeCycleHook
35-
from .proto import ComponentType, EventHandlerDict, VdomDict, VdomJson
35+
from .types import ComponentType, EventHandlerDict, VdomDict, VdomJson
3636
from .vdom import validate_vdom_json
3737

3838

src/idom/core/proto.py renamed to src/idom/core/types.py

+12
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,15 @@ class EventHandlerType(Protocol):
180180
181181
When ``None``, it is left to a :class:`LayoutType` to auto generate a unique ID.
182182
"""
183+
184+
185+
class VdomDictConstructor(Protocol):
186+
"""Standard function for constructing a :class:`VdomDict`"""
187+
188+
def __call__(
189+
self,
190+
*attributes_and_children: VdomAttributesAndChildren,
191+
key: str = ...,
192+
event_handlers: Optional[EventHandlerMapping] = ...,
193+
) -> VdomDict:
194+
...

src/idom/core/vdom.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
merge_event_handlers,
1414
to_event_handler_function,
1515
)
16-
from idom.core.proto import (
16+
from idom.core.types import (
1717
EventHandlerDict,
1818
EventHandlerMapping,
1919
EventHandlerType,
@@ -320,7 +320,7 @@ def _is_single_child(value: Any) -> bool:
320320
if _debug_is_single_child(value):
321321
return True
322322

323-
from .proto import ComponentType
323+
from .types import ComponentType
324324

325325
if hasattr(value, "__iter__") and not hasattr(value, "__len__"):
326326
logger.error(

src/idom/html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160

161161
from typing import Any, Mapping
162162

163-
from .core.proto import Key, VdomDict
163+
from .core.types import Key, VdomDict
164164
from .core.vdom import coalesce_attributes_and_children, make_vdom_constructor
165165

166166

src/idom/sample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import webbrowser
44
from typing import Any
55

6-
from idom.server.proto import ServerType
6+
from idom.server.types import ServerType
77

88
from . import html
99
from .core.component import component
10-
from .core.proto import VdomDict
10+
from .core.types import VdomDict
1111
from .server.utils import find_available_port, find_builtin_server_type
1212

1313

src/idom/server/fastapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from fastapi import FastAPI
44

5-
from idom.core.proto import ComponentConstructor
5+
from idom.core.types import ComponentConstructor
66

77
from .starlette import (
88
Config,

src/idom/server/flask.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR
2323
from idom.core.dispatcher import dispatch_single_view
2424
from idom.core.layout import LayoutEvent, LayoutUpdate
25-
from idom.core.proto import ComponentConstructor, ComponentType
25+
from idom.core.types import ComponentConstructor, ComponentType
2626

2727
from .utils import CLIENT_BUILD_DIR, threaded, wait_on_event
2828

src/idom/server/prefab.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22
from typing import Any, Dict, Optional, Tuple, TypeVar
33

4-
from idom.core.proto import ComponentConstructor
4+
from idom.core.types import ComponentConstructor
55
from idom.widgets import MountFunc, MultiViewMount, hotswap, multiview
66

7-
from .proto import ServerFactory, ServerType
7+
from .types import ServerFactory, ServerType
88
from .utils import find_available_port, find_builtin_server_type
99

1010

src/idom/server/sanic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ensure_shared_view_dispatcher_future,
2424
)
2525
from idom.core.layout import Layout, LayoutEvent
26-
from idom.core.proto import ComponentConstructor
26+
from idom.core.types import ComponentConstructor
2727

2828
from .utils import CLIENT_BUILD_DIR, threaded, wait_on_event
2929

src/idom/server/starlette.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ensure_shared_view_dispatcher_future,
3131
)
3232
from idom.core.layout import Layout, LayoutEvent
33-
from idom.core.proto import ComponentConstructor
33+
from idom.core.types import ComponentConstructor
3434

3535
from .utils import CLIENT_BUILD_DIR, poll, threaded
3636

src/idom/server/tornado.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from idom.config import IDOM_WEB_MODULES_DIR
1717
from idom.core.dispatcher import VdomJsonPatch, dispatch_single_view
1818
from idom.core.layout import Layout, LayoutEvent
19-
from idom.core.proto import ComponentConstructor
19+
from idom.core.types import ComponentConstructor
2020

2121
from .utils import CLIENT_BUILD_DIR, threaded, wait_on_event
2222

src/idom/server/proto.py renamed to src/idom/server/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from typing_extensions import Protocol
77

8-
from idom.core.proto import ComponentConstructor
8+
from idom.core.types import ComponentConstructor
99

1010

1111
_App = TypeVar("_App")

src/idom/server/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import idom
1414

15-
from .proto import ServerFactory
15+
from .types import ServerFactory
1616

1717

1818
CLIENT_BUILD_DIR = Path(idom.__file__).parent / "client"

src/idom/testing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from idom.core.events import EventHandler, to_event_handler_function
3535
from idom.core.hooks import LifeCycleHook, current_hook
3636
from idom.server.prefab import hotswap_server
37-
from idom.server.proto import ServerFactory, ServerType
37+
from idom.server.types import ServerFactory, ServerType
3838
from idom.server.utils import find_available_port
3939

4040
from .log import ROOT_LOGGER

src/idom/types.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Exports common types from:
2+
3+
- :mod:`idom.core.types`
4+
- :mod:`idom.server.types`
5+
"""
6+
7+
from .core.types import (
8+
ComponentConstructor,
9+
ComponentType,
10+
EventHandlerDict,
11+
EventHandlerFunc,
12+
EventHandlerMapping,
13+
EventHandlerType,
14+
ImportSourceDict,
15+
Key,
16+
LayoutType,
17+
VdomAttributes,
18+
VdomAttributesAndChildren,
19+
VdomChild,
20+
VdomChildren,
21+
VdomDict,
22+
VdomJson,
23+
)
24+
from .server.types import ServerFactory, ServerType
25+
26+
27+
__all__ = [
28+
"ComponentConstructor",
29+
"ComponentType",
30+
"EventHandlerDict",
31+
"EventHandlerFunc",
32+
"EventHandlerMapping",
33+
"EventHandlerType",
34+
"ImportSourceDict",
35+
"Key",
36+
"LayoutType",
37+
"VdomAttributes",
38+
"VdomAttributesAndChildren",
39+
"VdomChild",
40+
"VdomChildren",
41+
"VdomDict",
42+
"VdomJson",
43+
"ServerFactory",
44+
"ServerType",
45+
]

0 commit comments

Comments
 (0)