code: def render_and_create_dir(dirname, context, output_dir, environment,
                            overwrite_if_exists=False):
      
      name_tmpl = environment.from_string(dirname)
      rendered_dirname = name_tmpl.render(**context)
  
      dir_to_create = os.path.normpath(
          os.path.join(output_dir, rendered_dirname)
      )
  
      logger.debug('Rendered dir {} must exist in output_dir {}'.format(
          dir_to_create,
          output_dir
      ))
  
      output_dir_exists = os.path.exists(dir_to_create)
  
      if output_dir_exists:
          if overwrite_if_exists:
              logger.debug(
                  'Output directory {} already exists,'
                  'overwriting it'.format(dir_to_create)
              )
          else:
              msg = 'Error: "{}" directory already exists'.format(dir_to_create)
              raise OutputDirExistsException(msg)
      else:
          make_sure_path_exists(dir_to_create)
  
      return dir_to_create, not output_dir_exists
docs: Render name of a directory, create the directory, return its path.