Skip to content

Commit d62d231

Browse files
committed
Rename to _copier_operation
1 parent 8f1ab8f commit d62d231

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
@@ -362,7 +362,7 @@ def _execute_tasks(self, tasks: Sequence[Task]) -> None:
362362
operation = _operation.get()
363363
for i, task in enumerate(tasks):
364364
extra_context = {f"_{k}": v for k, v in task.extra_vars.items()}
365-
extra_context["_operation"] = operation
365+
extra_context["_copier_operation"] = operation
366366

367367
if not cast_to_bool(self._render_value(task.condition, extra_context)):
368368
continue
@@ -663,7 +663,7 @@ def match_exclude(self) -> Callable[[Path], bool]:
663663
# Include the current operation in the rendering context.
664664
# Note: This method is a cached property, it needs to be regenerated
665665
# when reusing an instance in different contexts.
666-
extra_context = {"_operation": _operation.get()}
666+
extra_context = {"_copier_operation": _operation.get()}
667667
return self._path_matcher(
668668
self._render_string(exclusion, extra_context=extra_context)
669669
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
@@ -140,7 +140,7 @@ The name of the project root directory.
140140

141141
Some variables are only available in select contexts:
142142

143-
### `_operation`
143+
### `_copier_operation`
144144

145145
The current operation, either `"copy"` or `"update"`.
146146

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)