Compiles a Jinja2 template to python code.

  :param env: a Jinja2 Environment instance.
  :param src_path: path to the source file.
  :param dst_path: path to the destination file.
  :param encoding: template encoding.
  :param base_dir: the base path to be removed from the compiled template filename.

def compile_file(env, src_path, dst_path, encoding='utf-8', base_dir=''):
  """Compiles a Jinja2 template to python code.

  :param env: a Jinja2 Environment instance.
  :param src_path: path to the source file.
  :param dst_path: path to the destination file.
  :param encoding: template encoding.
  :param base_dir: the base path to be removed from the compiled template filename.
  """
  src_file = file(src_path, 'r')
  source = src_file.read().decode(encoding)
  name = src_path.replace(base_dir, '')
  raw = env.compile(source, name=name, filename=name, raw=True)
  src_file.close()

  dst_file = open(dst_path, 'w')
  dst_file.write(raw)
  dst_file.close()