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

Commit 4fafbc7

Browse files
authored
Merge pull request #84 from Seluj78/feature/cached_args
2 parents 818b0a3 + d83883c commit 4fafbc7

9 files changed

Lines changed: 56 additions & 35 deletions

File tree

.potodoignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
venv/*
1+
venv/

potodo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """Jules Lasne"""
44
__email__ = "jules.lasne@gmail.com"
5-
__version__ = "0.15.0"
5+
__version__ = "0.16.0"

potodo/cache.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from pathlib import Path
55
from typing import cast
66
from typing import Dict
7+
from typing import Any
78

89
from potodo import __version__ as VERSION
910
from potodo.po_file import PoFileStats
1011

1112

1213
def get_cache_file_content(
14+
cache_args: Any,
1315
path: str = ".potodo/cache.pickle",
1416
) -> Dict[Path, PoFileStats]:
1517
logging.debug("Trying to load cache from %s", path)
@@ -21,18 +23,18 @@ def get_cache_file_content(
2123
return {}
2224
else:
2325
logging.debug("Found cache")
24-
if data.get("version") != VERSION:
26+
if data.get("version") != VERSION or cache_args != data.get("args"):
2527
logging.info("Found old cache, ignored it.")
2628
return {}
2729
else:
2830
return cast(Dict[Path, PoFileStats], data["data"])
2931

3032

3133
def set_cache_content(
32-
obj: Dict[Path, PoFileStats], path: str = ".potodo/cache.pickle"
34+
obj: Dict[Path, PoFileStats], cache_args: Any, path: str = ".potodo/cache.pickle"
3335
) -> None:
3436
os.makedirs(os.path.dirname(path), exist_ok=True)
35-
data = {"version": VERSION, "data": obj}
37+
data = {"version": VERSION, "args": cache_args, "data": obj}
3638
with open(path, "wb") as handle:
3739
pickle.dump(data, handle)
3840
logging.debug("Set cache to %s", path)

potodo/ignore.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

potodo/interactive.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import cast
33
from typing import Iterable
44
from typing import List
5+
from typing import Callable
56

67
from simple_term_menu import TerminalMenu
78

@@ -61,13 +62,16 @@ def _confirmation_menu(choosen_file: str, directory: str) -> int:
6162
return cast(int, choice)
6263

6364

64-
def get_dir_list(repo_path: Path, exclude: Iterable[Path]) -> List[str]:
65+
def get_dir_list(
66+
repo_path: Path, exclude: Iterable[Path], ignore_matches: Callable[[str], bool]
67+
) -> List[str]:
6568
return list(
6669
set(
6770
[
6871
file.parent.name
6972
for file in repo_path.rglob("*.po")
7073
if not any(is_within(file, excluded) for excluded in exclude)
74+
and not ignore_matches(str(file))
7175
]
7276
)
7377
)

potodo/po_file.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from typing import Mapping
99
from typing import Sequence
1010
from typing import Set
11+
from typing import Callable
12+
from typing import Any
1113

1214
import polib
1315

@@ -69,7 +71,11 @@ def is_within(file: Path, excluded: Path) -> bool:
6971

7072

7173
def get_po_stats_from_repo_or_cache(
72-
repo_path: Path, exclude: Iterable[Path], no_cache: bool = False
74+
repo_path: Path,
75+
exclude: Iterable[Path],
76+
cache_args: Any,
77+
ignore_matches: Callable[[str], bool],
78+
no_cache: bool = False,
7379
) -> Mapping[str, List[PoFileStats]]:
7480
"""Gets all the po files recursively from 'repo_path'
7581
and cache if no_cache is set to False, excluding those in
@@ -85,6 +91,7 @@ def get_po_stats_from_repo_or_cache(
8591
file
8692
for file in repo_path.rglob("*.po")
8793
if not any(is_within(file, excluded) for excluded in exclude)
94+
and not ignore_matches(str(file))
8895
]
8996

9097
# Group files by directory
@@ -107,7 +114,8 @@ def get_po_stats_from_repo_or_cache(
107114
}
108115
else:
109116
cached_files = get_cache_file_content(
110-
str(repo_path.resolve()) + "/.potodo/cache.pickle"
117+
cache_args=cache_args,
118+
path=str(repo_path.resolve()) + "/.potodo/cache.pickle",
111119
)
112120
po_stats_per_directory = dict()
113121
for directory, po_files in po_files_per_directory.items():
@@ -121,7 +129,9 @@ def get_po_stats_from_repo_or_cache(
121129
cached_files[po_file.resolve()] = cached_file = PoFileStats(po_file)
122130
po_stats_per_directory[directory].append(cached_file)
123131
set_cache_content(
124-
cached_files, path=str(repo_path.resolve()) + "/.potodo/cache.pickle"
132+
cached_files,
133+
cache_args,
134+
path=str(repo_path.resolve()) + "/.potodo/cache.pickle",
125135
)
126136

127137
return po_stats_per_directory

potodo/potodo.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from typing import List
1010
from typing import Sequence
1111
from typing import Tuple
12+
from gitignore_parser import parse_gitignore
1213

1314
from potodo import __version__
1415
from potodo.arguments_handling import check_args
1516
from potodo.github import get_issue_reservations
16-
from potodo.ignore import get_ignore_content
1717
from potodo.interactive import _confirmation_menu
1818
from potodo.interactive import _directory_list_menu
1919
from potodo.interactive import _file_list_menu
@@ -99,15 +99,37 @@ def exec_potodo(
9999
:param is_interactive: Switches output to an interactive CLI menu
100100
"""
101101

102-
ignore_file_content = get_ignore_content(repo_path=path)
103-
exclude.extend(ignore_file_content)
102+
cache_args = {
103+
"path": path,
104+
"exclude": exclude,
105+
"above": above,
106+
"below": below,
107+
"only_fuzzy": only_fuzzy,
108+
"offline": offline,
109+
"hide_reserved": hide_reserved,
110+
"counts": counts,
111+
"json_format": json_format,
112+
"exclude_fuzzy": exclude_fuzzy,
113+
"exclude_reserved": exclude_reserved,
114+
"only_reserved": only_reserved,
115+
"show_reservation_dates": show_reservation_dates,
116+
"no_cache": no_cache,
117+
"is_interactive": is_interactive,
118+
}
119+
120+
try:
121+
ignore_matches = parse_gitignore(path / ".potodoignore")
122+
except FileNotFoundError:
123+
ignore_matches = parse_gitignore("/dev/null")
104124

105125
# Initialize the arguments
106126
issue_reservations = get_issue_reservations(offline, hide_reserved, path)
107127

108128
dir_stats: List[Any] = []
109129
if is_interactive:
110-
directory_options = get_dir_list(repo_path=path, exclude=exclude)
130+
directory_options = get_dir_list(
131+
repo_path=path, exclude=exclude, ignore_matches=ignore_matches
132+
)
111133
while True:
112134
selected_dir = _directory_list_menu(directory_options)
113135
if selected_dir == (len(directory_options) - 1):
@@ -139,7 +161,9 @@ def exec_potodo(
139161
else:
140162
exit()
141163
else:
142-
po_files_and_dirs = get_po_stats_from_repo_or_cache(path, exclude, no_cache)
164+
po_files_and_dirs = get_po_stats_from_repo_or_cache(
165+
path, exclude, cache_args, ignore_matches, no_cache
166+
)
143167
for directory_name, po_files in sorted(po_files_and_dirs.items()):
144168
# For each directory and files in this directory
145169
buffer: List[Any] = []

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
polib==1.1.0
22
requests==2.24.0
33
simple-term-menu==0.10.2
4+
gitignore_parser==0.0.8

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package_dir={"potodo": "potodo"},
2121
entry_points={"console_scripts": ["potodo=potodo.potodo:main"]},
2222
include_package_data=True,
23-
install_requires=["polib", "requests", "simple-term-menu"],
23+
install_requires=["polib", "requests", "simple-term-menu", "gitignore_parser"],
2424
license="MIT license",
2525
zip_safe=False,
2626
keywords="potodo",

0 commit comments

Comments
 (0)