Skip to content

Commit b7967a5

Browse files
committed
initial docs for CLI and config options
also includes improved scrollbar styling
1 parent 5dfef51 commit b7967a5

File tree

11 files changed

+108
-25
lines changed

11 files changed

+108
-25
lines changed

docs/source/_static/css/better-scrollbar.css

Whitespace-only changes.

docs/source/command-line.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Command-line
2+
============
3+
4+
IDOM supplies a CLI for:
5+
6+
- Displaying version information
7+
- Installing Javascript packages
8+
- Restoring IDOM's client
9+
10+
11+
Show Version Info
12+
-----------------
13+
14+
To see the version of ``idom`` being run:
15+
16+
.. code-block:: bash
17+
18+
idom version
19+
20+
You can also show all available versioning information:
21+
22+
.. code-block:: bash
23+
24+
idom version --verbose
25+
26+
This is useful for bug reports.
27+
28+
29+
Install Javascript Packages
30+
---------------------------
31+
32+
You can install Javascript packages at the command line rather than doing it
33+
:ref:`programmatically <Dynamically Install Javascript>`:
34+
35+
.. code-block:: bash
36+
37+
idom install some-js-package versioned-js-package@^1.0.0
38+
39+
If the package is already installed then the build will be skipped.
40+
41+
42+
Restore The Client
43+
------------------
44+
45+
Replace IDOM's client with a backup from its original installation.
46+
47+
.. code-block:: bash
48+
49+
idom restore
50+
51+
This is useful if a build of the client fails and leaves it in an unusable state.

docs/source/configuration-options.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Configuration Options
2+
=====================
3+
4+
IDOM provides a series of configuration options that can be set using environment
5+
variables or, for those which allow it, using a programatic interface.
6+
7+
.. automodule:: idom.config
8+
:members:
9+
10+
11+
.. autoclass:: idom.config._option.Option
12+
:members:

docs/source/index.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ Libraries for defining and controlling interactive webpages with Python
1010
installation
1111
getting-started
1212
life-cycle-hooks
13+
package-api
14+
examples
15+
16+
.. toctree::
17+
:hidden:
18+
:caption: Advanced Usage
19+
1320
core-concepts
1421
javascript-components
22+
command-line
23+
configuration-options
1524
specifications
16-
package-api
17-
examples
1825

1926
.. toctree::
2027
:hidden:

docs/source/installation.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ For more installation options see the :ref:`Extra Features` section.
1717

1818
.. note::
1919

20-
To contribute to IDOM, refer to the :ref:`Developer Guide` instructions.
20+
IDOM also supplies a :ref:`Flake8 Plugin` to help enforce the :ref:`Rules of Hooks`
2121

2222

2323
Extra Features
2424
--------------
2525

26-
Optionally installable features of IDOM. To install them use the given "Name" from the table below
26+
Optionally installable features of IDOM. To include, them use the given "Name" from the
27+
table below:
2728

2829
.. code-block:: bash
2930
@@ -136,9 +137,8 @@ How It Works
136137
Once ``idom`` has been imported at your application's entrypoint, any following modules
137138
imported with a ``# dialect=html`` header comment get transpiled just before they're
138139
executed. This is accomplished by using Pyalect_ to hook a transpiler into Pythons
139-
import system. The :class:`~idom.dialect.HtmlDialectTranspiler` which implements
140-
Pyalect_'s :class:`~pyalect.dialect.Transpiler` interface using some tooling from
141-
htm.py_.
140+
import system. The :class:`~idom.dialect.HtmlDialectTranspiler` implements Pyalect_'s
141+
:class:`~pyalect.dialect.Transpiler` interface using some tooling from htm.py_.
142142

143143

144144
.. Links

docs/source/life-cycle-hooks.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Rules of Hooks
300300

301301
Hooks are just normal Python functions, but there's a bit of magic to them, and in order
302302
for that magic to work you've got to follow two rules. Thankfully we supply a
303-
`Flake8 Linter Plugin`_ to help enforce them.
303+
:ref:`Flake8 Plugin` to help enforce them.
304304

305305

