-
Notifications
You must be signed in to change notification settings - Fork 15
/
tasks.py
90 lines (63 loc) · 2.09 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from invoke import task
from pathlib import Path
try:
from tqdm import tqdm
except ModuleNotFoundError:
def tqdm(iter, *args, **kwargs):
return iter
from typing import List, Iterable
import itertools
CLANG_FORMAT_CMD = "clang-format -i {}"
# List of folder names to be ignoreed when formatting
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('./src/').rglob("*.cpp")
headers = Path('./src/').rglob("*.h")
wrapper_sources = Path('./wrapper/').rglob("*.cpp")
wrapper_headers = Path('./wrapper/').rglob("*.h")
all_sources = filter_paths(itertools.chain(sources, headers, wrapper_headers, wrapper_sources))
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):
...
VENV_PYTHON_EXEC = "./venv/bin/python"
@task
def create_venv(c):
if not Path("venv").exists():
c.run("python3 -m venv venv")
c.run(f"{VENV_PYTHON_EXEC} -m pip install -r requirements-dev.txt")
else:
print("venv already exists")
@task
def install_ccorelib(c):
c.run(f"{VENV_PYTHON_EXEC} -m pip install --verbose wrapper/cccorelib")
@task
def install_pycc(c):
c.run(f"{VENV_PYTHON_EXEC} -m pip install --verbose wrapper/pycc")
@task
def test_cccorelib(c):
c.run(f"{VENV_PYTHON_EXEC} -m pytest wrapper/cccorelib/tests")
@task
def test_pycc(c):
c.run(f"{VENV_PYTHON_EXEC} -m pytest wrapper/pycc/tests")