#!/usr/bin/env python

import json
import logging
import os
import sys


log = logging.getLogger(__name__)


def post_mkproject(args=None):
    project_venv = os.getenv('VIRTUAL_ENV')
    project_name = os.path.basename(project_venv)
    project_path_file = os.path.join(project_venv, '.project')
    interpreter = os.path.join(project_venv, 'bin/python')

    try:
        with open(project_path_file, 'r') as f:
            project_folder = f.readline().rstrip('\r\n')
    except IOError:
        sys.exit('Virtualenv project not found.\n')

    create_sublime_project_file(project_folder, project_name, interpreter)


def make_project(target_folder=None):
    if not target_folder:
        target_folder = os.getcwd()

    venv_path = os.getenv('VIRTUAL_ENV')

    if not venv_path:
        sys.exit('You need to be inside a virtualenv for using subvenv.')

    project_name = os.path.basename(venv_path)
    interpreter = sys.executable

    create_sublime_project_file(target_folder, project_name, interpreter)


def create_sublime_project_file(project_folder, project_name, interpreter):
    sublime_file_name = "{}.sublime-project".format(project_name)
    settings_text = {
        "folders": [
            {
                "follow_symlinks": True,
                "path": project_folder,
            },
        ],
        "settings": {
            "python_interpreter": interpreter,
        },
    }
    target_path = (os.path.join(project_folder, sublime_file_name))

    try:
        with open(target_path, 'w') as f:
            f.write(json.dumps(settings_text, sort_keys=True, indent=4))
    except IOError:
        sys.exit(
            'Cannot create file.\n\
             Attempted path: {}'.format(project_folder)
        )

@@ -129,24 +129,122 @@
 args=None):%0A
+    %22%22%22%0A    Create a Sublime text project file on%0A    virtualenvwrapper project creation.%0A    %22%22%22%0A
     project_
@@ -720,476 +720,382 @@
 def 
-make_project(target_folder=None):%0A    if not target_fold
+create_sublime_project_file(project_folder, project_name, interpret
 er
+)
 :%0A    
-    target_folder = os.getcwd()%0A%0A    venv_path = os.getenv('VIRTUAL_ENV')%0A%0A    if not venv_path:%0A        sys.exit('You need to be inside a virtualenv for using subvenv.')%0A%0A    project_name = os.path.basename(venv_path)%0A    interpreter = sys.executable%0A%0A    create_sublime_project_file(target_folder, project_name, interpreter)%0A%0A%0Adef create_sublime_project_file(project_folder, project_name, interpreter):
+%22%22%22%0A    Create a Sublime Text project file in the given project folder.%0A%0A    Args:%0A        project_folder (str): path to project folder%0A        project_name (str): name of the project%0A        interpreter (str): path to the Python interpreter used for the%0A                           project%0A%0A    %22%22%22
 %0A   
@@ -1740,8 +1740,600 @@
       )%0A
+%0A%0Adef make_project(target_folder=None):%0A    %22%22%22%0A    Create a Sublime project file based on the current virtual environment.%0A%0A    If no target folder is specified, the file will be created in%0A    the current working directory.%0A%0A    %22%22%22%0A    if not target_folder:%0A        target_folder = os.getcwd()%0A%0A    venv_path = os.getenv('VIRTUAL_ENV')%0A%0A    if not venv_path:%0A        sys.exit('You need to be inside a virtualenv for using subvenv.')%0A%0A    project_name = os.path.basename(venv_path)%0A    interpreter = sys.executable%0A%0A    create_sublime_project_file(target_folder, project_name, interpreter)%0A

add docstrings