Skip to content

Commit

Permalink
replaced flake8 with ruff
Browse files Browse the repository at this point in the history
added all fixes to make ruff happy
  • Loading branch information
venthur committed Aug 23, 2024
1 parent 3f93f20 commit fd0c528
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mypy: $(VENV)

.PHONY: lint
lint: $(VENV)
$(BIN)/flake8
$(BIN)/ruff check .

.PHONY: release
release: $(VENV)
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# noqa
#
# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -14,9 +14,10 @@

import os
import sys

sys.path.insert(0, os.path.abspath('..'))

import gron
import gron # noqa

# -- Project information -----------------------------------------------------

Expand Down
7 changes: 1 addition & 6 deletions gron/__init__.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 3 additions & 5 deletions gron/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Gron's command line interface (CLI).
Attributes
----------
parser : argparse.ArgumentParser
Expand All @@ -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(
Expand All @@ -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`.
Expand Down
9 changes: 4 additions & 5 deletions gron/gron.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion gron/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""This module provides gron's version. """
"""Module providing gron's version."""

__VERSION__ = '1.3.0'
17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# noqa
27 changes: 17 additions & 10 deletions tests/test_gron.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Test version."""

import gron


def test_version() -> None:
"""Test version."""
assert hasattr(gron, '__VERSION__')

0 comments on commit fd0c528

Please sign in to comment.