Simplify by dropping cache_args.

This commit is contained in:
Julien Palard 2020-12-03 10:02:50 +01:00
parent e024458174
commit 94bbad09a3
3 changed files with 4 additions and 27 deletions

View File

@ -3,7 +3,6 @@ import os
import pickle
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Any
from typing import cast
from typing import Dict
@ -12,7 +11,6 @@ from potodo.po_file import PoFileStats
def get_cache_file_content(
cache_args: Any,
path: str = ".potodo/cache.pickle",
) -> Dict[Path, PoFileStats]:
logging.debug("Trying to load cache from %s", path)
@ -24,7 +22,7 @@ def get_cache_file_content(
return {}
else:
logging.debug("Found cache")
if data.get("version") != VERSION or cache_args != data.get("args"):
if data.get("version") != VERSION:
logging.info("Found old cache, ignored it.")
return {}
else:
@ -32,10 +30,10 @@ def get_cache_file_content(
def set_cache_content(
obj: Dict[Path, PoFileStats], cache_args: Any, path: str = ".potodo/cache.pickle"
obj: Dict[Path, PoFileStats], path: str = ".potodo/cache.pickle"
) -> None:
os.makedirs(os.path.dirname(path), exist_ok=True)
data = {"version": VERSION, "args": cache_args, "data": obj}
data = {"version": VERSION, "data": obj}
with NamedTemporaryFile(
mode="wb", delete=False, dir=str(Path(path).parent), prefix=Path(path).name
) as tmp:

View File

@ -2,7 +2,6 @@ import itertools
import logging
import os
from pathlib import Path
from typing import Any
from typing import Callable
from typing import Dict
from typing import Iterable
@ -74,7 +73,6 @@ from potodo.cache import set_cache_content # noqa
def get_po_stats_from_repo_or_cache(
repo_path: Path,
exclude: Iterable[Path],
cache_args: Any,
ignore_matches: Callable[[str], bool],
no_cache: bool = False,
) -> Mapping[str, List[PoFileStats]]:
@ -115,7 +113,6 @@ def get_po_stats_from_repo_or_cache(
}
else:
cached_files = get_cache_file_content(
cache_args=cache_args,
path=str(repo_path.resolve()) + "/.potodo/cache.pickle",
)
po_stats_per_directory = dict()
@ -131,7 +128,6 @@ def get_po_stats_from_repo_or_cache(
po_stats_per_directory[directory].append(cached_file)
set_cache_content(
cached_files,
cache_args,
path=str(repo_path.resolve()) + "/.potodo/cache.pickle",
)

View File

@ -81,29 +81,12 @@ def non_interactive_output(
) -> None:
dir_stats: List[Any] = []
# Initialize the arguments
cache_args = {
"path": path,
"exclude": exclude,
"above": above,
"below": below,
"only_fuzzy": only_fuzzy,
"offline": offline,
"hide_reserved": hide_reserved,
"counts": counts,
"json_format": json_format,
"exclude_fuzzy": exclude_fuzzy,
"exclude_reserved": exclude_reserved,
"only_reserved": only_reserved,
"show_reservation_dates": show_reservation_dates,
"no_cache": no_cache,
"is_interactive": is_interactive,
}
issue_reservations = get_issue_reservations(offline, hide_reserved, path)
total_translated: int = 0
total_entries: int = 0
po_files_and_dirs = get_po_stats_from_repo_or_cache(
path, exclude, cache_args, ignore_matches, no_cache
path, exclude, ignore_matches, no_cache
)
for directory_name, po_files in sorted(po_files_and_dirs.items()):
# For each directory and files in this directory