New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Know about current context in hooks #1983
Comments
Ah, in fact I can just get my parent cmdline 😄 In bash: cat /proc/$PPID/cmdline | tr '\0' ' ' and in python: import psutil
import os
ppid = psutil.Process(os.getppid())
print(ppid.cmdline()) and work this output from there 🚀 If there's a more native way, I'll be happy to use it 🙏 |
Hello @michael-todorovic, Could you expand on your use case a bit more? I would love to know what do you plan to use this for. |
Hello, A skeleton can be instantiated multiple time on a single repo: think about a postgresql skeleton and that we can have several postgresql clusters per repo. This should create multiple replay files as answers will differ from one cluster to another. Currently, the replay file is named against the skeleton name. In my src_path = ".cookiecutter-replay/{{ cookiecutter.__project_slug }}.json"
dest_path = ".cookiecutter-replay/{{ cookiecutter.__replay_name }}.json"
if os.path.exists(src_path):
print(f"Post-hook: renaming {src_path} to {dest_path}")
os.rename(src_path, dest_path) in post-hook. In my "__replay_name": "{{ cookiecutter.__project_slug }}_{{ cookiecutter.subcomponent }}" In my repo, this results in:
so anyone from my team can replay an upgraded skeleton later with the same answers. I wanted to know in the hook whether I'm in a replay mode or not in order to avoid renaming the json file (and likely some other things I didn't think of). I'm pretty sure that "runmode" awareness can be useful in some other cases 😄 |
I've got a similar challenge, but in a different context. I use cruft to manage template drift. In my cookiecutter template I use post-hooks to initialise some gitignored .env files for local directory. Post-hook asks for Personal Access Tokens and does some access validation. When 'cruft update' runs, it runs the template twice (old and new versions) to generate the diff to apply, and I don't want post-hook to run during that period. If I could reliably detect the replay condition from the hook, I could shortcut it. I am conscious that this looks more like a workaround for cruft and the point of replay is to reproduce the behaviour like for like. However, I think this feature would be useful for anyone who uses post-hooks for validation or environment setup, which does not make sense to repeat during replay. |
@igor-lobanov-maersk thanks for linking that tool, I wasn't aware of it 😄 👀 |
Description:
I'm trying to run stuff in hooks depending on I'm replaying or not
What I've run:
I have created some py/sh hooks but I can't find how is run cookiecutter. For example, I'd like to know if I used
--replay-file
from my hook. I tried anexport
or echo$@
in bash or dumpcookiecutter
in python but I didn't anything useful for me.Would you have an idea?
Thanks!
The text was updated successfully, but these errors were encountered: