@alloy-js/python 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +7 -0
  3. package/api-extractor.json +4 -0
  4. package/dist/src/builtins/python.d.ts +9 -0
  5. package/dist/src/builtins/python.d.ts.map +1 -0
  6. package/dist/src/builtins/python.js +17 -0
  7. package/dist/src/components/Atom.d.ts +19 -0
  8. package/dist/src/components/Atom.d.ts.map +1 -0
  9. package/dist/src/components/Atom.js +82 -0
  10. package/dist/src/components/CallSignature.d.ts +79 -0
  11. package/dist/src/components/CallSignature.d.ts.map +1 -0
  12. package/dist/src/components/CallSignature.js +201 -0
  13. package/dist/src/components/ClassDeclaration.d.ts +37 -0
  14. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  15. package/dist/src/components/ClassDeclaration.js +83 -0
  16. package/dist/src/components/ClassInstantiation.d.ts +24 -0
  17. package/dist/src/components/ClassInstantiation.d.ts.map +1 -0
  18. package/dist/src/components/ClassInstantiation.js +35 -0
  19. package/dist/src/components/Declaration.d.ts +48 -0
  20. package/dist/src/components/Declaration.d.ts.map +1 -0
  21. package/dist/src/components/Declaration.js +37 -0
  22. package/dist/src/components/EnumDeclaration.d.ts +164 -0
  23. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  24. package/dist/src/components/EnumDeclaration.js +278 -0
  25. package/dist/src/components/EnumMember.d.ts +46 -0
  26. package/dist/src/components/EnumMember.d.ts.map +1 -0
  27. package/dist/src/components/EnumMember.js +67 -0
  28. package/dist/src/components/FunctionCallExpression.d.ts +19 -0
  29. package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
  30. package/dist/src/components/FunctionCallExpression.js +40 -0
  31. package/dist/src/components/FunctionDeclaration.d.ts +47 -0
  32. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
  33. package/dist/src/components/FunctionDeclaration.js +107 -0
  34. package/dist/src/components/ImportStatement.d.ts +39 -0
  35. package/dist/src/components/ImportStatement.d.ts.map +1 -0
  36. package/dist/src/components/ImportStatement.js +104 -0
  37. package/dist/src/components/MemberExpression.d.ts +97 -0
  38. package/dist/src/components/MemberExpression.d.ts.map +1 -0
  39. package/dist/src/components/MemberExpression.js +308 -0
  40. package/dist/src/components/NoNamePolicy.d.ts +23 -0
  41. package/dist/src/components/NoNamePolicy.d.ts.map +1 -0
  42. package/dist/src/components/NoNamePolicy.js +27 -0
  43. package/dist/src/components/PyDoc.d.ts +90 -0
  44. package/dist/src/components/PyDoc.d.ts.map +1 -0
  45. package/dist/src/components/PyDoc.js +280 -0
  46. package/dist/src/components/PythonBlock.d.ts +23 -0
  47. package/dist/src/components/PythonBlock.d.ts.map +1 -0
  48. package/dist/src/components/PythonBlock.js +31 -0
  49. package/dist/src/components/Reference.d.ts +13 -0
  50. package/dist/src/components/Reference.d.ts.map +1 -0
  51. package/dist/src/components/Reference.js +18 -0
  52. package/dist/src/components/SourceFile.d.ts +46 -0
  53. package/dist/src/components/SourceFile.d.ts.map +1 -0
  54. package/dist/src/components/SourceFile.js +75 -0
  55. package/dist/src/components/StatementList.d.ts +25 -0
  56. package/dist/src/components/StatementList.d.ts.map +1 -0
  57. package/dist/src/components/StatementList.js +29 -0
  58. package/dist/src/components/VariableDeclaration.d.ts +62 -0
  59. package/dist/src/components/VariableDeclaration.d.ts.map +1 -0
  60. package/dist/src/components/VariableDeclaration.js +131 -0
  61. package/dist/src/components/index.d.ts +19 -0
  62. package/dist/src/components/index.d.ts.map +1 -0
  63. package/dist/src/components/index.js +18 -0
  64. package/dist/src/create-module.d.ts +16 -0
  65. package/dist/src/create-module.d.ts.map +1 -0
  66. package/dist/src/create-module.js +64 -0
  67. package/dist/src/index.d.ts +8 -0
  68. package/dist/src/index.d.ts.map +1 -0
  69. package/dist/src/index.js +7 -0
  70. package/dist/src/name-policy.d.ts +5 -0
  71. package/dist/src/name-policy.d.ts.map +1 -0
  72. package/dist/src/name-policy.js +47 -0
  73. package/dist/src/parameter-descriptor.d.ts +31 -0
  74. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  75. package/dist/src/parameter-descriptor.js +1 -0
  76. package/dist/src/symbol-creation.d.ts +4 -0
  77. package/dist/src/symbol-creation.d.ts.map +1 -0
  78. package/dist/src/symbol-creation.js +24 -0
  79. package/dist/src/symbols/custom-output-scope.d.ts +10 -0
  80. package/dist/src/symbols/custom-output-scope.d.ts.map +1 -0
  81. package/dist/src/symbols/custom-output-scope.js +25 -0
  82. package/dist/src/symbols/index.d.ts +7 -0
  83. package/dist/src/symbols/index.d.ts.map +1 -0
  84. package/dist/src/symbols/index.js +6 -0
  85. package/dist/src/symbols/python-member-scope.d.ts +7 -0
  86. package/dist/src/symbols/python-member-scope.d.ts.map +1 -0
  87. package/dist/src/symbols/python-member-scope.js +9 -0
  88. package/dist/src/symbols/python-module-scope.d.ts +25 -0
  89. package/dist/src/symbols/python-module-scope.d.ts.map +1 -0
  90. package/dist/src/symbols/python-module-scope.js +52 -0
  91. package/dist/src/symbols/python-output-symbol.d.ts +19 -0
  92. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -0
  93. package/dist/src/symbols/python-output-symbol.js +22 -0
  94. package/dist/src/symbols/reference.d.ts +4 -0
  95. package/dist/src/symbols/reference.d.ts.map +1 -0
  96. package/dist/src/symbols/reference.js +60 -0
  97. package/dist/src/symbols/scopes.d.ts +5 -0
  98. package/dist/src/symbols/scopes.d.ts.map +1 -0
  99. package/dist/src/symbols/scopes.js +4 -0
  100. package/dist/src/utils.d.ts +7 -0
  101. package/dist/src/utils.d.ts.map +1 -0
  102. package/dist/src/utils.js +12 -0
  103. package/dist/test/callsignatures.test.d.ts +2 -0
  104. package/dist/test/callsignatures.test.d.ts.map +1 -0
  105. package/dist/test/callsignatures.test.js +276 -0
  106. package/dist/test/classdeclarations.test.d.ts +2 -0
  107. package/dist/test/classdeclarations.test.d.ts.map +1 -0
  108. package/dist/test/classdeclarations.test.js +397 -0
  109. package/dist/test/classinstantiations.test.d.ts +2 -0
  110. package/dist/test/classinstantiations.test.d.ts.map +1 -0
  111. package/dist/test/classinstantiations.test.js +168 -0
  112. package/dist/test/enums.test.d.ts +2 -0
  113. package/dist/test/enums.test.d.ts.map +1 -0
  114. package/dist/test/enums.test.js +211 -0
  115. package/dist/test/externals.test.d.ts +2 -0
  116. package/dist/test/externals.test.d.ts.map +1 -0
  117. package/dist/test/externals.test.js +219 -0
  118. package/dist/test/functioncallexpressions.test.d.ts +2 -0
  119. package/dist/test/functioncallexpressions.test.d.ts.map +1 -0
  120. package/dist/test/functioncallexpressions.test.js +156 -0
  121. package/dist/test/functiondeclaration.test.d.ts +2 -0
  122. package/dist/test/functiondeclaration.test.d.ts.map +1 -0
  123. package/dist/test/functiondeclaration.test.js +363 -0
  124. package/dist/test/imports.test.d.ts +2 -0
  125. package/dist/test/imports.test.d.ts.map +1 -0
  126. package/dist/test/imports.test.js +262 -0
  127. package/dist/test/memberexpressions.test.d.ts +2 -0
  128. package/dist/test/memberexpressions.test.d.ts.map +1 -0
  129. package/dist/test/memberexpressions.test.js +879 -0
  130. package/dist/test/namepolicies.test.d.ts +2 -0
  131. package/dist/test/namepolicies.test.d.ts.map +1 -0
  132. package/dist/test/namepolicies.test.js +109 -0
  133. package/dist/test/pydocs.test.d.ts +2 -0
  134. package/dist/test/pydocs.test.d.ts.map +1 -0
  135. package/dist/test/pydocs.test.js +500 -0
  136. package/dist/test/references.test.d.ts +2 -0
  137. package/dist/test/references.test.d.ts.map +1 -0
  138. package/dist/test/references.test.js +49 -0
  139. package/dist/test/sourcefiles.test.d.ts +2 -0
  140. package/dist/test/sourcefiles.test.d.ts.map +1 -0
  141. package/dist/test/sourcefiles.test.js +198 -0
  142. package/dist/test/utils.d.ts +23 -0
  143. package/dist/test/utils.d.ts.map +1 -0
  144. package/dist/test/utils.js +88 -0
  145. package/dist/test/values.test.d.ts +2 -0
  146. package/dist/test/values.test.d.ts.map +1 -0
  147. package/dist/test/values.test.js +78 -0
  148. package/dist/test/variables.test.d.ts +2 -0
  149. package/dist/test/variables.test.d.ts.map +1 -0
  150. package/dist/test/variables.test.js +173 -0
  151. package/dist/tsconfig.tsbuildinfo +1 -0
  152. package/package.json +39 -0
  153. package/src/builtins/python.ts +20 -0
  154. package/src/components/Atom.tsx +76 -0
  155. package/src/components/CallSignature.tsx +251 -0
  156. package/src/components/ClassDeclaration.tsx +98 -0
  157. package/src/components/ClassInstantiation.tsx +54 -0
  158. package/src/components/Declaration.tsx +91 -0
  159. package/src/components/EnumDeclaration.tsx +291 -0
  160. package/src/components/EnumMember.tsx +92 -0
  161. package/src/components/FunctionCallExpression.tsx +36 -0
  162. package/src/components/FunctionDeclaration.tsx +121 -0
  163. package/src/components/ImportStatement.tsx +134 -0
  164. package/src/components/MemberExpression.tsx +456 -0
  165. package/src/components/NoNamePolicy.tsx +31 -0
  166. package/src/components/PyDoc.tsx +331 -0
  167. package/src/components/PythonBlock.tsx +26 -0
  168. package/src/components/Reference.tsx +21 -0
  169. package/src/components/SourceFile.tsx +93 -0
  170. package/src/components/StatementList.tsx +28 -0
  171. package/src/components/VariableDeclaration.tsx +180 -0
  172. package/src/components/index.ts +18 -0
  173. package/src/create-module.ts +102 -0
  174. package/src/index.ts +7 -0
  175. package/src/name-policy.ts +101 -0
  176. package/src/parameter-descriptor.ts +36 -0
  177. package/src/symbol-creation.ts +36 -0
  178. package/src/symbols/custom-output-scope.ts +35 -0
  179. package/src/symbols/index.ts +6 -0
  180. package/src/symbols/python-member-scope.ts +12 -0
  181. package/src/symbols/python-module-scope.ts +89 -0
  182. package/src/symbols/python-output-symbol.ts +36 -0
  183. package/src/symbols/reference.ts +99 -0
  184. package/src/symbols/scopes.ts +9 -0
  185. package/src/utils.ts +27 -0
  186. package/temp/api.json +7207 -0
  187. package/test/callsignatures.test.tsx +256 -0
  188. package/test/classdeclarations.test.tsx +320 -0
  189. package/test/classinstantiations.test.tsx +159 -0
  190. package/test/enums.test.tsx +203 -0
  191. package/test/externals.test.tsx +190 -0
  192. package/test/functioncallexpressions.test.tsx +145 -0
  193. package/test/functiondeclaration.test.tsx +327 -0
  194. package/test/imports.test.tsx +214 -0
  195. package/test/memberexpressions.test.tsx +725 -0
  196. package/test/namepolicies.test.tsx +109 -0
  197. package/test/pydocs.test.tsx +528 -0
  198. package/test/references.test.tsx +36 -0
  199. package/test/sourcefiles.test.tsx +131 -0
  200. package/test/utils.tsx +131 -0
  201. package/test/values.test.tsx +61 -0
  202. package/test/variables.test.tsx +153 -0
  203. package/tsconfig.json +12 -0
  204. package/tsdoc-metadata.json +11 -0
  205. package/vitest.config.ts +10 -0
  206. package/vitest.setup.ts +1 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=namepolicies.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namepolicies.test.d.ts","sourceRoot":"","sources":["../../test/namepolicies.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,109 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { d } from "@alloy-js/core/testing";
