Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Flake8 with Ruff #278

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

39 changes: 12 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: [--add-import=from __future__ import annotations]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat, flake8-logging]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
Expand All @@ -51,13 +31,13 @@ repos:
exclude: ^tests/

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.5.3
rev: 1.7.0
hooks:
- id: pyproject-fmt
additional_dependencies: [tox]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
rev: v0.16
hooks:
- id: validate-pyproject

Expand All @@ -73,5 +53,10 @@ repos:
args: [--prose-wrap=always, --print-width=88]
exclude: ^.github/ISSUE_TEMPLATE/bug_report.md$

- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

ci:
autoupdate_schedule: quarterly
27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,28 @@ version.source = "vcs"
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.isort]
profile = "black"
[tool.ruff.lint]
select = [
"C4", # flake8-comprehensions
"E", # pycodestyle errors
"EM", # flake8-errmsg
"F", # pyflakes errors
"I", # isort
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8-2020
]
extend-ignore = [
"E203", # Whitespace before ':'
"E221", # Multiple spaces before operator
"E226", # Missing whitespace around arithmetic operator
"E241", # Multiple spaces after ','
]

[tool.ruff.lint.isort]
known-first-party = ["prettytable"]
required-imports = ["from __future__ import annotations"]
25 changes: 14 additions & 11 deletions src/prettytable/prettytable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,11 +1483,13 @@ def del_column(self, fieldname) -> None:
fieldname - The field name of the column you want to delete."""

if fieldname not in self._field_names:
raise ValueError(
"Can't delete column %r which is not a field name of this table."
" Field names are: %s"
% (fieldname, ", ".join(map(repr, self._field_names)))
msg = (
"Can't delete column {!r} which is not a field name of this table."
" Field names are: {}".format(
fieldname, ", ".join(map(repr, self._field_names))
)
)
raise ValueError(msg)

col_index = self._field_names.index(fieldname)
del self._field_names[col_index]
Expand Down Expand Up @@ -1804,11 +1806,12 @@ def get_string(self, **kwargs) -> str:
if options["border"] and options["hrules"] == FRAME:
lines.append(self._stringify_hrule(options, where="bottom_"))

if "orgmode" in self.__dict__ and self.orgmode is True:
tmp = list()
for line in lines:
tmp.extend(line.split("\n"))
lines = ["|" + line[1:-1] + "|" for line in tmp]
if "orgmode" in self.__dict__ and self.orgmode:
lines = [
"|" + new_line[1:-1] + "|"
for old_line in lines
for new_line in old_line.split("\n")
]

return "\n".join(lines)

Expand Down Expand Up @@ -2085,7 +2088,7 @@ def get_json_string(self, **kwargs) -> str:
import json

options = self._get_options(kwargs)
json_options: Any = dict(indent=4, separators=(",", ": "), sort_keys=True)
json_options: Any = {"indent": 4, "separators": (",", ": "), "sort_keys": True}
json_options.update(
{key: value for key, value in kwargs.items() if key not in options}
)
Expand Down Expand Up @@ -2419,7 +2422,7 @@ def _get_formatted_latex_string(self, options):


def _str_block_width(val):
import wcwidth # type: ignore
import wcwidth # type: ignore[import-not-found]

return wcwidth.wcswidth(_re.sub("", val))

Expand Down
Loading