-
Notifications
You must be signed in to change notification settings - Fork 55
/
generate_zenml_project.py
137 lines (109 loc) · 2.63 KB
/
generate_zenml_project.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""Generate a ZenML project for a tool"""
import argparse
import logging
import os
import shutil
from textwrap import dedent
def get_hello_world_str():
return dedent(
f"""\
import logging
def main():
pass
if __name__ == "__main__":
logging.basicConfig(level="INFO")
main()
"""
)
def get_readme_str(name: str):
return dedent(
f"""\
# Playground for {name}
## Installation
```
cd {name}
poetry install
```
"""
)
def get_flake8_str():
return dedent(
"""\
[flake8]
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9
ignore = E203, E266, E501, W503, F403, F401
"""
)
def get_project_toml_str(name: str, author: str = "Author <[email protected]>"):
return dedent(
f"""\
[tool.poetry]
name = "{name}"
version = "1.0.0"
description = "{name}"
authors = ["{author}"]
license = "Apache 2.0"
[tool.poetry.dependencies]
python = ">=3.7.0,<3.9.0"
[tool.poetry.dev-dependencies]
black = "^21.9b0"
isort = "^5.9.3"
pytest = "^6.2.5"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.isort]
profile = "black"
known_third_party = []
skip_glob = []
line_length = 79
[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
)/
'''
"""
)
def write_file(path: str, content: str):
with open(path, "w") as f:
f.write(content)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("tool_name", type=str, help="Name of the tool")
args = parser.parse_args()
path = os.path.join(os.getcwd(), args.tool_name)
src_path = os.path.join(path, "src")
if os.path.exists(path):
raise AssertionError(f"{path} already exists!")
toml_str = get_project_toml_str(args.tool_name)
flake8_str = get_flake8_str()
py_str = get_hello_world_str()
readme_str = get_readme_str(args.tool_name)
# make dirs
os.mkdir(path)
os.mkdir(src_path)
# copy .gitignore
shutil.copy(
os.path.join(os.getcwd(), ".gitignore"),
os.path.join(path, ".gitignore"),
)
# write files
write_file(os.path.join(path, ".flake8"), flake8_str)
write_file(os.path.join(src_path, "main.py"), py_str)
write_file(os.path.join(path, "pyproject.toml"), toml_str)
write_file(os.path.join(path, "README.md"), readme_str)
if __name__ == "__main__":
logging.basicConfig(level="INFO")
main()