Skip to content

Commit 59ba620

Browse files
authored
Merge pull request #10 from vertti/ruff
Use Ruff
2 parents d0322e2 + 9017468 commit 59ba620

File tree

6 files changed

+29
-44
lines changed

6 files changed

+29
-44
lines changed

.flake8

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ jobs:
3232
run: |
3333
poetry install
3434
35-
- name: Lint with flake8, black, isort and mypy
35+
- name: Lint with Ruff and Mypy
3636
run: |
37-
poetry run isort --check .
38-
poetry run black --check .
39-
poetry run flake8 .
37+
poetry run ruff check --output-format=github .
38+
poetry run ruff format --diff
4039
poetry run mypy .
41-
poetry run pydocstyle daffy/
4240
4341
- name: Test with pytest
4442
run: |

.pre-commit-config.yaml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
repos:
2-
- repo: https://github.com/timothycrosley/isort
3-
rev: 5.12.0
4-
hooks:
5-
- id: isort
6-
- repo: https://github.com/psf/black
7-
rev: 23.11.0 # Replace by any tag/version: https://github.com/psf/black/tags
8-
hooks:
9-
- id: black
10-
language_version: python3
11-
- repo: https://gitlab.com/pycqa/flake8
12-
rev: 6.1.0
13-
hooks:
14-
- id: flake8
15-
- repo: https://github.com/pre-commit/mirrors-mypy
16-
rev: v1.7.1
17-
hooks:
18-
- id: mypy
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.9.1
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
# Run the formatter.
9+
- id: ruff-format

daffy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
annotate your functions so that they document themselves and that documentation is kept up-to-date by validating
66
the input and output on runtime.
77
"""
8+
89
__version__ = "0.5.0"
910

1011
from .decorators import df_in # noqa

daffy/decorators.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Decorators for DAFFY DataFrame Column Validator."""
2+
23
import inspect
34
import logging
45
from functools import wraps
@@ -16,13 +17,13 @@ def _check_columns(df: pd.DataFrame, columns: ColumnsDef, strict: bool) -> None:
1617
if isinstance(columns, dict):
1718
for column, dtype in columns.items():
1819
assert column in df.columns, f"Column {column} missing from DataFrame. Got {_describe_pd(df)}"
19-
assert (
20-
df[column].dtype == dtype
21-
), f"Column {column} has wrong dtype. Was {df[column].dtype}, expected {dtype}"
20+
assert df[column].dtype == dtype, (
21+
f"Column {column} has wrong dtype. Was {df[column].dtype}, expected {dtype}"
22+
)
2223
if strict:
23-
assert len(df.columns) == len(
24-
columns
25-
), f"DataFrame contained unexpected column(s): {', '.join(set(df.columns) - set(columns))}"
24+
assert len(df.columns) == len(columns), (
25+
f"DataFrame contained unexpected column(s): {', '.join(set(df.columns) - set(columns))}"
26+
)
2627

2728

2829
def df_out(columns: Optional[ColumnsDef] = None, strict: bool = False) -> Callable:
@@ -84,9 +85,9 @@ def wrapper_df_in(func: Callable) -> Callable:
8485
@wraps(func)
8586
def wrapper(*args: str, **kwargs: Any) -> Any:
8687
df = _get_parameter(func, name, *args, **kwargs)
87-
assert isinstance(
88-
df, pd.DataFrame
89-
), f"Wrong parameter type. Expected Pandas DataFrame, got {type(df).__name__} instead."
88+
assert isinstance(df, pd.DataFrame), (
89+
f"Wrong parameter type. Expected Pandas DataFrame, got {type(df).__name__} instead."
90+
)
9091
if columns:
9192
_check_columns(df, columns, strict)
9293
return func(*args, **kwargs)

pyproject.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,18 @@ pandas = ">=1.5.1,<3.0.0"
3535

3636
[tool.poetry.group.dev.dependencies]
3737
pytest = "^7.4.3"
38-
isort = "^5.12.0"
39-
black = "^23.11.0"
40-
flake8 = "^6.1.0"
41-
pre-commit = "^3.5.0"
38+
pre-commit = "^4.0.0"
4239
mypy = "^1.7.1"
4340
pytest-mock = "^3.12.0"
4441
pytest-cov = "^4.1.0"
4542
coverage = {extras = ["toml"], version = "^7.3.2"}
4643
pydocstyle = "^6.3.0"
44+
ruff = "^0.9.1"
4745

4846
[build-system]
4947
requires = ["poetry-core>=1.0.0"]
5048
build-backend = "poetry.core.masonry.api"
5149

52-
[tool.isort]
53-
profile = "black"
54-
multi_line_output = 3
55-
5650
[tool.coverage.run]
5751
branch = true
5852
source = ["daffy"]
@@ -61,5 +55,9 @@ source = ["daffy"]
6155
show_missing = true
6256
fail_under = 95
6357

64-
[tool.black]
58+
[tool.ruff]
6559
line-length = 120
60+
target-version = "py39"
61+
62+
[tool.ruff.lint]
63+
select = ["F", "E", "W", "I", "N"]

0 commit comments

Comments
 (0)