Even better.

This commit is contained in:
antoine 2020-06-04 09:37:15 +02:00
parent dbd8e514f5
commit fb4ec5bd0b
3 changed files with 13 additions and 15 deletions

View File

@ -67,23 +67,27 @@ def get_po_files_from_repo(
repo_path: str, exclude: Iterable[str]
) -> Mapping[str, Sequence[PoFileStats]]:
"""Gets all the po files recursively from 'repo_path', excluding those in
'exclude'. Return a list with all directories and PoFile instances of
'exclude'. Return a dict with all directories and PoFile instances of
`.po` files in those directories.
"""
# Get all the files matching `**/*.po`
# not being in the exclusion list or in
# any (sub)folder from the exclusion list
all_po_files: Sequence[Path] = [
all_po_files: Sequence[Path] = (
file
for file in Path(repo_path).rglob("*.po")
if not any(is_within(file, Path(excluded)) for excluded in exclude)
]
)
# Separates each directory and places all pofiles for each directory accordingly
# Group files by directory
po_files_per_directory: Mapping[str, Set[Path]] = {
name: set(files) for name, files in
itertools.groupby(all_po_files, key=lambda path: path.parent.name)
name: set(files)
# We assume the ouput of rglob to be sorted,
# so each 'name' is unique within groupby
for name, files in itertools.groupby(
all_po_files, key=lambda path: path.parent.name
)
}
end_dict: Dict[str, Sequence[PoFileStats]] = {}

View File

@ -93,7 +93,7 @@ def exec_potodo(
Will run everything based on the given parameters
:param path: The path to search into
:param exclude: folders within 'path' to be ignored
:param exclude: folders or files to be ignored
:param above: The above threshold
:param below: The below threshold
:param fuzzy: Should only fuzzies be printed

View File

@ -19,10 +19,7 @@ config = {
def test_txt_output(capsys):
exec_potodo(
json_format=False,
**config
)
exec_potodo(json_format=False, **config)
captured = capsys.readouterr()
assert "file1.po" in captured.out
@ -35,10 +32,7 @@ def test_txt_output(capsys):
def test_output(capsys):
exec_potodo(
json_format=True,
**config
)
exec_potodo(json_format=True, **config)
output = json.loads(capsys.readouterr().out)
expected = [