Skip to content

Commit

Permalink
Fix lint (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Nov 1, 2018
1 parent 7e031b5 commit 5524757
Show file tree
Hide file tree
Showing 55 changed files with 100 additions and 98 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -18,7 +18,7 @@ markers =
notebook: Jupyter notebook tests

[flake8]
ignore = E128 E731 E252 F841 W605
ignore = E128 E731
max-line-length = 999

[zest.releaser]
Expand Down
4 changes: 2 additions & 2 deletions websauna/system/__init__.py
Expand Up @@ -93,7 +93,7 @@ class Initializer:
We deliberate push imports inside methods, so that it is unlikely we'd have any import time side effects caused by some less elegant solutions, like gevent.
"""

def __init__(self, global_config: dict, settings: t.Optional[dict]=None):
def __init__(self, global_config: dict, settings: t.Optional[dict] = None):
"""
:param global_config: Dictionary as passed to WSGI entry point.
Expand Down Expand Up @@ -661,7 +661,7 @@ def configure_tasks(self):
"""Scan all Python modules with asynchoronous and periodic tasks to be imported."""
try:
import celery # noQA
except ImportError as e:
except ImportError:
# Celery not installed as optional dependency
return

Expand Down
2 changes: 1 addition & 1 deletion websauna/system/admin/menu.py
Expand Up @@ -58,7 +58,7 @@ class Entry:

caret = "fa fa-caret-down"

def __init__(self, id: str, label: str, icon: str=None, caret: str=None, css_class: str=None, template: str=None, submenu: Menu=None, condition: t.Callable=None, link: t.Callable=None, extra: dict=None):
def __init__(self, id: str, label: str, icon: str = None, caret: str = None, css_class: str = None, template: str = None, submenu: Menu = None, condition: t.Callable = None, link: t.Callable = None, extra: dict = None):
"""
:param id: Machine id and CSS id for this menu entry
:param label: Human-readable label of the menu item
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/admin/utils.py
Expand Up @@ -54,7 +54,7 @@ def get_model_admin_for_sqlalchemy_object(admin: IAdmin, instance: object) -> Mo
return model_manager[model_admin_id]


def get_admin_url_for_sqlalchemy_object(admin: IAdmin, instance: object, view_name: str=None) -> str:
def get_admin_url_for_sqlalchemy_object(admin: IAdmin, instance: object, view_name: str = None) -> str:
"""Return direct URL to the admin view page of this object:
Example:
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/core/breadcrumbs.py
Expand Up @@ -20,7 +20,7 @@ def get_human_readable_resource_name(resource: Resource) -> str:
return resource.__name__


def get_breadcrumbs(context: Resource, request: Request, root_iface: type=None, current_view_name=None, current_view_url=None) -> t.List:
def get_breadcrumbs(context: Resource, request: Request, root_iface: type = None, current_view_name=None, current_view_url=None) -> t.List:
"""Create breadcrumbs path data how to get to this resource from the root.
Traverse context :class:`Resource` up to the root resource in the reverse order. Fill in data for rendering
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/core/messages.py
Expand Up @@ -64,7 +64,7 @@ def __ne__(self, other):
return not(self == other)


def add(request: Request, msg: str, kind: str="info", msg_id: str=None, extra: dict=None, html=False, allow_duplicates=False):
def add(request: Request, msg: str, kind: str = "info", msg_id: str = None, extra: dict = None, html=False, allow_duplicates=False):
"""Add a message which is shown to the user on the next page load.
This is so called Flash message. The message is stored in the session. On the next page load, the HTML templates and framework must read all pending messages from the session store and display them to the user. Usually this is a notification rendered at the top of the page.
Expand Down
4 changes: 2 additions & 2 deletions websauna/system/core/redis.py
Expand Up @@ -82,7 +82,7 @@ def log_redis_statistics(redis: StrictRedis):
logger.debug("Redis connection statistics - process: %s, thread: %s, created: %d, max: %d, in-use: %d, available: %d", process_name, thread_name, created, max_connections, available, in_use)


def get_redis(request_or_registry: t.Union[Request, Registry], url: str=None, redis_client=StrictRedis, **redis_options) -> StrictRedis:
def get_redis(request_or_registry: t.Union[Request, Registry], url: str = None, redis_client=StrictRedis, **redis_options) -> StrictRedis:
"""Get a connection to Redis.
Example:
Expand Down Expand Up @@ -136,7 +136,7 @@ def is_sane_redis(config: Configurator) -> bool:
redis = get_redis(config.registry)
redis.set("websauna_session_test", True)
return True
except ConnectionError as e:
except ConnectionError:
return False


Expand Down
2 changes: 1 addition & 1 deletion websauna/system/core/render.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
}
self.js_requires_head = False

def request_resource(self, kind: str, resource_url: str, js_requires_head: bool=False):
def request_resource(self, kind: str, resource_url: str, js_requires_head: bool = False):
"""A widget or something wants to place a CSS or JS file on the page rendering.
:param kind: "js" or "css"
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/core/route.py
Expand Up @@ -65,7 +65,7 @@ def callback(scanner, _name, wrapped):
return wrapped


def add_template_only_view(config: Configurator, pattern: str, name: str, template: str, view_args: t.Optional[dict]=None, route_args: t.Optional[dict]=None):
def add_template_only_view(config: Configurator, pattern: str, name: str, template: str, view_args: t.Optional[dict] = None, route_args: t.Optional[dict] = None):
"""Adds a view which do not have a specific view function assgined.
The view will render a template with the default template context.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/core/sitemap.py
Expand Up @@ -411,7 +411,7 @@ def _get_route_data(route, registry):
yield route.name, pattern, view


def include_in_sitemap(include: t.Optional[bool]=None, condition: t.Optional[t.Callable]=None):
def include_in_sitemap(include: t.Optional[bool] = None, condition: t.Optional[t.Callable] = None):
"""A function decorator to determine if a view should be included in the automatically generated sitemap.
You need to give either ``include`` argument or ``condition``. If this view decorator is not present the view is always included.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/core/views/redirect.py
Expand Up @@ -11,7 +11,7 @@
from websauna.system.core.simpleroute import add_simple_route


def redirect_view(path: str, new_path: str=None, new_route: str=None, status_code: int=302, name: str=None):
def redirect_view(path: str, new_path: str = None, new_route: str = None, status_code: int = 302, name: str = None):
"""Generate a redirect view.
Assign the return value of this function to a module level variable. `configuration.scan()` will pick it up and make a redirect route.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/crud/__init__.py
Expand Up @@ -135,7 +135,7 @@ def fetch_object(self, id: str) -> object:
"""
raise NotImplementedError('Please use concrete subclass like websauna.syste.crud.sqlalchemy')

def get_object_url(self, obj: object, view_name: t.Optional[str]=None) -> str:
def get_object_url(self, obj: object, view_name: t.Optional[str] = None) -> str:
"""Get URL for view for an object inside this CRUD.
:param obj: Raw object, e.g. SQLAlchemy instance, which can be wrapped with ``wrap_to_resource``.
Expand Down
4 changes: 2 additions & 2 deletions websauna/system/crud/formgenerator.py
Expand Up @@ -53,7 +53,7 @@ class FormGenerator:
"""

def __init__(self, schema_customizer: t.Callable=None, schema_binder: t.Callable=None):
def __init__(self, schema_customizer: t.Callable = None, schema_binder: t.Callable = None):
"""Initialize Form Generator."""
self.schema_customizer = schema_customizer
self.schema_binder = schema_binder
Expand Down Expand Up @@ -116,7 +116,7 @@ class SQLAlchemyFormGenerator(FormGenerator):
For example use case see :py:class:`websauna.system.user.adminviews.UserAdd`.
"""

def __init__(self, includes=None, field_mapper=DefaultSQLAlchemyFieldMapper(), customize_schema: t.Callable=None, schema_binder: t.Callable=None):
def __init__(self, includes=None, field_mapper=DefaultSQLAlchemyFieldMapper(), customize_schema: t.Callable = None, schema_binder: t.Callable = None):
"""Initialize SQLAlchemyFormGenerator."""
self.includes = includes
self.field_mapper = field_mapper
Expand Down
34 changes: 18 additions & 16 deletions websauna/system/crud/listing.py
Expand Up @@ -25,13 +25,15 @@ class Column:
def __init__(
self,
id: str,
name: t.Optional[str]=None,
name: t.Optional[str] = None,
renderer=None,
header_template: t.Optional[str]=None,
body_template: t.Optional[str]=None,
getter: t.Optional[t.Callable]=None,
format: t.Optional[str]=None,
navigate_view_name=None, navigate_url_getter=None):
header_template: t.Optional[str] = None,
body_template: t.Optional[str] = None,
getter: t.Optional[t.Callable] = None,
format: t.Optional[str] = None,
navigate_view_name=None,
navigate_url_getter=None
):
"""Initialize Column.
:param id: Column id. Must match field id on the model
Expand Down Expand Up @@ -87,7 +89,7 @@ def get_navigate_target(self, resource: Resource, request: Request):
"""
return resource

def get_navigate_url(self, resource: Resource, request: Request, view_name: t.Optional[str]=None):
def get_navigate_url(self, resource: Resource, request: Request, view_name: t.Optional[str] = None):
"""Get the link where clicking this item should take the user.
By default, navigate to "show" view of the resource.
Expand Down Expand Up @@ -144,10 +146,10 @@ class ControlsColumn(Column):

def __init__(
self,
id: str='controls',
name: t.Optional[str]='Actions',
header_template: t.Optional[str]='crud/column_header_controls.html',
body_template: t.Optional[str]='crud/column_body_controls.html'
id: str = 'controls',
name: t.Optional[str] = 'Actions',
header_template: t.Optional[str] = 'crud/column_header_controls.html',
body_template: t.Optional[str] = 'crud/column_body_controls.html'
):
"""Initialize ControlsColumn.
Expand All @@ -166,10 +168,10 @@ def __init__(
self,
id: str,
name: str,
navigate_view_name: t.Optional[str]=None,
timezone: t.Optional[str]=None,
header_template: t.Optional[str]=None,
body_template: t.Optional[str]='crud/column_body_friendly_time.html'
navigate_view_name: t.Optional[str] = None,
timezone: t.Optional[str] = None,
header_template: t.Optional[str] = None,
body_template: t.Optional[str] = 'crud/column_body_friendly_time.html'
):
"""Initialize FriendlyTimeColumn.
Expand All @@ -189,7 +191,7 @@ def __init__(
class Table:
"""Describe table columns to a CRUD listing view."""

def __init__(self, columns: t.Optional[t.List[Column]]=None):
def __init__(self, columns: t.Optional[t.List[Column]] = None):
"""Initialize Table.
:param columns: List of columns to be used to render the list view.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/crud/paginator.py
Expand Up @@ -264,7 +264,7 @@ class DefaultPaginator:

default_size = 20

def __init__(self, template: t.Optional[str]=None, default_size: t.Optional[int]=None):
def __init__(self, template: t.Optional[str] = None, default_size: t.Optional[int] = None):
"""Initialize DefaultPaginator.
:param template: Path to paginator template.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/crud/sqlalchemy.py
Expand Up @@ -36,7 +36,7 @@ class CRUD(_CRUD):
A traversing endpoint which maps listing, add, edit and delete views for an SQLAlchemy model.
"""

def __init__(self, request: IRequest, model: t.Optional[type]=None):
def __init__(self, request: IRequest, model: t.Optional[type] = None):
"""Create a CRUD root resource for a given model.
:param request: Current HTTP Request.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/crud/views.py
Expand Up @@ -51,7 +51,7 @@ class ResourceButton:
#: The template used to render this button. Also overridable through the constructor.
template = "crud/resource_button.html"

def __init__(self, id: t.Optional[str]=None, name: t.Optional[str]=None, template: t.Optional[str]=None, permission: t.Optional[str]=None, tooltip: t.Optional[str]=None, feature: t.Optional[str]=None):
def __init__(self, id: t.Optional[str] = None, name: t.Optional[str] = None, template: t.Optional[str] = None, permission: t.Optional[str] = None, tooltip: t.Optional[str] = None, feature: t.Optional[str] = None):
"""
:param id: Id of the button to be used as HTML id
:param name: Human readable label of the button
Expand Down
4 changes: 2 additions & 2 deletions websauna/system/devop/cmdline.py
Expand Up @@ -61,7 +61,7 @@ def setup_logging(config_uri, disable_existing_loggers=False):
loader.setup_logging(disable_existing_loggers=disable_existing_loggers)


def setup_console_logging(log_level: t.Optional[str]=None):
def setup_console_logging(log_level: t.Optional[str] = None):
"""Setup console logging.
Aimed to give easy sane defaults for logging in command line applications.
Expand Down Expand Up @@ -90,7 +90,7 @@ def setup_console_logging(log_level: t.Optional[str]=None):
logger.setLevel(logging.ERROR)


def init_websauna(config_uri: str, sanity_check: bool=False, console_app: bool=False, extra_options: dict=None) -> Request:
def init_websauna(config_uri: str, sanity_check: bool = False, console_app: bool = False, extra_options: dict = None) -> Request:
"""Initialize Websauna WSGI application for a command line oriented script.
Example:
Expand Down
6 changes: 3 additions & 3 deletions websauna/system/devop/scripts/__init__.py
Expand Up @@ -27,7 +27,7 @@
"""


def feedback(message: str, display_border: bool=True):
def feedback(message: str, display_border: bool = True):
"""Display a feedback message on the console then exit.
:param message: Message to be displayed to the user.
Expand All @@ -40,7 +40,7 @@ def feedback(message: str, display_border: bool=True):
print(message)


def feedback_and_exit(message: str, status_code: t.Optional[int]=None, display_border: bool=True):
def feedback_and_exit(message: str, status_code: t.Optional[int] = None, display_border: bool = True):
"""Display a feedback message on the console then exit.
:param message: Message to be displayed to the user.
Expand All @@ -61,7 +61,7 @@ def get_config_uri(argv: t.List[str]) -> str:
return prepare_config_uri(config_uri)


def usage_message(argv: t.List[str], additional_params: str='', additional_line: t.Optional[str]=None):
def usage_message(argv: t.List[str], additional_params: str = '', additional_line: t.Optional[str] = None):
"""Display usage message and exit.
:param argv: Command line arguments.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/collectstatic.py
Expand Up @@ -13,7 +13,7 @@
from websauna.system.devop.scripts import usage_message


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Read through all configured static views and compile their assets to ``collected-static`` folder.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/createtable.py
Expand Up @@ -16,7 +16,7 @@
from websauna.system.model.meta import Base


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Print out sql statements needed to construct currently configured models.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down
8 changes: 4 additions & 4 deletions websauna/system/devop/scripts/createuser.py
Expand Up @@ -38,9 +38,9 @@ def create(
request,
username: str,
email: str,
password: t.Optional[str]=None,
source: str='command_line',
admin: bool=False
password: t.Optional[str] = None,
source: str = 'command_line',
admin: bool = False
) -> IUserModel:
"""Create a new site user from command line.
Expand Down Expand Up @@ -77,7 +77,7 @@ def create(
return u


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Create a new site user from command line.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/dbshell.py
Expand Up @@ -16,7 +16,7 @@
from websauna.system.devop.scripts import usage_message


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Run pgcli shell on the database specified on the configuration file.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/dumpdb.py
Expand Up @@ -22,7 +22,7 @@
logger = logging.getLogger(__name__)


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Wrapper for pgsql-dump.bash script.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/proutes.py
Expand Up @@ -10,7 +10,7 @@
from websauna.system.devop.scripts import proxy_to_pyramid_script


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Proxy to Pyramid proutes script.
This script is deprecated and will be removed in Websauna 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/pserve.py
Expand Up @@ -17,7 +17,7 @@
pass


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Proxy to Pyramid pserve script.
This script is deprecated and will be removed in Websauna 1.0.0
Expand Down
4 changes: 2 additions & 2 deletions websauna/system/devop/scripts/sanitycheck.py
Expand Up @@ -25,7 +25,7 @@
"""


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Execute a sanity check on the configuration.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand All @@ -40,7 +40,7 @@ def main(argv: t.List[str]=sys.argv):
init_websauna(config_uri, sanity_check=True)
except SanityCheckFailed as exc:
feedback_and_exit(FAIL_MSG.format(exception=str(exc)), 10)
except FileNotFoundError as exc:
except FileNotFoundError:
feedback_and_exit(NOT_FOUND_MSG.format(config_uri=config_uri), 10)

feedback_and_exit(SUCCESS_MSG, 0)
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/settings.py
Expand Up @@ -16,7 +16,7 @@
from websauna.system.devop.scripts import usage_message


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Display settings for a given configuration file.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down
2 changes: 1 addition & 1 deletion websauna/system/devop/scripts/shell.py
Expand Up @@ -27,7 +27,7 @@
raise ImportError("You need to install IPython to use this shell") from e


def main(argv: t.List[str]=sys.argv):
def main(argv: t.List[str] = sys.argv):
"""Execute the IPython shell prompt with Websauna configuration already initialised.
:param argv: Command line arguments, second one needs to be the uri to a configuration file.
Expand Down

0 comments on commit 5524757

Please sign in to comment.