Add tox configuration to enable PEP-8 checks, and fix various failures

- E126 continuation line over-indented for hanging indent
- E127 continuation line over-indented for visual indent
- E128 continuation line under-indented for visual indent
- E131 continuation line unaligned for hanging indent
- E265 block comment should start with '# '
- E272 multiple spaces before keyword
- E302 expected 2 blank lines, found <n>
- E712 comparison to False should be 'if cond is False:' or 'if not cond:'
- F401 '<name>' imported but unused

Change-Id: I2344cf2e8fd7910e72e9d8043423d25e43065ef2
This commit is contained in:
David Pursehouse 2015-11-05 13:38:56 +09:00
parent 0939be787c
commit fbb61e9c1d
18 changed files with 68 additions and 48 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.pyc
.DS_Store
bootstrap.py
.tox

View File

@ -8,4 +8,3 @@
:copyright: 2007 by Armin Ronacher.
:license: BSD
"""
from lodgeit.application import make_app

View File

@ -9,6 +9,7 @@
:license: BSD
"""
def get_controller(name):
cname, hname = name.split('/')
module = __import__('lodgeit.controllers.' + cname, None, None, [''])

View File

@ -23,7 +23,7 @@ from lodgeit.lib.captcha import check_hashed_solution, Captcha
class PasteController(object):
"""Provides all the handler callback for paste related stuff."""
#XXX:dc: using language here clashes with internationalization terms
# XXX:dc: using language here clashes with internationalization terms
def new_paste(self, language=None):
"""The 'create a new paste' view."""
language = local.request.args.get('language', language)
@ -74,14 +74,14 @@ class PasteController(object):
language = parent.language
private = parent.private
return render_to_response('new_paste.html',
languages=list_languages(),
parent=parent,
code=code,
language=language,
error=error,
show_captcha=show_captcha,
private=private
)
languages=list_languages(),
parent=parent,
code=code,
language=language,
error=error,
show_captcha=show_captcha,
private=private
)
def show_paste(self, identifier, raw=False):
"""Show an existing paste."""
@ -113,9 +113,9 @@ class PasteController(object):
if paste is None:
raise NotFound()
return render_to_response('paste_tree.html',
paste=paste,
current=identifier
)
paste=paste,
current=identifier
)
def compare_paste(self, new_id=None, old_id=None):
"""Render a diff view for two pastes."""
@ -133,10 +133,10 @@ class PasteController(object):
raise NotFound()
return render_to_response('compare_paste.html',
old=old,
new=new,
diff=old.compare_to(new, template=True)
)
old=old,
new=new,
diff=old.compare_to(new, template=True)
)
def unidiff_paste(self, new_id=None, old_id=None):
"""Render an udiff for the two pastes."""
@ -155,7 +155,7 @@ class PasteController(object):
style_name = local.request.form.get('style')
resp = redirect(local.request.headers.get('referer') or
url_for('pastes/new_paste'))
#XXX:dc: use some sort of form element validation instead
# XXX:dc: use some sort of form element validation instead
if style_name in STYLES:
resp.set_cookie('style', style_name)
return resp

View File

@ -25,7 +25,7 @@ def session_factory():
return orm.create_session(application.engine, **options)
session = orm.scoped_session(session_factory,
scopefunc=_local_manager.get_ident)
scopefunc=_local_manager.get_ident)
class ModelBase(object):
@ -38,7 +38,7 @@ class ModelBase(object):
# configure the declarative base
Model = declarative_base(name='Model', cls=ModelBase,
mapper=orm.mapper, metadata=metadata)
mapper=orm.mapper, metadata=metadata)
ModelBase.query = session.query_property()

View File

@ -40,7 +40,7 @@ def check_for_link_spam(code):
if len(spans) > MAX_LINK_PERCENTAGE:
return True
return (sum(starmap(sub, spans)) * -100) / (len(code) or 1) \
> MAX_LINK_PERCENTAGE
> MAX_LINK_PERCENTAGE
def is_spam(code):

View File

@ -287,7 +287,7 @@ class GridBackground(Layer):
for i in xrange(image.size[0] / self.size + 1):
draw.line((0, i * self.size + self.offset[1],
image.size[0], i * self.size+self.offset[1]),
fill=self.color)
fill=self.color)
return image
@ -408,5 +408,5 @@ class SineWarp(WarpBase):
def get_transform(self, image):
return (lambda x, y, a=self.amplitude, p=self.period,
o=self.offset: (math.sin((y + o[0]) * p) * a + x,
math.sin((x + o[1]) * p) * a + y))
o=self.offset: (math.sin((y + o[0]) * p) * a + x,
math.sin((x + o[1]) * p) * a + y))

View File

@ -1,4 +1,4 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
lodgeit.libs.filterable
~~~~~~~~~~~~~~~~~~~~~~~
@ -30,12 +30,12 @@ ACTIONS = {
}
}
ACTIONS_MAP = {
'is': lambda f, v: f == v,
'contains': lambda f, v: f.contains(v),
'is': lambda f, v: f == v,
'contains': lambda f, v: f.contains(v),
'startswith': lambda f, v: f.startswith(v),
'greater': lambda f, v: f > v,
'lower': lambda f, v: f < v,
'bool': lambda f, v: f == (v == 'true'),
'greater': lambda f, v: f > v,
'lower': lambda f, v: f < v,
'bool': lambda f, v: f == (v == 'true'),
}

