Skip to content

Commit

Permalink
Merge pull request #58 from drawstack/pylint
Browse files Browse the repository at this point in the history
Pylint all source, add pylint to travis, use psycopg2-binary
  • Loading branch information
ergo committed Mar 6, 2018
2 parents 0990075 + 9953215 commit ee46533
Show file tree
Hide file tree
Showing 43 changed files with 397 additions and 318 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ matrix:
- python: "3.5"
env: BCRYPT="enabled" DB_STRING="postgres://postgres@127.0.0.1:5432/test"

- python: "3.6"
env: BCRYPT="enabled" DB_STRING="postgres://postgres@127.0.0.1:5432/test"

- python: "pypy"
env:

Expand All @@ -48,19 +51,22 @@ addons:
postgresql: "9.3"

install:
- pip install flake8 rstcheck
- pip install -e ".[test]"

before_script:
- psql -c 'create database test;' -U postgres
- if [ -n "$MYSQL" ]; then mysql -e 'create database test;'; fi

script:
- python setup.py develop
- if [ -n "$BCRYPT" ]; then pip install bcrypt; fi
- if [ -n "$PYBCRYPT" ]; then pip install py-bcrypt; fi
- if [ -n "$BCRYPT" ]; then pip install psycopg2; fi
- if [ -n "$BCRYPT" ]; then pip install psycopg2-binary; fi
- if [ -n "$PYBCRYPT" ]; then pip install psycopg2cffi; fi
- if [ -n "$MYSQL" ]; then pip install http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip#md5=3df394d89300db95163f17c843ef49df; fi

# PyLint
- pylint --disable=all --enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,jobs=4 ziggurat_foundations/

- py.test ziggurat_foundations/tests/

# flake8 and rstcheck
Expand Down
22 changes: 15 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
__version__['minor'],
__version__['patch'])

test_deps = [
"coverage",
"flake8",
"pylint",
"pyramid",
"pytest",
"pytest-cov",
"rstcheck"
]

setup(
name='ziggurat_foundations',
version=version,
Expand All @@ -40,18 +50,16 @@
zip_safe=True,
include_package_data=True,
test_suite='ziggurat_foundations.tests',
tests_require=[
"coverage",
"pytest",
"psycopg2",
"pytest-cov"
],
tests_require=test_deps,
install_requires=[
"sqlalchemy",
"passlib>=1.6.1",
"paginate",
"paginate_sqlalchemy",
"alembic",
'zope.deprecation >= 3.5.0',
"six"]
"six"],
extras_require = {
'test': test_deps,
}
)
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NC='\033[0m' # No Color

RST_FILES=`find . -name "*.rst" -printf "%p "`
RST_CHECK=$(rstcheck $RST_FILES --report 2 3>&1 1>&2 2>&3 | tee >(cat - >&2)) # fd=STDERR_FILENO
# FLAKE8=$(flake8 ./ziggurat_foundations/)
FLAKE8=$(flake8 ./ziggurat_foundations/)

echo -e "${RED}"
if [ -n "$RST_CHECK" ] ||
Expand Down
16 changes: 9 additions & 7 deletions ziggurat_foundations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from ziggurat_foundations.utils import ModelProxy, noop
from ziggurat_foundations.utils import ModelProxy

__version__ = {'major': 0, 'minor': 8, 'patch': 0}

Expand All @@ -14,8 +14,7 @@ def import_model_service_mappings():
UserPermissionService
from ziggurat_foundations.models.services.user_resource_permission import \
UserResourcePermissionService
from ziggurat_foundations.models.services.group_resource_permission import \
GroupResourcePermissionService
from ziggurat_foundations.models.services.group_resource_permission import GroupResourcePermissionService # noqa
from ziggurat_foundations.models.services.resource import ResourceService
from ziggurat_foundations.models.services.resource_tree import \
ResourceTreeService
Expand All @@ -38,9 +37,11 @@ def import_model_service_mappings():

