Skip to content

Commit 788fd86

Browse files
committed
cli improvements
1 parent 74ad578 commit 788fd86

File tree

10 files changed

+74
-25
lines changed

10 files changed

+74
-25
lines changed

docs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ADD MANIFEST.in ./
2323
ADD README.md ./
2424

2525
RUN pip install -e .[all]
26-
RUN python -m idom install victory semantic-ui-react @material-ui/core
26+
RUN python -m idom client install victory semantic-ui-react @material-ui/core
2727

2828
# Build the Docs
2929
# --------------

docs/source/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Simply install your javascript library of choice using the ``idom`` CLI:
5757

5858
.. code-block:: bash
5959
60-
idom install victory
60+
idom client install victory
6161
6262
Then import the module with :class:`~idom.widgets.utils.Module`:
6363

docs/source/examples/super_simple_chart.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import idom
44

55

6+
# we use this to make writing our React code a bit easier
7+
idom.install("htm")
8+
69
path_to_source_file = Path(__file__).parent / "super_simple_chart.js"
710
ssc = idom.Module("super-simple-chart", source_file=path_to_source_file)
811

docs/source/javascript-components.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using the ``idom`` CLI:
3838

3939
.. code-block:: bash
4040
41-
idom install @material-ui/core
41+
idom client install @material-ui/core
4242
4343
Or at runtime with :func:`idom.client.module.install` (this is useful if you're working
4444
in a REPL or Jupyter Notebook):

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ def test_docs(session: Session) -> None:
142142

143143
def install_idom_dev(session: Session, extras: str = "stable") -> None:
144144
session.install("-e", f".[{extras}]")
145-
session.run("idom", "restore")
145+
session.run("idom", "client", "restore")

requirements/pkg-deps.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ jsonpatch >=1.26
77
typer >=0.3.2
88
click-spinner >=0.1.10
99
fastjsonschema >=2.14.5
10+
rich >=9.13.0

src/idom/cli.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
11
from typing import List
22

33
import typer
4+
from rich.console import Console
5+
from rich.table import Table
46

57
import idom
68
from idom.client import manage as manage_client
79

810

911
main = typer.Typer()
10-
show = typer.Typer()
11-
main.add_typer(show, name="show", short_help="Display information about IDOM")
12+
console = Console()
1213

14+
# --- Subcommands ---
15+
client = typer.Typer(name="client", short_help="Manage IDOM's built-in client")
16+
show = typer.Typer(name="show", short_help="Display information about IDOM")
17+
main.add_typer(client)
18+
main.add_typer(show)
1319

14-
@main.command()
20+
21+
@client.command()
1522
def install(packages: List[str]) -> None:
16-
"""Install a Javascript package from NPM"""
17-
manage_client.build(packages)
23+
"""Install a Javascript package from NPM into the client"""
24+
manage_client.build(packages, clean_build=False)
1825
return None
1926

2027

21-
@main.command()
22-
def restore(clean_build: bool = True) -> None:
23-
"""Return to a fresh install of IDOM's client"""
28+
@client.command()
29+
def rebuild(clean: bool = False) -> None:
30+
"""Rebuild the client (keeps currently installed packages by default)"""
31+
manage_client.build([], clean_build=clean)
32+
33+
34+
@client.command()
35+
def restore() -> None:
36+
"""Return to a fresh install of Ithe client"""
2437
manage_client.restore()
2538
return None
2639

2740

2841
@show.command()
29-
def version() -> None:
30-
"""The version of IDOM"""
31-
typer.echo(idom.__version__)
42+
def version(verbose: bool = False) -> None:
43+
"""Show version information"""
44+
if not verbose:
45+
console.print(idom.__version__)
46+
else:
47+
table = Table()
48+
49+
table.add_column("Package")
50+
table.add_column("Version")
51+
table.add_column("Language")
52+
53+
table.add_row("idom", str(idom.__version__), "Python")
54+
55+
for js_pkg, js_ver in manage_client.dependency_versions().items():
56+
table.add_row(js_pkg, js_ver, "Javascript")
57+
58+
console.print(table)

src/idom/client/manage.py

Lines changed: 7 additions & 2 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 Iterable, List, Sequence, Set, Union
7+
from typing import Dict, Iterable, List, Sequence, Set, Union
88

99
from idom.config import IDOM_CLIENT_WEB_MODULE_BASE_URL
1010

@@ -63,11 +63,16 @@ def web_module_path(package_name: str, must_exist: bool = False) -> Path:
6363
return path
6464

6565

66+
def dependency_versions() -> Dict[str, str]:
67+
package_json = _private.build_dir() / "package.json"
68+
return json.loads(package_json.read_text())["dependencies"]
69+
70+
6671
def restore() -> None:
6772
_private.restore_build_dir_from_backup()
6873

6974

70-
def build(packages_to_install: Sequence[str], clean_build: bool = False) -> None:
75+
def build(packages_to_install: Sequence[str], clean_build: bool = True) -> None:
7176
packages_to_install = list(packages_to_install)
7277

7378
with TemporaryDirectory() as tempdir:

src/idom/client/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def install(
3838
pkg_names = {_private.get_package_name(pkg) for pkg in packages}
3939

4040
if ignore_installed or pkg_names.difference(manage.web_module_names()):
41-
manage.build(packages)
41+
manage.build(packages, clean_build=False)
4242

4343
return (
4444
Module(pkg_names.pop(), fallback=fallback)

tests/test_cli.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,36 @@
22

33
import idom
44
from idom.cli import main
5-
from idom.client.manage import web_module_exists
5+
from idom.client.manage import dependency_versions, web_module_exists
66

77

88
cli_runner = CliRunner()
99

1010

1111
def test_install():
12-
result = cli_runner.invoke(main, ["install", "jquery"])
13-
assert result.exit_code == 0
12+
assert cli_runner.invoke(main, ["client", "install", "jquery"]).exit_code == 0
1413
assert web_module_exists("jquery")
1514

1615

1716
def test_restore():
18-
result = cli_runner.invoke(main, ["restore"])
19-
assert result.exit_code == 0
17+
assert cli_runner.invoke(main, ["client", "restore"]).exit_code == 0
2018

2119

2220
def test_show_version():
23-
result = cli_runner.invoke(main, ["show", "version"])
24-
assert idom.__version__ in result.stdout
21+
terse_result = cli_runner.invoke(main, ["show", "version"])
22+
assert idom.__version__ in terse_result.stdout
23+
24+
verbose_result = cli_runner.invoke(main, ["show", "version", "--verbose"])
25+
26+
actual_rows = []
27+
for line in verbose_result.stdout.split("\n"):
28+
maybe_row = list(map(str.strip, filter(None, line.split("│"))))
29+
if len(maybe_row) > 1:
30+
actual_rows.append(maybe_row)
31+
32+
expected_rows = [["idom", idom.__version__, "Python"]] + [
33+
[js_pkg, js_ver, "Javascript"]
34+
for js_pkg, js_ver in dependency_versions().items()
35+
]
36+
37+
assert actual_rows == expected_rows

0 commit comments

Comments
 (0)