Skip to content

Commit 703ed6a

Browse files
committed
Attempt new rewrite script
1 parent 0b4db73 commit 703ed6a

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ test = [
194194
]
195195
build = [
196196
'hatch run "src/build_scripts/clean_js_dir.py"',
197+
'bun install --cwd "src/js"',
197198
'hatch run javascript:build_event_to_object',
198199
'hatch run javascript:build_client',
199200
'hatch run javascript:build_app',

src/reactpy/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import click
22

33
import reactpy
4-
from reactpy._console.rewrite_camel_case_props import rewrite_camel_case_props
54
from reactpy._console.rewrite_keys import rewrite_keys
5+
from reactpy._console.rewrite_props import rewrite_props
66

77

88
@click.group()
@@ -12,7 +12,7 @@ def app() -> None:
1212

1313

1414
app.add_command(rewrite_keys)
15-
app.add_command(rewrite_camel_case_props)
15+
app.add_command(rewrite_props)
1616

1717

1818
if __name__ == "__main__":

src/reactpy/_console/rewrite_camel_case_props.py renamed to src/reactpy/_console/rewrite_props.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
@click.command()
2222
@click.argument("paths", nargs=-1, type=click.Path(exists=True))
23-
def rewrite_camel_case_props(paths: list[str]) -> None:
24-
"""Rewrite camelCase props to snake_case"""
23+
def rewrite_props(paths: list[str]) -> None:
24+
"""Rewrite snake_case to props to camelCase"""
2525

2626
for p in map(Path, paths):
2727
for f in [p] if p.is_file() else p.rglob("*.py"):
@@ -50,8 +50,11 @@ def find_nodes_to_change(tree: ast.AST) -> list[ChangedNode]:
5050

5151

5252
def conv_attr_name(name: str) -> str:
53-
new_name = CAMEL_CASE_SUB_PATTERN.sub("_", name).lower()
54-
return f"{new_name}_" if new_name in kwlist else new_name
53+
if name in kwlist:
54+
return name
55+
result = name.replace("_", " ").title().replace(" ", "")
56+
result = name[0].lower() + name[1:]
57+
return result
5558

5659

5760
def _construct_prop_item(key: str, value: ast.expr) -> tuple[str, ast.expr]:

tests/test_console/test_rewrite_camel_case_props.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import pytest
55
from click.testing import CliRunner
66

7-
from reactpy._console.rewrite_camel_case_props import (
7+
from reactpy._console.rewrite_props import (
88
generate_rewrite,
9-
rewrite_camel_case_props,
9+
rewrite_props,
1010
)
1111

1212

@@ -16,7 +16,7 @@ def test_rewrite_camel_case_props_declarations(tmp_path):
1616
tempfile: Path = tmp_path / "temp.py"
1717
tempfile.write_text("html.div(dict(camelCase='test'))")
1818
result = runner.invoke(
19-
rewrite_camel_case_props,
19+
rewrite_props,
2020
args=[str(tmp_path)],
2121
catch_exceptions=False,
2222
)
@@ -29,7 +29,7 @@ def test_rewrite_camel_case_props_declarations_no_files():
2929
runner = CliRunner()
3030

3131
result = runner.invoke(
32-
rewrite_camel_case_props,
32+
rewrite_props,
3333
args=["directory-does-no-exist"],
3434
catch_exceptions=False,
3535
)

0 commit comments

Comments
 (0)