Skip to content

Commit

Permalink
core: some fixes after refactoring due to missing type annotations
Browse files Browse the repository at this point in the history
also fix diff mode with two files
  • Loading branch information
karlicoss committed Oct 17, 2023
1 parent 4d5f8b7 commit 232ffc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/bleanser/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
from glob import glob as do_glob
from pathlib import Path
import os
from typing import Optional, List
from typing import Optional, List, Type

from .common import logger, Dry, Move, Remove, Mode
from .processor import compute_instructions, apply_instructions, bleanser_tmp_directory
from .processor import BaseNormaliser, compute_instructions, apply_instructions, bleanser_tmp_directory

import click


# TODO use context and default_map
# https://click.palletsprojects.com/en/7.x/commands/#overriding-defaults
def main(*, Normaliser) -> None:
def main(*, Normaliser: Type[BaseNormaliser]) -> None:
# meh.. by default the width is stupid, like 80 chars
context_settings = {
'max_content_width': 120,
Expand All @@ -34,16 +34,17 @@ def call_main() -> None:
@click.option ('--from', 'from_', type=int , default=None)
@click.option ('--to' , type=int , default=None)
def diff(path1: str, path2: Path, *, glob: bool, from_: Optional[int], to: Optional[int], vim: bool, difftool: str) -> None:
if to is None:
assert from_ is not None
to = from_ + 2

path1_: Path
if path2 is _DEFAULT:
if glob:
assert path2 is _DEFAULT, path2
if to is None:
assert from_ is not None
to = from_ + 2
paths = _get_paths(path=path1, from_=from_, to=to, glob=glob)
assert len(paths) == 2, paths
[path1_, path2] = paths
else:
assert path2 is not _DEFAULT
path1_ = Path(path1)
path2 = Path(path2)

Expand All @@ -62,7 +63,7 @@ def diff(path1: str, path2: Path, *, glob: bool, from_: Optional[int], to: Optio
@click.option('--stdout', is_flag=True, help='print normalised files to stdout instead of printing the path to it')
def normalised(path: Path, stdout: bool) -> None:
with bleanser_tmp_directory() as base_tmp_dir:
n = Normaliser(input=path, base_tmp_dir=base_tmp_dir)
n = Normaliser(original=path, base_tmp_dir=base_tmp_dir)
with n.do_normalise() as cleaned:
if stdout:
print(cleaned.read_text())
Expand Down
6 changes: 3 additions & 3 deletions src/bleanser/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,10 @@ def stat() -> str:


# TODO write a test for this
def compute_diff(path1: Path, path2: Path, *, Normaliser) -> List[str]:
def compute_diff(path1: Path, path2: Path, *, Normaliser: Type[BaseNormaliser]) -> List[str]:
with bleanser_tmp_directory() as base_tmp_dir:
n1 = Normaliser(input=path1, base_tmp_dir=base_tmp_dir)
n2 = Normaliser(input=path2, base_tmp_dir=base_tmp_dir)
n1 = Normaliser(original=path1, base_tmp_dir=base_tmp_dir)
n2 = Normaliser(original=path2, base_tmp_dir=base_tmp_dir)

with n1.do_normalise() as res1, n2.do_normalise() as res2:
# ok, I guess diff_filter=None makes more sense here?
Expand Down

0 comments on commit 232ffc2

Please sign in to comment.