View File

@ -14,7 +14,7 @@ import csv
from operator import itemgetter
from pygments.util import ClassNotFound
from pygments.lexers import get_lexer_by_name, get_lexer_for_filename, \
get_lexer_for_mimetype, PhpLexer, TextLexer, get_all_lexers
get_lexer_for_mimetype, PhpLexer, TextLexer, get_all_lexers
from pygments.styles import get_all_styles
from pygments.formatters import HtmlFormatter
@ -23,7 +23,7 @@ from lodgeit.i18n import lazy_gettext as _
from lodgeit.utils import render_template
from lodgeit.lib.diff import prepare_udiff
from lodgeit.lib.compilerparser import parse_gcc_messages, \
parse_javac_messages
parse_javac_messages
from werkzeug import escape
@ -167,11 +167,12 @@ def highlight_multifile(code):
start, filename, lang = last
section_code = _escaped_marker.sub('', code[start:pos])
if section_code:
if filename:
filename_html = u'<p class="filename">%s</p>' % escape(filename)
else:
filename_html = u''
result.append(u'<div class="section">%s%s</div>' % (
filename and u'<p class="filename">%s</p>'
% escape(filename) or u'',
highlight(section_code, lang)
))
filename_html, highlight(section_code, lang)))
for match in _section_marker_re.finditer(code):
start = match.start()

View File

@ -37,7 +37,7 @@ class JSONRequestHandler(object):
kwargs = {}
else:
raise TypeError('arguments as object or list expected')
#XXX:dc: use flatland to validate these args before passing onward
# XXX:dc: use flatland to validate these args before passing onward
response = {
'data': self.funcs[method_name](*args, **kwargs),
'error': None

View File

@ -14,7 +14,7 @@ from lodgeit.database import db
from lodgeit.lib.xmlrpc import XMLRPCRequestHandler
from lodgeit.lib.json import JSONRequestHandler
from lodgeit.lib.highlighting import STYLES, LANGUAGES, get_style, \
get_language_for
get_language_for
xmlrpc = XMLRPCRequestHandler()
@ -32,6 +32,8 @@ def exported(name, hidden=False):
_public_methods = None
def get_public_methods():
"""Returns the public methods."""
global _public_methods

View File

@ -34,8 +34,8 @@ class Paste(db.Model):
private_id = db.Column(db.String(40), unique=True, nullable=True)
children = db.relation('Paste', cascade='all',
primaryjoin=parent_id == paste_id,
backref=db.backref('parent', remote_side=[paste_id]))
primaryjoin=parent_id == paste_id,
backref=db.backref('parent', remote_side=[paste_id]))
def __init__(self, code, language, parent_id=None, user_hash=None,
private=False):
@ -43,7 +43,7 @@ class Paste(db.Model):
language = 'text'
self.code = u'\n'.join(code.splitlines())
self.language = language
#XXX:dc: set these a bit more sanely, allowing two types is bad
# XXX:dc: set these a bit more sanely, allowing two types is bad
if parent_id:
self.parent_id = parent_id
self.pub_date = datetime.now()
@ -90,12 +90,12 @@ class Paste(db.Model):
"""Get the new replies for the ower of a request and flag them
as handled.
"""
#XXX:dc:clean this query up to just return the ids
# XXX:dc:clean this query up to just return the ids
ids = [x.paste_id for x in Paste.query.filter_by(
user_hash=local.request.user_hash).all()]
user_hash=local.request.user_hash).all()]
paste_list = Paste.query.filter(db.and_(
Paste.parent_id.in_(ids),
Paste.handled == False,
Paste.handled is False,
)).order_by(Paste.paste_id.desc()).all()
for paste in paste_list:
paste.handled = True

View File

@ -85,7 +85,6 @@ class Request(RequestBase):
lang = session.get('locale')
if lang is None:
lang = 'en'
#lang = (self.accept_languages.best or 'en').split('-')[0]
self.locale = Locale.parse(lang)
def set_language(self, lang):

View File

@ -69,7 +69,7 @@ def load_default_settings():
if key in settings:
if key in ('clipboard', 'open_browser'):
settings[key] = p[1].strip().lower() in \
('true', '1', 'on', 'yes')
('true', '1', 'on', 'yes')
else:
settings[key] = p[1].strip()
f.close()

2
test-requirements.txt Normal file
View File

@ -0,0 +1,2 @@
flake8

View File

@ -5,5 +5,5 @@ default+apiclient=wsgi
wsgi=wsgi
[default+apiclient.wsgi]
server-entry-point = tests.utilities:foo
server-entry-point = tests.utilities.runner:foo
base_url = http://www.localhost:5001

View File

@ -1 +0,0 @@
from .runner import foo

16
tox.ini Normal file
View File

@ -0,0 +1,16 @@
[tox]
minversion = 1.6
envlist = pep8
skipsdist = True
[testenv]
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt
[testenv:pep8]
commands = flake8
[flake8]
show-source = true
max-line-length = 80
exclude = ENV,.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools