audreyr/cookiecutter — pull request #136 by alixedi (2013-12-17 09:24:00+00:00)
Title: Passing cookiecutter context to hooks using os.environ #60

Started using [pydanny's](https://github.com/pydanny) [cookiecutter-djangopackage](https://github.com/pydanny/cookiecutter-djangopackage) for my projects about a month back and noticed that it did not include a demo project. I wanted the following directory structure:

- repo_name
+ docs
+ tests
+ app_name
+ --- lots of files ---
+ demo (django project)
+ demo
+ **symbolic link to ../app_name**

I failed to implement the above scenario because I did not have access to the cookiecutter context in my hooks and therefore `app_name`.

I looked up the code and found that:
+ `generate.generate_files` function was calling the `hook.run_hook` function
+ `generate.generate_files` function had cookiecutter context that was required in the hooks.
+ Finally, the environment variables passed to the process initiated by the `subprocess.Popen` function can be controlled by setting `os.environ` dictionary - [Reference](http://stackoverflow.com/questions/4906977/python-environment-variables)

The implementation that followed seems simple and elegant. I am now able to write the symbolic link command that accesses `app_name` from cookiecutter context by extracting it from `os.environ`. All the tests are passing. If you approve, I will update the documentation to reflect this feature.

N. B. This is my first pull-request. I have tried to follow the instructions chalked out in `contribution guide` but there is a chance I may have missed a point or two. I am eager to improve upon this.