@@ -3,6 +3,7 @@ pub mod tagspecs;
33use std:: fs;
44use std:: path:: Path ;
55
6+ use camino:: Utf8Path ;
67use config:: Config ;
78use config:: ConfigError as ExternalConfigError ;
89use config:: File ;
@@ -40,15 +41,15 @@ pub struct Settings {
4041}
4142
4243impl Settings {
43- pub fn new ( project_root : & Path ) -> Result < Self , ConfigError > {
44+ pub fn new ( project_root : & Utf8Path ) -> Result < Self , ConfigError > {
4445 let user_config_file = ProjectDirs :: from ( "com.github" , "joshuadavidthomas" , "djls" )
4546 . map ( |proj_dirs| proj_dirs. config_dir ( ) . join ( "djls.toml" ) ) ;
4647
4748 Self :: load_from_paths ( project_root, user_config_file. as_deref ( ) )
4849 }
4950
5051 fn load_from_paths (
51- project_root : & Path ,
52+ project_root : & Utf8Path ,
5253 user_config_path : Option < & Path > ,
5354 ) -> Result < Self , ConfigError > {
5455 let mut builder = Config :: builder ( ) ;
@@ -74,13 +75,13 @@ impl Settings {
7475 }
7576
7677 builder = builder. add_source (
77- File :: from ( project_root. join ( ".djls.toml" ) )
78+ File :: from ( project_root. join ( ".djls.toml" ) . as_std_path ( ) )
7879 . format ( FileFormat :: Toml )
7980 . required ( false ) ,
8081 ) ;
8182
8283 builder = builder. add_source (
83- File :: from ( project_root. join ( "djls.toml" ) )
84+ File :: from ( project_root. join ( "djls.toml" ) . as_std_path ( ) )
8485 . format ( FileFormat :: Toml )
8586 . required ( false ) ,
8687 ) ;
@@ -120,7 +121,7 @@ mod tests {
120121 #[ test]
121122 fn test_load_no_files ( ) {
122123 let dir = tempdir ( ) . unwrap ( ) ;
123- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
124+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
124125 // Add assertions for future default fields here
125126 assert_eq ! (
126127 settings,
@@ -140,7 +141,7 @@ mod tests {
140141 fn test_load_djls_toml_only ( ) {
141142 let dir = tempdir ( ) . unwrap ( ) ;
142143 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , "debug = true" ) . unwrap ( ) ;
143- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
144+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
144145 assert_eq ! (
145146 settings,
146147 Settings {
@@ -154,7 +155,7 @@ mod tests {
154155 fn test_load_venv_path_config ( ) {
155156 let dir = tempdir ( ) . unwrap ( ) ;
156157 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , "venv_path = '/path/to/venv'" ) . unwrap ( ) ;
157- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
158+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
158159 assert_eq ! (
159160 settings,
160161 Settings {
@@ -168,7 +169,7 @@ mod tests {
168169 fn test_load_dot_djls_toml_only ( ) {
169170 let dir = tempdir ( ) . unwrap ( ) ;
170171 fs:: write ( dir. path ( ) . join ( ".djls.toml" ) , "debug = true" ) . unwrap ( ) ;
171- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
172+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
172173 assert_eq ! (
173174 settings,
174175 Settings {
@@ -184,7 +185,7 @@ mod tests {
184185 // Write the setting under [tool.djls]
185186 let content = "[tool.djls]\n debug = true\n " ;
186187 fs:: write ( dir. path ( ) . join ( "pyproject.toml" ) , content) . unwrap ( ) ;
187- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
188+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
188189 assert_eq ! (
189190 settings,
190191 Settings {
@@ -203,7 +204,7 @@ mod tests {
203204 let dir = tempdir ( ) . unwrap ( ) ;
204205 fs:: write ( dir. path ( ) . join ( ".djls.toml" ) , "debug = false" ) . unwrap ( ) ;
205206 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , "debug = true" ) . unwrap ( ) ;
206- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
207+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
207208 // djls.toml wins
208209 assert_eq ! (
209210 settings,
@@ -220,7 +221,7 @@ mod tests {
220221 let pyproject_content = "[tool.djls]\n debug = false\n " ;
221222 fs:: write ( dir. path ( ) . join ( "pyproject.toml" ) , pyproject_content) . unwrap ( ) ;
222223 fs:: write ( dir. path ( ) . join ( ".djls.toml" ) , "debug = true" ) . unwrap ( ) ;
223- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
224+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
224225 // .djls.toml wins
225226 assert_eq ! (
226227 settings,
@@ -238,7 +239,7 @@ mod tests {
238239 fs:: write ( dir. path ( ) . join ( "pyproject.toml" ) , pyproject_content) . unwrap ( ) ;
239240 fs:: write ( dir. path ( ) . join ( ".djls.toml" ) , "debug = false" ) . unwrap ( ) ;
240241 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , "debug = true" ) . unwrap ( ) ;
241- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
242+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
242243 // djls.toml wins
243244 assert_eq ! (
244245 settings,
@@ -258,8 +259,11 @@ mod tests {
258259 let pyproject_content = "[tool.djls]\n debug = false\n " ; // Project: false
259260 fs:: write ( project_dir. path ( ) . join ( "pyproject.toml" ) , pyproject_content) . unwrap ( ) ;
260261
261- let settings =
262- Settings :: load_from_paths ( project_dir. path ( ) , Some ( & user_conf_path) ) . unwrap ( ) ;
262+ let settings = Settings :: load_from_paths (
263+ Utf8Path :: from_path ( project_dir. path ( ) ) . unwrap ( ) ,
264+ Some ( & user_conf_path) ,
265+ )
266+ . unwrap ( ) ;
263267 // pyproject.toml overrides user
264268 assert_eq ! (
265269 settings,
@@ -278,8 +282,11 @@ mod tests {
278282 fs:: write ( & user_conf_path, "debug = true" ) . unwrap ( ) ; // User: true
279283 fs:: write ( project_dir. path ( ) . join ( "djls.toml" ) , "debug = false" ) . unwrap ( ) ; // Project: false
280284
281- let settings =
282- Settings :: load_from_paths ( project_dir. path ( ) , Some ( & user_conf_path) ) . unwrap ( ) ;
285+ let settings = Settings :: load_from_paths (
286+ Utf8Path :: from_path ( project_dir. path ( ) ) . unwrap ( ) ,
287+ Some ( & user_conf_path) ,
288+ )
289+ . unwrap ( ) ;
283290 // djls.toml overrides user
284291 assert_eq ! (
285292 settings,
@@ -301,8 +308,11 @@ mod tests {
301308 let user_conf_path = user_dir. path ( ) . join ( "config.toml" ) ;
302309 fs:: write ( & user_conf_path, "debug = true" ) . unwrap ( ) ;
303310
304- let settings =
305- Settings :: load_from_paths ( project_dir. path ( ) , Some ( & user_conf_path) ) . unwrap ( ) ;
311+ let settings = Settings :: load_from_paths (
312+ Utf8Path :: from_path ( project_dir. path ( ) ) . unwrap ( ) ,
313+ Some ( & user_conf_path) ,
314+ )
315+ . unwrap ( ) ;
306316 assert_eq ! (
307317 settings,
308318 Settings {
@@ -321,8 +331,11 @@ mod tests {
321331 fs:: write ( project_dir. path ( ) . join ( "pyproject.toml" ) , pyproject_content) . unwrap ( ) ;
322332
323333 // Should load project settings fine, ignoring non-existent user config
324- let settings =
325- Settings :: load_from_paths ( project_dir. path ( ) , Some ( & user_conf_path) ) . unwrap ( ) ;
334+ let settings = Settings :: load_from_paths (
335+ Utf8Path :: from_path ( project_dir. path ( ) ) . unwrap ( ) ,
336+ Some ( & user_conf_path) ,
337+ )
338+ . unwrap ( ) ;
326339 assert_eq ! (
327340 settings,
328341 Settings {
@@ -339,7 +352,9 @@ mod tests {
339352 fs:: write ( project_dir. path ( ) . join ( "djls.toml" ) , "debug = true" ) . unwrap ( ) ;
340353
341354 // Call helper with None for user path
342- let settings = Settings :: load_from_paths ( project_dir. path ( ) , None ) . unwrap ( ) ;
355+ let settings =
356+ Settings :: load_from_paths ( Utf8Path :: from_path ( project_dir. path ( ) ) . unwrap ( ) , None )
357+ . unwrap ( ) ;
343358 assert_eq ! (
344359 settings,
345360 Settings {
@@ -358,7 +373,7 @@ mod tests {
358373 let dir = tempdir ( ) . unwrap ( ) ;
359374 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , "debug = not_a_boolean" ) . unwrap ( ) ;
360375 // Need to call Settings::new here as load_from_paths doesn't involve ProjectDirs
361- let result = Settings :: new ( dir. path ( ) ) ;
376+ let result = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) ;
362377 assert ! ( result. is_err( ) ) ;
363378 assert ! ( matches!( result. unwrap_err( ) , ConfigError :: Config ( _) ) ) ;
364379 }
@@ -390,7 +405,7 @@ args = [
390405]
391406"# ;
392407 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , content) . unwrap ( ) ;
393- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
408+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
394409
395410 assert_eq ! ( settings. tagspecs( ) . len( ) , 2 ) ;
396411
@@ -423,7 +438,7 @@ args = [
423438]
424439"# ;
425440 fs:: write ( dir. path ( ) . join ( "pyproject.toml" ) , content) . unwrap ( ) ;
426- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
441+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
427442
428443 assert_eq ! ( settings. tagspecs( ) . len( ) , 1 ) ;
429444 let cache = & settings. tagspecs ( ) [ 0 ] ;
@@ -446,7 +461,7 @@ args = [
446461]
447462"# ;
448463 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , content) . unwrap ( ) ;
449- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
464+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
450465
451466 let test = & settings. tagspecs ( ) [ 0 ] ;
452467 assert_eq ! ( test. args. len( ) , 3 ) ;
@@ -485,7 +500,7 @@ args = [
485500]
486501"# ;
487502 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , content) . unwrap ( ) ;
488- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
503+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
489504
490505 let if_tag = & settings. tagspecs ( ) [ 0 ] ;
491506 assert_eq ! ( if_tag. name, "if" ) ;
@@ -508,7 +523,7 @@ args = [
508523]
509524"# ;
510525 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , content) . unwrap ( ) ;
511- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
526+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
512527
513528 let block_tag = & settings. tagspecs ( ) [ 0 ] ;
514529 assert_eq ! ( block_tag. name, "block" ) ;
@@ -532,7 +547,7 @@ module = "myapp.tags"
532547args = []
533548"# ;
534549 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , content) . unwrap ( ) ;
535- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
550+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
536551
537552 assert ! ( settings. debug( ) ) ;
538553 assert_eq ! ( settings. venv_path( ) , Some ( "/path/to/venv" ) ) ;
@@ -557,7 +572,7 @@ args = [
557572]
558573"# ;
559574 fs:: write ( dir. path ( ) . join ( "djls.toml" ) , content) . unwrap ( ) ;
560- let settings = Settings :: new ( dir. path ( ) ) . unwrap ( ) ;
575+ let settings = Settings :: new ( Utf8Path :: from_path ( dir. path ( ) ) . unwrap ( ) ) . unwrap ( ) ;
561576
562577 let test = & settings. tagspecs ( ) [ 0 ] ;
563578 assert_eq ! ( test. args. len( ) , 6 ) ;
0 commit comments