From 56c8d405ef8e83913a1d9dbeb1646a3c0ff3a123 Mon Sep 17 00:00:00 2001
From: Crystal Lee <52181740+cry-stal-lee@users.noreply.github.com>
Date: Sat, 25 Mar 2023 09:11:53 -0700
Subject: [PATCH] Add ruff (#881)

---
 .flake8                 | 13 -------------
 .gitignore              |  1 +
 .pre-commit-config.yaml |  5 +++++
 CONTRIBUTING.md         |  8 +++++++-
 Makefile                |  6 ++----
 pyproject.toml          | 14 +++++++++++---
 requirements.txt        |  5 ++---
 7 files changed, 28 insertions(+), 24 deletions(-)
 delete mode 100644 .flake8
 create mode 100644 .pre-commit-config.yaml

diff --git a/.flake8 b/.flake8
deleted file mode 100644
index 03883b5f7..000000000
--- a/.flake8
+++ /dev/null
@@ -1,13 +0,0 @@
-[flake8]
-exclude =
-    .venv
-    __pycache__
-    notebooks
-    .ipynb_checkpoints
-    examples
-# Recommend matching the black line length (default 88),
-# rather than using the flake8 default of 79:
-max-line-length = 88
-extend-ignore =
-    # See https://github.com/PyCQA/pycodestyle/issues/373
-    E203,
diff --git a/.gitignore b/.gitignore
index f888afc8f..0900a937e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,7 @@ coverage.xml
 *.py,cover
 .hypothesis/
 .pytest_cache/
+.ruff_cache
 
 # Translations
 *.mo
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 000000000..7e43d3b05
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,5 @@
+repos:
+  - repo: https://github.com/charliermarsh/ruff-pre-commit
+    rev: v0.0.243
+    hooks:
+      - id: ruff
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ab185fe3d..4dcd73cfe 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,7 +53,13 @@ You can format and lint your changes with the following commands in the root dir
 make format; make lint
 ```
 
-We run an assortment of linters: `black`, `isort`, `mypy`, `flake8`.
+You can also make use of our pre-commit hooks by setting up git hook scripts:
+
+```bash
+pre-commit install
+```
+
+We run an assortment of linters: `black`, `ruff`, `mypy`.
 
 ### Testing
 
diff --git a/Makefile b/Makefile
index 11f224f37..eb1e3c09a 100644
--- a/Makefile
+++ b/Makefile
@@ -2,13 +2,11 @@
 
 format:
 	black .
-	isort .
 
 lint:
 	mypy .
 	black . --check
-	isort . --check
-	flake8 .
+	ruff check .
 
 test:
-	pytest tests
\ No newline at end of file
+	pytest tests
diff --git a/pyproject.toml b/pyproject.toml
index dd8bdcdb7..8e44e5b0c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,15 @@
-[tool.isort]
-profile = "black"
-
 [tool.mypy]
 ignore_missing_imports = "True"
 disallow_untyped_defs = "True"
 exclude = ["notebooks", "build", "examples"]
+
+[tool.ruff]
+exclude = [
+    ".venv",
+    "__pycache__",
+    ".ipynb_checkpoints",
+    ".mypy_cache",
+    ".ruff_cache",
+    "examples",
+    "notebooks",
+]
diff --git a/requirements.txt b/requirements.txt
index fc1e2aeaf..f58524987 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,8 +14,7 @@ types-setuptools==67.1.0.0
 
 # linting
 black==22.12.0
-isort==5.11.4
 mypy==0.991
-flake8==6.0.0
-flake8-docstrings==1.6.0
+pre-commit==3.2.0
 pylint==2.15.10
+ruff==0.0.259
\ No newline at end of file
-- 
GitLab