Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

generate_zenml_project.py 2.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. """Generate a ZenML project for a tool"""
  2. import argparse
  3. import logging
  4. import os
  5. import shutil
  6. from textwrap import dedent
  7. def get_hello_world_str():
  8. return dedent(
  9. f"""\
  10. import logging
  11. def main():
  12. pass
  13. if __name__ == "__main__":
  14. logging.basicConfig(level="INFO")
  15. main()
  16. """
  17. )
  18. def get_readme_str(name: str):
  19. return dedent(
  20. f"""\
  21. # Playground for {name}
  22. ## Installation
  23. ```
  24. cd {name}
  25. poetry install
  26. ```
  27. """
  28. )
  29. def get_flake8_str():
  30. return dedent(
  31. """\
  32. [flake8]
  33. max-line-length = 79
  34. max-complexity = 18
  35. select = B,C,E,F,W,T4,B9
  36. ignore = E203, E266, E501, W503, F403, F401
  37. """
  38. )
  39. def get_project_toml_str(name: str, author: str = "Author <author@gmail.com>"):
  40. return dedent(
  41. f"""\
  42. [tool.poetry]
  43. name = "{name}"
  44. version = "1.0.0"
  45. description = "{name}"
  46. authors = ["{author}"]
  47. license = "Apache 2.0"
  48. [tool.poetry.dependencies]
  49. python = ">=3.7.0,<3.9.0"
  50. [tool.poetry.dev-dependencies]
  51. black = "^21.9b0"
  52. isort = "^5.9.3"
  53. pytest = "^6.2.5"
  54. [build-system]
  55. requires = ["poetry-core>=1.0.0"]
  56. build-backend = "poetry.core.masonry.api"
  57. [tool.isort]
  58. profile = "black"
  59. known_third_party = []
  60. skip_glob = []
  61. line_length = 79
  62. [tool.black]
  63. line-length = 79
  64. include = '\.pyi?$'
  65. exclude = '''
  66. /(
  67. \.git
  68. | \.hg
  69. | \.mypy_cache
  70. | \.tox
  71. | \.venv
  72. | _build
  73. | buck-out
  74. | build
  75. )/
  76. '''
  77. """
  78. )
  79. def write_file(path: str, content: str):
  80. with open(path, "w") as f:
  81. f.write(content)
  82. def main():
  83. parser = argparse.ArgumentParser()
  84. parser.add_argument("tool_name", type=str, help="Name of the tool")
  85. args = parser.parse_args()
  86. path = os.path.join(os.getcwd(), args.tool_name)
  87. src_path = os.path.join(path, "src")
  88. if os.path.exists(path):
  89. raise AssertionError(f"{path} already exists!")
  90. toml_str = get_project_toml_str(args.tool_name)
  91. flake8_str = get_flake8_str()
  92. py_str = get_hello_world_str()
  93. readme_str = get_readme_str(args.tool_name)
  94. # make dirs
  95. os.mkdir(path)
  96. os.mkdir(src_path)
  97. # copy .gitignore
  98. shutil.copy(
  99. os.path.join(os.getcwd(), ".gitignore"),
  100. os.path.join(path, ".gitignore"),
  101. )
  102. # write files
  103. write_file(os.path.join(path, ".flake8"), flake8_str)
  104. write_file(os.path.join(src_path, "main.py"), py_str)
  105. write_file(os.path.join(path, "pyproject.toml"), toml_str)
  106. write_file(os.path.join(path, "README.md"), readme_str)
  107. if __name__ == "__main__":
  108. logging.basicConfig(level="INFO")
  109. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...