Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _render(path: str) -> str:
return LazyDict(
**{
name: lambda path=path: load_answersfile_data(
self.dst_path, _render(path)
self.dst_path, _render(path), warn_on_missing=True
)
for name, path in self.template.external_data.items()
}
Expand Down
6 changes: 2 additions & 4 deletions copier/subproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from pathlib import Path
from typing import Callable

import yaml
from plumbum.machines import local
from pydantic.dataclasses import dataclass

from .template import Template
from .types import AbsolutePath, AnyByStrDict, VCSTypes
from .user_data import load_answersfile_data
from .vcs import get_git, is_in_git_repo


Expand Down Expand Up @@ -55,9 +55,7 @@ def _cleanup(self) -> None:
def _raw_answers(self) -> AnyByStrDict:
"""Get last answers, loaded raw as yaml."""
try:
return yaml.safe_load(
(self.local_abspath / self.answers_relpath).read_text("utf-8")
)
return load_answersfile_data(self.local_abspath, self.answers_relpath)
except OSError:
return {}

Expand Down
10 changes: 7 additions & 3 deletions copier/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,19 @@
def load_answersfile_data(
dst_path: StrOrPath,
answers_file: StrOrPath = ".copier-answers.yml",
*,
warn_on_missing: bool = False,
) -> AnyByStrDict:
"""Load answers data from a `$dst_path/$answers_file` file if it exists."""
try:
with Path(dst_path, answers_file).open(encoding="utf-8") as fd:
return yaml.safe_load(fd)
except (FileNotFoundError, IsADirectoryError):
warnings.warn(
f"File not found; returning empty dict: {answers_file}", MissingFileWarning
)
if warn_on_missing:
warnings.warn(

Check warning on line 531 in copier/user_data.py

View check run for this annotation

Codecov / codecov/patch

copier/user_data.py#L531

Added line #L531 was not covered by tests
f"File not found; returning empty dict: {answers_file}",
MissingFileWarning,
)
return {}


Expand Down
Loading