306306
Only call outside flow controls

docs/source/package-api.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,3 @@ Useful Tools
9797

9898
.. automodule:: idom.utils
9999
:members:
100-
101-
102-
Configuration Options
103-
---------------------
104-
105-
.. automodule:: idom.config
106-
:members:

src/idom/_option.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,38 @@ def __init__(
1414
self,
1515
name: str,
1616
default: _O,
17-
immutable: bool = False,
17+
mutable: bool = True,
1818
validator: Callable[[Any], _O] = lambda x: cast(_O, x),
1919
) -> None:
2020
self.name = name
2121
self._default = default
22-
self._immutable = immutable
22+
self._mutable = mutable
2323
self._validator = validator
2424
self._value = validator(os.environ.get(name, default))
2525

26+
@property
27+
def mutable(self) -> bool:
28+
"""Whether this option can be modified after being loaded"""
29+
return self._mutable
30+
2631
def get(self) -> _O:
32+
"""Get the current value of this option."""
2733
return self._value
2834

2935
def set(self, new: _O) -> _O:
30-
if self._immutable:
36+
"""Set the value of this configuration option
37+
38+
Raises a ``TypeError`` if this option is immutable.
39+
"""
40+
if not self._mutable:
3141
raise TypeError(f"{self} cannot be modified after initial load")
3242
old = self._value
3343
self._value = self._validator(new)
3444
return old
3545

3646
def reset(self) -> _O:
47+
"""Reset the value of this option to its default setting"""
3748
return self.set(self._default)
3849

3950
def __repr__(self) -> str:
40-
return f"Option(name={self.name!r}, value={self._value!r})"
51+
return f"Option({self.name}={self._value!r})"

src/idom/config.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
from pathlib import Path
2+
from typing import cast
23

34
from . import _option
45

56

67
IDOM_DEBUG_MODE = _option.Option(
78
"IDOM_DEBUG_MODE",
89
default=False,
9-
immutable=True,
10+
mutable=False,
1011
validator=lambda x: bool(int(x)),
1112
)
12-
"""Turn on/off debug mode"""
13+
"""This immutable option turns on/off debug mode
14+
15+
The string values ``1`` and ``0`` are mapped to ``True`` and ``False`` respectively.
16+
17+
When debug is on, extra validation measures are applied that negatively impact
18+
performance but can be used to catch bugs. Additionally, the default log level for IDOM
19+
is set to ``DEBUG``.
20+
"""
1321

1422
IDOM_CLIENT_BUILD_DIR = _option.Option(
1523
"IDOM_CLIENT_BUILD_DIR",
1624
default=Path(__file__).parent / "client" / "build",
1725
validator=Path,
1826
)
19-
"""The location IDOM will use for its client application"""
27+
"""The location IDOM will use to store its client application"""
2028

2129
IDOM_CLIENT_WEB_MODULE_BASE_URL = _option.Option(
2230
"IDOM_CLIENT_WEB_MODULE_BASE_URL",
2331
default=".",
24-
validator=lambda x: str(x).rstrip("/"),
32+
validator=lambda x: cast(str, x[:-1] if x.endswith("/") else x),
2533
)
2634
"""The base URL where all user-installed web modules reside"""

tests/test__option.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def test_option_repr():
1010
opt = Option("A_FAKE_OPTION", "some-value")
11-
assert repr(opt) == "Option(name='A_FAKE_OPTION', value='some-value')"
11+
assert repr(opt) == "Option(A_FAKE_OPTION='some-value')"
1212

1313

1414
@mock.patch.dict(os.environ, {"A_FAKE_OPTION": "value-from-environ"})
@@ -36,7 +36,8 @@ def test_option_validator():
3636

3737

3838
def test_immutable_option():
39-
opt = Option("A_FAKE_OPTION", "default-value", immutable=True)
39+
opt = Option("A_FAKE_OPTION", "default-value", mutable=False)
40+
assert not opt.mutable
4041
with pytest.raises(TypeError, match="cannot be modified after initial load"):
4142
opt.set("a-new-value")
4243

0 commit comments

Comments
 (0)