<commit_before>import os
from StringIO import StringIO
import textwrap

from fabric.api import put, sudo
from fabric.context_managers import cd, prefix

from depl.deploy._utils import nginx_config, install_nginx, move_project_to_www


def load(settings, package):
    remote_path = '/var/www/depl-' + settings['id']
    local_path = os.path.abspath('.')

    # python projects should always have a 'requirements.txt'.
    if not os.path.exists(os.path.join(local_path, 'requirements.txt')):
        raise LookupError("requirements.txt doesn't exist in your Python project.")

    # configure nginx
    socket = remote_path + '/uwsgi.sock'
    uwsgi_nginx = "include uwsgi_params; uwsgi_pass unix:%s;" % socket

    locations = {'/': uwsgi_nginx}
    nginx_conf = nginx_config(settings['url'], settings['port'], locations)
    nginx_file = StringIO(nginx_conf)

    if settings['wsgi'] is None:
        raise ValueError("wsgi parameter needs to be defined to deploy python") 
    uwsgi_file = _gen_uwsgi_file(settings['wsgi'], remote_path, socket)

    uwsgi_start_file = _gen_uwsgi_start_file(remote_path)

    def install_python():
        sudo('pip install virtualenv virtualenvwrapper')
        with cd(remote_path):
            sudo('ls venv || virtualenv venv', user='www-data')
            with prefix('source venv/bin/activate'):
                sudo('pip install -r requirements.txt', user='www-data')
                sudo('pip install uwsgi', user='www-data')

    def setup_uwsgi():
        sudo('mkdir /etc/uwsgi && mkdir /etc/uwsgi/vassals || true')
        #logs
        sudo('mkdir /var/log/uwsgi || true')
        sudo('chown -R www-data:www-data /var/log/uwsgi')

        put(uwsgi_file, '/etc/uwsgi/vassals/depl-%s.ini' % settings['id'], use_sudo=True)
        put(uwsgi_start_file, '/etc/init/uwsgi.conf', use_sudo=True)
        sudo('service uwsgi restart')

    commands = [<commit_msg>no need for virtualenvwrapper<commit_after>import os
from StringIO import StringIO
import textwrap

from fabric.api import put, sudo
from fabric.context_managers import cd, prefix

from depl.deploy._utils import nginx_config, install_nginx, move_project_to_www


def load(settings, package):
    remote_path = '/var/www/depl-' + settings['id']
    local_path = os.path.abspath('.')

    # python projects should always have a 'requirements.txt'.
    if not os.path.exists(os.path.join(local_path, 'requirements.txt')):
        raise LookupError("requirements.txt doesn't exist in your Python project.")

    # configure nginx
    socket = remote_path + '/uwsgi.sock'
    uwsgi_nginx = "include uwsgi_params; uwsgi_pass unix:%s;" % socket

    locations = {'/': uwsgi_nginx}
    nginx_conf = nginx_config(settings['url'], settings['port'], locations)
    nginx_file = StringIO(nginx_conf)

    if settings['wsgi'] is None:
        raise ValueError("wsgi parameter needs to be defined to deploy python") 
    uwsgi_file = _gen_uwsgi_file(settings['wsgi'], remote_path, socket)

    uwsgi_start_file = _gen_uwsgi_start_file(remote_path)

    def install_python():
        sudo('pip install virtualenv')
        with cd(remote_path):
            sudo('ls venv || virtualenv venv', user='www-data')
            with prefix('source venv/bin/activate'):
                sudo('pip install -r requirements.txt', user='www-data')
                sudo('pip install uwsgi', user='www-data')

    def setup_uwsgi():
        sudo('mkdir /etc/uwsgi && mkdir /etc/uwsgi/vassals || true')
        #logs
        sudo('mkdir /var/log/uwsgi || true')
        sudo('chown -R www-data:www-data /var/log/uwsgi')

        put(uwsgi_file, '/etc/uwsgi/vassals/depl-%s.ini' % settings['id'], use_sudo=True)
        put(uwsgi_start_file, '/etc/init/uwsgi.conf', use_sudo=True)
        sudo('service uwsgi restart')

    commands = [
{'fraction_non_alphanumeric': 0.12598425196850394, 'fraction_numerical': 0.0, 'mean_word_length': 3.335608646188851, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2318931', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1227, 'n_words': 284}