Skip to content

Cross-platform tasks? Pehaps via bundled Python scripts? #649

Answered by pawamoy
aaronsteers asked this question in Q&A
Discussion options

You must be logged in to vote

You can definitely add a task that runs a Python script. This Python script can then delete itself indeed:

_tasks:
- "{{ _copier_python }} postgen.py"
# postgen.py, at the root of your template
def update_yaml_file():
    ...

def delete_self():
    os.remove(__file__)

def main():
    update_yaml_file()
    delete_self()

if __name__ == "__main__":
    main()

Note that {{ _copier_python }} is the Python interpreter used by Copier, so if Copier was installed in an isolated venv (through pipx for example), then you will only have access to the packages installed in this venv. If you are absolutely sure that there will always be a python or python3 (or /usr/local/bin/python or Anaconda, etc…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@yajo
Comment options

yajo Apr 24, 2022
Maintainer

@bittner
Comment options

Answer selected by aaronsteers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants