Skip to content

Commit bd1b13a

Browse files
committed
Added Pipfile for use with Pipenv
Also: - Added flake8 invoke task to run flake8 static analysis - Started fixing flake8 warnings
1 parent 546f773 commit bd1b13a

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ htmlcov
2121
# mypy optional static type checker
2222
.mypy_cache
2323
*~
24+
25+
# Pipenv (this is a library, not an application)
26+
.venv
27+
Pipfile.lock

Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[packages]
7+
wcwidth = "*"
8+
9+
[dev-packages]
10+
tableformatter = {editable = true,path = "."}
11+
flake8 = "*"
12+
invoke = "*"
13+
pytest = "*"
14+
pytest-cov = "*"

tableformatter.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Collection
1818
except ImportError:
1919
from typing import Container, Generic, Sized, TypeVar
20+
2021
# Python 3.5
2122
# noinspection PyAbstractClass
2223
class Collection(Generic[TypeVar('T_co', covariant=True)], Container, Sized, Iterable):
@@ -174,12 +175,12 @@ def _wrap_chunks(self, chunks):
174175
del chunks[-1]
175176

176177
while chunks:
177-
l = _wcswidth(chunks[-1])
178+
length = _wcswidth(chunks[-1])
178179

179180
# Can at least squeeze this chunk onto the current line.
180-
if cur_len + l <= width:
181+
if cur_len + length <= width:
181182
cur_line.append(chunks.pop())
182-
cur_len += l
183+
cur_len += length
183184

184185
# Nope, this line is full.
185186
else:
@@ -197,19 +198,15 @@ def _wrap_chunks(self, chunks):
197198
del cur_line[-1]
198199

199200
if cur_line:
200-
if (self.max_lines is None or
201-
len(lines) + 1 < self.max_lines or
202-
(not chunks or
203-
self.drop_whitespace and
204-
len(chunks) == 1 and
205-
not chunks[0].strip()) and cur_len <= width):
201+
if (self.max_lines is None or len(lines) + 1 < self.max_lines
202+
or (not chunks or self.drop_whitespace and len(chunks) == 1 and not chunks[0].strip())
203+
and cur_len <= width):
206204
# Convert current line back to a string and store it in
207205
# list of all lines (return value).
208206
lines.append(indent + ''.join(cur_line))
209207
else:
210208
while cur_line:
211-
if (cur_line[-1].strip() and
212-
cur_len + _wcswidth(self.placeholder) <= width):
209+
if cur_line[-1].strip() and cur_len + _wcswidth(self.placeholder) <= width:
213210
cur_line.append(self.placeholder)
214211
lines.append(indent + ''.join(cur_line))
215212
break
@@ -218,8 +215,7 @@ def _wrap_chunks(self, chunks):
218215
else:
219216
if lines:
220217
prev_line = lines[-1].rstrip()
221-
if (_wcswidth(prev_line) + _wcswidth(self.placeholder) <=
222-
self.width):
218+
if _wcswidth(prev_line) + _wcswidth(self.placeholder) <= self.width:
223219
lines[-1] = prev_line + self.placeholder
224220
break
225221
lines.append(indent + self.placeholder.lstrip())
@@ -233,7 +229,7 @@ def _translate_tabs(text: str) -> str:
233229
tabpos = text.find('\t')
234230
while tabpos >= 0:
235231
before_text = text[:tabpos]
236-
after_text = text[tabpos+1:]
232+
after_text = text[tabpos + 1:]
237233
before_width = _wcswidth(before_text)
238234
tab_pad = TAB_WIDTH - (before_width % TAB_WIDTH)
239235
text = before_text + '{: <{width}}'.format('', width=tab_pad) + after_text
@@ -351,25 +347,26 @@ def _pad_columns(text: str, pad_char: str, align: Union[ColumnAlignment, str], w
351347
"""Returns a string padded out to the specified width"""
352348
text = _translate_tabs(text)
353349
display_width = _printable_width(text)
350+
diff = width - display_width
354351
if display_width >= width:
355352
return text
356353

357354
if align in (ColumnAlignment.AlignLeft, ColumnAlignment.AlignLeft.format_string()):
358355
out_text = text
359-
out_text += '{:{pad}<{width}}'.format('', pad=pad_char, width=width-display_width)
356+
out_text += '{:{pad}<{width}}'.format('', pad=pad_char, width=diff)
360357
elif align in (ColumnAlignment.AlignRight, ColumnAlignment.AlignRight.format_string()):
361-
out_text = '{:{pad}<{width}}'.format('', pad=pad_char, width=width-display_width)
358+
out_text = '{:{pad}<{width}}'.format('', pad=pad_char, width=diff)
362359
out_text += text
363360
elif align in (ColumnAlignment.AlignCenter, ColumnAlignment.AlignCenter.format_string()):
364-
lead_pad = int((width - display_width) / 2)
365-
tail_pad = width - display_width - lead_pad
361+
lead_pad = diff // 2
362+
tail_pad = diff - lead_pad
366363

367364
out_text = '{:{pad}<{width}}'.format('', pad=pad_char, width=lead_pad)
368365
out_text += text
369366
out_text += '{:{pad}<{width}}'.format('', pad=pad_char, width=tail_pad)
370367
else:
371368
out_text = text
372-
out_text += '{:{pad}<{width}}'.format('', pad=pad_char, width=width-display_width)
369+
out_text += '{:{pad}<{width}}'.format('', pad=pad_char, width=diff)
373370

374371
return out_text
375372

@@ -565,7 +562,7 @@ def border_right_span(self, row_index: Union[int, None]) -> str:
565562
bg_reset = self.bg_reset if self.bg_reset is not None else TableColors.BG_RESET
566563
return bg_reset + '║'
567564

568-
def col_divider_span(self, row_index : Union[int, None]) -> str:
565+
def col_divider_span(self, row_index: Union[int, None]) -> str:
569566
bg_reset = self.bg_reset if self.bg_reset is not None else TableColors.BG_RESET
570567
bg_primary = self.bg_primary if self.bg_primary is not None else TableColors.BG_RESET
571568
bg_alt = self.bg_alt if self.bg_alt is not None else TableColors.BG_COLOR_ROW

tasks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# coding=utf-8
3+
# flake8: noqa E302
34
"""Development related tasks to be run with 'invoke'.
45
56
Make sure you satisfy the following Python module requirements if you are trying to publish a release to PyPI:
@@ -164,3 +165,9 @@ def pypi_test(context):
164165
context.run('twine upload --repository-url https://test.pypi.org/legacy/ dist/*')
165166
namespace.add_task(pypi_test)
166167

168+
# Flake8 - linter and tool for style guide enforcement and linting
169+
@invoke.task
170+
def flake8(context):
171+
"Run flake8 linter and tool for style guide enforcement"
172+
context.run("flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics --exclude=.git,__pycache__,.tox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov")
173+
namespace.add_task(flake8)

0 commit comments

Comments
 (0)