flatten_comma_separated_values()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
cc 2
nop 1
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