11from __future__ import annotations
22
3+ import filecmp
34import logging
45import shutil
56from 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+
225230def _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 ()} "
0 commit comments