Skip to content

Commit

Permalink
ci: add ruff to lint process (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 21, 2024
1 parent cb82d87 commit 9c708a2
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 deletions.
29 changes: 28 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ twine = '^5.1.1'
semver = '^3.0.0'
setuptools-scm = '^8.0.0'
debugpy = '^1.6.6'
ruff = '>=0.7.0'

[tool.black]
line-length = 88
Expand Down
13 changes: 7 additions & 6 deletions src/syrupy/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def _get_file_basename(
return test_location.basename


def _count_leading_whitespace(s: str) -> int:
return len(s) - len(s.lstrip())


class SnapshotReporter(ABC):
_context_line_count = 1

Expand Down Expand Up @@ -383,16 +387,13 @@ def __limit_context(self, lines: List[str]) -> Iterator[str]:
num_lines = len(lines)
if num_lines:
if num_lines > self._context_line_max:
count_leading_whitespace: Callable[[str], int] = lambda s: len(s) - len(
s.lstrip()
)
if self._context_line_count:
num_space = (
count_leading_whitespace(lines[self._context_line_count - 1])
+ count_leading_whitespace(lines[-self._context_line_count])
_count_leading_whitespace(lines[self._context_line_count - 1])
+ _count_leading_whitespace(lines[-self._context_line_count])
) // 2
else:
num_space = count_leading_whitespace(lines[num_lines // 2])
num_space = _count_leading_whitespace(lines[num_lines // 2])
yield " " * num_space + self._marker_context_max
if self._context_line_count and num_lines > 1:
yield from lines[-self._context_line_count :] # noqa: E203
Expand Down
2 changes: 1 addition & 1 deletion tasks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def benchmark(ctx, report=False):
Run and generate benchmarks for current code
"""

ctx.run(f"pytest benchmarks --benchmark-json=benchmarks.json")
ctx.run("pytest benchmarks --benchmark-json=benchmarks.json")
6 changes: 3 additions & 3 deletions tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def install(ctx, upgrade=False):
Install dependencies and update lock file.
"""
if upgrade:
ctx_run(ctx, f"poetry update")
ctx_run(ctx, "poetry update")
else:
ctx_run(ctx, f"poetry lock")
ctx_run(ctx, f"poetry install")
ctx_run(ctx, "poetry lock")
ctx_run(ctx, "poetry install")


@task
Expand Down
1 change: 1 addition & 0 deletions tasks/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"black": lambda fix: f"python -m black {'' if fix else '--check'} .",
"flake8": lambda _: "python -m flake8 src tests benchmarks *.py",
"mypy": lambda _: "python -m mypy --strict src benchmarks",
"ruff": lambda _: "python -m ruff check",
}


Expand Down
2 changes: 0 additions & 2 deletions tasks/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from invoke import task

from .utils import ctx_run
Expand Down

0 comments on commit 9c708a2

Please sign in to comment.