Skip to content

Latest commit

 

History

History
220 lines (153 loc) · 4 KB

README.md

File metadata and controls

220 lines (153 loc) · 4 KB

yhttp-pony

PyPI Build Coverage Status

Pony ORM extension for yhttp.

Install

sudo apt`install python3-dev libpq-dev postgresql  # Postgresql
pip install yhttp-pony

Usage

This is how to use the extension.

from yhttp import Appliation, json
from yhttp.ext import pony as ponyext 
from pony.orm import db_session as dbsession, PrimaryKey, Required


app = Application()
app.settings.merge('''
db:
  url: postgres://postgres:postgres@localhost/foo
''')
db = ponyext.install(app)


class Foo(db.Entity):
    id = PrimaryKey(int, auto=True)
    title = Required(str)


@app.route()
@json
@dbsession
def get(req):
    return {f.id:f.title for f in Foo.select()}


app.ready()

Command line interface

There is some command line interfaces which will be automatically added to your application when you call dbmanager.install(app, ...) and ponyext.install(app, ...).

myapp db create
myapp db objects create
myapp db drop

Extending db sub-command

import easycli
from yhttp.ext import dbmanager, ponyext

from mypackage import app  # yhttp application


class InsertMockupCommand(easycli.SubCommand):
    __command__ = 'insert-mockup'

    def __call__(self, args):
        ponyext.initialize(app.db, app.settings.db)

        # Insert mockup data

        ponyext.deinitialize(app.db)


class VerifyObjectsCommand(easycli.SubCommand):
    __command__ = 'verify'
    __aliases__ = ['v']

    def __call__(self, args):
        ponyext.initialize(app.db, app.settings.db)

        # Verify database objects

        ponyext.deinitialize(app.db)

...

dbmanager.install(app, cliarguments=[InsertMockupCommand])
db = ponyext.install(app, cliarguments=[VerifyObjectsCommand])

Use it as:

myapp db create
myapp db insert-mockup
myapp db objects create
myapp db objects verify
myapp db drop

Contribution

Dependencies

Install postgresql brefore use of this project.

apt install postgresql

Prepare

Create and grant the postgresql role with createdb permission to authenticate the current unix user within postgresql using the peer authentication.

echo "CREATE USER ${USER} WITH CREATEDB" | sudo -u postgres psql
# Or
echo "ALTER USER ${USER} CREATEDB" | sudo -u postgres psql

Virtualenv

Create virtual environment:

make venv

Delete virtual environment:

make venv-delete

Activate the virtual environment:

source ./activate.sh

Install (editable mode)

Install this project as editable mode and all other development dependencies:

make env

Tests

Execute all tests:

make test

Execute specific test(s) using wildcard:

make test F=tests/test_db*
make test F=tests/test_form.py::test_querystringform

refer to pytest documentation for more info about invoking tests.

Execute tests and report coverage result:

make cover
make cover F=tests/test_static.py
make cover-html

Lint

make lint

Distribution

Execute these commands to create Python's standard distribution packages at dist directory:

make sdist
make wheel

Or

make dist

to create both sdidst and wheel packages.

Clean build directory

Execute:

make clean

to clean-up previous dist/* and build/* directories.

PyPI

WARNING: Do not do this if you'r not responsible as author and or maintainer of this project.

Execute

make clean
make pypi

to upload sdists and wheel packages on PyPI.