3
+ import { expect, it } from "vitest";
4
+ import { enumModule } from "../src/builtins/python.js";
5
+ import * as py from "../src/index.js";
6
+ import { toSourceText } from "./utils.js";
7
+ it("correct formatting of class name", () => {
8
+ const result = toSourceText([_$createComponent(py.ClassDeclaration, {
9
+ name: "a-really-WeirdClass-name"
10
+ })]);
11
+ const expected = d`
12
+ class AReallyWeirdClassName:
13
+ pass
14
+
15
+
16
+ `;
17
+ expect(result).toRenderTo(expected);
18
+ });
19
+ it("correct formatting of Enum name and EnumMember names", () => {
20
+ const result = toSourceText([_$createComponent(py.EnumDeclaration, {
21
+ name: "priority",
22
+ style: "functional",
23
+ members: [{
24
+ name: "high",
25
+ value: 1
26
+ }, {
27
+ name: "Medium",
28
+ value: 2
29
+ }, {
30
+ name: "lowValue",
31
+ value: 3
32
+ }]
33
+ })], {
34
+ externals: [enumModule]
35
+ });
36
+ const expected = d`
37
+ from enum import Enum
38
+
39
+ Priority = Enum('Priority', {'HIGH' : 1, 'MEDIUM' : 2, 'LOW_VALUE' : 3})
40
+ `;
41
+ expect(result).toRenderTo(expected);
42
+ });
43
+ it("renders a function with parameters", () => {
44
+ const result = toSourceText([_$createComponent(py.FunctionDeclaration, {
45
+ name: "quirklyNamed-Function",
46
+ parameters: [{
47
+ name: "a-parameter",
48
+ type: "int"
49
+ }],
50
+ args: true,
51
+ kwargs: true,
52
+ children: "print(x, y)"
53
+ })]);
54
+ expect(result).toRenderTo(d`
55
+ def quirkly_named_function(a_parameter: int, *args, **kwargs):
56
+ print(x, y)
57
+
58
+
59
+ `);
60
+ });
61
+ it("correct formatting of call signature parameters names", () => {
62
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
63
+ parameters: [{
64
+ name: "this-is-a-number",
65
+ type: "int"
66
+ }, {
67
+ name: "andThisIsADict",
68
+ type: "dict"
69
+ }]
70
+ })]);
71
+ expect(result).toRenderTo(`this_is_a_number: int, and_this_is_a_dict: dict`);
72
+ });
73
+ it("correct formatting of call statement vars", () => {
74
+ const result = toSourceText([_$createComponent(py.StatementList, {
75
+ get children() {
76
+ return _$createComponent(py.ClassInstantiation, {
77
+ target: "test",
78
+ get args() {
79
+ return [_$createComponent(py.VariableDeclaration, {
80
+ name: "this-is-a-long-name",
81
+ get initializer() {
82
+ return _$createComponent(py.Atom, {
83
+ jsValue: "A name"
84
+ });
85
+ },
86
+ callStatementVar: true
87
+ }), _$createComponent(py.VariableDeclaration, {
88
+ name: "andThisIsANumber",
89
+ get initializer() {
90
+ return _$createComponent(py.Atom, {
91
+ jsValue: 42
92
+ });
93
+ },
94
+ callStatementVar: true
95
+ })];
96
+ }
97
+ });
98
+ }
99
+ })]);
100
+ expect(result).toRenderTo(`test(this_is_a_long_name="A name", and_this_is_a_number=42)`);
101
+ });
102
+ it("correct formatting of variable name", () => {
103
+ const res = toSourceText([_$createComponent(py.VariableDeclaration, {
104
+ name: "myVar",
105
+ type: "int",
106
+ initializer: 42
107
+ })]);
108
+ expect(res).toBe(`my_var: int = 42`);
109
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pydocs.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pydocs.test.d.ts","sourceRoot":"","sources":["../../test/pydocs.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,500 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { Prose } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { describe, expect, it } from "vitest";
5
+ import { enumModule } from "../src/builtins/python.js";
6
+ import * as py from "../src/index.js";
7
+ import { toSourceText } from "./utils.js";
8
+ describe("PyDoc", () => {
9
+ it("formats properly", () => {
10
+ const res = toSourceText([_$createComponent(py.PyDoc, {
11
+ get children() {
12
+ return [_$createComponent(Prose, {
13
+ children: "This is an example of a long docstring that will be broken in lines. We will also render another paragraph after this one."
14
+ }), _$createComponent(Prose, {
15
+ children: "This is another paragraph, and there's a line break before it."
16
+ })];
17
+ }
18
+ })], {
19
+ printOptions: {
20
+ printWidth: 40
21
+ }
22
+ });
23
+ expect(res).toRenderTo(d`
24
+ """
25
+ This is an example of a long docstring
26
+ that will be broken in lines. We will
27
+ also render another paragraph after this
28
+ one.
29
+
30
+ This is another paragraph, and there's a
31
+ line break before it.
32
+ """
33
+
34
+
35
+ `);
36
+ });
37
+ });
38
+ describe("PyDocExample", () => {
39
+ it("creates docstring with a code sample", () => {
40
+ const res = toSourceText([_$createComponent(py.PyDoc, {
41
+ get children() {
42
+ return [_$createComponent(Prose, {
43
+ children: "This is an example of a docstring with a code sample."
44
+ }), _$createComponent(py.PyDocExample, {
45
+ children: "print(\"Hello world!\")"
46
+ })];
47
+ }
48
+ })], {
49
+ printOptions: {
50
+ printWidth: 40
51
+ }
52
+ });
53
+ expect(res).toRenderTo(d`
54
+ """
55
+ This is an example of a docstring with a
56
+ code sample.
57
+
58
+ >> print("Hello world!")
59
+ """
60
+
61
+
62
+ `);
63
+ });
64
+ it("creates docstring with more than one code sample", () => {
65
+ const res = toSourceText([_$createComponent(py.PyDoc, {
66
+ get children() {
67
+ return [_$createComponent(Prose, {
68
+ children: "This is an example of a docstring with a code sample."
69
+ }), _$createComponent(py.PyDocExample, {
70
+ children: "print(\"Hello world!\")"
71
+ }), _$createComponent(py.PyDocExample, {
72
+ children: "print(\"Hello world again!\")"
73
+ })];
74
+ }
75
+ })], {
76
+ printOptions: {
77
+ printWidth: 40
78
+ }
79
+ });
80
+ expect(res).toRenderTo(d`
81
+ """
82
+ This is an example of a docstring with a
83
+ code sample.
84
+
85
+ >> print("Hello world!")
86
+
87
+ >> print("Hello world again!")
88
+ """
89
+
90
+
91
+ `);
92
+ });
93
+ it("creates docstring with a multiline code sample", () => {
94
+ const res = toSourceText([_$createComponent(py.PyDoc, {
95
+ get children() {
96
+ return [_$createComponent(Prose, {
97
+ children: "This is an example of a docstring with a code sample."
98
+ }), _$createComponent(py.PyDocExample, {
99
+ get children() {
100
+ return ["print(\"Hello world!\")", _$createIntrinsic("br", {}), "x = \"Hello\"", _$createIntrinsic("br", {}), "print(x)"];
101
+ }
102
+ })];
103
+ }
104
+ })], {
105
+ printOptions: {
106
+ printWidth: 40
107
+ }
108
+ });
109
+ expect(res).toRenderTo(d`
110
+ """
111
+ This is an example of a docstring with a
112
+ code sample.
113
+
114
+ >> print("Hello world!")
115
+ >> x = "Hello"
116
+ >> print(x)
117
+ """
118
+
119
+
120
+ `);
121
+ });
122
+ });
123
+ describe("GoogleStyleDocParam", () => {
124
+ it("name only", () => {
125
+ const res = toSourceText([_$createComponent(py.PyDoc, {
126
+ get children() {
127
+ return _$createComponent(py.GoogleStyleDocParam, {
128
+ name: "somebody"
129
+ });
130
+ }
131
+ })]);
132
+ expect(res).toRenderTo(d`
133
+ """
134
+ somebody
135
+ """
136
+
137
+
138
+ `);
139
+ });
140
+ it("name and type", () => {
141
+ const res = toSourceText([_$createComponent(py.PyDoc, {
142
+ get children() {
143
+ return _$createComponent(py.GoogleStyleDocParam, {
144
+ name: "somebody",
145
+ type: "str"
146
+ });
147
+ }
148
+ })]);
149
+ expect(res).toRenderTo(d`
150
+ """
151
+ somebody (str)
152
+ """
153
+
154
+
155
+ `);
156
+ });
157
+ it("name, type and description", () => {
158
+ const res = toSourceText([_$createComponent(py.PyDoc, {
159
+ get children() {
160
+ return _$createComponent(py.GoogleStyleDocParam, {
161
+ name: "somebody",
162
+ type: "str",
163
+ children: "Somebody's name."
164
+ });
165
+ }
166
+ })]);
167
+ expect(res).toRenderTo(d`
168
+ """
169
+ somebody (str): Somebody's name.
170
+ """
171
+
172
+
173
+ `);
174
+ });
175
+ it("name, type, description, and optional", () => {
176
+ const res = toSourceText([_$createComponent(py.PyDoc, {
177
+ get children() {
178
+ return _$createComponent(py.GoogleStyleDocParam, {
179
+ name: "somebody",
180
+ type: "str",
181
+ optional: true,
182
+ children: "Somebody's name."
183
+ });
184
+ }
185
+ })]);
186
+ expect(res).toRenderTo(d`
187
+ """
188
+ somebody (str, optional): Somebody's name.
189
+ """
190
+
191
+
192
+ `);
193
+ });
194
+ it("name, type, description, and optional with default value", () => {
195
+ const res = toSourceText([_$createComponent(py.PyDoc, {
196
+ get children() {
197
+ return _$createComponent(py.GoogleStyleDocParam, {
198
+ name: "somebody",
199
+ type: "str",
200
+ optional: true,
201
+ defaultValue: "John Doe",
202
+ children: "Somebody's name."
203
+ });
204
+ }
205
+ })]);
206
+ expect(res).toRenderTo(d`
207
+ """
208
+ somebody (str, optional): Somebody's name. Defaults to \"John Doe\".
209
+ """
210
+
211
+
212
+ `);
213
+ });
214
+ it("name, type, description, and optional with default value with a very long description", () => {
215
+ const res = toSourceText([_$createComponent(py.PyDoc, {
216
+ get children() {
217
+ return [_$createComponent(py.GoogleStyleDocParam, {
218
+ name: "somebody",
219
+ type: "str",
220
+ optional: true,
221
+ defaultValue: "John Doe",
222
+ children: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., \"Agent X\"). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller."
223
+ }), _$createComponent(py.GoogleStyleDocParam, {
224
+ name: "somebody2",
225
+ type: "str",
226
+ children: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., \"Agent X\"). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller."
227
+ })];
228
+ }
229
+ })], {
230
+ printOptions: {
231
+ printWidth: 80
232
+ }
233
+ });
234
+ expect(res).toRenderTo(d`
235
+ """
236
+ somebody (str, optional): Somebody's name. This can be any string representing a
237
+ person, whether it's a first name, full name, nickname, or even a codename
238
+ (e.g., "Agent X"). It's used primarily for display purposes, logging, or
239
+ greeting messages and is not required to be unique or validated unless
240
+ specified by the caller. Defaults to \"John Doe\".
241
+
242
+ somebody2 (str): Somebody's name. This can be any string representing a person,
243
+ whether it's a first name, full name, nickname, or even a codename (e.g.,
244
+ "Agent X"). It's used primarily for display purposes, logging, or greeting
245
+ messages and is not required to be unique or validated unless specified by
246
+ the caller.
247
+ """
248
+
249
+
250
+ `);
251
+ });
252
+ it("name, type, description, and optional with default value with a description containing a linebreak", () => {
253
+ const res = toSourceText([_$createComponent(py.PyDoc, {
254
+ get children() {
255
+ return _$createComponent(py.GoogleStyleDocParam, {
256
+ name: "somebody",
257
+ type: "str",
258
+ optional: true,
259
+ defaultValue: "John Doe",
260
+ get children() {
261
+ return ["Somebody's name. This is one line", _$createIntrinsic("hbr", {}), "This is another line."];
262
+ }
263
+ });
264
+ }
265
+ })], {
266
+ printOptions: {
267
+ printWidth: 80
268
+ }
269
+ });
270
+ expect(res).toRenderTo(d`
271
+ """
272
+ somebody (str, optional): Somebody's name. This is one line
273
+ This is another line. Defaults to \"John Doe\".
274
+ """
275
+
276
+
277
+ `);
278
+ });
279
+ });
280
+ describe("Full example", () => {
281
+ it("renders correctly in a Class", () => {
282
+ const doc = _$createComponent(py.ClassDoc, {
283
+ get description() {
284
+ return [_$createComponent(Prose, {
285
+ children: "This is an example of a long docstring that will be broken in lines. We will also render another paragraph after this one."
286
+ }), _$createComponent(py.PyDocExample, {
287
+ get children() {
288
+ return ["print(\"Hello world!\")", _$createIntrinsic("br", {}), "x = \"Hello\"", _$createIntrinsic("br", {}), "print(x)"];
289
+ }
290
+ })];
291
+ },
292
+ parameters: [{
293
+ name: "somebody",
294
+ type: "str",
295
+ optional: true,
296
+ default: "John Doe",
297
+ doc: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., 'Agent X'). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller. Defaults to \"John Doe\"."
298
+ }, {
299
+ name: "somebody2",
300
+ type: "str",
301
+ doc: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., 'Agent X'). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller."
302
+ }],
303
+ style: "google"
304
+ });
305
+ const res = toSourceText([_$createComponent(py.ClassDeclaration, {
306
+ name: "A",
307
+ doc: doc,
308
+ get children() {
309
+ return _$createComponent(py.StatementList, {
310
+ get children() {
311
+ return [_$createComponent(py.VariableDeclaration, {
312
+ name: "just_name"
313
+ }), _$createComponent(py.VariableDeclaration, {
314
+ name: "name_and_type",
315
+ type: "number"
316
+ }), _$createComponent(py.VariableDeclaration, {
317
+ name: "name_type_and_value",
318
+ type: "number",
319
+ initializer: 12
320
+ })];
321
+ }
322
+ });
323
+ }
324
+ })], {
325
+ printOptions: {
326
+ printWidth: 80,
327
+ tabWidth: 4
328
+ }
329
+ });
330
+ expect(res).toRenderTo(d`
331
+ class A:
332
+ """
333
+ This is an example of a long docstring that will be broken in lines. We will
334
+ also render another paragraph after this one.
335
+
336
+ >> print("Hello world!")
337
+ >> x = "Hello"
338
+ >> print(x)
339
+
340
+ Args:
341
+ somebody (str, optional): Somebody's name. This can be any string
342
+ representing a person, whether it's a first name, full name,
343
+ nickname, or even a codename (e.g., 'Agent X'). It's used primarily
344
+ for display purposes, logging, or greeting messages and is not
345
+ required to be unique or validated unless specified by the caller.
346
+ Defaults to \"John Doe\".
347
+
348
+ somebody2 (str): Somebody's name. This can be any string representing a
349
+ person, whether it's a first name, full name, nickname, or even a
350
+ codename (e.g., 'Agent X'). It's used primarily for display
351
+ purposes, logging, or greeting messages and is not required to be
352
+ unique or validated unless specified by the caller.
353
+ """
354
+ just_name = None
355
+ name_and_type: number = None
356
+ name_type_and_value: number = 12
357
+
358
+
359
+ `);
360
+ });
361
+ it("renders correctly in a Function", () => {
362
+ const doc = _$createComponent(py.FunctionDoc, {
363
+ get description() {
364
+ return [_$createComponent(Prose, {
365
+ children: "This is an example of a long docstring that will be broken in lines. We will also render another paragraph after this one."
366
+ }), _$createComponent(py.PyDocExample, {
367
+ get children() {
368
+ return ["print(\"Hello world!\")", _$createIntrinsic("br", {}), "x = \"Hello\"", _$createIntrinsic("br", {}), "print(x)"];
369
+ }
370
+ })];
371
+ },
372
+ parameters: [{
373
+ name: "somebody",
374
+ type: "str",
375
+ optional: true,
376
+ default: "John Doe",
377
+ doc: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., 'Agent X'). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller. Defaults to \"John Doe\"."
378
+ }, {
379
+ name: "somebody2",
380
+ type: "str",
381
+ doc: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., 'Agent X'). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller."
382
+ }],
383
+ returns: "The return value. True for success, False otherwise.",
384
+ raises: ["ValueError: If somebody2 is equal to somebody."],
385
+ style: "google"
386
+ });
387
+ const res = toSourceText([_$createComponent(py.FunctionDeclaration, {
388
+ name: "some_function",
389
+ doc: doc,
390
+ get children() {
391
+ return _$createComponent(py.StatementList, {
392
+ get children() {
393
+ return [_$createComponent(py.VariableDeclaration, {
394
+ name: "just_name"
395
+ }), _$createComponent(py.VariableDeclaration, {
396
+ name: "name_and_type",
397
+ type: "number"
398
+ }), _$createComponent(py.VariableDeclaration, {
399
+ name: "name_type_and_value",
400
+ type: "number",
401
+ initializer: 12
402
+ })];
403
+ }
404
+ });
405
+ }
406
+ })], {
407
+ printOptions: {
408
+ printWidth: 80,
409
+ tabWidth: 4
410
+ }
411
+ });
412
+ expect(res).toRenderTo(d`
413
+ def some_function():
414
+ """
415
+ This is an example of a long docstring that will be broken in lines. We will
416
+ also render another paragraph after this one.
417
+
418
+ >> print("Hello world!")
419
+ >> x = "Hello"
420
+ >> print(x)
421
+
422
+ Args:
423
+ somebody (str, optional): Somebody's name. This can be any string
424
+ representing a person, whether it's a first name, full name,
425
+ nickname, or even a codename (e.g., 'Agent X'). It's used primarily
426
+ for display purposes, logging, or greeting messages and is not
427
+ required to be unique or validated unless specified by the caller.
428
+ Defaults to \"John Doe\".
429
+
430
+ somebody2 (str): Somebody's name. This can be any string representing a
431
+ person, whether it's a first name, full name, nickname, or even a
432
+ codename (e.g., 'Agent X'). It's used primarily for display
433
+ purposes, logging, or greeting messages and is not required to be
434
+ unique or validated unless specified by the caller.
435
+
436
+ Returns:
437
+ The return value. True for success, False otherwise.
438
+
439
+ Raises:
440
+ ValueError: If somebody2 is equal to somebody.
441
+ """
442
+ just_name = None
443
+ name_and_type: number = None
444
+ name_type_and_value: number = 12
445
+
446
+
447
+ `);
448
+ });
449
+ it("renders correctly in a Variable", () => {
450
+ const res = toSourceText([_$createComponent(py.VariableDeclaration, {
451
+ name: "myVar",
452
+ initializer: 42,
453
+ doc: "This is a very long docstring that will be broken in two lines when rendered. This part of the docstring will be in the second line."
454
+ })], {
455
+ printOptions: {
456
+ printWidth: 80,
457
+ tabWidth: 4
458
+ }
459
+ });
460
+ expect(res).toRenderTo(d`
461
+ # This is a very long docstring that will be broken in two lines when rendered.
462
+ # This part of the docstring will be in the second line.
463
+ my_var = 42
464
+ `);
465
+ });
466
+ it("classic enum with explicit values", () => {
467
+ const result = toSourceText([_$createComponent(py.EnumDeclaration, {
468
+ name: "Color",
469
+ baseType: "IntEnum",
470
+ members: [{
471
+ name: "RED",
472
+ value: "1",
473
+ doc: "The color red."
474
+ }, {
475
+ name: "GREEN",
476
+ value: "2",
477
+ doc: "The color green."
478
+ }, {
479
+ name: "BLUE",
480
+ value: "3",
481
+ doc: "The color blue."
482
+ }],
483
+ doc: "An enum representing colors."
484
+ })], {
485
+ externals: [enumModule]
486
+ });
487
+ const expected = d`
488
+ from enum import IntEnum
489
+
490
+ # An enum representing colors.
491
+ class Color(IntEnum):
492
+ RED = 1 # The color red.
493
+ GREEN = 2 # The color green.
494
+ BLUE = 3 # The color blue.
495
+
496
+
497
+ `;
498
+ expect(result).toRenderTo(expected);
499
+ });
500
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=references.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"references.test.d.ts","sourceRoot":"","sources":["../../test/references.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { refkey } from "@alloy-js/core";
3
+ import { describe, it } from "vitest";
4
+ import * as py from "../src/index.js";
5
+ import { assertFileContents, toSourceTextMultiple } from "./utils.js";
6
+ describe("Reference", () => {
7
+ it("Verifies that a reference is correctly resolved", () => {
8
+ const rk1 = refkey();
9
+ const res = toSourceTextMultiple([_$createComponent(py.SourceFile, {
10
+ path: "models.py",
11
+ get children() {
12
+ return _$createComponent(py.ClassDeclaration, {
13
+ name: "User",
14
+ refkey: rk1
15
+ });
16
+ }
17
+ }), _$createComponent(py.SourceFile, {
18
+ path: "services.py",
19
+ get children() {
20
+ return _$createComponent(py.VariableDeclaration, {
21
+ name: "current_user",
22
+ get type() {
23
+ return _$createComponent(py.Reference, {
24
+ refkey: rk1
25
+ });
26
+ },
27
+ get initializer() {
28
+ return _$createComponent(py.ClassInstantiation, {
29
+ target: "User",
30
+ args: ['"Marvin"']
31
+ });
32
+ }
33
+ });
34
+ }
35
+ })]);
36
+ assertFileContents(res, {
37
+ "models.py": `
38
+ class User:
39
+ pass
40
+
41
+ `,
42
+ "services.py": `
43
+ from models import User
44
+
45
+ current_user: User = User("Marvin")
46
+ `
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sourcefiles.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourcefiles.test.d.ts","sourceRoot":"","sources":["../../test/sourcefiles.test.tsx"],"names":[],"mappings":""}