Replies: 2 comments 1 reply
-
Sounds like you want some custom behavior. Try using tasks.
https://copier.readthedocs.io/en/stable/configuring/#tasks
El vie., 20 may. 2022 21:01, Martín Gaitán ***@***.***>
escribió:
… Hi, I'm new with copier and I'm very glad to have found such a good tool.
I'm trying to use it to generate new subpackages inside a project that
already exists, while also update some existing files.
For instance, my template currently is like this
📁 my_copier_template
├── 📄 copier.yml
├── 📁 existing_package/
│ └── 📁 {{ subpackage_name }}
│ └── 📄 {{ module_name }}.py
and I got the subpackage in my existing package
├── 📁 existing_package/
│ └── 📄 existing_module.py
│ └── 📁 existing_subpackage1
│ └── 📁 <subpackage_name>
│ └── 📄 <module_name>.py
But now I want to update also existing_module.py, for instance to append
something after a comment that matches a regex pattern.
Is that possible?
—
Reply to this email directly, view it on GitHub
<#670>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHNXDJZEPQJV3ZWYQVZICLVK7VPXANCNFSM5WQN5L6A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mgaitan
-
I've implemented a script that works for a very basic use case: when I need to append a new content to my
from pathlib import Path
from copier.tools import Style, printf
printf("Running after edit script")
for to_append in Path('.').glob('**/*.append'):
text_to_append = to_append.read_text()
target = Path(str(to_append).rstrip(".append"))
printf("Appended into", target, style=Style.WARNING)
target.write_text(target.read_text() + text_to_append)
to_append.unlink()
Path("after-edit.py").unlink()
_tasks:
- ["{{ _copier_python }}", after-edit.py] PS: I'm wondering if I could run the script without copying it to the target folder (and then self-deleting it from the script's last line). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm new with copier and I'm very glad to have found such a good tool.
I'm trying to use it to generate new subpackages inside a project that already exists, while also update some existing files.
For instance, my template currently is like this
and I got the subpackage in my existing package
But now I want to update also
existing_module.py
, for instance to append something after a comment that matches a regex pattern.Is that possible?
Beta Was this translation helpful? Give feedback.
All reactions