Skip to content

Commit 5c597e4

Browse files
committed
Rename to _copier_operation
1 parent 8cdedb2 commit 5c597e4

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

copier/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _execute_tasks(self, tasks: Sequence[Task]) -> None:
356356
operation = _operation.get()
357357
for i, task in enumerate(tasks):
358358
extra_context = {f"_{k}": v for k, v in task.extra_vars.items()}
359-
extra_context["_operation"] = operation
359+
extra_context["_copier_operation"] = operation
360360

361361
if not cast_to_bool(self._render_value(task.condition, extra_context)):
362362
continue
@@ -656,7 +656,7 @@ def match_exclude(self) -> Callable[[Path], bool]:
656656
# Include the current operation in the rendering context.
657657
# Note: This method is a cached property, it needs to be regenerated
658658
# when reusing an instance in different contexts.
659-
extra_context = {"_operation": _operation.get()}
659+
extra_context = {"_copier_operation": _operation.get()}
660660
return self._path_matcher(
661661
self._render_string(exclusion, extra_context=extra_context)
662662
for exclusion in self.all_exclusions

docs/configuring.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,12 +966,12 @@ Each pattern can be templated using Jinja.
966966

967967
!!! example
968968

969-
Templating `exclude` patterns using `_operation` allows to have files
969+
Templating `exclude` patterns using `_copier_operation` allows to have files
970970
that are rendered once during `copy`, but are never updated:
971971

972972
```yaml
973973
_exclude:
974-
- "{% if _operation == 'update' -%}src/*_example.py{% endif %}"
974+
- "{% if _copier_operation == 'update' -%}src/*_example.py{% endif %}"
975975
```
976976

977977
!!! info
@@ -1587,7 +1587,7 @@ other items not present.
15871587
- ["{{ _copier_python }}", task.py]
15881588
# Run a command during the initial copy operation only, excluding updates
15891589
- command: ["{{ _copier_python }}", task.py]
1590-
when: "{{ _operation == 'copy' }}"
1590+
when: "{{ _copier_operation == 'copy' }}"
15911591
# OS-specific task (supported values are "linux", "macos", "windows" and `None`)
15921592
- command: rm {{ name_of_the_project }}/README.md
15931593
when: "{{ _copier_conf.os in ['linux', 'macos'] }}"

docs/creating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ The current phase, one of `"prompt"`,`"tasks"`, `"migrate"` or `"render"`.
150150

151151
Some variables are only available in select contexts:
152152

153-
### `_operation`
153+
### `_copier_operation`
154154

155155
The current operation, either `"copy"` or `"update"`.
156156

tests/test_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def test_exclude_templating_with_operation(
1414
) -> None:
1515
"""
1616
Ensure it's possible to create one-off boilerplate files that are not
17-
managed during updates via `_exclude` using the `_operation` context variable.
17+
managed during updates via `_exclude` using the `_copier_operation` context variable.
1818
"""
1919
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
2020

21-
template = "{% if _operation == 'update' %}copy-only{% endif %}"
21+
template = "{% if _copier_operation == 'update' %}copy-only{% endif %}"
2222
with local.cwd(src):
2323
build_file_tree(
2424
{
@@ -67,8 +67,8 @@ def test_task_templating_with_operation(
6767
"copier.yml": (
6868
f"""\
6969
_tasks:
70-
- command: echo {{{{ _operation }}}} >> {json.dumps(str(task_counter))}
71-
when: "{{{{ _operation == 'copy' }}}}"
70+
- command: echo {{{{ _copier_operation }}}} >> {json.dumps(str(task_counter))}
71+
when: "{{{{ _copier_operation == 'copy' }}}}"
7272
"""
7373
),
7474
"{{ _copier_conf.answers_file }}.jinja": "{{ _copier_answers|to_yaml }}",

0 commit comments

Comments
 (0)