From 3fb21c46c9ba143c909b2c0fb43fa0792085c52b Mon Sep 17 00:00:00 2001
From: Henry Schreiner <HenrySchreinerIII@gmail.com>
Date: Fri, 28 Apr 2023 12:53:26 -0400
Subject: [PATCH] chore: move to using Ruff (#85)

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
---
 .pre-commit-config.yaml              | 15 +++++++---
 docs/conf.py                         |  4 +--
 noxfile.py                           |  2 ++
 pyproject.toml                       | 43 ++++++++++++++++++++++++++++
 src/scikit_build_example/__init__.py |  2 ++
 tests/test_basic.py                  |  2 ++
 6 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4631207..8db408b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -33,13 +33,20 @@ repos:
   - id: requirements-txt-fixer
   - id: trailing-whitespace
 
-# Runs Black, pyupgrade, isort, autoflake, blacken-docs
-- repo: https://github.com/Zac-HD/shed
-  rev: 2023.3.1
+# Black, the code formatter, natively supports pre-commit
+- repo: https://github.com/psf/black
+  rev: 23.3.0
   hooks:
-  - id: shed
+  - id: black
     exclude: ^(docs)
 
+# Check linting and style issues
+- repo: https://github.com/charliermarsh/ruff-pre-commit
+  rev: "v0.0.263"
+  hooks:
+    - id: ruff
+      args: ["--fix", "--show-fixes"]
+
 # Changes tabs to spaces
 - repo: https://github.com/Lucas-C/pre-commit-hooks
   rev: v1.5.1
diff --git a/docs/conf.py b/docs/conf.py
index 160bbef..65ccb1f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -10,9 +10,7 @@
 #
 # All configuration values have a default; values that are commented out
 # serve to show the default.
-
-import os
-import sys
+from __future__ import annotations
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
diff --git a/noxfile.py b/noxfile.py
index 0466a51..050d60a 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
 import nox
 
 nox.options.sessions = ["lint", "tests"]
diff --git a/pyproject.toml b/pyproject.toml
index 731b5cd..fc2ef76 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -44,3 +44,46 @@ test-command = "pytest {project}/tests"
 test-extras = ["test"]
 test-skip = ["*universal2:arm64"]
 build-verbosity = 1
+
+
+[tool.ruff]
+select = [
+  "E", "F", "W", # flake8
+  "B",           # flake8-bugbear
+  "I",           # isort
+  "ARG",         # flake8-unused-arguments
+  "C4",          # flake8-comprehensions
+  "EM",          # flake8-errmsg
+  "ICN",         # flake8-import-conventions
+  "ISC",         # flake8-implicit-str-concat
+  "G",           # flake8-logging-format
+  "PGH",         # pygrep-hooks
+  "PIE",         # flake8-pie
+  "PL",          # pylint
+  "PT",          # flake8-pytest-style
+  "PTH",         # flake8-use-pathlib
+  "RET",         # flake8-return
+  "RUF",         # Ruff-specific
+  "SIM",         # flake8-simplify
+  "T20",         # flake8-print
+  "UP",          # pyupgrade
+  "YTT",         # flake8-2020
+  "EXE",         # flake8-executable
+  "NPY",         # NumPy specific rules
+  "PD",          # pandas-vet
+]
+extend-ignore = [
+  "PLR",    # Design related pylint codes
+  "E501",   # Line too long
+]
+target-version = "py37"
+src = ["src"]
+unfixable = [
+  "T20",  # Removes print statements
+  "F841", # Removes unused variables
+]
+flake8-unused-arguments.ignore-variadic-names = true
+isort.required-imports = ["from __future__ import annotations"]
+
+[tool.ruff.per-file-ignores]
+"tests/**" = ["T20"]
diff --git a/src/scikit_build_example/__init__.py b/src/scikit_build_example/__init__.py
index c9fb958..15188e5 100644
--- a/src/scikit_build_example/__init__.py
+++ b/src/scikit_build_example/__init__.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
 from ._core import __doc__, __version__, add, subtract
 
 __all__ = ["__doc__", "__version__", "add", "subtract"]
diff --git a/tests/test_basic.py b/tests/test_basic.py
index 080f627..93da71b 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
 import scikit_build_example as m
 
 
-- 
GitLab