verboselib.cli.text   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 25
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A stringify_path() 0 2 1
A flatten_comma_separated_values() 0 13 2
A normalize_eols() 0 8 3
1
import itertools
2
import sys
3
4
if sys.version_info >= (3, 9):
5
  List = list
6
else:
7
  from typing import List
8
9
from pathlib import Path
10
from typing import Optional
11
12
13
def normalize_eols(contents: str) -> str:
14
  lines = contents.splitlines()
15
16
  # Ensure last line has its EOL
17
  if lines and lines[-1]:
18
    lines.append("")
19
20
  return "\n".join(lines)
21
22
23
def flatten_comma_separated_values(values: Optional[List[str]]) -> List[str]:
24
  if not values:
25
    return []
26
27
  return list(itertools.chain(*[
28
    filter(
29
      len,
30
      map(
31
        str.strip,
32
        x.split(","),
33
      ),
34
    )
35
    for x in values
36
  ]))
37
38
39
def stringify_path(path: Path) -> str:
40
  return str(path.as_posix())
41