~sirn/fanboi2

f81c2510c0021cbb79023527579b155b46bf0581 — Kridsada Thanabulpong 7 years ago 6ac25b0
Setup application in provisioning and PyPy3 support.

The provisioning script now creates the database, setup the application
in development mode including installing its requirement as well as
removing some package not compatible with PyPy3 and replace it with
equivalent that actually works.
M .gitignore => .gitignore +1 -6
@@ 32,10 32,5 @@ logs/
*.gz

# User settings
settings.ini
development.ini
alembic.ini

# Provisioning
provisioning/*_hosts
provisioning/host_vars
!provisioning/development_hosts

M .travis.yml => .travis.yml +1 -1
@@ 3,7 3,7 @@ python: "3.2"
script: nosetests
install: "pip install . --use-mirrors"
before_script: 'psql -c "create database fanboi2;" -U postgres'
env: POSTGRESQL_TEST_DATABASE=postgresql://postgres@localhost:5432/fanboi2
env: POSTGRESQL_TEST_DATABASE=postgresql+pg8000://postgres@localhost:5432/fanboi2

notifications:
    email: false

M Vagrantfile => Vagrantfile +18 -6
@@ 27,6 27,7 @@ Vagrant.configure("2") do |config|
    sudo apt-get -y install nodejs

    sudo -u postgres createuser -ds vagrant || true
    sudo -u postgres createuser -ds fanboi2 || true
    sudo sh -c 'echo "local all all trust" > /etc/postgresql/9.2/main/pg_hba.conf'
    sudo sh -c 'echo "host all all 127.0.0.1/32 trust" >> /etc/postgresql/9.2/main/pg_hba.conf'
    sudo sh -c 'echo "host all all ::1/128 trust" >> /etc/postgresql/9.2/main/pg_hba.conf'


@@ 35,12 36,23 @@ Vagrant.configure("2") do |config|

  config.vm.provision :shell, privileged: false, inline: <<-EOF
    cd /tmp
    curl -sLO https://bitbucket.org/pypy/pypy/downloads/pypy3-2.3.1-linux64.tar.bz2
    tar -xvjf pypy3-2.3.1-linux64.tar.bz2
    mv pypy3-2.3.1-linux64/ $HOME/pypy
    curl https://bootstrap.pypa.io/ez_setup.py -o - | $HOME/pypy/bin/pypy
    curl https://bootstrap.pypa.io/get-pip.py -o - | $HOME/pypy/bin/pypy
    rm -rf $HOME/pypy3
    curl -sL https://bitbucket.org/pypy/pypy/downloads/pypy3-2.3.1-linux64.tar.bz2 | tar -xjf -
    mv pypy3*/ $HOME/pypy3
    curl -sL https://bootstrap.pypa.io/ez_setup.py | $HOME/pypy3/bin/pypy
    curl -sL https://bootstrap.pypa.io/get-pip.py | $HOME/pypy3/bin/pypy
    echo '. "$HOME/.bashrc"' > $HOME/.profile
    echo 'export PATH="$HOME/pypy/bin:$HOME/bin:$PATH"' >> $HOME/.profile
    echo 'export PATH="$HOME/pypy3/bin:$HOME/bin:$PATH"' >> $HOME/.profile

    psql template1 -c "CREATE DATABASE fanboi2_development;"
    psql template1 -c "CREATE DATABASE fanboi2_test;"

    cd /vagrant
    rm -rf fanboi2.egg-info
    rm -rf node_modules
    cp development.ini.sample development.ini
    cp alembic.ini.sample alembic.ini
    $HOME/pypy3/bin/pypy setup.py develop
    $HOME/pypy3/bin/alembic upgrade head
  EOF
end

A alembic.ini.sample => alembic.ini.sample +3 -0
@@ 0,0 1,3 @@
[alembic]
script_location = %(here)s/migration
pyramid_configuration = %(here)s/development.ini

A development.ini.sample => development.ini.sample +71 -0
@@ 0,0 1,71 @@
[app:main]
use = egg:fanboi2

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_debugtoolbar
    pyramid_tm

debugtoolbar.hosts = 0.0.0.0/0

