Skip to content

Commit 762281f

Browse files
committed
put all modules under web_modules + more test coverage
1 parent 73b2f56 commit 762281f

File tree

14 files changed

+70
-73
lines changed

14 files changed

+70
-73
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
repos:
2-
- repo: https://github.com/ambv/black
2+
- repo: https://github.com/ambv/black
33
rev: stable
44
hooks:
5-
- id: black
6-
language_version: python3.6
7-
- repo: https://github.com/PyCQA/flake8
5+
- id: black
6+
language_version: python3.6
7+
- repo: https://github.com/PyCQA/flake8
88
rev: 3.7.9
99
hooks:
10-
- id: flake8
11-
- repo: https://github.com/pre-commit/mirrors-mypy
10+
- id: flake8
11+
- repo: https://github.com/pre-commit/mirrors-mypy
1212
rev: v0.761
1313
hooks:
14-
- id: mypy
14+
- id: mypy
1515
additional_dependencies: [pyalect]
16+
- repo: https://github.com/kynan/nbstripout
17+
rev: master
18+
hooks:
19+
- id: nbstripout
20+
files: ".ipynb"

docs/source/extras.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ While ``your_module.py`` should contain the following:
105105
106106
# dialect=html
107107
from idom import html
108-
assert html("<div/>") == {"tagName": "div"}
108+
assert html(f"<div/>") == {"tagName": "div"}
109109
110110
And that's it!
111111

examples/chart.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import React from "../web_modules/react.js";
2-
import {
3-
VictoryBar,
4-
VictoryChart,
5-
VictoryTheme,
6-
Bar,
7-
} from "../web_modules/victory.js";
8-
import htm from "../web_modules/htm.js";
1+
import React from "./react.js";
2+
import { VictoryBar, VictoryChart, VictoryTheme, Bar } from "./victory.js";
3+
import htm from "./htm.js";
94

105
const html = htm.bind(React.createElement);
116

idom/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
from .tools import Var, html_to_vdom
1717

18+
# try to automatically setup the dialect's import hook
1819
try:
1920
import pyalect
2021
import tagged
2122
import htm
22-
except ImportError:
23+
except ImportError: # pragma: no cover
2324
pass
2425
else:
2526
from . import dialect

idom/client/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules
22
web_modules
3-
user_modules

idom/client/__init__.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,31 @@
1212
CORE_MODULES = CLIENT_DIR / "core_modules"
1313
NODE_MODULES = CLIENT_DIR / "node_modules"
1414
WEB_MODULES = CLIENT_DIR / "web_modules"
15-
USER_MODULES = CLIENT_DIR / "user_modules"
1615

1716

18-
def import_path(prefix: str, name: str) -> str:
19-
path = f"../{prefix}/{name}.js"
20-
if not module_exists(prefix, name):
17+
def import_path(name: str) -> str:
18+
path = f"../{WEB_MODULES.name}/{name}.js"
19+
if not module_exists(name):
2120
raise ValueError(f"Module '{path}' does not exist.")
2221
return path
2322

2423

2524
def define_module(name: str, source: str) -> str:
26-
path = _create_module_os_path(USER_MODULES, name)
25+
path = _create_web_module_os_path(name)
2726
with path.open("w+") as f:
2827
f.write(source)
29-
return import_path("user_modules", name)
28+
return import_path(name)
3029

3130

32-
def delete_module(prefix: str, name: str) -> None:
33-
path = _find_module_os_path(prefix, name)
31+
def delete_module(name: str) -> None:
32+
path = _find_web_module_os_path(name)
3433
if path is None:
35-
raise ValueError(f"Module '{import_path(prefix, name)}' does not exist.")
34+
raise ValueError(f"Module '{name}' does not exist.")
3635
_delete_os_paths(path)
3736

3837

39-
def module_exists(prefix: Union[str, Path], name: str) -> bool:
40-
return _find_module_os_path(prefix, name) is not None
38+
def module_exists(name: str) -> bool:
39+
return _find_web_module_os_path(name) is not None
4140

4241

4342
def install(dependencies: Dict[str, str]) -> None:
@@ -65,7 +64,7 @@ def install(dependencies: Dict[str, str]) -> None:
6564

6665

6766
def restore() -> None:
68-
_delete_os_paths(WEB_MODULES, NODE_MODULES, USER_MODULES)
67+
_delete_os_paths(WEB_MODULES, NODE_MODULES)
6968
_run_subprocess(["npm", "install"], CLIENT_DIR)
7069
_run_subprocess(["npm", "run", "snowpack"], CLIENT_DIR)
7170

@@ -99,11 +98,8 @@ def _run_subprocess(args: List[str], cwd: Union[str, Path]):
9998
raise
10099

101100

102-
def _find_module_os_path(prefix: Union[str, Path], name: str) -> Optional[Path]:
103-
if isinstance(prefix, str):
104-
path = CLIENT_DIR / prefix
105-
else:
106-
path = prefix
101+
def _find_web_module_os_path(name: str) -> Optional[Path]:
102+
path = WEB_MODULES
107103
for name_part in name.split("/"):
108104
if not path.is_dir():
109105
return None
@@ -114,11 +110,8 @@ def _find_module_os_path(prefix: Union[str, Path], name: str) -> Optional[Path]:
114110
return full_path
115111

116112

117-
def _create_module_os_path(prefix: Union[str, Path], name: str) -> Path:
118-
if isinstance(prefix, str):
119-
path = CLIENT_DIR / prefix
120-
else:
121-
path = prefix
113+
def _create_web_module_os_path(name: str) -> Path:
114+
path = WEB_MODULES
122115
for n in name.split("/"):
123116
if not path.exists():
124117
path.mkdir()

idom/core/element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818

1919

20-
if TYPE_CHECKING:
20+
if TYPE_CHECKING: # pragma: no cover
2121
from .layout import AbstractLayout
2222
from .vdom import VdomDict # noqa
2323

idom/server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
for name in ["sanic"]:
1414
try:
1515
import_module(name)
16-
except ImportError:
16+
except ImportError: # pragma: no cover
1717
pass
1818
else:
1919
import_module(__name__ + "." + name)

idom/widgets/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def __init__(
6363
install: Union[str, bool] = False,
6464
) -> None:
6565
if install:
66-
if not client.module_exists("web_modules", package):
66+
if not client.module_exists(package):
6767
if isinstance(install, str):
6868
client.install({install: package})
6969
else:
7070
client.install({package: package})
71-
new_import_path = client.import_path("web_modules", package)
71+
new_import_path = client.import_path(package)
7272
if new_import_path is None:
7373
raise ValueError(f"Unexpectedly failed to find install of {package}")
7474
package = new_import_path

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ xfail_strict = True
2929
addopts = --cov=idom
3030

3131
[coverage:report]
32-
fail_under = 86
32+
fail_under = 87
3333
show_missing = True
3434
skip_covered = True
3535
sort = Miss
3636
exclude_lines =
3737
pragma: no cover
3838
\.\.\.
39+
raise NotImplementedError

0 commit comments

Comments
 (0)