ruff/python/ruff-ecosystem
Zanie Blue 0029b4fd07
Fix ecosystem format line changed counts (#9158)
We were erroneously including patch headers so for each _file_ changed
we could include an extra added and removed line e.g. we counted the
diff in the following as +4 -4 instead of +3 -3.

```diff
diff --git a/tests/test_param_include_in_schema.py b/tests/test_param_include_in_schema.py
index 26201e9..f461947 100644
--- a/tests/test_param_include_in_schema.py
+++ b/tests/test_param_include_in_schema.py
@@ -9,14 +9,14 @@ app = FastAPI()
 
 @app.get("/hidden_cookie")
 async def hidden_cookie(
-    hidden_cookie: Optional[str] = Cookie(default=None, include_in_schema=False)
+    hidden_cookie: Optional[str] = Cookie(default=None, include_in_schema=False),
 ):
     return {"hidden_cookie": hidden_cookie}
 
 
 @app.get("/hidden_header")
 async def hidden_header(
-    hidden_header: Optional[str] = Header(default=None, include_in_schema=False)
+    hidden_header: Optional[str] = Header(default=None, include_in_schema=False),
 ):
     return {"hidden_header": hidden_header}
 
@@ -28,7 +28,7 @@ async def hidden_path(hidden_path: str = Path(include_in_schema=False)):
 
 @app.get("/hidden_query")
 async def hidden_query(
-    hidden_query: Optional[str] = Query(default=None, include_in_schema=False)
+    hidden_query: Optional[str] = Query(default=None, include_in_schema=False),
 ):
     return {"hidden_query": hidden_query}
 
```

Tested with a single project locally e.g.

> ℹ️ ecosystem check **detected format changes**. (+65 -65 lines in 39
files in 1 projects)
> 
> <details><summary><a
href="https://github.com/tiangolo/fastapi">tiangolo/fastapi</a> (+65 -65
lines across 39 files)

instead of

> ℹ️ ecosystem check **detected format changes**. (+104 -104 lines in 39
files in 1 projects)
>
> <details><summary><a
href="https://github.com/tiangolo/fastapi">tiangolo/fastapi</a> (+104
-104 lines across 39 files)
2023-12-16 00:14:17 -06:00
..
ruff_ecosystem Fix ecosystem format line changed counts (#9158) 2023-12-16 00:14:17 -06:00
pyproject.toml Use tool.ruff.lint in more places (#8317) 2023-10-28 18:39:38 -05:00
README.md Add support for ruff-ecosystem format comparisons with black (#8419) 2023-11-02 01:29:25 +00:00

ruff-ecosystem

Compare lint and format results for two different ruff versions (e.g. main and a PR) on real world projects.

Installation

From the Ruff project root, install with pip:

pip install -e ./python/ruff-ecosystem

Usage

ruff-ecosystem <check | format> <baseline executable> <comparison executable>

Note executable paths may be absolute, relative to the current working directory, or will be looked up in the current Python environment and PATH.

Run ruff check ecosystem checks comparing your debug build to your system Ruff:

ruff-ecosystem check ruff "./target/debug/ruff"

Run ruff format ecosystem checks comparing your debug build to your system Ruff:

ruff-ecosystem format ruff "./target/debug/ruff"

Run ruff format ecosystem checks comparing with changes to code that is already formatted:

ruff-ecosystem format ruff "./target/debug/ruff" --format-comparison ruff-then-ruff

Run ruff format ecosystem checks comparing with the Black formatter:

ruff-ecosystem format black ruff -v --cache python/checkouts --format-comparison black-and-ruff

The default output format is markdown, which includes nice summaries of the changes. You can use --output-format json to display the raw data — this is particularly useful when making changes to the ecosystem checks.

Development

When developing, it can be useful to set the --pdb flag to drop into a debugger on failure:

ruff-ecosystem check ruff "./target/debug/ruff" --pdb

You can also provide a path to cache checkouts to speed up repeated runs:

ruff-ecosystem check ruff "./target/debug/ruff" --cache ./repos