mako.directories = fanboi2:templates
sqlalchemy.url = postgresql+pg8000://vagrant:@127.0.0.1:5432/fanboi2_development
redis.url = redis://127.0.0.1:6379/0
celery.broker = redis://127.0.0.1:6379/1
akismet.key =
dnsbl.providers =

dogpile.backend = dogpile.cache.memcached
dogpile.arguments.url = 127.0.0.1:11211
dogpile.arguments.distributed_lock = true

session.type = file
session.data_dir = %(here)s/tmp/session/data
session.lock_dir = %(here)s/tmp/session/lock
session.key = _session
session.httponly = true
session.secret = DEVELOPMENT_USE_ONLY_CHANGE_ME_IN_PROD

app.timezone = Asia/Bangkok
app.secret = DEVELOPMENT_USE_ONLY_CHANGE_ME_IN_PROD

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

[loggers]
keys = root, fanboi2, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_fanboi2]
level = DEBUG
handlers =
qualname = fanboi2

[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

M fanboi2/__init__.py => fanboi2/__init__.py +1 -1
@@ 95,7 95,7 @@ def configure_components(cfg):  # pragma: no cover
    #
    # This bug only applies to Python 3.2.3 only.
    from .tasks import celery, configure_celery
    engine = engine_from_config(cfg, 'sqlalchemy.', client_encoding='utf8')
    engine = engine_from_config(cfg, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    redis_conn.from_url(cfg['redis.url'])

M fanboi2/formatters.py => fanboi2/formatters.py +3 -2
@@ 1,12 1,12 @@
import html
import isodate
import misaka
import pytz
import re
import urllib
import urllib.parse as urlparse
from collections import OrderedDict
from html.parser import HTMLParser
from markdown import Markdown
from markupsafe import Markup




@@ 165,7 165,8 @@ def format_markdown(context, request, text):
    :rtype: Markup
    """
    if text is not None:
        return Markup(misaka.html(str(text)))
        markdown = Markdown()
        return Markup(markdown.convert(str(text)))


RE_ANCHOR = re.compile(r'%s(\d+)(\-)?(\d+)?' % html.escape('>>'))

M fanboi2/tests/__init__.py => fanboi2/tests/__init__.py +1 -1
@@ 7,7 7,7 @@ from sqlalchemy import create_engine

DATABASE_URI = os.environ.get(
    'POSTGRESQL_TEST_DATABASE',
    'postgresql://fanboi2:fanboi2@localhost:5432/fanboi2_test')
    'postgresql+pg8000://fanboi2:@localhost:5432/fanboi2_test')


class DummyRedis(object):

M fanboi2/tests/test_formatters.py => fanboi2/tests/test_formatters.py +4 -4
@@ 169,10 169,10 @@ class TestFormatters(unittest.TestCase):
        from markupsafe import Markup
        request = self._makeRequest()
        tests = [
            ('**Hello, world!**', '<p><strong>Hello, world!</strong></p>\n'),
            ('<b>Foobar</b>', '<p><b>Foobar</b></p>\n'),
            ('Split\n\nParagraph', '<p>Split</p>\n\n<p>Paragraph</p>\n'),
            ('Split\nlines', '<p>Split\nlines</p>\n'),
            ('**Hello, world!**', '<p><strong>Hello, world!</strong></p>'),
            ('<b>Foobar</b>', '<p><b>Foobar</b></p>'),
            ('Split\n\nParagraph', '<p>Split</p>\n<p>Paragraph</p>'),
            ('Split\nlines', '<p>Split\nlines</p>'),
        ]
        for source, target in tests:
            self.assertEqual(format_markdown(None, request, source),

M setup.py => setup.py +2 -3
@@ 20,10 20,9 @@ requires = [
    'alembic >=0.6.2, <0.7',
    'celery >=3.1, <3.2',
    'transaction',
    'psycopg2',
    'pg8000',
    'zope.sqlalchemy',
    'redis',
    'hiredis',
    'dogpile.cache',
    'python3-memcached',
    'pytz',


@@ 32,7 31,7 @@ requires = [

    # Frontend
    'isodate',
    'misaka',
    'Markdown',  # Deprecate me.

    # Tests
    'nose',