1
1
from __future__ import annotations
2
2
3
+ import filecmp
3
4
import logging
4
5
import shutil
5
6
from dataclasses import dataclass
@@ -189,18 +190,14 @@ def module_from_file(
189
190
symlink:
190
191
Whether the web module should be saved as a symlink to the given ``file``.
191
192
"""
192
- source_file = Path (file )
193
+ source_file = Path (file ). resolve ()
193
194
target_file = _web_module_path (name )
194
195
if not source_file .exists ():
195
196
raise FileNotFoundError (f"Source file does not exist: { source_file } " )
196
197
197
198
if not target_file .exists ():
198
199
_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 ):
204
201
logger .info (
205
202
f"Existing web module { name !r} will "
206
203
f"be replaced with { target_file .resolve ()} "
@@ -222,6 +219,14 @@ def module_from_file(
222
219
)
223
220
224
221
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
+
225
230
def _copy_file (target : Path , source : Path , symlink : bool ) -> None :
226
231
target .parent .mkdir (parents = True , exist_ok = True )
227
232
if symlink :
@@ -259,7 +264,7 @@ def module_from_string(
259
264
"""
260
265
target_file = _web_module_path (name )
261
266
262
- if target_file .exists ():
267
+ if target_file .exists () and target_file . read_text () != content :
263
268
logger .info (
264
269
f"Existing web module { name !r} will "
265
270
f"be replaced with { target_file .resolve ()} "
0 commit comments