-
Notifications
You must be signed in to change notification settings - Fork 15
/
tasks.py
53 lines (36 loc) · 1.15 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from invoke import task
from pathlib import Path
from tqdm import tqdm
from typing import List, Iterable
import itertools
CLANG_FORMAT_CMD = "clang-format -i {}"
DISALLOW_LIST = ['_skbuild']
def filter_paths(paths: Iterable[Path]) -> List[Path]:
filtered_paths = []
for path in paths:
allowed = True
for p in DISALLOW_LIST:
if p in path.parts:
allowed = False
if allowed:
filtered_paths.append(path)
return filtered_paths
@task
def clang_format(c):
sources = Path('.').rglob("*.cpp")
headers = Path('.').rglob("*.h")
all_sources = filter_paths(itertools.chain(sources, headers))
print('Formating source files')
for path in tqdm(all_sources, ncols=80):
c.run(f"clang-format -i {path}")
@task
def cmake_format(c):
cmakelists = list(Path('.').rglob('CMakeLists.txt'))
cmakes = list(Path("./cmake").iterdir())
all_cmakes = filter_paths(itertools.chain(cmakes, cmakelists))
print('Formating CMakeLists.txt')
for path in tqdm(all_cmakes, ncols=80):
c.run(f'cmake-format -i {path}')
@task(clang_format, cmake_format)
def format(c):
...