Skip to content

Commit

Permalink
Enable flake8 linting via pre-commit
Browse files Browse the repository at this point in the history
This should make very easy to enable additional linters without having
to change CI jobs or the way user lints.

Configuration is mostly copied from tox project itself, with few
removals.
  • Loading branch information
ssbarnea committed Sep 25, 2019
1 parent 1ec339c commit d54eaf6
Show file tree
Hide file tree
Showing 15 changed files with 1,878 additions and 1,413 deletions.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
- ./venv
key: v1-dependencies-{{ checksum ".circleci/requirements.txt" }}

- run:
name: run linting
command: |
. venv/bin/activate
tox -e lint
# run tests!
- run:
name: run tests
Expand All @@ -49,4 +55,3 @@ jobs:
- store_artifacts:
path: test-reports
destination: test-reports

16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/python/black
rev: 19.3b0
hooks:
- id: black
args: [--safe]
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: flake8
language_version: python3
1 change: 0 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
- 0.4: Unicode support, Python3 support, ``rst`` tables.
- 0.3: Initial PyPI release. Table formats: ``simple``, ``plain``,
``grid``, ``pipe``, and ``orgtbl``.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,3 @@ Maier, Andy MacKinlay, Thomas Roten, Jue Wang, Joe King, Samuel Phan,
Nick Satterly, Daniel Robbins, Dmitry B, Lars Butler, Andreas Maier,
Dick Marinus, Sébastien Celles, Yago González, Andrew Gaul, Wim Glenn,
Jean Michel Rouly, Tim Gates, John Vandenberg.

43 changes: 25 additions & 18 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,44 @@ def run_tabulate(table, widechars=False):
"""

methods = [(u"join with tabs and newlines", "join_table(table)"),
(u"csv to StringIO", "csv_table(table)"),
(u"asciitable (%s)" % asciitable.__version__, "run_asciitable(table)"),
(u"tabulate (%s)" % tabulate.__version__, "run_tabulate(table)"),
(u"tabulate (%s, WIDE_CHARS_MODE)" % tabulate.__version__, "run_tabulate(table, widechars=True)"),
(u"PrettyTable (%s)" % prettytable.__version__, "run_prettytable(table)"),
(u"texttable (%s)" % texttable.__version__, "run_texttable(table)"),
]
methods = [
("join with tabs and newlines", "join_table(table)"),
("csv to StringIO", "csv_table(table)"),
("asciitable (%s)" % asciitable.__version__, "run_asciitable(table)"),
("tabulate (%s)" % tabulate.__version__, "run_tabulate(table)"),
(
"tabulate (%s, WIDE_CHARS_MODE)" % tabulate.__version__,
"run_tabulate(table, widechars=True)",
),
("PrettyTable (%s)" % prettytable.__version__, "run_prettytable(table)"),
("texttable (%s)" % texttable.__version__, "run_texttable(table)"),
]


if tabulate.wcwidth is None:
del(methods[4])
del methods[4]


def benchmark(n):
global methods
if '--onlyself' in sys.argv[1:]:
methods = [ m for m in methods if m[0].startswith("tabulate") ]
if "--onlyself" in sys.argv[1:]:
methods = [m for m in methods if m[0].startswith("tabulate")]
else:
methods = methods

results = [(desc, timeit(code, setup_code, number=n)/n * 1e6)
for desc, code in methods]
results = [
(desc, timeit(code, setup_code, number=n) / n * 1e6) for desc, code in methods
]
mintime = min(map(lambda x: x[1], results))
results = [(desc, t, t/mintime) for desc, t in
sorted(results, key=lambda x: x[1])]
table = tabulate.tabulate(results,
[u"Table formatter", u"time, μs", u"rel. time"],
u"rst", floatfmt=".1f")
results = [
(desc, t, t / mintime) for desc, t in sorted(results, key=lambda x: x[1])
]
table = tabulate.tabulate(
results, ["Table formatter", "time, μs", "rel. time"], "rst", floatfmt=".1f"
)

import platform

if platform.platform().startswith("Windows"):
print(table)
elif python_version_tuple()[0] < "3":
Expand Down
64 changes: 34 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import re

# strip links from the descripton on the PyPI
if python_version_tuple()[0] >= '3':
if python_version_tuple()[0] >= "3":
LONG_DESCRIPTION = open("README.md", "r", encoding="utf-8").read()
else:
LONG_DESCRIPTION = open("README.md", "r").read()

# strip Build Status from the PyPI package
try:
if python_version_tuple()[:2] >= ('2', '7'):
if python_version_tuple()[:2] >= ("2", "7"):
status_re = "^Build status\n(.*\n){7}"
LONG_DESCRIPTION = re.sub(status_re, "", LONG_DESCRIPTION, flags=re.M)
except TypeError:
Expand All @@ -28,35 +28,39 @@
else:
raise

install_options = os.environ.get("TABULATE_INSTALL","").split(",")
install_options = os.environ.get("TABULATE_INSTALL", "").split(",")
libonly_flags = set(["lib-only", "libonly", "no-cli", "without-cli"])
if libonly_flags.intersection(install_options):
console_scripts = []
else:
console_scripts = ['tabulate = tabulate:_main']


setup(name='tabulate',
version='0.8.6',
description='Pretty-print tabular data',
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author='Sergey Astanin',
author_email='[email protected]',
url='https://github.com/astanin/python-tabulate',
license='MIT',
classifiers= [ "Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Topic :: Software Development :: Libraries" ],
py_modules = ['tabulate'],
entry_points = {'console_scripts': console_scripts},
extras_require = {'widechars': ['wcwidth']},
test_suite = 'nose.collector')
console_scripts = ["tabulate = tabulate:_main"]


setup(
name="tabulate",
version="0.8.6",
description="Pretty-print tabular data",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author="Sergey Astanin",
author_email="[email protected]",
url="https://github.com/astanin/python-tabulate",
license="MIT",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Topic :: Software Development :: Libraries",
],
py_modules=["tabulate"],
entry_points={"console_scripts": console_scripts},
extras_require={"widechars": ["wcwidth"]},
test_suite="nose.collector",
)
Loading

0 comments on commit d54eaf6

Please sign in to comment.