Skip to content

Commit

Permalink
🆕 DOCKERIZE starter weppy
Browse files Browse the repository at this point in the history
README.md edited online with Bitbucket

:up: Update readme's python version
  • Loading branch information
mijdavis2 committed Apr 25, 2016
1 parent 2e07328 commit 40d2d71
Show file tree
Hide file tree
Showing 29 changed files with 111 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = my_weppy_app/cli.py,my_weppy_app/dev_utils.py
omit = starter_weppy/cli.py,starter_weppy/dev_utils.py
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
FROM ubuntu:latest
MAINTAINER Michael J Davis "[email protected]"
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["run.py"]
FROM python:3.5-onbuild
EXPOSE 8000
CMD ["python3", "./run.py"]
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ weppy" structure with an app name as an argument.
## Run

Requirements:
- Python 2.7.11
- Python 3.5.1

For automated pip and virtual env setup and creation,
clone this repository and in your terminal do:
Expand All @@ -40,6 +40,12 @@ pip install -r requirements.txt
python run.py
```

**Run in Docker**

```
docker build -t starter-weppy .
docker run -it -p 80:8000 --rm --name starter-weppy starter-weppy
```

## Develop

Expand All @@ -54,7 +60,7 @@ To start the app in development mode, do:
python run.py --dev
```

See ```my_weppy_app_/cli.py``` for cli commands.
See ```starter_weppy/cli.py``` for cli commands.

## Test

Expand All @@ -64,5 +70,5 @@ testing.
Run the app in dev mode. Then in another shell, do:

```
py.test -v -s --cov-report term-missing --cov=my_weppy_app tests
py.test -v -s --cov-report term-missing --cov=starter_weppy tests
```
19 changes: 0 additions & 19 deletions my_weppy_app/cli.py

This file was deleted.

6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
argparse==1.4.0
coverage==4.0.3
pytest-cov==2.2.1
weppy-BS3==0.4
wsgiref==0.1.2
pytest==2.9.1
weppy==0.6.4
weppy-Haml==0.3
weppy-Assets==0.3.1
wheel==0.29.0
8 changes: 4 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from contextlib import contextmanager
from argparse import ArgumentParser
from my_weppy_app import app
from starter_weppy import app


@contextmanager
def run_in_dev():
from my_weppy_app.dev_utils import setup_dev_users, remove_dev_users
from starter_weppy.dev_utils import setup_dev_users, remove_dev_users
setup_dev_users()
try:
yield
Expand All @@ -14,12 +14,12 @@ def run_in_dev():


if __name__ == "__main__":
arg_parser = ArgumentParser(description="MyWeppyApp running utility.")
arg_parser = ArgumentParser(description="StarterWeppy running utility.")
arg_parser.add_argument('-d', '--dev', help="Setup add dev users and enable verbose logging",
action='store_true')
args = arg_parser.parse_args()
if args.dev:
with run_in_dev():
app.run()
else:
app.run(debug=False)
app.run(host="0.0.0.0", debug=False)
13 changes: 8 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

VERSION=0.1.0
USAGE='Usage: source setup.sh -hv -p "/path/to/python/" -r "repoName" -q "/path/to/requirements.txt"'
PY_MAJ_REQ=3
PY_MIN_REQ=5
PY_PAT_REQ=1

# --- Option processing --------------------------------------------
while getopts ":v:h:p:r:q:" o; do
Expand Down Expand Up @@ -59,19 +62,19 @@ fi
if [ ! "$PYTHON" ]
then
echo "No python version designated."
echo "Using machine's default python version"
PYTHON="$( which python )"
echo "Using machine's default python$PY_MAJ_REQ.$PY_MIN_REQ version"
PYTHON="$( which python"$PY_MAJ_REQ"."$PY_MIN_REQ" )"
fi

PMAJOR="$( "$PYTHON" -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major);' )"
PMINOR="$( "$PYTHON" -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(minor);' )"
PPATCH="$( "$PYTHON" -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(patch);' )"

