prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Expand Environment Variables in Cookiecutter Configuration File
  I set my cookiecutterrc file via an environment variable, like this:
  
  ```
  export COOKIECUTTER_CONFIG="$XDG_CONFIG_HOME/cookiecutter/cookiecutterrc"
  ```
  
  In my cookiecutterrc, I'd like to use those same environment variables to set paths, however they don't currently expand:
  
  ```
  default_context:
      full_name: "Nathan Farrar"
      email: "nathan.farrar@gmail.com"
      github_username: "nfarrar"
  cookiecutters_dir: "$XDG_CACHE_HOME/cookiecutter/template"
  replay_dir: "$XDG_CACHE_HOME/cookiecutter/replay"
  abbreviations:
      pp: https://github.com/audreyr/cookiecutter-pypackage.git
      gh: https://github.com/{0}.git
      bb: https://bitbucket.org/{0}
  ```
  
  For example:
  
  ```
  $ cookiecutter pp
  $ ls ~/
  ...
  drwxr-xr-x   3 nfarrar staff  102 Feb 28 07:37 '$XDG_CACHE_HOME'
  ...
  ```
  
  
  </issue>
  <code>
  [start of cookiecutter/config.py]
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 
  4 """
  5 cookiecutter.config
  6 -------------------
  7 
  8 Global configuration handling
  9 """
  10 
  11 from __future__ import unicode_literals
  12 import copy
  13 import logging
  14 import os
  15 import io
  16 
  17 import poyo
  18 
  19 from .exceptions import ConfigDoesNotExistException
  20 from .exceptions import InvalidConfiguration
  21 
  22 
  23 logger = logging.getLogger(__name__)
  24 
  25 USER_CONFIG_PATH = os.path.expanduser('~/.cookiecutterrc')
  26 
  27 DEFAULT_CONFIG = {
  28     'cookiecutters_dir': os.path.expanduser('~/.cookiecutters/'),
  29     'replay_dir': os.path.expanduser('~/.cookiecutter_replay/'),
  30     'default_context': {}
  31 }
  32 
  33 
  34 def get_config(config_path):
  35     """
  36     Retrieve the config from the specified path, returning it as a config dict.
  37     """
  38 
  39     if not os.path.exists(config_path):
  40         raise ConfigDoesNotExistException
  41 
  42     logger.debug('config_path is {0}'.format(config_path))
  43     with io.open(config_path, encoding='utf-8') as file_handle:
  44         try:
  45             yaml_dict = poyo.parse_string(file_handle.read())
  46         except poyo.exceptions.PoyoException as e:
  47             raise InvalidConfiguration(
  48                 'Unable to parse YAML file {}. Error: {}'
  49                 ''.format(config_path, e)
  50             )
  51 
  52     config_dict = copy.copy(DEFAULT_CONFIG)
  53     config_dict.update(yaml_dict)
  54 
  55     return config_dict
  56 
  57 
  58 def get_user_config(config_file=USER_CONFIG_PATH):
  59     """Retrieve the config from a file or return the defaults if None is
  60     passed. If an environment variable `COOKIECUTTER_CONFIG` is set up, try
  61     to load its value. Otherwise fall back to a default file or config.
  62     """
  63     # Do NOT load a config. Return defaults instead.
  64     if config_file is None:
  65         return copy.copy(DEFAULT_CONFIG)
  66 
  67     # Load the given config file
  68     if config_file and config_file is not USER_CONFIG_PATH:
  69         return get_config(config_file)
  70 
  71     try:
  72         # Does the user set up a config environment variable?
  73         env_config_file = os.environ['COOKIECUTTER_CONFIG']
  74     except KeyError:
  75         # Load an optional user config if it exists
  76         # otherwise return the defaults
  77         if os.path.exists(USER_CONFIG_PATH):
  78             return get_config(USER_CONFIG_PATH)
  79         else:
  80             return copy.copy(DEFAULT_CONFIG)
  81     else:
  82         # There is a config environment variable. Try to load it.
  83         # Do not check for existence, so invalid file paths raise an error.
  84         return get_config(env_config_file)
  85
  [end of cookiecutter/config.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/cookiecutter/config.py b/cookiecutter/config.py
  --- a/cookiecutter/config.py
  +++ b/cookiecutter/config.py
  @@ -31,6 +31,13 @@
   }
   
   
  +def _expand_path(path):
  +    """Expand both environment variables and user home in the given path."""
  +    path = os.path.expandvars(path)
  +    path = os.path.expanduser(path)
  +    return path
  +
  +
   def get_config(config_path):
       """
       Retrieve the config from the specified path, returning it as a config dict.
  @@ -52,6 +59,12 @@
       config_dict = copy.copy(DEFAULT_CONFIG)
       config_dict.update(yaml_dict)
   
  +    raw_replay_dir = config_dict['replay_dir']
  +    config_dict['replay_dir'] = _expand_path(raw_replay_dir)
  +
  +    raw_cookies_dir = config_dict['cookiecutters_dir']
  +    config_dict['cookiecutters_dir'] = _expand_path(raw_cookies_dir)
  +
       return config_dict
  
verification_info: {"golden_diff": "diff --git a/cookiecutter/config.py b/cookiecutter/config.py\n--- a/cookiecutter/config.py\n+++ b/cookiecutter/config.py\n@@ -31,6 +31,13 @@\n }\n \n \n+def _expand_path(path):\n+    \"\"\"Expand both environment variables and user home in the given path.\"\"\"\n+    path = os.path.expandvars(path)\n+    path = os.path.expanduser(path)\n+    return path\n+\n+\n def get_config(config_path):\n     \"\"\"\n     Retrieve the config from the specified path, returning it as a config dict.\n@@ -52,6 +59,12 @@\n     config_dict = copy.copy(DEFAULT_CONFIG)\n     config_dict.update(yaml_dict)\n \n+    raw_replay_dir = config_dict['replay_dir']\n+    config_dict['replay_dir'] = _expand_path(raw_replay_dir)\n+\n+    raw_cookies_dir = config_dict['cookiecutters_dir']\n+    config_dict['cookiecutters_dir'] = _expand_path(raw_cookies_dir)\n+\n     return config_dict\n", "issue": "Expand Environment Variables in Cookiecutter Configuration File\nI set my cookiecutterrc file via an environment variable, like this:\n\n```\nexport COOKIECUTTER_CONFIG=\"$XDG_CONFIG_HOME/cookiecutter/cookiecutterrc\"\n```\n\nIn my cookiecutterrc, I'd like to use those same environment variables to set paths, however they don't currently expand:\n\n```\ndefault_context:\n    full_name: \"Nathan Farrar\"\n    email: \"nathan.farrar@gmail.com\"\n    github_username: \"nfarrar\"\ncookiecutters_dir: \"$XDG_CACHE_HOME/cookiecutter/template\"\nreplay_dir: \"$XDG_CACHE_HOME/cookiecutter/replay\"\nabbreviations:\n    pp: https://github.com/audreyr/cookiecutter-pypackage.git\n    gh: https://github.com/{0}.git\n    bb: https://bitbucket.org/{0}\n```\n\nFor example:\n\n```\n$ cookiecutter pp\n$ ls ~/\n...\ndrwxr-xr-x   3 nfarrar staff  102 Feb 28 07:37 '$XDG_CACHE_HOME'\n...\n```\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.config\n-------------------\n\nGlobal configuration handling\n\"\"\"\n\nfrom __future__ import unicode_literals\nimport copy\nimport logging\nimport os\nimport io\n\nimport poyo\n\nfrom .exceptions import ConfigDoesNotExistException\nfrom .exceptions import InvalidConfiguration\n\n\nlogger = logging.getLogger(__name__)\n\nUSER_CONFIG_PATH = os.path.expanduser('~/.cookiecutterrc')\n\nDEFAULT_CONFIG = {\n    'cookiecutters_dir': os.path.expanduser('~/.cookiecutters/'),\n    'replay_dir': os.path.expanduser('~/.cookiecutter_replay/'),\n    'default_context': {}\n}\n\n\ndef get_config(config_path):\n    \"\"\"\n    Retrieve the config from the specified path, returning it as a config dict.\n    \"\"\"\n\n    if not os.path.exists(config_path):\n        raise ConfigDoesNotExistException\n\n    logger.debug('config_path is {0}'.format(config_path))\n    with io.open(config_path, encoding='utf-8') as file_handle:\n        try:\n            yaml_dict = poyo.parse_string(file_handle.read())\n        except poyo.exceptions.PoyoException as e:\n            raise InvalidConfiguration(\n                'Unable to parse YAML file {}. Error: {}'\n                ''.format(config_path, e)\n            )\n\n    config_dict = copy.copy(DEFAULT_CONFIG)\n    config_dict.update(yaml_dict)\n\n    return config_dict\n\n\ndef get_user_config(config_file=USER_CONFIG_PATH):\n    \"\"\"Retrieve the config from a file or return the defaults if None is\n    passed. If an environment variable `COOKIECUTTER_CONFIG` is set up, try\n    to load its value. Otherwise fall back to a default file or config.\n    \"\"\"\n    # Do NOT load a config. Return defaults instead.\n    if config_file is None:\n        return copy.copy(DEFAULT_CONFIG)\n\n    # Load the given config file\n    if config_file and config_file is not USER_CONFIG_PATH:\n        return get_config(config_file)\n\n    try:\n        # Does the user set up a config environment variable?\n        env_config_file = os.environ['COOKIECUTTER_CONFIG']\n    except KeyError:\n        # Load an optional user config if it exists\n        # otherwise return the defaults\n        if os.path.exists(USER_CONFIG_PATH):\n            return get_config(USER_CONFIG_PATH)\n        else:\n            return copy.copy(DEFAULT_CONFIG)\n    else:\n        # There is a config environment variable. Try to load it.\n        # Do not check for existence, so invalid file paths raise an error.\n        return get_config(env_config_file)\n", "path": "cookiecutter/config.py"}]}