@@ -82,12 +82,13 @@ def include_js(
8282 ~ui.tags.script
8383 ~include_css
8484 """
85+ file_path = check_path (path )
8586
8687 if method == "inline" :
87- return tags .script (read_utf8 (path ), ** kwargs )
88+ return tags .script (read_utf8 (file_path ), ** kwargs )
8889
8990 include_files = method == "link_files"
90- path_dest , hash = maybe_copy_files (path , include_files )
91+ path_dest , hash = maybe_copy_files (file_path , include_files )
9192
9293 dep , src = create_include_dependency ("include-js-" + hash , path_dest , include_files )
9394
@@ -159,11 +160,12 @@ def include_css(
159160 ~include_js
160161 """
161162
163+ file_path = check_path (path )
162164 if method == "inline" :
163- return tags .style (read_utf8 (path ), type = "text/css" )
165+ return tags .style (read_utf8 (file_path ), type = "text/css" )
164166
165167 include_files = method == "link_files"
166- path_dest , hash = maybe_copy_files (path , include_files )
168+ path_dest , hash = maybe_copy_files (file_path , include_files )
167169
168170 dep , src = create_include_dependency (
169171 "include-css-" + hash , path_dest , include_files
@@ -177,6 +179,17 @@ def include_css(
177179# ---------------------------------------------------------------------------
178180
179181
182+ def check_path (path : Path | str ) -> Path :
183+ path = Path (path )
184+ if not path .exists ():
185+ err = f"""
186+ { path .absolute ()} does not exist.
187+ Files are typically placed in the app directory and refered to with 'Path(__file__) / { path .name } '
188+ """
189+ raise RuntimeError (err )
190+ return path
191+
192+
180193def create_include_dependency (
181194 name : str , path : str , include_files : bool
182195) -> tuple [HTMLDependency , str ]:
@@ -232,8 +245,8 @@ def get_hash(path: Path | str, include_files: bool) -> str:
232245
233246
234247def get_file_key (path : Path | str ) -> str :
235- path_str = str (path ) if isinstance ( path , Path ) else path
236- return path_str + "-" + str (os . path .getmtime ( path_str ) )
248+ path = Path (path )
249+ return str ( path ) + "-" + str (path .stat (). st_mtime )
237250
238251
239252def hash_deterministic (s : str ) -> str :
0 commit comments