Skip to content

Commit 8038ec2

Browse files
committed
Changes for DEVELOP branch
1 parent e2e25d3 commit 8038ec2

File tree

18 files changed

+158
-34
lines changed

18 files changed

+158
-34
lines changed

.gitignore

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
/env/
33
/venv/
44

5+
.DS_Store
6+
.coverage
7+
.idea
8+
.module-cache
9+
.vagrant
10+
.python-version
11+
512
# Python compiled byte code
613
*.pyc
714

@@ -20,9 +27,6 @@ dist/
2027
# Staticfiles
2128
staticfiles/
2229

23-
# PyCharm
24-
.idea
25-
2630
# npm
2731
npm-debug.log
2832

Makefile

+67-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test fasttest run lint pep8 eslint
1+
.PHONY: test fasttest run lint pep8 eslint manage
22

33
# Project settings
44
LEVEL ?= development
@@ -23,12 +23,41 @@ else
2323
PYTHON = $(ENV)/bin/python
2424
endif
2525

26+
# Gunicorn settings
27+
GUNICORN_NAME ?= myezh
28+
GUNICORN_WORKERS ?= $(shell python -c "import multiprocessing; print(multiprocessing.cpu_count() * 2 + 1);")
29+
LOGS_DIR ?= ./logs
2630
SERVER_HOST ?= 0.0.0.0
27-
SERVER_PORT ?= 8000
31+
SERVER_PORT ?= 8008
32+
33+
# Other settings
34+
DJANGO_SERVER ?= runserver
35+
DJANGO_SHELL ?= shell_plus
36+
37+
# Setup bootstrapper & Gunicorn args
38+
has_bootstrapper = $(shell python -m bootstrapper --version 2>&1 | grep -v "No module")
39+
ifeq ($(LEVEL),development)
40+
bootstrapper_args = -d
41+
gunicorn_args = --reload
42+
requirements = -r requirements.txt -r requirements-dev.txt
43+
else
44+
gunicorn_args = --access-logfile=$(LOGS_DIR)/gunicorn.access.log \
45+
--error-logfile=$(LOGS_DIR)/gunicorn.error.log
46+
requirements = -r requirements.txt
47+
endif
48+
49+
# Enable to install packages from non-HTTPS private PyPI
50+
PIP_TRUSTED_HOST ?= pypi.ezhome.io
51+
52+
53+
# Clean from temporary files
54+
clean:
55+
find ./$(PROJECT)/ $(ENV) -name "*.pyc" -o -type d -empty -exec rm -rf {} +
2856

2957
# Easy testing
30-
test:
31-
python manage.py test
58+
test: clean pep8
59+
$(COVERAGE) run --branch ./$(PROJECT)/manage.py test $(TEST_ARGS)
60+
$(COVERAGE) report
3261

3362
# Fast testing
3463
fasttest:
@@ -38,6 +67,28 @@ fasttest:
3867
run:
3968
python manage.py runserver $(SERVER_HOST):$(SERVER_PORT)
4069

70+
install: install-github-key install-py install-static
71+
72+
install-github-key:
73+
ssh-keygen -H -F github.com > /dev/null || ssh-keyscan -H github.com >> ~/.ssh/known_hosts
74+
75+
install-py:
76+
ifneq ($(has_bootstrapper),)
77+
PIP_TRUSTED_HOST=$(PIP_TRUSTED_HOST) python -m bootstrapper -e $(ENV)/ $(bootstrapper_args)
78+
else
79+
[ ! -d "$(ENV)/" ] && virtualenv $(ENV)/ || :
80+
PIP_TRUSTED_HOST=$(PIP_TRUSTED_HOST) $(ENV)/bin/pip install $(requirements)
81+
endif
82+
83+
install-static:
84+
npm install
85+
# bower install
86+
# ifneq ($(CIRCLECI),)
87+
# -bower update
88+
# else
89+
# bower update
90+
# endif
91+
4192
# Linter
4293
lint: pep8
4394

@@ -52,3 +103,15 @@ eslint:
52103
ifeq ($(LEVEL),development)
53104
npm run lint
54105
endif
106+
107+
# Wrapper around manage command
108+
manage:
109+
$(PYTHON) ./$(PROJECT)/manage.py $(COMMAND)
110+
111+
# Development Server
112+
devserver: clean
113+
COMMAND="$(DJANGO_SERVER) $(SERVER_HOST):$(SERVER_PORT)" $(MAKE) manage
114+
115+
# Production Server
116+
server: clean pep8
117+
LEVEL=$(LEVEL) PYTHONPATH=$(PROJECT) $(GUNICORN) -b $(SERVER_HOST):$(SERVER_PORT) -w $(GUNICORN_WORKERS) -n $(GUNICORN_NAME) -t 60 --graceful-timeout 60 $(gunicorn_args) $(GUNICORN_ARGS) $(PROJECT).wsgi:application

circle.yml

+19-9
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@ machine:
33
environment:
44
COVERALLS_REPO_TOKEN: BIJEGOKsEvdhmwdLlC2QMSp1k9tbjwBYk
55
DATABASE_URL: postgres://ubuntu:@127.0.0.1:5432/circle_test
6-
DJANGO_SETTINGS_MODULE: django_and_angular.settings
6+
DJANGO_SETTINGS_MODULE: django_and_angular.settings.development
77
LEVEL: development
8-
98
timezone:
10-
Russia/Moscow # Set the timezone
11-
12-
# Version of ruby to use
9+
America/Los_Angeles
10+
node:
11+
version: 5.5.0
1312
python:
14-
version:
15-
2.7.11
13+
version: 2.7.10
14+
services:
15+
- postgresql
16+
17+
dependencies:
18+
cache_directories:
19+
- bower_components
20+
- node_modules
21+
- webpack/.babel_cache
22+
override:
23+
- pip install -U pip wheel
24+
- make install
1625

