From b4762ccf9fdf2c7b8443d016008604038cd564c0 Mon Sep 17 00:00:00 2001
From: Bruno BELANYI <bruno@belanyi.fr>
Date: Sat, 23 Nov 2024 18:45:57 +0000
Subject: [PATCH] nix: migrate to 'ruff'

Having just the one tool is better.

Incidentally, this fixes the ternary formatting, which was messed up in
recent `black` versions.
---
 .isort.cfg          |  2 --
 2020/d17/ex1/ex1.py |  1 -
 2020/d17/ex2/ex2.py |  1 -
 2021/d25/ex1/ex1.py |  4 +++-
 2022/d07/ex1/ex1.py |  1 -
 2022/d07/ex2/ex2.py |  1 -
 flake.nix           | 19 +++++++++----------
 ruff.toml           |  8 ++++++++
 8 files changed, 20 insertions(+), 17 deletions(-)
 delete mode 100644 .isort.cfg
 create mode 100644 ruff.toml

diff --git a/.isort.cfg b/.isort.cfg
deleted file mode 100644
index b9fb3f3..0000000
--- a/.isort.cfg
+++ /dev/null
@@ -1,2 +0,0 @@
-[settings]
-profile=black
diff --git a/2020/d17/ex1/ex1.py b/2020/d17/ex1/ex1.py
index dd9efee..03bf46b 100755
--- a/2020/d17/ex1/ex1.py
+++ b/2020/d17/ex1/ex1.py
@@ -41,7 +41,6 @@ def update(grid: Grid) -> Grid:
 
 
 def solve(grid: Grid) -> int:
-
     for __ in range(6):
         grid = update(grid)
 
diff --git a/2020/d17/ex2/ex2.py b/2020/d17/ex2/ex2.py
index 8589288..ba979a1 100755
--- a/2020/d17/ex2/ex2.py
+++ b/2020/d17/ex2/ex2.py
@@ -41,7 +41,6 @@ def update(grid: Grid) -> Grid:
 
 
 def solve(grid: Grid) -> int:
-
     for __ in range(6):
         grid = update(grid)
 
diff --git a/2021/d25/ex1/ex1.py b/2021/d25/ex1/ex1.py
index ed01bf2..5d6f612 100755
--- a/2021/d25/ex1/ex1.py
+++ b/2021/d25/ex1/ex1.py
@@ -63,7 +63,9 @@ def solve(input: List[str]) -> int:
                     (
                         "v"
                         if Point(x, y) in map.south
-                        else ">" if Point(x, y) in map.east else "."
+                        else ">"
+                        if Point(x, y) in map.east
+                        else "."
                     )
                     for y in range(map.dimensions.y)
                 )
diff --git a/2022/d07/ex1/ex1.py b/2022/d07/ex1/ex1.py
index 43e49f1..fcd28d4 100755
--- a/2022/d07/ex1/ex1.py
+++ b/2022/d07/ex1/ex1.py
@@ -8,7 +8,6 @@ FileSystem = dict[str, Union[int, "FileSystem"]]
 
 def solve(input: list[str]) -> int:
     def build_tree(input: list[str], i: int = 0) -> tuple[FileSystem, int]:
-
         fs: FileSystem = {}
 
         while i < len(input):
diff --git a/2022/d07/ex2/ex2.py b/2022/d07/ex2/ex2.py
index 9886cf0..6a6d447 100755
--- a/2022/d07/ex2/ex2.py
+++ b/2022/d07/ex2/ex2.py
@@ -8,7 +8,6 @@ FileSystem = dict[str, Union[int, "FileSystem"]]
 
 def solve(input: list[str]) -> int:
     def build_tree(input: list[str], i: int = 0) -> tuple[FileSystem, int]:
-
         fs: FileSystem = {}
 
         while i < len(input):
diff --git a/flake.nix b/flake.nix
index 36616f8..dc747a0 100644
--- a/flake.nix
+++ b/flake.nix
@@ -39,17 +39,17 @@
             src = self;
 
             hooks = {
-              black = {
-                enable = true;
-              };
-
-              isort = {
-                enable = true;
-              };
-
               nixpkgs-fmt = {
                 enable = true;
               };
+
+              ruff = {
+                enable = true;
+              };
+
+              ruff-format = {
+                enable = true;
+              };
             };
           };
         };
@@ -57,12 +57,11 @@
         devShell = pkgs.mkShell {
           buildInputs = with pkgs; [
             (python3.withPackages (ps: with ps; [
-              black
-              isort
               mypy
               z3
             ]))
             pyright
+            ruff
           ];
 
           inherit (self.checks.${system}.pre-commit) shellHook;
diff --git a/ruff.toml b/ruff.toml
new file mode 100644
index 0000000..a34e1ec
--- /dev/null
+++ b/ruff.toml
@@ -0,0 +1,8 @@
+[lint]
+extend-select = [
+    "I", # Import sorting is a lint check
+]
+ignore = [
+    "E731", # Assigning lambdas is sometimes more readable
+    "E741", # Ambiguous variable names are good enough actually
+]