From fd0c528d2ecf5f4f96ce61c052578058e47ff072 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Fri, 23 Aug 2024 14:26:06 +0200 Subject: [PATCH] replaced flake8 with ruff added all fixes to make ruff happy --- .flake8 | 2 -- CHANGELOG.md | 1 + Makefile | 2 +- docs/conf.py | 5 +++-- gron/__init__.py | 7 +------ gron/__main__.py | 8 +++----- gron/gron.py | 9 ++++----- gron/version.py | 2 +- pyproject.toml | 17 ++++++++++++++++- tests/__init__.py | 1 + tests/test_gron.py | 27 +++++++++++++++++---------- tests/test_version.py | 3 +++ 12 files changed, 51 insertions(+), 33 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 1d3dc3e..0000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -exclude = venv,docs diff --git a/CHANGELOG.md b/CHANGELOG.md index f2a60db..92b8202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * updated dev dependencies * bumped minimum python version to 3.10 +* replaced flake8 with ruff, added all fixes to make ruff happy ## [1.3.0] - 2022-11-11 diff --git a/Makefile b/Makefile index 74ae5b6..e2126c5 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ mypy: $(VENV) .PHONY: lint lint: $(VENV) - $(BIN)/flake8 + $(BIN)/ruff check . .PHONY: release release: $(VENV) diff --git a/docs/conf.py b/docs/conf.py index 0f75286..578b77d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# noqa # # Configuration file for the Sphinx documentation builder. # @@ -14,9 +14,10 @@ import os import sys + sys.path.insert(0, os.path.abspath('..')) -import gron +import gron # noqa # -- Project information ----------------------------------------------------- diff --git a/gron/__init__.py b/gron/__init__.py index c4be537..3b0dc2c 100644 --- a/gron/__init__.py +++ b/gron/__init__.py @@ -1,9 +1,4 @@ -""" - -All imports here are unused in this module but exported as public -interface. - -""" +"""All imports here are exported as public interface.""" from gron.gron import gron as gron # noqa from gron.version import __VERSION__ as __VERSION__ # noqa diff --git a/gron/__main__.py b/gron/__main__.py index db541cd..722e1d2 100644 --- a/gron/__main__.py +++ b/gron/__main__.py @@ -1,6 +1,5 @@ """Gron's command line interface (CLI). - Attributes ---------- parser : argparse.ArgumentParser @@ -9,12 +8,11 @@ # remove when we don't support py38 anymore from __future__ import annotations + import argparse import sys -from gron import gron -from gron import __VERSION__ - +from gron import __VERSION__, gron parser = argparse.ArgumentParser() parser.add_argument( @@ -30,7 +28,7 @@ def main() -> None: - """Gron's CLI + """Gron's CLI. This method reads the arguments for the command line interface and runs `gron`. diff --git a/gron/gron.py b/gron/gron.py index cfe7f4a..38c1f5b 100644 --- a/gron/gron.py +++ b/gron/gron.py @@ -1,9 +1,8 @@ -"""Gron's core functions. - -""" +"""Gron's core functions.""" # remove when we don't support py38 anymore from __future__ import annotations + import json from typing import Any @@ -41,7 +40,7 @@ def walk(node: Any, name: str) -> str: for k, v in sorted(node.items()): res.append(walk(v, name + convert('.' + k))) return '\n'.join(sorted(res)) - elif isinstance(node, (list, tuple)): + elif isinstance(node, list | tuple): res = [] res.append(f"{name} = [];") for i, e in enumerate(node): @@ -67,7 +66,7 @@ def convert(name: str) -> str: """ if '-' in name or ' ' in name: - return '["{}"]'.format(name[1:]) + return f'["{name[1:]}"]' return name diff --git a/gron/version.py b/gron/version.py index 8dc2570..9e2aabb 100644 --- a/gron/version.py +++ b/gron/version.py @@ -1,3 +1,3 @@ -"""This module provides gron's version. """ +"""Module providing gron's version.""" __VERSION__ = '1.3.0' diff --git a/pyproject.toml b/pyproject.toml index f28c6e8..74d4078 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,10 +30,10 @@ gron = "gron.__main__:main" [project.optional-dependencies] dev = [ "build==1.2.1", - "flake8==7.1.1", "mypy==1.11.1", "pytest-cov==5.0.0", "pytest==8.3.2", + "ruff==0.6.0", "sphinx==8.0.2", "twine==5.1.1", "wheel==0.44.0", @@ -53,6 +53,21 @@ addopts = """ --cov-report=term-missing:skip-covered """ +[tool.ruff] +line-length = 79 +target-version = "py310" + +[tool.ruff.lint] +select = [ + "F", # pyflakes + "E", "W", # pycodestyle + "C90", # mccabe + "I", # isort + "D", # pydocstyle + "UP" # pyupgrade +] +pydocstyle.convention = "numpy" + [tool.mypy] files = "gron,tests" strict = true diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..4ede8e6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1 @@ +# noqa diff --git a/tests/test_gron.py b/tests/test_gron.py index e721534..4efb414 100644 --- a/tests/test_gron.py +++ b/tests/test_gron.py @@ -1,10 +1,13 @@ +"""Test gron.""" + from gron import gron def test_github_data() -> None: - with open('./tests/data/github.json', 'r') as fh: + """Test github data.""" + with open('./tests/data/github.json') as fh: IN = fh.read().strip() - with open('./tests/data/github.gron', 'r') as fh: + with open('./tests/data/github.gron') as fh: OUT = fh.read().strip() out = gron(IN) assert out == OUT @@ -21,36 +24,40 @@ def test_github_data() -> None: def test_one() -> None: - with open('./tests/data/one.json', 'r') as fh: + """Test one.""" + with open('./tests/data/one.json') as fh: IN = fh.read().strip() - with open('./tests/data/one.gron', 'r') as fh: + with open('./tests/data/one.gron') as fh: OUT = fh.read().strip() out = gron(IN) assert out == OUT def test_two() -> None: - with open('./tests/data/two.json', 'r') as fh: + """Test two.""" + with open('./tests/data/two.json') as fh: IN = fh.read().strip() - with open('./tests/data/two.gron', 'r') as fh: + with open('./tests/data/two.gron') as fh: OUT = fh.read().strip() out = gron(IN) assert out == OUT def test_three() -> None: - with open('./tests/data/three.json', 'r') as fh: + """Test three.""" + with open('./tests/data/three.json') as fh: IN = fh.read().strip() - with open('./tests/data/three.gron', 'r') as fh: + with open('./tests/data/three.gron') as fh: OUT = fh.read().strip() out = gron(IN) assert out == OUT def test_ugly() -> None: - with open('./tests/data/ugly.json', 'r') as fh: + """Test ugly.""" + with open('./tests/data/ugly.json') as fh: IN = fh.read().strip() - with open('./tests/data/ugly.gron', 'r') as fh: + with open('./tests/data/ugly.gron') as fh: OUT = fh.read().strip() out = gron(IN) assert out == OUT diff --git a/tests/test_version.py b/tests/test_version.py index 9e8df8b..df00ab5 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,5 +1,8 @@ +"""Test version.""" + import gron def test_version() -> None: + """Test version.""" assert hasattr(gron, '__VERSION__')