File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed
Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -293,7 +293,9 @@ def _external_data(self) -> _LazyDict:
293293 return _LazyDict (
294294 ** {
295295 name : lambda path = path : load_answersfile_data (
296- self .dst_path , self ._render_string (path )
296+ self .dst_path ,
297+ self ._render_string (path ),
298+ warn_on_missing = True ,
297299 )
298300 for name , path in self .template .external_data .items ()
299301 }
Original file line number Diff line number Diff line change 1010from pathlib import Path
1111from typing import Callable
1212
13- import yaml
1413from plumbum .machines import local
1514from pydantic .dataclasses import dataclass
1615
1716from .template import Template
1817from .types import AbsolutePath , AnyByStrDict , VCSTypes
18+ from .user_data import load_answersfile_data
1919from .vcs import get_git , is_in_git_repo
2020
2121
@@ -55,9 +55,7 @@ def _cleanup(self) -> None:
5555 def _raw_answers (self ) -> AnyByStrDict :
5656 """Get last answers, loaded raw as yaml."""
5757 try :
58- return yaml .safe_load (
59- (self .local_abspath / self .answers_relpath ).read_text ("utf-8" )
60- )
58+ return load_answersfile_data (self .local_abspath , self .answers_relpath )
6159 except OSError :
6260 return {}
6361
Original file line number Diff line number Diff line change @@ -504,15 +504,19 @@ def parse_yaml_string(string: str) -> Any:
504504def load_answersfile_data (
505505 dst_path : StrOrPath ,
506506 answers_file : StrOrPath = ".copier-answers.yml" ,
507+ * ,
508+ warn_on_missing : bool = False ,
507509) -> AnyByStrDict :
508510 """Load answers data from a `$dst_path/$answers_file` file if it exists."""
509511 try :
510512 with Path (dst_path , answers_file ).open (encoding = "utf-8" ) as fd :
511513 return yaml .safe_load (fd )
512514 except (FileNotFoundError , IsADirectoryError ):
513- warnings .warn (
514- f"File not found; returning empty dict: { answers_file } " , MissingFileWarning
515- )
515+ if warn_on_missing :
516+ warnings .warn (
517+ f"File not found; returning empty dict: { answers_file } " ,
518+ MissingFileWarning ,
519+ )
516520 return {}
517521
518522
You can’t perform that action at this time.
0 commit comments