MCPcopy
hub / github.com/copier-org/copier / build_file_tree

Function build_file_tree

tests/helpers.py:112–139  ·  view source on GitHub ↗

Builds a file tree based on the received spec. Params: spec: A mapping from filesystem paths to file contents. If the content is a Path object a symlink to the path will be created instead. dedent: Dedent file contents.

(
    spec: Mapping[StrOrPath, str | bytes | Path],
    dedent: bool = True,
    encoding: str = "utf-8",
)

Source from the content-addressed store, hash-verified

110
111
112def build_file_tree(
113 spec: Mapping[StrOrPath, str | bytes | Path],
114 dedent: bool = True,
115 encoding: str = "utf-8",
116) -> None:
117 """Builds a file tree based on the received spec.
118
119 Params:
120 spec:
121 A mapping from filesystem paths to file contents. If the content is
122 a Path object a symlink to the path will be created instead.
123
124 dedent: Dedent file contents.
125 """
126 for path, contents in spec.items():
127 path = Path(path)
128 path.parent.mkdir(parents=True, exist_ok=True)
129 if isinstance(contents, Path):
130 path.symlink_to(contents)
131 else:
132 binary = isinstance(contents, bytes)
133 if not binary and dedent:
134 assert isinstance(contents, str)
135 contents = textwrap.dedent(contents)
136 mode = "wb" if binary else "w"
137 enc = None if binary else encoding
138 with Path(path).open(mode, encoding=enc) as fd:
139 fd.write(contents)
140
141
142def expect_prompt(

Calls

no outgoing calls