Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #105 from JulienPalard/mdk/cache-args
Browse files Browse the repository at this point in the history
  • Loading branch information
Seluj78 authored Dec 27, 2020
2 parents e024458 + fae940f commit eed6d80
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion potodo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Jules Lasne"""
__email__ = "[email protected]"
__version__ = "0.19.1"
__version__ = "0.19.2"
8 changes: 3 additions & 5 deletions potodo/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pickle
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Any
from typing import cast
from typing import Dict

Expand All @@ -12,7 +11,6 @@


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)
Expand All @@ -24,18 +22,18 @@ 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:
return cast(Dict[Path, PoFileStats], data["data"])


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:
Expand Down
4 changes: 0 additions & 4 deletions potodo/po_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import os
from pathlib import Path
from typing import Any
from typing import Callable
from typing import Dict
from typing import Iterable
Expand Down Expand Up @@ -74,7 +73,6 @@ def is_within(file: Path, excluded: Path) -> bool:
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]]:
Expand Down Expand Up @@ -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()
Expand All @@ -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",
)

Expand Down
19 changes: 1 addition & 18 deletions potodo/potodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eed6d80

Please sign in to comment.