diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index 03dfa66..2fd1e3a 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -1,8 +1,10 @@ +import sys from timeit import timeit -import tabulate + import prettytable import texttable -import sys + +import tabulate setup_code = r""" from csv import writer diff --git a/pyproject.toml b/pyproject.toml index 95fddca..2ba8dad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,8 +47,13 @@ dev = [ line-length = 99 [tool.ruff.lint] -extend-select = ["W", "C90"] +extend-select = ["W", "I", "C90"] ignore = ["E721", "C901"] [tool.ruff.lint.mccabe] max-complexity = 22 + +[tool.ruff.lint.isort] +combine-as-imports = true +force-sort-within-sections = true +known-local-folder = ["common"] diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 249b3ff..9e48785 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -1,8 +1,8 @@ """Pretty-print tabular data.""" from importlib.metadata import ( - version as _version, PackageNotFoundError as _PackageNotFoundError, + version as _version, ) try: @@ -10,19 +10,19 @@ except _PackageNotFoundError: __version__ = "unknown" -import warnings from collections import namedtuple from collections.abc import Iterable, Sized +import dataclasses from decimal import Decimal +from functools import partial, reduce from html import escape as htmlescape -from itertools import chain, zip_longest as izip_longest -from functools import reduce, partial import io -import re +from itertools import chain, zip_longest as izip_longest import math -import textwrap -import dataclasses +import re import sys +import textwrap +import warnings try: import wcwidth # optional wide-character (CJK) support diff --git a/test/common.py b/test/common.py index 31d6b82..b557b85 100644 --- a/test/common.py +++ b/test/common.py @@ -1,7 +1,8 @@ -import pytest # noqa: F401 -from pytest import skip, raises # noqa: F401 import warnings +import pytest # noqa: F401 +from pytest import raises, skip # noqa: F401 + def assert_equal(expected, result): print("Expected:\n%r\n" % expected) diff --git a/test/test_api.py b/test/test_api.py index 512a84d..3e0963a 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -1,11 +1,11 @@ """API properties.""" -from tabulate import tabulate, tabulate_formats, simple_separated_format -from common import skip +from tabulate import simple_separated_format, tabulate, tabulate_formats +from common import skip try: - from inspect import signature, _empty + from inspect import _empty, signature except ImportError: signature = None _empty = None diff --git a/test/test_cli.py b/test/test_cli.py index 2f7faa8..625eea1 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1,16 +1,12 @@ """Command-line interface.""" import os -import sys - - import subprocess +import sys import tempfile - from common import assert_equal - SAMPLE_SIMPLE_FORMAT = "\n".join( [ "----- ------ -------------", diff --git a/test/test_input.py b/test/test_input.py index c2d19c5..908d8d7 100644 --- a/test/test_input.py +++ b/test/test_input.py @@ -1,6 +1,7 @@ """Test support of the various forms of tabular data.""" -from tabulate import tabulate, SEPARATING_LINE +from tabulate import SEPARATING_LINE, tabulate + from common import assert_equal, assert_in, raises, skip try: diff --git a/test/test_internal.py b/test/test_internal.py index 5d521d0..49ae0ba 100644 --- a/test/test_internal.py +++ b/test/test_internal.py @@ -2,7 +2,7 @@ import tabulate as T -from common import assert_equal, skip, rows_to_pipe_table_str, cols_to_pipe_str +from common import assert_equal, cols_to_pipe_str, rows_to_pipe_table_str, skip def test_multiline_width(): diff --git a/test/test_output.py b/test/test_output.py index 93de112..088dff7 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -1,10 +1,12 @@ """Test output of the various forms of tabular data.""" from decimal import Decimal + from pytest import mark -from common import assert_equal, raises, skip, check_warnings -from tabulate import tabulate, simple_separated_format, SEPARATING_LINE +from tabulate import SEPARATING_LINE, simple_separated_format, tabulate + +from common import assert_equal, check_warnings, raises, skip # _test_table shows # - coercion of a string to a number, diff --git a/test/test_regression.py b/test/test_regression.py index de950b3..c23d34d 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -1,6 +1,7 @@ """Regression tests.""" -from tabulate import tabulate, TableFormat, Line, DataRow +from tabulate import DataRow, Line, TableFormat, tabulate + from common import assert_equal, skip diff --git a/test/test_textwrapper.py b/test/test_textwrapper.py index 7cd1581..41f523c 100644 --- a/test/test_textwrapper.py +++ b/test/test_textwrapper.py @@ -1,11 +1,11 @@ """Discretely test functionality of our custom TextWrapper""" import datetime - -from tabulate import _CustomTextWrap as CTW, tabulate, _strip_ansi from textwrap import TextWrapper as OTW -from common import skip, assert_equal +from tabulate import _CustomTextWrap as CTW, _strip_ansi, tabulate + +from common import assert_equal, skip def test_wrap_multiword_non_wide():