Skip to content
This repository has been archived by the owner on Jul 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #24 from Samael500/dev
Browse files Browse the repository at this point in the history
.2 version
  • Loading branch information
samael500 authored Oct 9, 2016
2 parents 131c1ad + 86cbd89 commit 607965f
Show file tree
Hide file tree
Showing 28 changed files with 665 additions and 298 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ target/

# custom
*.json
venv?/
venv/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lint:
make pyflakes

test:
# TODO: run test when it be
$(VENV_PATH)nosetests ./tests/ --with-specplugin

ci_test:
make test
Expand Down
2 changes: 1 addition & 1 deletion falstart/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.7"
__version__ = "0.2.0"
7 changes: 5 additions & 2 deletions falstart/falstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def from_user(msg, default, validate, yesno=False):
def read_data(args):
VARS.update(args)

proj_name = ''.join(re.split(r'[^a-z]', (VARS.get('root_dir') or 'test').lower()))
proj_name = ''.join(re.split(r'[^a-z]', (VARS.get('root_dir') or 'awesome').lower()))
VARS['proj_name'] = proj_name or from_user(
'Enter a project name', proj_name, r'^[a-z]+([a-z]|\d)*$')
if not VARS.get('root_dir'):
Expand All @@ -61,6 +61,9 @@ def read_data(args):
VARS['dj_version'] = from_user(
'Django version', VARS.get('dj_version'), r'^([0-9]{1,2}\.){1,2}[0-9]{1,2}$')

VARS['box_name'] = 'debian/{}'.format(from_user(
'Debian version (for vagrant box)', VARS.get('box_name', '')[len('debian/'):], r'^\w+'))

while True:
py_version = from_user(
'Python version', VARS.get('py_version'), r'^([0-9]{1,2}\.){1,2}[0-9]{1,2}$')
Expand All @@ -74,7 +77,7 @@ def read_data(args):
VARS['proj_ip'] = from_user(
'Vagrant box IP-addr', VARS.get('proj_ip'), r'^([0-9]{1,3}\.){3}[0-9]{1,3}$')

for name in 'POSTGRES', 'CELERY', 'REDIS':
for name in 'POSTGRES', 'CELERY', 'REDIS', 'SENTRY':
VARS[name] = from_user(
'Do you nead a {}?'.format(name), VARS.get(name, False), r'^[YyNn]{1}$', yesno=True)

Expand Down
28 changes: 14 additions & 14 deletions falstart/local_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import subprocess

from textwrap import dedent
from jinja2 import Environment, FileSystemLoader


Expand Down Expand Up @@ -84,9 +85,11 @@ def start_box():
render_template('provision_fabfile.j2', 'provision/fabric_provisioner.py')
render_template('requirements.j2', 'requirements.txt')
render_template('requirements.j2', 'requirements-remote.txt')
render_template('settings_local.j2', '{proj_name}/settings_local.py.example'.format(**VARS))
render_template('lintrc.j2', '.lintrc')
render_template('coveragerc.j2', '.coveragerc')
render_template('py_codes/settings_local.j2', '{proj_name}/settings_local.py.example'.format(**VARS))
if VARS.get('CELERY'):
render_template('celery.j2', '{proj_name}/celery.py'.format(**VARS))
render_template('py_codes/celery.j2', '{proj_name}/celery.py'.format(**VARS))
# copy templates for vagrant fabric render
put(os.path.join(VARS['templates_dir'], 'vagrant_templates'), 'provision/templates')
try:
Expand All @@ -105,20 +108,17 @@ def start_box():

def falstart_commit():
""" Try to commit after box start """
ignore = (
'*.py[cod]',
'__pycache__/',
'# custom ignore',
'settings_local.py',
'.vagrant',
'var/',
'static/',
'',
)
render_template('gitignore.j2', '.gitignore')
extra_ignore = dedent('''
# custom ignore'
settings_local.py
.vagrant
static/
''')

falstart_print('Update .gitignore')
with open('.gitignore', 'a') as gitignore:
gitignore.write('\n'.join(ignore))
gitignore.write(extra_ignore)

for attempt in range(2):
try:
Expand Down Expand Up @@ -148,5 +148,5 @@ def make_custom_box():

def rmproj():
""" Remove project """
run('cd {root_dir} && vagrant destroy'.format(**VARS))
run('cd {root_dir} && vagrant destroy -f'.format(**VARS))
run('rm {root_dir} -rf'.format(**VARS))
3 changes: 3 additions & 0 deletions falstart/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
dj_version='1.9.5',
py_version='3.5.1',
pyenv_version=None,

# extra configs
SENTRY=False,
)
26 changes: 21 additions & 5 deletions falstart/templates/Makefile.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
VENV_PATH := /home/vagrant/venv/bin
VENV_PATH := $(HOME)/venv/bin
PROJ_NAME := {{ proj_name }}

