Completed
Push — master ( 3c108b...266306 )
by Oleksandr
03:35
created

verboselib.cli.paths.find_source_files_paths()   C

Complexity

Conditions 9

Size

Total Lines 36
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 36
rs 6.6666
c 0
b 0
f 0
cc 9
nop 5
1
import fnmatch
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
import os
3
4
from pathlib import Path
5
6
from typing import List
7
from typing import Set
8
from typing import Text
9
10
from .text import stringify_path
11
from .utils import print_out
12
13
14
MESSAGES_DIR_NAME = "LC_MESSAGES"
15
16
17
def make_messages_dir_path(locales_dir_path: Path, locale: Text) -> Path:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
18
  return locales_dir_path / locale / MESSAGES_DIR_NAME
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
19
20
21
def make_pot_file_path(locales_dir_path: Path, domain: Text) -> Path:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
22
  return locales_dir_path / f"{domain}.pot"
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
23
24
25
def make_po_file_path(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
26
  locales_dir_path: Path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
27
  locale: Text,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
28
  domain: Text,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
29
) -> Path:
30
31
  messages_dir_path = make_messages_dir_path(locales_dir_path, locale)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
32
  messages_file_name = f"{domain}.po"
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
33
34
  return messages_dir_path / messages_file_name
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
35
36
37
def make_mo_file_path(po_file_path: Path) -> Path:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
38
  return po_file_path.parent / f"{po_file_path.stem}.mo"
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
39
40
41
def get_names_of_immediate_subdirectories(root: Path) -> List[Text]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
42
  return [
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
43
    node.name
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
44
    for node in root.iterdir()
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
45
    if node.is_dir()
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
46
  ]
47
48
49
def ensure_dir_exists(path: Path) -> None:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
50
  path.mkdir(parents=True, exist_ok=True)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
51
52
53
def is_path_ignored(path: Path, ignore_patterns: List[Text]) -> bool:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
54
  for pattern in ignore_patterns:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
55
    if fnmatch.fnmatchcase(path.name, pattern):
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
56
      return True
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
57
  else:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Bug introduced by
The else clause is not necessary as the loop does not contain a break statement.

If the loop cannot exit early through the use of break, the else part will always be executed. You can therefore just leave off the else.

Loading history...
58
    return False
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
59
60
61
def normalize_dir_patterns(patterns: List[Text]) -> List[Text]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
62
  dir_suffix = "{os.sep}*"
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
63
  return [
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
64
    (
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
65
       p[:-len(dir_suffix)]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
66
      if p.endswith(dir_suffix)
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
67
      else p
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
68
    )
69
    for p in patterns
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
70
  ]
71
72
73
def find_source_files_paths(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
74
  root_dir_path: Path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
75
  ignore_patterns: List[Text],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
76
  extensions: Set[Text],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
77
  follow_links: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
78
  verbose: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block.
Loading history...
79
) -> List[Path]:
80
81
  result = []
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
82
83
  walker = os.walk(
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
84
    top=stringify_path(root_dir_path),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
85
    topdown=True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
86
    followlinks=follow_links,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
87
  )
88
89
  normalized_ignore_patterns = normalize_dir_patterns(ignore_patterns)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
90
91
  for dir_path, dir_names, file_names in walker:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
92
93
    for dir_name in dir_names[:]:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
94
      path = Path(os.path.normpath(os.path.join(dir_path, dir_name)))
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
95
      if is_path_ignored(path, normalized_ignore_patterns):
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
96
        dir_names.remove(dir_name)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
97
        if verbose:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
98
          print_out(f"ignoring dir '{stringify_path(path.absolute())}'")
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 20 spaces were expected, but 10 were found.
Loading history...
99
100
    for file_name in file_names:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
101
      path = Path(os.path.normpath(os.path.join(dir_path, file_name)))
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
102
      if is_path_ignored(path, ignore_patterns):
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
103
        if verbose:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
104
          print_out(f"ignoring file '{stringify_path(path.absolute())}'")
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 20 spaces were expected, but 10 were found.
Loading history...
105
      elif path.suffix in extensions:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
106
        result.append(path)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
107
108
  return list(sorted(result))
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
109