Can a cookiecutter pre_prompt.py hook access the value of the template's `output_dir`?

96 views Asked by At

I'm attempting to write a simple cookiecutter pre_prompt.py validation script that inspects the parent directory from which the template is being executed.

Unfortunately, I cannot figure out how to determine the value of output_dir via Jinja.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

print(os.path.dirname(os.getcwd()))

print(f"{{ cookiecutter.output_dir}}")

The above simplistic example_template/hooks/pre_prompt.py script results in the following:

$ cookiecutter example_template

/tmp/cookiecuttera0gwfqwi
{ cookiecutter.output_dir}

This shows that the value of os.path.dirname(os.getcwd()) is the temporary directory created during template processing while my naïve attempt to access {{ cookiecutter.output_dir}} was not interpreted by Jinja in any meaningful way.

0

There are 0 answers