diff --git a/.github/workflows/lint-python.yaml b/.github/workflows/lint-python.yaml index 1563d39a38a2..7f3fa718fef5 100644 --- a/.github/workflows/lint-python.yaml +++ b/.github/workflows/lint-python.yaml @@ -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: diff --git a/py-polars/.flake8 b/py-polars/.flake8 deleted file mode 100644 index 52df48a5ec68..000000000000 --- a/py-polars/.flake8 +++ /dev/null @@ -1,22 +0,0 @@ -[flake8] -max-line-length = 88 -ban-relative-imports = true -docstring-convention = all -extend-ignore = - # Satisfy black: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 - E203, - # pydocstyle: http://www.pydocstyle.org/en/stable/error_codes.html - # numpy convention with a few additional lints - D107, D203, D212, D401, D402, D415, D416, - # TODO: Remove errors below to further improve docstring linting - D1, - # flake8-simplify - SIM102, SIM117, - -extend-exclude = - # Automatically generated test artifacts - venv/, - target/, - -per-file-ignores = - polars/datatypes.py: B019 diff --git a/py-polars/Makefile b/py-polars/Makefile index 194aafd8e354..76746913d22b 100644 --- a/py-polars/Makefile +++ b/py-polars/Makefile @@ -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 diff --git a/py-polars/polars/__init__.py b/py-polars/polars/__init__.py index 5d6dc6d51653..da0361f6f157 100644 --- a/py-polars/polars/__init__.py +++ b/py-polars/polars/__init__.py @@ -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, @@ -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 diff --git a/py-polars/polars/internals/anonymous_scan.py b/py-polars/polars/internals/anonymous_scan.py index 15cb4fbc6668..905ad0f1271c 100644 --- a/py-polars/polars/internals/anonymous_scan.py +++ b/py-polars/polars/internals/anonymous_scan.py @@ -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: """ @@ -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: """ @@ -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: """ diff --git a/py-polars/polars/internals/series/utils.py b/py-polars/polars/internals/series/utils.py index cfcb7734d5d9..3df49f0b69a4 100644 --- a/py-polars/polars/internals/series/utils.py +++ b/py-polars/polars/internals/series/utils.py @@ -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 diff --git a/py-polars/pyproject.toml b/py-polars/pyproject.toml index 63acab3e79fa..052270bbf7ae 100644 --- a/py-polars/pyproject.toml +++ b/py-polars/pyproject.toml @@ -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 @@ -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"] diff --git a/py-polars/requirements-lint.txt b/py-polars/requirements-lint.txt index 4c13367408d8..4c2ceb23dc48 100644 --- a/py-polars/requirements-lint.txt +++ b/py-polars/requirements-lint.txt @@ -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 diff --git a/py-polars/tests/unit/test_df.py b/py-polars/tests/unit/test_df.py index dd672bbb46e9..4cbd569a2f8b 100644 --- a/py-polars/tests/unit/test_df.py +++ b/py-polars/tests/unit/test_df.py @@ -1,4 +1,3 @@ -# flake8: noqa: W291 from __future__ import annotations import sys