if [[ "$PMAJOR" -eq 2 ]] && [[ "$PMINOR" -eq 7 ]] && [[ "$PPATCH" -gt 10 ]]
if [[ "$PMAJOR" -ge $PY_MAJ_REQ ]] && [[ "$PMINOR" -ge $PYMIN_REQ ]] && [[ "$PPATCH" -ge $PY_PAT_REQ ]]
then
echo "Python version is good enough: $PMAJOR.$PMINOR.$PPATCH."
else
echo "Python version must be 2.7.11."
echo "Python version must be $PY_MAJ_REQ.$PY_MIN_REQ.$PY_PAT_REQ."
echo "Yours is $PMAJOR.$PMINOR.$PPATCH :("
return 1
fi
Expand Down Expand Up @@ -150,4 +153,4 @@ while read dependency; do
fi
done < "$REQUIREMENTS_DIR"/requirements.txt

export PYTHONPATH="$THIS_DIR":$HOME/.virtualenvs/"$REQUIRED_VENV"/lib/python2.7/site-packages:"$REQUIREMENTS_DIR"
export PYTHONPATH="$THIS_DIR":$HOME/.virtualenvs/"$REQUIRED_VENV"/lib/python"$PMAJOR"."$PMINOR"/site-packages:"$REQUIREMENTS_DIR"
8 changes: 4 additions & 4 deletions my_weppy_app/__init__.py → starter_weppy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
app.language_write = True

# init database and auth
from models.user import User
from starter_weppy.models.user import User

# init auth before passing db models due to dependencies
# on auth tables in the other models
Expand All @@ -26,7 +26,7 @@
)

