File tree 4 files changed +26
-13
lines changed
4 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,4 @@ requests >=2
7
7
colorlog >=6
8
8
asgiref >=3
9
9
lxml >=4
10
- typer >=8, <9
10
+ click >=8, <9
Original file line number Diff line number Diff line change 3
3
import ast
4
4
import re
5
5
from collections .abc import Sequence
6
- from glob import iglob
6
+ from glob import glob
7
7
from keyword import kwlist
8
8
from pathlib import Path
9
9
from textwrap import indent
20
20
21
21
22
22
@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.
26
26
27
27
The old API required users to pass a dictionary of attributes to html element
28
28
constructor functions. For example:
@@ -50,8 +50,8 @@ def update_html_usages(patterns: list[str]) -> None:
50
50
just above its changes. As such it requires manual intervention to put those
51
51
comments back in their original location.
52
52
"""
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" ):
55
55
result = generate_rewrite (file = file , source = file .read_text ())
56
56
if result is not None :
57
57
file .write_text (result )
Original file line number Diff line number Diff line change 2
2
3
3
import logging
4
4
from typing import Any , Mapping , cast
5
+ from warnings import warn
5
6
6
7
from fastjsonschema import compile as compile_json_schema
7
8
@@ -153,20 +154,32 @@ def vdom(
153
154
"""
154
155
model : VdomDict = {"tagName" : tag }
155
156
156
- children : list [VdomChild ] = []
157
+ flattened_children : list [VdomChild ] = []
157
158
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 )
158
171
if _is_single_child (child ):
159
- children .append (child )
172
+ flattened_children .append (child )
160
173
else :
161
- children .extend (child )
174
+ flattened_children .extend (child )
162
175
163
176
attributes , event_handlers = separate_attributes_and_event_handlers (attributes )
164
177
165
178
if attributes :
166
179
model ["attributes" ] = attributes
167
180
168
- if children :
169
- model ["children" ] = children
181
+ if flattened_children :
182
+ model ["children" ] = flattened_children
170
183
171
184
if event_handlers :
172
185
model ["eventHandlers" ] = event_handlers
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def test_update_html_usages(tmp_path):
13
13
tempfile : Path = tmp_path / "temp.py"
14
14
tempfile .write_text ("html.div({'className': test})" )
15
15
16
- result = runner .invoke (update_html_usages , str (tempfile ))
16
+ result = runner .invoke (update_html_usages , str (tmp_path ))
17
17
18
18
if result .exception :
19
19
raise result .exception
You can’t perform that action at this time.
0 commit comments