1726
test:
1827
override:
19-
- TEST_ARGS=--with-xunit make lint test
28+
- TEST_ARGS='--with-xunit --with-json-extended' make lint test
2029

2130
post:
22-
- coveralls
31+
# - coveralls
2332
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
2433
- "[ -r nosetests.xml ] && mv nosetests.xml $CIRCLE_TEST_REPORTS/junit/ || :"
34+
- "[ -r nosetests.json ] && mv nosetests.json $CIRCLE_TEST_REPORTS/junit/ || :"
2535

2636
# # Override /etc/hosts
2737
# hosts:

nosetests.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="2" errors="0" failures="0" skip="0"><testcase classname="authentication.tests.AuthenticationTestCase" name="test_failure" time="0.000"></testcase><testcase classname="authentication.tests.AuthenticationTestCase" name="test_success" time="0.000"></testcase></testsuite>

requirements-dev.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
coverage==4.0
2+
coveralls==1.0
3+
django-nose==1.4.2
14
flake8==2.3.0
25
flake8-import-order==0.5.3
36
flake8-pep257==1.0.3
7+
https://github.com/zheller/flake8-quotes/tarball/aef86c4f8388e790332757e5921047ad53160a75#egg=flake8-quotes
8+
nose==1.3.7
9+
nosetests-json-extended==0.1.0
410
pep257==0.6.0
511
pep8==1.6.2
612
pep8-naming==0.3.3
13+
pyflakes==1.0.0

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
Django==1.7.1
1+
Django==1.8.4
22
dj-database-url==0.3.0
33
dj-static==0.0.6
44
django-appconf==0.6
55
django-compressor==1.4
66
djangorestframework==3.0.0
77
drf-nested-routers==0.9.0
88
gunicorn==19.1.1
9+
psycopg2==2.6.1
910
raven==5.10.2
1011
six==1.8.0
1112
static3==0.5.1

src/authentication/tests.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
# Create your tests here.
1+
from django.test import TestCase
2+
3+
4+
class AuthenticationTestCase(TestCase):
5+
6+
def test_success(self):
7+
pass
8+
9+
def test_failure(self):
10+
# self.fail('Failed test')
11+
pass

src/django_and_angular/settings/__init__.py

Whitespace-only changes.

src/django_and_angular/settings.py renamed to src/django_and_angular/settings/defaults.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
https://docs.djangoproject.com/en/1.7/ref/settings/
99
"""
1010

11-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1211
import os
13-
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
1412

13+
import dj_database_url
14+
15+
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
17+
18+
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
1519

1620
# Quick-start development settings - unsuitable for production
1721
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
1822

19-
# SECURITY WARNING: keep the secret key used in production secret!
20-
SECRET_KEY = '$6(x*g_2g9l_*g8peb-@anl5^*8q!1w)k&e&2!i)t6$s8kia94'
21-
2223
# SECURITY WARNING: don't run with debug turned on in production!
2324
DEBUG = os.environ.get('DEBUG', True)
2425

@@ -60,8 +61,6 @@
6061
# Database
6162
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
6263

63-
import dj_database_url
64-
6564
DATABASES = {
6665
'default': dj_database_url.config(
6766
default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
@@ -86,7 +85,7 @@
8685
# https://docs.djangoproject.com/en/1.7/howto/static-files/
8786

8887
STATIC_URL = '/static/'
89-
STATIC_ROOT = 'staticfiles'
88+
STATIC_ROOT = 'static/'
9089

9190
STATICFILES_DIRS = (
9291
os.path.join(BASE_DIR, 'static'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .injector import inject_settings
2+
3+
4+
inject_settings(
5+
'django_and_angular.settings.defaults',
6+
locals()
7+
)
8+
9+
# SECURITY WARNING: keep the secret key used in production secret!
10+
SECRET_KEY = '$6(x*g_2g9l_*g8peb-@anl5^*8q!1w)k&e&2!i)t6$s8kia94'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from importlib import import_module
2+
3+
4+
def inject_settings(path, context, fail_silently=False):
5+
"""Inject settings from module at path to the given context.
6+
7+
Do not raise an Import Error when fail silently enabled.
8+
"""
9+
try:
10+
module = import_module(path)
11+
except ImportError:
12+
if fail_silently:
13+
return
14+
raise
15+
16+
for attr in dir(module):
17+
if attr[0] == '_' or not attr.isupper():
18+
continue
19+
context[attr] = getattr(module, attr)

src/manage.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python
2+
# flake8: noqa
3+
24
import os
35
import sys
46

57
if __name__ == "__main__":
6-
os.environ.setdefault(
7-
"DJANGO_SETTINGS_MODULE",
8-
"django_and_angular.settings"
9-
)
8+
level = os.environ.get('LEVEL') or 'development'
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
10+
'django_and_angular.settings.{0}'.format(level))
1011

1112
from django.core.management import execute_from_command_line
1213

src/posts/views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from rest_framework import permissions, viewsets
22
from rest_framework.response import Response
33

4-
from posts.models import Post
5-
from posts.permissions import IsAuthorOfPost
6-
from posts.serializers import PostSerializer
4+
from .models import Post
5+
from .permissions import IsAuthorOfPost
6+
from .serializers import PostSerializer
77

88

99
class PostViewSet(viewsets.ModelViewSet):
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

static/javascripts/authentication/services/authentication.service.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
isAuthenticated: isAuthenticated,
2727
login: login,
2828
logout: logout,
29-
register: register,
3029
setAuthenticatedAccount: setAuthenticatedAccount,
3130
unauthenticate: unauthenticate
3231
};

0 commit comments

Comments
 (0)