# adding sessions and authorization handlers
from utils import get_cryptogen_string
from starter_weppy.utils import get_cryptogen_string
app.route.common_handlers = [
SessionCookieManager(get_cryptogen_string(16)),
db.handler,
Expand All @@ -40,7 +40,7 @@
app.use_extension(Haml)

# Expose controllers
from controllers import main, api
from starter_weppy.controllers import main, api

# Commands
import cli
from starter_weppy import cli
19 changes: 19 additions & 0 deletions starter_weppy/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Usage: weppy --app=starter_weppy <command>
Example: weppy --app=starter_weppy shell
"""
from starter_weppy import app


@app.cli.command('routes')
def print_routing():
print(app.route.routes_out)


@app.cli.command('get_users')
def print_users():
from starter_weppy import db
from starter_weppy.models.user import User
rows = db(User.email).select()
for row in rows:
print(row)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from weppy import AppModule
from weppy.tools import ServiceHandler
from my_weppy_app import app
from starter_weppy import app

api = AppModule(app, 'api', __name__, url_prefix='api')
api.common_handlers = [ServiceHandler('json')]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
from weppy import response, url
from weppy.tools import requires
from my_weppy_app import app, auth, db
from starter_weppy import app, auth, db


@app.on_error(404)
def error_404():
response.meta.title = "MyWeppyApp-404"
response.meta.title = "StarterWeppy-404"
return app.render_template("404.haml")


@app.route("/")
def welcome():
response.meta.title = "MyWeppyApp"
response.meta.title = "StarterWeppy"
return dict()


@app.route('/account(/<str:f>)?(/<str:k>)?')
def account(f, k):
response.meta.title = "MyWeppyApp | Account"
response.meta.title = "StarterWeppy | Account"
form = auth(f, k)
return dict(req=f, form=form)


@app.route()
def users():
response.meta.title = "MyWeppyApp | Users"
response.meta.title = "StarterWeppy | Users"
users = db(db.User.id > 0).select()
return dict(users=users)

Expand All @@ -33,6 +33,6 @@ def users():
@requires(auth.is_logged_in, url('main.account', 'login'))
def profile(userid):
user = db.User(id=userid)
response.meta.title = "MyWeppyApp | " + user.first_name + " " + \
response.meta.title = "StarterWeppy | " + user.first_name + " " + \
user.last_name + " profile"
return dict(user=user)
12 changes: 6 additions & 6 deletions my_weppy_app/dev_utils.py → starter_weppy/dev_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from my_weppy_app import db
from starter_weppy import db
from tests.fixtures import *


Expand All @@ -16,15 +16,15 @@ def setup_dev_users():
password=TEST_USER.password
)
db.commit()
print "Admin: {}\n" \
"User: {}\n".format(admin.__dict__, user.__dict__)
print("Admin: {}\n"
"User: {}\n".format(admin.__dict__, user.__dict__))


def remove_dev_users():
from my_weppy_app.models.user import User
from starter_weppy.models.user import User
from tests.fixtures import TEST_ADMIN, TEST_USER
print db(User.email == TEST_ADMIN.email).select()
print db(User.email == TEST_USER.email).select()
print(db(User.email == TEST_ADMIN.email).select())
print(db(User.email == TEST_USER.email).select())
db(User.email == TEST_ADMIN.email).delete()
db(User.email == TEST_USER.email).delete()
db.commit()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.navbar-brand{href: "{{=url('main.welcome')}}"} MyWeppyApp
%a.navbar-brand{href: "{{=url('main.welcome')}}"} StarterWeppy
.collapse.navbar-collapse
%ul.nav.navbar-nav
%li
Expand All @@ -34,6 +34,6 @@
%footer.footer.navbar.navbar-inverse.navbar-fixed-bottom
.container{style: "padding-top:10px"}
%p.text-muted copyright MyWeppyApp 2016
%p.text-muted copyright StarterWeppy 2016
- include_static 'bs3/bootstrap.min.js'
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.navbar-brand{href: "{{=url('main.welcome')}}"} MyWeppyApp
%a.navbar-brand{href: "{{=url('main.welcome')}}"} StarterWeppy
.collapse.navbar-collapse
%ul.nav.navbar-nav
%li
Expand All @@ -40,7 +40,7 @@
- include
%footer.footer.navbar.navbar-inverse.navbar-fixed-bottom
.container{style: "padding-top:10px"}
%p.text-muted copyright MyWeppyApp 2016
.container{style: "padding-top:15px"}
%p.text-muted copyright StarterWeppy 2016
- include_static 'bs3/bootstrap.min.js'
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- extend "layout.haml"

.container
%h1 Welcome to MyWeppyApp
%h1 Welcome to StarterWeppy
%p Let's build something cool.
File renamed without changes.
8 changes: 1 addition & 7 deletions tests/api_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import pytest
import json
from my_weppy_app import app


@pytest.fixture()
def client():
return app.test_client()
from tests.fixtures import *


def test_api_response(client):
Expand Down
31 changes: 7 additions & 24 deletions tests/client_test.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
import pytest
from my_weppy_app import app, db, User
from my_weppy_app import utils
from tests.fixtures import TEST_USER


@pytest.fixture()
def client():
return app.test_client()
from starter_weppy import User, db
from starter_weppy import utils
from .fixtures import *


def test_welcome_page_access(client):
resp = client.get('/')
assert 'Welcome to MyWeppyApp' in resp.data
assert 'Welcome to StarterWeppy' in resp.data


def test_error_404(client):
resp = client.get(utils.get_cryptogen_string())
assert "<title>MyWeppyApp-404</title>" in resp.data
assert "<title>StarterWeppy-404</title>" in resp.data


def test_account_page_access(client):
resp = client.get('/account/login')
assert "MyWeppyApp | Account" in resp.data
assert "StarterWeppy | Account" in resp.data


def test_users_page_access(client):
resp = client.get('/users/')
assert "MyWeppyApp | Users" in resp.data


@pytest.fixture()
def logged_client(client):
resp = client.get('/account/login')
client.post('/account/login', data={
'email': TEST_USER.email,
'password': TEST_USER.password,
'_csrf_token': list(resp.context.session._csrf)[-1]
}, follow_redirects=True)
return client
assert "StarterWeppy | Users" in resp.data


def test_login_page(logged_client):
Expand Down
Loading

0 comments on commit 40d2d71

Please sign in to comment.