Repository: petrobras/ross (language: python)

Issue:
Start migration from black to ruff
Ruff now has the autoformat capabilities. We should start migrating from black to ruff.
https://docs.astral.sh/ruff/faq/#how-does-ruffs-formatter-compare-to-black


Discussion / hints:
Hi there!
I have marked this issue as stale because it has not had activity for 45 days.
Consider the following options:
- If the issue refers to a large task, break it in smaller issues that can be solved in
less than 45 days;
- Label the issue as `wontfix` or `wontfix for now` and close it.

Fix patch:
diff --git a/.flake8 b/.flake8
deleted file mode 100644
index 7d327ad65..000000000
--- a/.flake8
+++ /dev/null
@@ -1,7 +0,0 @@
-[flake8]
-ignore = E203, E266, E501, W503
-exclude = ross/tests
-# line length is intentionally set to 88 here because ROSS uses Black default config
-max-line-length = 88
-max-complexity = 18
-select = B,C,E,F,W,T4,B9
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index fb5f7f154..e09b540c2 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,9 @@
 repos:
-  - repo: https://github.com/psf/black
-    rev: 24.3.0
+  - repo: https://github.com/astral-sh/ruff-pre-commit
+  # Ruff version.
+    rev: v0.6.8
     hooks:
-      - id: black
-        language_version: python3 
+      # Run the linter.
+      - id: ruff
+      # Run the formatter.
+      - id: ruff-format
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 05d24076c..bedb31f60 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -5,13 +5,12 @@ These include bug reports, problems on the documentation, feedback, enhancement
 You can use the repository [Discussions](https://github.com/petrobras/ross/discussions)
 section for questions and further information.
 
-## Code style: Black
+## Code style: Ruff
 
-To format our code we use [Black](https://black.readthedocs.io/en/stable/), which is the *"uncompromising Python
-code formatter"*. You can configure your development environment to use Black before a commit. More information on how
-to set this is given at [Black's documentation](https://black.readthedocs.io/en/stable/integrations/index.html).
+To format our code we use [Ruff](https://docs.astral.sh/ruff/), which is the *"An extremely fast Python linter and code formatter"*. You can configure your development environment to use Ruff before a commit. More information on how
+to set this is given at [Ruff's documentation](https://docs.astral.sh/ruff/integrations/).
 
-We also recommend using the [pre-commit](https://pre-commit.com/) tool so that black is automatically run when doing a commit.
+We also recommend using the [pre-commit](https://docs.astral.sh/ruff/integrations/#pre-commit) tool so that Ruff is automatically run when doing a commit.
 
 (git-configuration)=
 
diff --git a/README.md b/README.md
index b7e541dd4..9bffede30 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
 <a href="https://codecov.io/gh/petrobras/ross">
 <img src="https://codecov.io/gh/petrobras/ross/branch/main/graph/badge.svg">
 </a>
-[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
+[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
 [![DOI](https://joss.theoj.org/papers/10.21105/joss.02120/status.svg)](https://doi.org/10.21105/joss.02120)
 
 ROSS is a Python library for rotordynamic analysis, which allows the construction of rotor models and their numerical
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 000000000..379e9bd06
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,28 @@
+[tool.ruff.lint]
+# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults.
+select = ["B", "C", "E", "F", "Q", "W"]
+
+# 2. Avoid enforcing line-length violations (`E501`)
+ignore = [
+    "B006","B007", "B017", "B023", "B024", "B027", "B028", "B904",
+    "C403", "C408", "C416", "C419", "C901",
+    "E203", "E266", "E501", "E711", "E721", "E722", "E731", "E741",
+    "F401", "F403", "F405", "F541", "F811", "F841",
+    "W291", "W293",
+]
+
+# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
+unfixable = ["B"]
+
+# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories.
+[tool.ruff.lint.per-file-ignores]
+"__init__.py" = ["E402"]
+"**/{tests}/*" = ["E402"]
+
+[tool.ruff.format]
+# 5. Use single quotes in `ruff format`.
+quote-style = "single"
+
+[tool.ruff.lint.flake8-quotes]
+docstring-quotes = "double"
+
diff --git a/setup.py b/setup.py
index 843e93117..bc7fbf2a5 100644
--- a/setup.py
+++ b/setup.py
@@ -55,8 +55,7 @@ def version(path):
         "linkify-it-py",
         "numpydoc",
         "sphinxcontrib-bibtex>=2.2",
-        "black",
-        "isort",
+        "ruff",
         "sphinx-design",
     ]
 }


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c96eca784..b27466c94 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -36,9 +36,9 @@ jobs:
         run: |
           pip install pytest
           pytest ross --cov=ross
-      - name: Code Lint 
+      - name: Run Ruff 
         run: |
-          black --check ross
+          ruff check ross
         if: success()
       - name: Coverage and Deployment
         run: codecov