Skip to content

Commit

Permalink
Add ruff (#158)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Jun 16, 2023
1 parent 166540c commit aecdffb
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 240 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ concurrency:
jobs:
test:
name: test ${{ matrix.py }}
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py:
- "3.12.0-beta.1"
- "3.12.0-beta.2"
- "3.11"
- "3.10"
- "3.9"
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:

check:
name: tox env ${{ matrix.tox_env }}
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/tox-ini-fmt
Expand Down
8 changes: 0 additions & 8 deletions .markdownlint.yaml

This file was deleted.

55 changes: 7 additions & 48 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,32 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--safe]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3]
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.0"
hooks:
- id: tox-ini-fmt
args: ["-p", "fix"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.9.2"
rev: "0.12.0"
hooks:
- id: pyproject-fmt
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.3.23
- flake8-comprehensions==3.12
- flake8-pytest-style==1.7.2
- flake8-spellcheck==0.28
- flake8-unused-arguments==0.0.13
- flake8-noqa==1.3.1
- pep8-naming==0.13.3
- flake8-pyproject==1.2.3
additional_dependencies: ["tox>=4.6"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
additional_dependencies:
- [email protected]
- "@prettier/[email protected]"
args: ["--print-width=120", "--prose-wrap=always"]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.272"
hooks:
- id: markdownlint
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
41 changes: 25 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.3",
"hatchling>=1.14",
"hatchling>=1.17.1",
]

[project]
Expand All @@ -29,13 +29,13 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
Expand All @@ -48,8 +48,8 @@ dependencies = [
]
optional-dependencies.test = [
"covdefaults>=2.3",
"pytest>=7.3.1",
"pytest-cov>=4",
"pytest>=7.3.2",
"pytest-cov>=4.1",
]
urls.Documentation = "https://tox.wiki"
urls.Homepage = "https://github.com/tox-dev/tox-ini-fmt/blob/main/README.md#tox-ini-fmt"
Expand All @@ -67,18 +67,27 @@ version.source = "vcs"
[tool.black]
line-length = 120

[tool.isort]
known_first_party = ["tox", "tests"]
profile = "black"
line_length = 120
add_imports = ["from __future__ import annotations"]

[tool.flake8]
max-complexity = 22
max-line-length = 120
unused-arguments-ignore-abstract-functions = true
noqa-require-code = true
dictionaries = ["en_US", "python", "technical", "django"]
[tool.ruff]
select = ["ALL"]
line-length = 120
target-version = "py37"
isort = {known-first-party = ["tox_ini_fmt"], required-imports = ["from __future__ import annotations"]}
ignore = [
"ANN101", # no typoe annotation for self
"ANN401", # allow Any as type annotation
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"S104", # Possible binding to all interface
]
[tool.ruff.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests...
"FBT", # don"t care about booleans as positional arguments in tests
"INP001", # no implicit namespace
"D", # don"t care about documentation in tests
"S603", # `subprocess` call: check for execution of untrusted input
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
]

[tool.coverage]
html.show_contexts = true
Expand Down
80 changes: 0 additions & 80 deletions setup.cfg

This file was deleted.

5 changes: 4 additions & 1 deletion src/tox_ini_fmt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Format tox.ini files."""
from __future__ import annotations

from .version import __version__

__all__ = ("__version__",)
__all__ = [
"__version__",
]
20 changes: 16 additions & 4 deletions src/tox_ini_fmt/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Main entry point."""
from __future__ import annotations

import difflib
Expand All @@ -14,6 +15,11 @@


def color_diff(diff: Iterable[str]) -> Iterable[str]:
"""
Display diff in colored mode.
:param diff: the diff lines
"""
for line in diff:
if line.startswith("+"):
yield GREEN + line + RESET
Expand All @@ -24,6 +30,12 @@ def color_diff(diff: Iterable[str]) -> Iterable[str]:


def run(args: Sequence[str] | None = None) -> int:
"""
Run the formatter.
:param args: CLI arguments
:return: exit code
"""
opts = cli_args(sys.argv[1:] if args is None else args)
changed = False
for tox_ini in opts.tox_ini:
Expand All @@ -35,7 +47,7 @@ def run(args: Sequence[str] | None = None) -> int:
formatted = format_tox_ini(before, opts)
changed |= before != formatted
if opts.stdout: # stdout just prints new format to stdout
print(formatted, end="")
print(formatted, end="") # noqa: T201
else:
if before != formatted:
with tox_ini.open("wt", newline=original_newlines) as file:
Expand All @@ -51,12 +63,12 @@ def run(args: Sequence[str] | None = None) -> int:
)
if diff:
diff_text = "\n".join(color_diff(diff))
print(diff_text) # print diff on change
print(diff_text) # print diff on change # noqa: T201
else:
print(f"no change for {name}")
print(f"no change for {name}") # noqa: T201
# exit with non success on change
return 1 if changed else 0


if __name__ == "__main__":
sys.exit(run())
raise SystemExit(run())
Loading

0 comments on commit aecdffb

Please sign in to comment.