From 208969bf1fe58490a958a04fe3152637c49b316d Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Tue, 30 Jan 2024 17:38:47 +0100 Subject: [PATCH] use ruff.flake8-tidy-imports to enforce absolute imports (#8680) --- .pre-commit-config.yaml | 6 ------ pyproject.toml | 12 ++++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4af262a0a04..c889edc470f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,12 +10,6 @@ repos: - id: check-yaml - id: debug-statements - id: mixed-line-ending - - repo: https://github.com/MarcoGorelli/absolufy-imports - rev: v0.3.1 - hooks: - - id: absolufy-imports - name: absolufy-imports - files: ^xarray/ - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: 'v0.1.9' diff --git a/pyproject.toml b/pyproject.toml index 2a185933b47..26132031da1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -242,8 +242,15 @@ extend-exclude = [ "doc", "_typed_ops.pyi", ] +extend-safe-fixes = [ + "TID252", # absolute imports +] target-version = "py39" +[tool.ruff.per-file-ignores] +# don't enforce absolute imports +"asv_bench/**" = ["TID252"] + [tool.ruff.lint] # E402: module level import not at top of file # E501: line too long - let black worry about that @@ -257,6 +264,7 @@ select = [ "F", # Pyflakes "E", # Pycodestyle "W", + "TID", # flake8-tidy-imports (absolute imports) "I", # isort "UP", # Pyupgrade ] @@ -264,6 +272,10 @@ select = [ [tool.ruff.lint.isort] known-first-party = ["xarray"] +[tool.ruff.lint.flake8-tidy-imports] +# Disallow all relative imports. +ban-relative-imports = "all" + [tool.pytest.ini_options] addopts = ["--strict-config", "--strict-markers"] filterwarnings = [