-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtasks.py
72 lines (62 loc) · 2.81 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
from pathlib import Path
from invoke import task
from jinja2 import Template
@task
def add_transformer(ctx, name, disabled=False):
root = Path(__file__).parent
template_dir = Path(root, "utils", "new_transformer_templates")
class_path = Path(root, "robotidy", "transformers", f"{name}.py")
docs = Path(root, "docs", "source", "transformers", f"{name}.rst")
print(f"Creating '{class_path.relative_to(root)}' file with transformer class definition")
with open(template_dir / "transformer.template") as f:
class_template = Template(f.read()).render(transformer_name=name, disabled=disabled)
with open(class_path, "w") as f:
f.write(class_template)
print(f"Creating '{docs.relative_to(root)} file with transformer full documentation")
with open(template_dir / "docs.template") as f:
docs_template = Template(f.read()).render(transformer_name=name, disabled=disabled)
with open(docs, "w") as f:
f.write(docs_template)
test_dir = Path(root, "tests", "atest", "transformers", name)
print(f"Creating '{test_dir.relative_to(root)}' directory with test stubs")
with open(template_dir / "test_transformer.template") as f:
test_template = Template(f.read()).render(transformer_name=name)
test_dir.mkdir(exist_ok=True)
(test_dir / "source").mkdir(exist_ok=True)
(test_dir / "expected").mkdir(exist_ok=True)
with open(test_dir / "__init__.py", "w") as f:
pass
with open(test_dir / "source" / "test.robot", "w") as f:
pass
with open(test_dir / "expected" / "test.robot", "w") as f:
pass
with open(test_dir / "test_transformer.py", "w") as f:
f.write(test_template)
_add_transformer_to_internal_list(name)
def _add_transformer_to_internal_list(name):
path = Path(Path(__file__).parent, "robotidy", "transformers", "__init__.py")
print(
f"Transformer '{name}' will be placed at the end of transformers list. "
f"You can change it in {path.relative_to(Path(__file__).parent)} file."
)
data = [[], []]
after_bracket = False
with open(path) as f:
for line in f:
if line == "]\n":
after_bracket = True
data[after_bracket].append(line)
data[0].append(f" '{name}',\n")
lines = data[0] + data[1]
with open(path, "w") as f:
f.writelines(lines)
@task
def create_release_docs(ctx, version):
root = Path(__file__).parent
template_path = root / "utils/release_docs_templates/new_release.template"
release_docs_path = root / f"docs/releasenotes/{version}.rst"
print(f"Creating '{release_docs_path}' file with initial release notes.")
with open(template_path) as fp:
doc_template = Template(fp.read()).render(version=version)
with open(release_docs_path, "w") as fp:
fp.write(doc_template)