Skip to content

Commit 39565b9

Browse files
committed
better logging for modules
1 parent dae287f commit 39565b9

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

noxfile.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import re
2+
from pathlib import Path
23
from typing import List
34

45
import nox
56
from nox.sessions import Session
67

78

8-
posargs_pattern = re.compile(r"^(\w+)\[(.+)\]$")
9+
HERE = Path(__file__).parent
10+
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
911

1012

1113
def get_posargs(name: str, session: Session) -> List[str]:
@@ -21,7 +23,7 @@ def get_posargs(name: str, session: Session) -> List[str]:
2123
"""
2224
collected_args: List[str] = []
2325
for arg in session.posargs:
24-
match = posargs_pattern.match(arg)
26+
match = POSARGS_PATTERN.match(arg)
2527
if match is not None:
2628
found_name, found_args = match.groups()
2729
if name == found_name:
@@ -34,16 +36,22 @@ def get_posargs(name: str, session: Session) -> List[str]:
3436
@nox.session(reuse_venv=True)
3537
def example(session: Session) -> None:
3638
"""Run an example"""
39+
if not session.posargs:
40+
print("No example name given. Choose from:")
41+
for found_example_file in (HERE / "docs" / "source" / "examples").glob("*.py"):
42+
print("-", found_example_file.stem)
43+
return None
44+
3745
session.install("matplotlib")
38-
session.install("-e", ".[stable]")
46+
install_idom_dev(session)
3947
session.run("python", "scripts/one_example.py", *session.posargs)
4048

4149

4250
@nox.session(reuse_venv=True)
4351
def docs(session: Session) -> None:
4452
"""Build and display documentation in the browser (automatically reloads on change)"""
4553
session.install("-r", "requirements/build-docs.txt")
46-
session.install("-e", ".[all]")
54+
install_idom_dev(session, extras="all")
4755
session.run(
4856
"python",
4957
"scripts/live_docs.py",
@@ -93,7 +101,7 @@ def test_python(session: Session) -> None:
93101
if "--no-cov" in pytest_args:
94102
session.install(".[all]")
95103
else:
96-
session.install("-e", ".[all]")
104+
install_idom_dev(session, extras="all")
97105

98106
session.run("pytest", "tests", *pytest_args)
99107

@@ -127,6 +135,11 @@ def test_style(session: Session) -> None:
127135
def test_docs(session: Session) -> None:
128136
"""Verify that the docs build and that doctests pass"""
129137
session.install("-r", "requirements/build-docs.txt")
130-
session.install("-e", ".[all]")
138+
install_idom_dev(session, extras="all")
131139
session.run("sphinx-build", "-b", "html", "docs/source", "docs/build")
132140
session.run("sphinx-build", "-b", "doctest", "docs/source", "docs/build")
141+
142+
143+
def install_idom_dev(session: Session, extras: str = "stable") -> None:
144+
session.install("-e", f".[{extras}]")
145+
session.run("idom", "restore")

src/idom/client/app/src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { mountLayout } from "idom-client-react";
22

3-
const userPackages = import("./user-packages.js").then((packages) => {
4-
packages.forEach((pkg) => {
5-
console.log(`Loaded ${pkg}`);
6-
});
3+
const userPackages = import("./user-packages.js").then((module) => {
4+
for (const pkgName in module.default) {
5+
module.default[pkgName].then((pkg) => {
6+
console.log(`Loaded module '${pkgName}'`);
7+
});
8+
}
79
});
810

911
export function mountLayoutWithWebSocket(element, endpoint, importSourceURL) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default [];
1+
export default {};

src/idom/client/manage.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from logging import getLogger
55
from pathlib import Path
66
from tempfile import TemporaryDirectory
7-
from typing import List, Sequence, Set, Union
7+
from typing import Iterable, List, Sequence, Set, Union
88

99
from idom.config import IDOM_CLIENT_WEB_MODULE_BASE_URL
1010

@@ -92,10 +92,9 @@ def build(packages_to_install: Sequence[str], clean_build: bool = False) -> None
9292
packages_to_install.append(f"{dep_name}@{dep_ver}")
9393
package_names_to_install.add(dep_name)
9494

95-
(temp_app_dir / "src" / "user-packages.js").write_text(
96-
_USER_PACKAGES_FILE_TEMPLATE.format(
97-
imports=",".join(f"import({pkg!r})" for pkg in package_names_to_install)
98-
)
95+
_write_user_packages_file(
96+
temp_app_dir / "src" / "user-packages.js",
97+
package_names_to_install,
9998
)
10099

101100
logger.info(f"Installing {packages_to_install or 'packages'} ...")
@@ -146,6 +145,14 @@ def _run_subprocess(args: List[str], cwd: Path) -> None:
146145
return None
147146

148147

148+
def _write_user_packages_file(filepath: Path, packages: Iterable[str]) -> None:
149+
filepath.write_text(
150+
_USER_PACKAGES_FILE_TEMPLATE.format(
151+
imports=",".join(f'"{pkg}":import({pkg!r})' for pkg in packages)
152+
)
153+
)
154+
155+
149156
_USER_PACKAGES_FILE_TEMPLATE = """// THIS FILE WAS GENERATED BY IDOM - DO NOT MODIFY
150-
export default [{imports}];
157+
export default {{{imports}}};
151158
"""

0 commit comments

Comments
 (0)