def make_passwordmanager(schemes=None):
"""
schemes contains a list of replace this list with the hash(es) you wish to support.
this example sets pbkdf2_sha256 as the default,
with support for legacy bcrypt hashes.
schemes contains a list of replace this list with the hash(es) you wish
to support.
this example sets pbkdf2_sha256 as the default,
with support for legacy bcrypt hashes.
:param schemes:
:return: CryptContext()
"""
Expand All @@ -63,7 +64,8 @@ def ziggurat_model_init(*args, **kwargs):
:param args:
:param kwargs:
:param passwordmanager, the password manager to override default one
:param passwordmanager_schemes, list of schemes for default passwordmanager to use
:param passwordmanager_schemes, list of schemes for default
passwordmanager to use
:return:
"""
models = ModelProxy()
Expand Down
10 changes: 5 additions & 5 deletions ziggurat_foundations/ext/pyramid/get_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import importlib
import logging

from ziggurat_foundations.exc import ZigguratException
from ziggurat_foundations.models.base import get_db_session
from ziggurat_foundations.models.services.user import UserService

Expand All @@ -14,16 +13,17 @@

def includeme(config):
settings = config.registry.settings
session_provider_callable = settings.get(

session_provider_callable_config = settings.get(
'%s.session_provider_callable' % CONFIG_KEY)

if not session_provider_callable:
if not session_provider_callable_config:
def session_provider_callable(request):
return get_db_session()

test_session_callable = None
else:
parts = session_provider_callable.split(':')
parts = session_provider_callable_config.split(':')
_tmp = importlib.import_module(parts[0])
session_provider_callable = getattr(_tmp, parts[1])
test_session_callable = "session exists"
Expand All @@ -32,7 +32,7 @@ def session_provider_callable(request):
# do request.user
def get_user(request):
userid = request.unauthenticated_userid
if test_session_callable == None:
if test_session_callable is None:
# set db_session to none to pass to the UserModel.by_id
db_session = None
else:
Expand Down
26 changes: 17 additions & 9 deletions ziggurat_foundations/ext/pyramid/sign_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pyramid.security

from ziggurat_foundations.exc import ZigguratException
from ziggurat_foundations.models.base import get_db_session
from ziggurat_foundations.models.services.user import UserService

Expand Down Expand Up @@ -47,7 +46,7 @@ def includeme(config):
'/sign_in')
sign_out_path = settings.get('%s.sign_in.sign_out_pattern' % CONFIG_KEY,
'/sign_out')
session_provider_callable = settings.get(
session_provider_callable_config = settings.get(
'%s.session_provider_callable' % CONFIG_KEY)
signin_came_from_key = settings.get('%s.sign_in.came_from_key' %
CONFIG_KEY, 'came_from')
Expand All @@ -56,19 +55,20 @@ def includeme(config):
signin_password_key = settings.get('%s.sign_in.password_key' %
CONFIG_KEY, 'password')

if not session_provider_callable:
if not session_provider_callable_config:
def session_provider_callable(request):
return get_db_session()
else:
parts = session_provider_callable.split(':')
parts = session_provider_callable_config.split(':')
_tmp = importlib.import_module(parts[0])
session_provider_callable = getattr(_tmp, parts[1])

endpoint = ZigguratSignInProvider(settings=settings,
session_getter=session_provider_callable,
signin_came_from_key=signin_came_from_key,
signin_username_key=signin_username_key,
signin_password_key=signin_password_key)
endpoint = ZigguratSignInProvider(
settings=settings,
session_getter=session_provider_callable,
signin_came_from_key=signin_came_from_key,
signin_username_key=signin_username_key,
signin_password_key=signin_password_key)

config.add_route('ziggurat.routes.sign_in', sign_in_path,
use_global_views=True,
Expand All @@ -79,6 +79,11 @@ def session_provider_callable(request):


class ZigguratSignInProvider(object):
signin_came_from_key = None
signin_username_key = None
signin_password_key = None
UserModel = None

def __init__(self, *args, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
Expand Down Expand Up @@ -107,3 +112,6 @@ def sign_in(self, request):
def sign_out(self, request):
headers = pyramid.security.forget(request)
return ZigguratSignOut(headers=headers)

def session_getter(self, request):
raise NotImplementedError()
6 changes: 5 additions & 1 deletion ziggurat_foundations/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import with_statement, unicode_literals
import os
from alembic import context
from sqlalchemy import create_engine, pool
from sqlalchemy import create_engine
from sqlalchemy.schema import MetaData
from logging.config import fileConfig

# pylint: disable=no-member

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
Expand All @@ -27,6 +29,7 @@
"pk": "pk_%(table_name)s"
})


def get_url():
url = os.getenv("DB_URL", "")
if url == "":
Expand All @@ -41,6 +44,7 @@ def get_url():
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"""
from __future__ import unicode_literals

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '13391c68750'
down_revision = '438c27ec1c9'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column('users', sa.Column('security_code_date', sa.DateTime(),
Expand Down

0 comments on commit ee46533

Please sign in to comment.