-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
executable file
·94 lines (88 loc) · 2.55 KB
/
example.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
#!/usr/bin/env python3
from pckbuilder import (
TypeComponent,
PackageComponent,
ModuleComponent,
MethodComponent,
FunctionComponent,
VariableComponent,
TypeComponent,
ClassComponent,
build,
)
def main():
"""Script entrypoint for testing the modulebuilder package."""
str_type = TypeComponent("str")
int_type = TypeComponent("int")
optional_list = TypeComponent("List", is_optional=True)
str_list = TypeComponent("List")
variables = [
VariableComponent("mystr", "test variable", str_type, value="hello world"),
VariableComponent("myint", "an integer variable", int_type, value=1),
VariableComponent("mylist", "A list", str_list, value=["hello", "world"]),
VariableComponent("myoptionallist", "A list", optional_list),
]
# classes = [ClassComponent("MyClass", "A test class component.")]
functions = [
FunctionComponent(
"my_function", "A test function component.", "print('hello world')"
),
FunctionComponent(
"my_second_function",
"A second test function component.",
"print('hello world')",
[VariableComponent("test", "a test function argument", str_type)],
[
VariableComponent(
"test_kw",
"a test function keyword argument",
str_type,
value="default value",
)
],
),
]
methods = [
MethodComponent(
"__init__",
"Initialize class instance.",
"self.mystr = mystr",
[
VariableComponent(
"mystr", "test variable", str_type, value="hello world"
)
],
)
]
classes = [
ClassComponent(
"MyClass",
"A test class",
[
VariableComponent(
"myclassvar", "test class variable", str_type, value="hello world"
)
],
methods,
)
]
module = ModuleComponent(
"test",
"My test module.",
["from typing import List, Optional"],
variables,
classes,
functions,
)
package = PackageComponent(
"mypackage",
"a test package",
"0.1.0",
modules=[module],
install_requirements=["httpx"],
keywords=["test", "mathijs"],
imports=["from .test import MyClass"],
)
build(package)
if __name__ == "__main__":
main()