Skip to content

Commit

Permalink
Flake8 the code.
Browse files Browse the repository at this point in the history
Including using the more modern style of writing binary operators at the beginning of the line.
  • Loading branch information
Michael Howitz committed Feb 8, 2019
1 parent 8289ea5 commit 2a8582f
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 113 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ matrix:
- python: "3.7"
dist: xenial
sudo: true
- python: 3.6
name: "Flake8"
install: pip install -U flake8
script: flake8 --doctests src setup.py
after_success:
install:
- pip install six==1.10.0 # force here to avoid conflit with zc.recipe.testrunner
- pip install zc.buildout
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignore =
bootstrap.py

[flake8]
ignore = E301
ignore = W503 # line break before binary operator
exclude = bootstrap.py

[bdist_wheel]
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
description="Zope's indexing and search solution.",
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
long_description=(open('README.rst').read() + '\n' +
open('CHANGES.rst').read()),
long_description=(open('README.rst').read()
+ '\n'
+ open('CHANGES.rst').read()),
packages=find_packages('src'),
namespace_packages=['Products'],
package_dir={'': 'src'},
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/DateRangeIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def matchingDummiesByTimeValue(value, precision=1):
for i, dummy in dummies:
start = datetime_to_minutes(dummy.start(), precision)
stop = datetime_to_minutes(dummy.stop(), precision)
if ((start is None or start <= value) and
(stop is None or stop >= value)):
if ((start is None or start <= value)
and (stop is None or stop >= value)):
result.append((i, dummy))
return result

Expand Down
8 changes: 4 additions & 4 deletions src/Products/ZCTextIndex/BaseIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def _add_wordinfo(self, wid, f, docid):
# Obscure: First check the type. If it's not a dict, it
# can't need conversion, and then we can avoid an expensive
# len(IIBTree).
if (isinstance(doc2score, type({})) and
len(doc2score) == self.DICT_CUTOFF):
if (isinstance(doc2score, type({}))
and len(doc2score) == self.DICT_CUTOFF):
doc2score = IIBTree(doc2score)
doc2score[docid] = f
self._wordinfo[wid] = doc2score # not redundant: Persistency!
Expand All @@ -297,8 +297,8 @@ def _mass_add_wordinfo(self, wid2weight, docid):
if doc2score is None:
doc2score = {}
new_word_count += 1
elif (isinstance(doc2score, dicttype) and
len(doc2score) == self.DICT_CUTOFF):
elif (isinstance(doc2score, dicttype)
and len(doc2score) == self.DICT_CUTOFF):
doc2score = IIBTree(doc2score)
doc2score[docid] = weight
self._wordinfo[wid] = doc2score # not redundant: Persistency!
Expand Down
14 changes: 7 additions & 7 deletions src/Products/ZCTextIndex/ZCTextIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ def __init__(self, id, extra=None, caller=None, index_factory=None,

self.index = self._index_factory(aq_base(self.getLexicon()))

security.declarePrivate('getLexicon')
@security.private
def getLexicon(self):
"""Get the lexicon for this index
"""
"""Get the lexicon for this index."""
if hasattr(aq_base(self), 'lexicon'):
# Fix up old ZCTextIndexes by removing direct lexicon ref
# and changing it to an ID
Expand Down Expand Up @@ -144,7 +143,7 @@ def getLexicon(self):

# External methods not in the Pluggable Index API

security.declareProtected(search_zcatalog, 'query')
@security.protected(search_zcatalog)
def query(self, query, nbest=10):
"""Return pair (mapping from docids to scores, num results).
Expand Down Expand Up @@ -348,7 +347,7 @@ def getPipelineNames(self):

_queryLexicon = DTMLFile('dtml/queryLexicon', globals())

security.declareProtected(LexiconQueryPerm, 'queryLexicon')
@security.protected(LexiconQueryPerm)
def queryLexicon(self, REQUEST, words=None, page=0, rows=20, cols=4):
"""Lexicon browser/query user interface
"""
Expand All @@ -363,8 +362,9 @@ def queryLexicon(self, REQUEST, words=None, page=0, rows=20, cols=4):
word_count = len(words)
rows = max(min(rows, 500), 1)
cols = max(min(cols, 12), 1)
page_count = (word_count / (rows * cols) +
(word_count % (rows * cols) > 0))
page_count = (word_count
/ (rows * cols)
+ (word_count % (rows * cols) > 0))
page = max(min(page, page_count - 1), 0)
start = rows * cols * page
end = min(rows * cols * (page + 1), word_count)
Expand Down
1 change: 1 addition & 0 deletions src/Products/ZCTextIndex/tests/testZCTextIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def testLexiconIsNotFoundRaisesLookupError(self):

def testInvalidIndexTypeRaisesValueError(self):
caller = LexiconHolder(self.lexicon)

class Extra(object):
index_type = 'Some invalid index type'
with self.assertRaises(ValueError):
Expand Down
8 changes: 5 additions & 3 deletions src/Products/ZCatalog/ProgressHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#
##############################################################################

from __future__ import print_function
import sys
import time
from logging import getLogger
Expand Down Expand Up @@ -52,15 +53,16 @@ def report(self, current, *args, **kw):
if self.savepoint:
transaction.savepoint(optimistic=True)
seconds_so_far = time.time() - self._start
seconds_to_go = (seconds_so_far / current *
(self._max - current))
seconds_to_go = (seconds_so_far
/ current
* (self._max - current))
end = DateTime(time.time() + seconds_to_go)
self.output('%d/%d (%.2f%%) Estimated termination: %s' %
(current, self._max, (100.0 * current / self._max),
end.strftime('%Y/%m/%d %H:%M:%Sh')))

def output(self, text):
print >> self.fp, '%s: %s' % (self._ident, text)
print('%s: %s' % (self._ident, text), file=self.fp)


class ZLogHandler(StdoutHandler):
Expand Down
Loading

0 comments on commit 2a8582f

Please sign in to comment.