Skip to content

Commit

Permalink
Update pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 committed Mar 23, 2022
1 parent c95b681 commit 9f8c993
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Expand Up @@ -2,14 +2,14 @@ exclude: ^tests/data/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.1.0
hooks:
- id: black

Expand All @@ -28,13 +28,13 @@ repos:
- id: isort

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.920
rev: v0.941
hooks:
- id: mypy
additional_dependencies: [click>=8.0.0, packaging>=21.0, types-dataclasses]
additional_dependencies: [click>=8.0.0, packaging>=21.0, types-dataclasses, rich>=10.13.0]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.11
rev: 0.7.14
hooks:
- id: mdformat
args: [--wrap=79]
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Expand Up @@ -44,11 +44,11 @@ channel on Python Discord. Here’s an
[invite link](https://discord.gg/RtVdv86PrH)!

[^1]: I'll fix this with a hash based solution eventually, but for now let's be
careful.
careful.

[^2]: I know it’s specifically for Black, but diff-shades is a development tool for
Black so I consider it acceptable - although I never asked … but then again, I
am a maintainer of Black so yeah :p
[^2]: I know it’s specifically for Black, but diff-shades is a development tool
for Black so I consider it acceptable - although I never asked … but then
again, I am a maintainer of Black so yeah :p

[nox]: https://nox.thea.codes/en/stable/
[pre-commit]: https://pre-commit.com/
2 changes: 1 addition & 1 deletion src/diff_shades/cli.py
Expand Up @@ -187,7 +187,7 @@ def main(
shutil.rmtree(diff_shades.results.CACHE_DIR)
diff_shades.results.CACHE_DIR.mkdir(parents=True, exist_ok=True)
if dump_html:
atexit.register(console.save_html, path=dump_html)
atexit.register(console.save_html, path=str(dump_html))


# fmt: off
Expand Down
9 changes: 6 additions & 3 deletions src/diff_shades/results.py
Expand Up @@ -10,7 +10,6 @@
import time
from dataclasses import asdict, dataclass, field
from datetime import datetime
from functools import lru_cache
from pathlib import Path
from typing import (
Any,
Expand Down Expand Up @@ -76,14 +75,18 @@ class ReformattedResult:
line_changes: Tuple[int, int] = (-1, -1)

def __post_init__(self) -> None:
self._diff_cache = ""
_convert_line_count(self)
if self.line_changes == (-1, -1):
changes = calculate_line_changes(self.diff("throw-away-name"))
object.__setattr__(self, "line_changes", changes)

@lru_cache(maxsize=None)
def diff(self, filepath: str) -> str:
return unified_diff(self.src, self.dst, f"a/{filepath}", f"b/{filepath}")
if self._diff_cache:
return self._diff_cache

self._diff_cache = unified_diff(self.src, self.dst, f"a/{filepath}", f"b/{filepath}")
return self._diff_cache


@dataclass(frozen=True)
Expand Down

0 comments on commit 9f8c993

Please sign in to comment.