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)
@ -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

@ -1,4 +1,4 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
lodgeit.libs.filterable
~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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

@ -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

@ -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()]
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):

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