Skip to content

Commit

Permalink
fix: better lazystuff than thunk-dict
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Dec 10, 2024
1 parent 3ee583d commit 4499002
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
21 changes: 3 additions & 18 deletions copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from jinja2.loaders import FileSystemLoader
from jinja2.sandbox import SandboxedEnvironment
from lazystuff.lazydict import lazydict
from pathspec import PathSpec
from plumbum import ProcessExecutionError, colors
from plumbum.cli.terminal import ask
Expand All @@ -38,7 +39,6 @@
from pydantic.dataclasses import dataclass
from pydantic_core import to_jsonable_python
from questionary import unsafe_prompt
from thunk_dict import ThunkDict

from .errors import (
CopierAnswersInterrupt,
Expand Down Expand Up @@ -71,22 +71,6 @@
_T = TypeVar("_T")


# HACK https://github.com/kevalii/thunk-dict/pull/1
# TODO Remove when merged and use ThunkDict directly
class _ThunkDict(ThunkDict):
def __init__(self, dictionary=None, *args, **kwargs):
class __LazyInternal__:
def release(self):
return self.value()

def __init__(self, item):
self.value = item

self.__LazyInternal__ = lambda: __LazyInternal__
super().__init__(dictionary, *args, **kwargs)
self.__LazyInternal__ = __LazyInternal__


@dataclass(config=ConfigDict(extra="forbid"))
class Worker:
"""Copier process state manager.
Expand Down Expand Up @@ -289,7 +273,7 @@ def _external_data(self) -> Mapping[str, Any]:
Files will only be parsed lazily on 1st access. This helps avoiding
circular dependencies when the file name also comes from a variable.
"""
return _ThunkDict(
return lazydict(
{
name: lambda path=path: load_answersfile_data(
self.dst_path, self._render_string(path)
Expand Down Expand Up @@ -376,6 +360,7 @@ def _system_render_context(self) -> Mapping[str, Any]:
# FIXME Remove it?
conf = asdict(self)
conf.pop("_cleanup_hooks")
conf.pop("answers")
conf.update(
{
"answers_file": self.answers_relpath,
Expand Down
27 changes: 15 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ eval-type-backport = { version = ">=0.1.3,<0.3.0", python = "<3.10" }
funcy = ">=1.17"
jinja2 = ">=3.1.4"
jinja2-ansible-filters = ">=1.3.1"
lazystuff = ">=1.2.0"
packaging = ">=23.0"
pathspec = ">=0.9.0"
plumbum = ">=1.6.9"
pydantic = ">=2.4.2"
pygments = ">=2.7.1"
pyyaml = ">=5.3.1"
questionary = ">=1.8.1"
thunk-dict = ">=0.1.1"

[tool.poetry.group.dev]
optional = true
Expand Down

0 comments on commit 4499002

Please sign in to comment.