Skip to content

Commit 6100ed4

Browse files
committed
only change files if content is changed
1 parent 83d2d3f commit 6100ed4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Diff for: src/idom/web/module.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import filecmp
34
import logging
45
import shutil
56
from dataclasses import dataclass
@@ -189,18 +190,14 @@ def module_from_file(
189190
symlink:
190191
Whether the web module should be saved as a symlink to the given ``file``.
191192
"""
192-
source_file = Path(file)
193+
source_file = Path(file).resolve()
193194
target_file = _web_module_path(name)
194195
if not source_file.exists():
195196
raise FileNotFoundError(f"Source file does not exist: {source_file}")
196197

197198
if not target_file.exists():
198199
_copy_file(target_file, source_file, symlink)
199-
elif not (
200-
symlink
201-
and target_file.is_symlink()
202-
and target_file.resolve() == source_file.resolve()
203-
):
200+
elif not _equal_files(source_file, target_file):
204201
logger.info(
205202
f"Existing web module {name!r} will "
206203
f"be replaced with {target_file.resolve()}"
@@ -222,6 +219,14 @@ def module_from_file(
222219
)
223220

224221

222+
def _equal_files(f1: Path, f2: Path) -> bool:
223+
f1 = f1.resolve()
224+
f2 = f2.resolve()
225+
return (
226+
(f1.is_symlink() or f2.is_symlink()) and (f1.resolve() == f2.resolve())
227+
) or filecmp.cmp(str(f1), str(f2), shallow=False)
228+
229+
225230
def _copy_file(target: Path, source: Path, symlink: bool) -> None:
226231
target.parent.mkdir(parents=True, exist_ok=True)
227232
if symlink:
@@ -259,7 +264,7 @@ def module_from_string(
259264
"""
260265
target_file = _web_module_path(name)
261266

262-
if target_file.exists():
267+
if target_file.exists() and target_file.read_text() != content:
263268
logger.info(
264269
f"Existing web module {name!r} will "
265270
f"be replaced with {target_file.resolve()}"

Diff for: tests/test_web/test_module.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,6 @@ def test_imported_components_can_render_children(driver, display):
229229

230230

231231
def test_module_from_string():
232-
idom.web.module_from_string("temp", "")
232+
idom.web.module_from_string("temp", "old")
233233
with assert_idom_logged(r"Existing web module .* will be replaced with"):
234-
idom.web.module_from_string("temp", "")
234+
idom.web.module_from_string("temp", "new")

0 commit comments

Comments
 (0)