Skip to content

Commit

Permalink
chore(python): Use ruff instead of isort, flake8 and pyupgrade (#5916)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuls committed Jan 3, 2023
1 parent 14f4736 commit 359b026
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 47 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/lint-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ jobs:
run: |
black --check .
blackdoc --check .
isort --check .
pyupgrade --py37-plus `find . -name "*.py" -type f`
flake8
ruff .
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
Expand Down
22 changes: 0 additions & 22 deletions py-polars/.flake8

This file was deleted.

4 changes: 1 addition & 3 deletions py-polars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ build-release: venv ## Compile and install a faster Polars binary

.PHONY: fmt
fmt: venv ## Run autoformatting and linting
$(VENV_BIN)/isort .
$(VENV_BIN)/black .
$(VENV_BIN)/blackdoc .
$(VENV_BIN)/pyupgrade --py37-plus `find polars tests docs -name "*.py" -type f`
$(VENV_BIN)/ruff .
cargo fmt --all
-dprint fmt
-$(VENV_BIN)/mypy
-$(VENV_BIN)/flake8

.PHONY: clippy
clippy: ## Run clippy
Expand Down
8 changes: 5 additions & 3 deletions py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ def version() -> str:
from polars.internals import BatchedCsvReader

# TODO remove need for wrap_df
from polars.internals.dataframe import wrap_df # noqa: F401
from polars.internals.dataframe import DataFrame
from polars.internals.dataframe import (
DataFrame,
wrap_df, # noqa: F401
)
from polars.internals.expr.expr import Expr
from polars.internals.functions import (
align_frames,
Expand Down Expand Up @@ -125,9 +127,9 @@ def version() -> str:
struct,
sum,
tail,
var,
)
from polars.internals.lazy_functions import to_list as list
from polars.internals.lazy_functions import var
from polars.internals.lazyframe import LazyFrame

# TODO: remove need for wrap_s
Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/anonymous_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from polars.dependencies import pyarrow as pa


def _deser_and_exec(
def _deser_and_exec( # noqa: D417
buf: bytes, with_columns: list[str] | None, *args: Any
) -> pli.DataFrame:
"""
Expand Down Expand Up @@ -84,7 +84,7 @@ def _scan_ds(
)


def _scan_ipc_impl(
def _scan_ipc_impl( # noqa: D417
uri: str, with_columns: list[str] | None, *args: Any
) -> pli.DataFrame:
"""
Expand Down Expand Up @@ -117,7 +117,7 @@ def _scan_ipc_fsspec(
return pli.LazyFrame._scan_python_function(schema, func_serialized)


def _scan_parquet_impl(
def _scan_parquet_impl( # noqa: D417
uri: str, with_columns: list[str] | None, *args: Any
) -> pli.DataFrame:
"""
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _EmptyBytecodeHelper:
def __init__(self) -> None:
# generate bytecode for empty functions with/without a docstring
def _empty_with_docstring() -> None:
""""""
"""""" # noqa: D419

def _empty_without_docstring() -> None:
pass
Expand Down
72 changes: 69 additions & 3 deletions py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ all = [
"polars[pyarrow,pandas,numpy,fsspec,connectorx,xlsx2csv,deltalake,timezone,matplotlib]",
]

[tool.isort]
profile = "black"

[tool.mypy]
files = ["polars", "tests"]
namespace_packages = true
Expand Down Expand Up @@ -88,4 +85,73 @@ exclude_lines = [
]

[tool.ruff]
# Assume Python 3.7.
target-version = "py37"

line-length = 88

extend-exclude = [
# Automatically generated test artifacts
"venv/",
"target/",
]

select = [
# pycodestyle
"E",
"W",
# Pyflakes
"F",
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# flake8-docstrings
"D",
# isort
"I001",
# flake8-simplify
"SIM",
# flake8-tidy-imports
"TID",
# flake8-quotes
"Q",
# pyupgrade
"UP",
]
ignore = []

extend-select = ["D"]
extend-ignore = [
# pydocstyle: http://www.pydocstyle.org/en/stable/error_codes.html
# numpy convention with a few additional lints
"D107",
"D203",
"D212",
"D402",
"D415",
"D416",
# TODO: Remove errors below to further improve docstring linting
# Ordered from most common to least common errors.
"D105",
"D100",
"D103",
"D102",
"D104",
"D101",
]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.flake8-quotes]
inline-quotes = "double"
docstring-quotes = "double"
multiline-quotes = "double"

[tool.ruff.per-file-ignores]
"polars/datatypes.py" = ["B019"]
"tests/*/*.py" = ["D100", "D103"]
"tests/docs/run_doc_examples.py" = ["D101", "D102", "D103"]
"tests/parametric/__init__.py" = ["D104"]
"tests/slow/__init__.py" = ["D104"]
9 changes: 1 addition & 8 deletions py-polars/requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
black==22.8.0
blackdoc==0.3.7
flake8==5.0.4
flake8-bugbear==22.10.25
flake8-comprehensions==3.10.0
flake8-docstrings==1.6.0
flake8-simplify==0.19.3
flake8-tidy-imports==4.8.0
isort==5.10.1
pyupgrade==3.1.0
ruff==0.0.208
1 change: 0 additions & 1 deletion py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: W291
from __future__ import annotations

import sys
Expand Down

0 comments on commit 359b026

Please sign in to comment.