runserver:
$(VENV_PATH)/python manage.py runserver 0.0.0.0:8000

start:
$(VENV_PATH)/gunicorn --preload -D -b 127.0.0.1:8000 $(PROJ_NAME).wsgi:application
mkdir -p var
$(VENV_PATH)/gunicorn --preload --pid var/gunicorn.pid \
-D -b 127.0.0.1:8000 $(PROJ_NAME).wsgi:application

stop:
kill `cat var/gunicorn.pid` || true

restart: stop start

pep8:
$(VENV_PATH)/pep8 --exclude=*migrations*,*settings_local.py* --max-line-length=119 --show-source $(PROJ_NAME)/
$(VENV_PATH)/pep8 --exclude=*migrations*,*settings_local.py* \
--max-line-length=119 --show-source $(PROJ_NAME)/

pyflakes:
$(VENV_PATH)/pylama --skip=*migrations* -l pyflakes $(PROJ_NAME)/
Expand All @@ -18,7 +26,15 @@ lint: pep8 pyflakes
test:
$(VENV_PATH)/python manage.py test -v 2 --noinput

ci_test: test lint
cover_test:
$(VENV_PATH)/coverage run --source=$(PROJ_NAME) manage.py test -v 2 --noinput

cover_report:
$(VENV_PATH)/coverage report -m
$(VENV_PATH)/coverage html
$(VENV_PATH)/coverage-badge > htmlcov/coverage.svg

ci_test: cover_test cover_report lint

wheel_install:
$(VENV_PATH)/pip install --no-index -f wheels/ -r requirements.txt
Expand All @@ -30,7 +46,7 @@ runcelery_multi:
$(VENV_PATH)/celery multi restart $(PROJ_NAME)_worker \
-A $(PROJ_NAME) -l info -B -s ./var/celerybeat-schedule \
--logfile="./var/celery_%n.log" \
--pidfile="./var/celery_%n.pid"
--pidfile="./var/celery_%n.pid"

stopcelery_multi:
kill `cat var/celery_$(PROJ_NAME)_worker.pid` || true
Expand Down
4 changes: 3 additions & 1 deletion falstart/templates/Vagrantfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ end
Vagrant.configure(2) do |config|
# Virtual machine parameters
config.vm.box = "#{box_name}"

config.vm.network "private_network", ip: ip_address

config.vm.synced_folder ".", "/vagrant", disabled: true
if SYNC_FOLDER then
if ENV['CI_FLAG'] or ENV['NO_NFS'] then
config.vm.synced_folder ".", "/home/vagrant/proj", type: "rsync"
Expand All @@ -27,6 +28,7 @@ Vagrant.configure(2) do |config|
:mount_options => ['actimeo=2']
end
end

config.vm.hostname = hostname
config.vm.post_up_message = "#{hostname} dev server successfuly started.
Connect to host with:
Expand Down
16 changes: 0 additions & 16 deletions falstart/templates/celery.j2

This file was deleted.

12 changes: 12 additions & 0 deletions falstart/templates/coveragerc.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[report]
omit =
venv/*
*/settings*
*/python?.?/*
*/site-packages/*
*/tests/*
*/migrations/*
*wsgi.py

exclude_lines =
pragma: no cover
90 changes: 90 additions & 0 deletions falstart/templates/gitignore.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
34 changes: 34 additions & 0 deletions falstart/templates/includes/app.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def app():
""" Run application tasks """
with cd(VARS['root_dir']):
# Create venv and install requirements
run('pyvenv-{{ pyenv_version }} {venv_path}'.format(**VARS))
# Install required python packages with pip from wheels archive
run('make wheel_install')
# run app tasks for devserver start
# Copy settings local
run('cd {project_name} && cp settings_local.py.example settings_local.py'.format(**VARS))


def localserver():
with cd(VARS['root_dir']):
# collect static files
for command in ('migrate --noinput', 'collectstatic --noinput', ): # 'compilemessages', ):
run('{venv_path}/bin/python manage.py {command}'.format(command=command, **VARS))
# make root dir available to read
# sudo('chmod 755 {base_dir}/static -R'.format(**VARS))
# Create user
create_user_py = dedent('''\
from django.contrib.auth import get_user_model
User = get_user_model()
User.objects.create_superuser(**{user_data})
''').format(**VARS)

run('echo "{create_user_py}" | {venv_path}/bin/python manage.py shell'.format(
create_user_py=create_user_py, **VARS))
run('mkdir var -p')

# Start{% if CELERY %} celery and{% endif %} runserver
run('make start', pty=False){% if CELERY %}
run('make runcelery_multi', pty=False){% endif %}
{# keep trailing newline #}
Loading

0 comments on commit 607965f

Please sign in to comment.