Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
priority: 0

- repo: https://github.com/crate-ci/typos
rev: v1.43.4
rev: v1.43.5
hooks:
- id: typos
priority: 0
Expand Down Expand Up @@ -66,7 +66,7 @@ repos:
priority: 0

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.36.1
rev: 0.36.2
hooks:
- id: check-github-workflows
priority: 0
Expand All @@ -93,7 +93,7 @@ repos:
priority: 0

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
rev: v0.15.2
hooks:
- id: ruff-format
priority: 0
Expand All @@ -117,7 +117,7 @@ repos:

# Priority 2: ruffen-docs runs after markdownlint-fix (both modify markdown).
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
rev: v0.15.2
hooks:
- id: ruff-format
name: mdtest format
Expand Down
2 changes: 1 addition & 1 deletion python/ruff-ecosystem/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ dependencies = ["unidiff==0.7.5", "tomli_w==1.2.0", "tomli==2.4.0"]
ruff-ecosystem = "ruff_ecosystem.cli:entrypoint"

[tool.ruff.lint]
extend-select = ["I"]
ignore = ["T100"]
preview = true
11 changes: 5 additions & 6 deletions python/ruff-ecosystem/ruff_ecosystem/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import time
from asyncio import create_subprocess_exec
from collections import Counter
from collections.abc import Iterable, Iterator, Sequence
from dataclasses import dataclass, field
from pathlib import Path
from subprocess import PIPE
from typing import TYPE_CHECKING, Iterable, Iterator, Self, Sequence
from typing import TYPE_CHECKING, Self

from ruff_ecosystem import logger
from ruff_ecosystem.markdown import (
Expand Down Expand Up @@ -417,7 +418,7 @@ def try_from_string(cls: type[Self], line: str) -> Self | None:

if match is None:
# Handle case where there are no regex match e.g.
# + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # noqa: E501, ERA001
# + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE"
# Which was found in local testing
return None

Expand Down Expand Up @@ -457,7 +458,7 @@ def from_simple_diff(cls, diff: Diff) -> CheckDiff:
diff = diff.without_unchanged_lines()

# Sort without account for the leading + / -
sorted_lines = list(sorted(diff, key=lambda line: line[2:]))
sorted_lines = sorted(diff, key=lambda line: line[2:])

# Parse the lines, drop lines that cannot be parsed
parsed_lines: list[DiagnosticLine] = list(
Expand Down Expand Up @@ -559,10 +560,8 @@ async def ruff_check(
raise ToolError(err.decode("utf8"))

# Strip summary lines so the diff is only diagnostic lines
lines = [
return [
line
for line in result.decode("utf8").splitlines()
if not CHECK_SUMMARY_LINE_RE.match(line)
]

return lines
4 changes: 2 additions & 2 deletions python/ruff-ecosystem/ruff_ecosystem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def entrypoint():
f"Could not find ruff baseline executable: {args.baseline_executable}",
sys.stderr,
)
exit(1)
sys.exit(1)
logger.info(
"Resolved baseline executable %s to %s",
args.baseline_executable,
Expand All @@ -69,7 +69,7 @@ def entrypoint():
f"Could not find ruff comparison executable: {args.comparison_executable}",
sys.stderr,
)
exit(1)
sys.exit(1)
logger.info(
"Resolved comparison executable %s to %s",
args.comparison_executable,
Expand Down
13 changes: 5 additions & 8 deletions python/ruff-ecosystem/ruff_ecosystem/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import time
from asyncio import create_subprocess_exec
from collections.abc import Sequence
from enum import Enum
from pathlib import Path
from subprocess import PIPE
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING

from unidiff import PatchSet

Expand Down Expand Up @@ -182,15 +183,14 @@ async def format_then_format(
options=options,
)
# Then get the diff from stdout
diff = await format(
return await format(
formatter=Formatter.ruff,
executable=ruff_comparison_executable.resolve(),
path=cloned_repo.path,
name=cloned_repo.fullname,
options=options,
diff=True,
)
return diff


async def format_and_format(
Expand Down Expand Up @@ -229,9 +229,7 @@ async def format_and_format(
)

# Then get the diff from the commit
diff = await cloned_repo.diff(commit)

return diff
return await cloned_repo.diff(commit)


async def format(
Expand Down Expand Up @@ -271,8 +269,7 @@ async def format(
if proc.returncode not in [0, 1]:
raise ToolError(err.decode("utf8"))

lines = result.decode("utf8").splitlines()
return lines
return result.decode("utf8").splitlines()


class FormatComparison(Enum):
Expand Down
5 changes: 2 additions & 3 deletions python/ruff-ecosystem/ruff_ecosystem/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio
import dataclasses
import json
from collections.abc import Awaitable
from enum import Enum
from pathlib import Path
from typing import Awaitable, TypeVar
from typing import TypeVar

from ruff_ecosystem import logger
from ruff_ecosystem.check import compare_check, markdown_check_result
Expand Down Expand Up @@ -96,8 +97,6 @@ async def limited_parallelism(coroutine: Awaitable[T]) -> T:
case _:
raise ValueError(f"Unknown output format {format}")

return None


async def clone_and_compare(
command: RuffCommand,
Expand Down
2 changes: 1 addition & 1 deletion python/ruff-ecosystem/ruff_ecosystem/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def patch_config(
toml = {}

# Do not write a toml file if it does not exist and we're just nulling values
if all((value is None for value in overrides.values())):
if all(value is None for value in overrides.values()):
yield
return

Expand Down
17 changes: 8 additions & 9 deletions python/ruff-ecosystem/ruff_ecosystem/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import abc
import dataclasses
import difflib
from collections.abc import Iterable, Iterator, Sequence
from dataclasses import dataclass, is_dataclass
from typing import TYPE_CHECKING, Any, Generator, Iterable, Sequence
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
from ruff_ecosystem.projects import ClonedRepository, Project
Expand All @@ -28,25 +29,25 @@ def __init__(self, lines: Iterable[str], leading_spaces: int = 0) -> None:
self.lines = list(lines)

# Compute added and removed lines once
self.added = list(
self.added = [
line[2:]
for line in self.lines
if line.startswith("+" + " " * leading_spaces)
# Do not include patch headers
and not line.startswith("+++")
)
self.removed = list(
]
self.removed = [
line[2:]
for line in self.lines
if line.startswith("-" + " " * leading_spaces)
# Do not include patch headers
and not line.startswith("---")
)
]

def __bool__(self) -> bool:
return bool(self.added or self.removed)

def __iter__(self) -> Generator[str, None, None]:
def __iter__(self) -> Iterator[str]:
yield from self.lines

@property
Expand All @@ -65,9 +66,7 @@ def from_pair(cls, baseline: Sequence[str], comparison: Sequence[str]):
return cls(difflib.ndiff(baseline, comparison), leading_spaces=1)

def without_unchanged_lines(self) -> Diff:
return Diff(
line for line in self.lines if line.startswith("+") or line.startswith("-")
)
return Diff(line for line in self.lines if line.startswith(("+", "-")))

def jsonable(self) -> Any:
return self.lines
Expand Down