Skip to content

Commit 79bd0ff

Browse files
committed
misc fixes
1 parent 598bcf7 commit 79bd0ff

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

requirements/pkg-deps.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ requests >=2
77
colorlog >=6
88
asgiref >=3
99
lxml >=4
10-
typer >=8, <9
10+
click >=8, <9

src/idom/_console/update_html_usages.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import ast
44
import re
55
from collections.abc import Sequence
6-
from glob import iglob
6+
from glob import glob
77
from keyword import kwlist
88
from pathlib import Path
99
from textwrap import indent
@@ -20,9 +20,9 @@
2020

2121

2222
@click.command()
23-
@click.argument("patterns", nargs=-1)
24-
def update_html_usages(patterns: list[str]) -> None:
25-
"""Rewrite files matching the given glob patterns to the new html element API.
23+
@click.argument("directories", nargs=-1)
24+
def update_html_usages(directories: list[str]) -> None:
25+
"""Rewrite files in the given directories to use the new html element API.
2626
2727
The old API required users to pass a dictionary of attributes to html element
2828
constructor functions. For example:
@@ -50,8 +50,8 @@ def update_html_usages(patterns: list[str]) -> None:
5050
just above its changes. As such it requires manual intervention to put those
5151
comments back in their original location.
5252
"""
53-
for pat in patterns:
54-
for file in map(Path, iglob(pat)):
53+
for d in directories:
54+
for file in Path(d).rglob("*.py"):
5555
result = generate_rewrite(file=file, source=file.read_text())
5656
if result is not None:
5757
file.write_text(result)

src/idom/core/vdom.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
from typing import Any, Mapping, cast
5+
from warnings import warn
56

67
from fastjsonschema import compile as compile_json_schema
78

@@ -153,20 +154,32 @@ def vdom(
153154
"""
154155
model: VdomDict = {"tagName": tag}
155156

156-
children: list[VdomChild] = []
157+
flattened_children: list[VdomChild] = []
157158
for child in children:
159+
if isinstance(child, dict) and "tagName" not in child:
160+
warn(
161+
(
162+
"Element constructor signatures have changed! A CLI tool for "
163+
"automatically updating code to the latest API has been provided "
164+
"with this release of IDOM (e.g. 'idom update-html-usages'). For "
165+
"start a discussion if you need help transitioning to this new "
166+
"interface: https://github.com/idom-team/idom/discussions/new?category=question"
167+
),
168+
DeprecationWarning,
169+
)
170+
attributes.update(child)
158171
if _is_single_child(child):
159-
children.append(child)
172+
flattened_children.append(child)
160173
else:
161-
children.extend(child)
174+
flattened_children.extend(child)
162175

163176
attributes, event_handlers = separate_attributes_and_event_handlers(attributes)
164177

165178
if attributes:
166179
model["attributes"] = attributes
167180

168-
if children:
169-
model["children"] = children
181+
if flattened_children:
182+
model["children"] = flattened_children
170183

171184
if event_handlers:
172185
model["eventHandlers"] = event_handlers

tests/test__console/test_update_html_usages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_update_html_usages(tmp_path):
1313
tempfile: Path = tmp_path / "temp.py"
1414
tempfile.write_text("html.div({'className': test})")
1515

16-
result = runner.invoke(update_html_usages, str(tempfile))
16+
result = runner.invoke(update_html_usages, str(tmp_path))
1717

1818
if result.exception:
1919
raise result.exception

0 commit comments

Comments
 (0)