Skip to content

Commit

Permalink
better logging for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Mar 14, 2021
1 parent dae287f commit 39565b9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
25 changes: 19 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import re
from pathlib import Path
from typing import List

import nox
from nox.sessions import Session


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


def get_posargs(name: str, session: Session) -> List[str]:
Expand All @@ -21,7 +23,7 @@ def get_posargs(name: str, session: Session) -> List[str]:
"""
collected_args: List[str] = []
for arg in session.posargs:
match = posargs_pattern.match(arg)
match = POSARGS_PATTERN.match(arg)
if match is not None:
found_name, found_args = match.groups()
if name == found_name:
Expand All @@ -34,16 +36,22 @@ def get_posargs(name: str, session: Session) -> List[str]:
@nox.session(reuse_venv=True)
def example(session: Session) -> None:
"""Run an example"""
if not session.posargs:
print("No example name given. Choose from:")
for found_example_file in (HERE / "docs" / "source" / "examples").glob("*.py"):
print("-", found_example_file.stem)
return None

session.install("matplotlib")
session.install("-e", ".[stable]")
install_idom_dev(session)
session.run("python", "scripts/one_example.py", *session.posargs)


@nox.session(reuse_venv=True)
def docs(session: Session) -> None:
"""Build and display documentation in the browser (automatically reloads on change)"""
session.install("-r", "requirements/build-docs.txt")
session.install("-e", ".[all]")
install_idom_dev(session, extras="all")
session.run(
"python",
"scripts/live_docs.py",
Expand Down Expand Up @@ -93,7 +101,7 @@ def test_python(session: Session) -> None:
if "--no-cov" in pytest_args:
session.install(".[all]")
else:
session.install("-e", ".[all]")
install_idom_dev(session, extras="all")

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

Expand Down Expand Up @@ -127,6 +135,11 @@ def test_style(session: Session) -> None:
def test_docs(session: Session) -> None:
"""Verify that the docs build and that doctests pass"""
session.install("-r", "requirements/build-docs.txt")
session.install("-e", ".[all]")
install_idom_dev(session, extras="all")
session.run("sphinx-build", "-b", "html", "docs/source", "docs/build")
session.run("sphinx-build", "-b", "doctest", "docs/source", "docs/build")


def install_idom_dev(session: Session, extras: str = "stable") -> None:
session.install("-e", f".[{extras}]")
session.run("idom", "restore")
10 changes: 6 additions & 4 deletions src/idom/client/app/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { mountLayout } from "idom-client-react";

const userPackages = import("./user-packages.js").then((packages) => {
packages.forEach((pkg) => {
console.log(`Loaded ${pkg}`);
});
const userPackages = import("./user-packages.js").then((module) => {
for (const pkgName in module.default) {
module.default[pkgName].then((pkg) => {
console.log(`Loaded module '${pkgName}'`);
});
}
});

export function mountLayoutWithWebSocket(element, endpoint, importSourceURL) {
Expand Down
2 changes: 1 addition & 1 deletion src/idom/client/app/src/user-packages.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default [];
export default {};
19 changes: 13 additions & 6 deletions src/idom/client/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from logging import getLogger
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import List, Sequence, Set, Union
from typing import Iterable, List, Sequence, Set, Union

from idom.config import IDOM_CLIENT_WEB_MODULE_BASE_URL

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

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

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


def _write_user_packages_file(filepath: Path, packages: Iterable[str]) -> None:
filepath.write_text(
_USER_PACKAGES_FILE_TEMPLATE.format(
imports=",".join(f'"{pkg}":import({pkg!r})' for pkg in packages)
)
)


_USER_PACKAGES_FILE_TEMPLATE = """// THIS FILE WAS GENERATED BY IDOM - DO NOT MODIFY
export default [{imports}];
export default {{{imports}}};
"""

0 comments on commit 39565b9

Please sign in to comment.