@typespec/http-client-python 0.8.1 → 0.8.3-dev.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 (114) hide show
  1. package/README.md +86 -84
  2. package/dist/emitter/code-model.d.ts +1 -2
  3. package/dist/emitter/code-model.d.ts.map +1 -1
  4. package/dist/emitter/code-model.js +5 -2
  5. package/dist/emitter/code-model.js.map +1 -1
  6. package/dist/emitter/emitter.d.ts +0 -2
  7. package/dist/emitter/emitter.d.ts.map +1 -1
  8. package/dist/emitter/emitter.js +21 -32
  9. package/dist/emitter/emitter.js.map +1 -1
  10. package/dist/emitter/http.d.ts +4 -4
  11. package/dist/emitter/http.d.ts.map +1 -1
  12. package/dist/emitter/http.js.map +1 -1
  13. package/dist/emitter/index.d.ts +1 -1
  14. package/dist/emitter/index.d.ts.map +1 -1
  15. package/dist/emitter/index.js +1 -1
  16. package/dist/emitter/index.js.map +1 -1
  17. package/dist/emitter/lib.d.ts +65 -22
  18. package/dist/emitter/lib.d.ts.map +1 -1
  19. package/dist/emitter/lib.js +51 -26
  20. package/dist/emitter/lib.js.map +1 -1
  21. package/dist/emitter/types.d.ts +3 -3
  22. package/dist/emitter/types.d.ts.map +1 -1
  23. package/dist/emitter/types.js.map +1 -1
  24. package/dist/emitter/utils.d.ts +5 -4
  25. package/dist/emitter/utils.d.ts.map +1 -1
  26. package/dist/emitter/utils.js +31 -16
  27. package/dist/emitter/utils.js.map +1 -1
  28. package/emitter/src/code-model.ts +16 -25
  29. package/emitter/src/emitter.ts +35 -51
  30. package/emitter/src/http.ts +18 -21
  31. package/emitter/src/index.ts +1 -1
  32. package/emitter/src/lib.ts +62 -41
  33. package/emitter/src/types.ts +13 -23
  34. package/emitter/src/utils.ts +36 -25
  35. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  36. package/eng/scripts/Generate.ps1 +3 -0
  37. package/eng/scripts/ci/pylintrc +1 -1
  38. package/eng/scripts/ci/regenerate.ts +92 -44
  39. package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
  40. package/generator/build/lib/pygen/codegen/__init__.py +7 -23
  41. package/generator/build/lib/pygen/codegen/_utils.py +26 -2
  42. package/generator/build/lib/pygen/codegen/models/code_model.py +38 -5
  43. package/generator/build/lib/pygen/codegen/serializers/__init__.py +21 -15
  44. package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +5 -2
  45. package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +1 -1
  46. package/generator/build/lib/pygen/codegen/templates/client_container.py.jinja2 +3 -1
  47. package/generator/build/lib/pygen/codegen/templates/config_container.py.jinja2 +3 -1
  48. package/generator/build/lib/pygen/codegen/templates/conftest.py.jinja2 +3 -1
  49. package/generator/build/lib/pygen/codegen/templates/enum_container.py.jinja2 +3 -1
  50. package/generator/build/lib/pygen/codegen/templates/init.py.jinja2 +3 -1
  51. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +3 -5
  52. package/generator/build/lib/pygen/codegen/templates/model_container.py.jinja2 +3 -1
  53. package/generator/build/lib/pygen/codegen/templates/model_init.py.jinja2 +3 -1
  54. package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +3 -1
  55. package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +3 -1
  56. package/generator/build/lib/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -21
  57. package/generator/build/lib/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +6 -2
  58. package/generator/build/lib/pygen/codegen/templates/packaging_templates/README.md.jinja2 +5 -5
  59. package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +3 -3
  60. package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +20 -9
  61. package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +9 -4
  62. package/generator/build/lib/pygen/codegen/templates/request_builders.py.jinja2 +3 -1
  63. package/generator/build/lib/pygen/codegen/templates/rest_init.py.jinja2 +3 -1
  64. package/generator/build/lib/pygen/codegen/templates/sample.py.jinja2 +3 -1
  65. package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +4 -25
  66. package/generator/build/lib/pygen/codegen/templates/test.py.jinja2 +3 -1
  67. package/generator/build/lib/pygen/codegen/templates/testpreparer.py.jinja2 +3 -1
  68. package/generator/build/lib/pygen/codegen/templates/types.py.jinja2 +3 -1
  69. package/generator/build/lib/pygen/codegen/templates/validation.py.jinja2 +3 -1
  70. package/generator/build/lib/pygen/codegen/templates/vendor.py.jinja2 +3 -1
  71. package/generator/build/lib/pygen/codegen/templates/version.py.jinja2 +3 -1
  72. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  73. package/generator/pygen/codegen/__init__.py +7 -23
  74. package/generator/pygen/codegen/_utils.py +26 -2
  75. package/generator/pygen/codegen/models/code_model.py +38 -5
  76. package/generator/pygen/codegen/serializers/__init__.py +21 -15
  77. package/generator/pygen/codegen/serializers/general_serializer.py +5 -2
  78. package/generator/pygen/codegen/serializers/test_serializer.py +1 -1
  79. package/generator/pygen/codegen/templates/client_container.py.jinja2 +3 -1
  80. package/generator/pygen/codegen/templates/config_container.py.jinja2 +3 -1
  81. package/generator/pygen/codegen/templates/conftest.py.jinja2 +3 -1
  82. package/generator/pygen/codegen/templates/enum_container.py.jinja2 +3 -1
  83. package/generator/pygen/codegen/templates/init.py.jinja2 +3 -1
  84. package/generator/pygen/codegen/templates/model_base.py.jinja2 +3 -5
  85. package/generator/pygen/codegen/templates/model_container.py.jinja2 +3 -1
  86. package/generator/pygen/codegen/templates/model_init.py.jinja2 +3 -1
  87. package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +3 -1
  88. package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +3 -1
  89. package/generator/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -21
  90. package/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +6 -2
  91. package/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +5 -5
  92. package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +3 -3
  93. package/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +20 -9
  94. package/generator/pygen/codegen/templates/patch.py.jinja2 +9 -4
  95. package/generator/pygen/codegen/templates/request_builders.py.jinja2 +3 -1
  96. package/generator/pygen/codegen/templates/rest_init.py.jinja2 +3 -1
  97. package/generator/pygen/codegen/templates/sample.py.jinja2 +3 -1
  98. package/generator/pygen/codegen/templates/serialization.py.jinja2 +4 -25
  99. package/generator/pygen/codegen/templates/test.py.jinja2 +3 -1
  100. package/generator/pygen/codegen/templates/testpreparer.py.jinja2 +3 -1
  101. package/generator/pygen/codegen/templates/types.py.jinja2 +3 -1
  102. package/generator/pygen/codegen/templates/validation.py.jinja2 +3 -1
  103. package/generator/pygen/codegen/templates/vendor.py.jinja2 +3 -1
  104. package/generator/pygen/codegen/templates/version.py.jinja2 +3 -1
  105. package/generator/pygen.egg-info/PKG-INFO +2 -2
  106. package/generator/pygen.egg-info/requires.txt +2 -2
  107. package/generator/setup.py +2 -2
  108. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_lro_rpc_async.py +2 -2
  109. package/generator/test/azure/mock_api_tests/test_azure_core_lro_rpc.py +1 -1
  110. package/generator/test/azure/requirements.txt +2 -1
  111. package/generator/test/generic_mock_api_tests/asynctests/test_streaming_jsonl_async.py +27 -0
  112. package/generator/test/generic_mock_api_tests/test_streaming_jsonl.py +25 -0
  113. package/generator/test/unbranded/requirements.txt +1 -0
  114. package/package.json +13 -6
@@ -1,5 +1,4 @@
1
1
  import {
2
- SdkApiVersionParameter,
3
2
  SdkBasicServiceMethod,
4
3
  SdkClientType,
5
4
  SdkCredentialParameter,
@@ -33,15 +32,10 @@ import {
33
32
  simpleTypesMap,
34
33
  typesMap,
35
34
  } from "./types.js";
36
- import {
37
- emitParamBase,
38
- getClientNamespace,
39
- getImplementation,
40
- removeUnderscoresFromNamespace,
41
- } from "./utils.js";
35
+ import { emitParamBase, getClientNamespace, getImplementation, getRootNamespace } from "./utils.js";
42
36
 
43
37
  function emitBasicMethod<TServiceOperation extends SdkServiceOperation>(
44
- context: PythonSdkContext<TServiceOperation>,
38
+ context: PythonSdkContext,
45
39
  rootClient: SdkClientType<TServiceOperation>,
46
40
  method: SdkBasicServiceMethod<TServiceOperation>,
47
41
  operationGroupName: string,
@@ -57,7 +51,7 @@ function emitBasicMethod<TServiceOperation extends SdkServiceOperation>(
57
51
  }
58
52
 
59
53
  function emitLroMethod<TServiceOperation extends SdkServiceOperation>(
60
- context: PythonSdkContext<TServiceOperation>,
54
+ context: PythonSdkContext,
61
55
  rootClient: SdkClientType<TServiceOperation>,
62
56
  method: SdkLroServiceMethod<TServiceOperation>,
63
57
  operationGroupName: string,
@@ -73,7 +67,7 @@ function emitLroMethod<TServiceOperation extends SdkServiceOperation>(
73
67
  }
74
68
 
75
69
  function emitPagingMethod<TServiceOperation extends SdkServiceOperation>(
76
- context: PythonSdkContext<TServiceOperation>,
70
+ context: PythonSdkContext,
77
71
  rootClient: SdkClientType<TServiceOperation>,
78
72
  method: SdkPagingServiceMethod<TServiceOperation>,
79
73
  operationGroupName: string,
@@ -89,7 +83,7 @@ function emitPagingMethod<TServiceOperation extends SdkServiceOperation>(
89
83
  }
90
84
 
91
85
  function emitLroPagingMethod<TServiceOperation extends SdkServiceOperation>(
92
- context: PythonSdkContext<TServiceOperation>,
86
+ context: PythonSdkContext,
93
87
  rootClient: SdkClientType<TServiceOperation>,
94
88
  method: SdkLroPagingServiceMethod<TServiceOperation>,
95
89
  operationGroupName: string,
@@ -104,13 +98,9 @@ function emitLroPagingMethod<TServiceOperation extends SdkServiceOperation>(
104
98
  }
105
99
  }
106
100
 
107
- function emitMethodParameter<TServiceOperation extends SdkServiceOperation>(
108
- context: PythonSdkContext<TServiceOperation>,
109
- parameter:
110
- | SdkEndpointParameter
111
- | SdkCredentialParameter
112
- | SdkMethodParameter
113
- | SdkApiVersionParameter,
101
+ function emitMethodParameter(
102
+ context: PythonSdkContext,
103
+ parameter: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter,
114
104
  ): Record<string, any>[] {
115
105
  if (parameter.kind === "endpoint") {
116
106
  if (parameter.type.kind === "union") {
@@ -163,7 +153,7 @@ function emitMethodParameter<TServiceOperation extends SdkServiceOperation>(
163
153
  }
164
154
 
165
155
  function emitMethod<TServiceOperation extends SdkServiceOperation>(
166
- context: PythonSdkContext<TServiceOperation>,
156
+ context: PythonSdkContext,
167
157
  rootClient: SdkClientType<TServiceOperation>,
168
158
  method: SdkServiceMethod<TServiceOperation>,
169
159
  operationGroupName: string,
@@ -181,7 +171,7 @@ function emitMethod<TServiceOperation extends SdkServiceOperation>(
181
171
  }
182
172
 
183
173
  function emitOperationGroups<TServiceOperation extends SdkServiceOperation>(
184
- context: PythonSdkContext<TServiceOperation>,
174
+ context: PythonSdkContext,
185
175
  client: SdkClientType<TServiceOperation>,
186
176
  rootClient: SdkClientType<TServiceOperation>,
187
177
  prefix: string,
@@ -237,7 +227,7 @@ function emitOperationGroups<TServiceOperation extends SdkServiceOperation>(
237
227
  }
238
228
 
239
229
  function emitClient<TServiceOperation extends SdkServiceOperation>(
240
- context: PythonSdkContext<TServiceOperation>,
230
+ context: PythonSdkContext,
241
231
  client: SdkClientType<TServiceOperation>,
242
232
  ): Record<string, any> {
243
233
  if (client.clientInitialization) {
@@ -280,15 +270,16 @@ function onlyUsedByPolling(usage: UsageFlags): boolean {
280
270
  );
281
271
  }
282
272
 
283
- export function emitCodeModel<TServiceOperation extends SdkServiceOperation>(
284
- sdkContext: PythonSdkContext<TServiceOperation>,
285
- ) {
273
+ export function emitCodeModel(sdkContext: PythonSdkContext) {
286
274
  // Get types
287
275
  const sdkPackage = sdkContext.sdkPackage;
288
276
  const codeModel: Record<string, any> = {
289
- namespace: removeUnderscoresFromNamespace(sdkPackage.rootNamespace).toLowerCase(),
277
+ namespace: getRootNamespace(sdkContext),
290
278
  clients: [],
291
279
  };
280
+ if (sdkPackage.licenseInfo) {
281
+ codeModel["licenseInfo"] = sdkPackage.licenseInfo;
282
+ }
292
283
  for (const client of sdkPackage.clients) {
293
284
  codeModel["clients"].push(emitClient(sdkContext, client));
294
285
  }
@@ -1,9 +1,4 @@
1
- import {
2
- createSdkContext,
3
- SdkContext,
4
- SdkHttpOperation,
5
- SdkServiceOperation,
6
- } from "@azure-tools/typespec-client-generator-core";
1
+ import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
7
2
  import { EmitContext, NoTarget } from "@typespec/compiler";
8
3
  import { execSync } from "child_process";
9
4
  import fs from "fs";
@@ -16,60 +11,53 @@ import { saveCodeModelAsYaml } from "./external-process.js";
16
11
  import { PythonEmitterOptions, PythonSdkContext, reportDiagnostic } from "./lib.js";
17
12
  import { runPython3 } from "./run-python3.js";
18
13
  import { disableGenerationMap, simpleTypesMap, typesMap } from "./types.js";
19
- import { md2Rst, removeUnderscoresFromNamespace } from "./utils.js";
14
+ import { getRootNamespace, md2Rst } from "./utils.js";
20
15
 
21
- export function getModelsMode(context: SdkContext): "dpg" | "none" {
22
- const specifiedModelsMode = context.emitContext.options["models-mode"];
23
- if (specifiedModelsMode) {
24
- const modelModes = ["dpg", "none"];
25
- if (modelModes.includes(specifiedModelsMode)) {
26
- return specifiedModelsMode;
27
- }
28
- reportDiagnostic(context.program, {
29
- code: "invalid-models-mode",
30
- target: NoTarget,
31
- format: { inValidValue: specifiedModelsMode },
32
- });
33
- }
34
- return "dpg";
35
- }
36
-
37
- function addDefaultOptions(sdkContext: SdkContext) {
16
+ function addDefaultOptions(sdkContext: PythonSdkContext) {
38
17
  const defaultOptions = {
39
18
  "package-version": "1.0.0b1",
40
19
  "generate-packaging-files": true,
41
- flavor: undefined,
42
20
  };
43
21
  sdkContext.emitContext.options = {
44
22
  ...defaultOptions,
45
23
  ...sdkContext.emitContext.options,
46
24
  };
47
25
  const options = sdkContext.emitContext.options;
48
- options["models-mode"] = getModelsMode(sdkContext);
49
- if (options["generate-packaging-files"]) {
50
- options["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane";
51
- }
52
26
  if (!options["package-name"]) {
53
- options["package-name"] = removeUnderscoresFromNamespace(
54
- (sdkContext.sdkPackage.rootNamespace ?? "").toLowerCase(),
55
- ).replace(/\./g, "-");
27
+ const namespace = getRootNamespace(sdkContext);
28
+ const packageName = namespace.replace(/\./g, "-");
29
+ reportDiagnostic(sdkContext.program, {
30
+ code: "no-package-name",
31
+ target: NoTarget,
32
+ format: { namespace, packageName },
33
+ });
34
+ options["package-name"] = packageName;
56
35
  }
57
- if (options.flavor !== "azure") {
36
+ if ((options as any).flavor !== "azure") {
58
37
  // if they pass in a flavor other than azure, we want to ignore the value
59
- options.flavor = undefined;
38
+ (options as any).flavor = undefined;
60
39
  }
61
- if (!options.flavor && sdkContext.emitContext.emitterOutputDir.includes("azure")) {
62
- options.flavor = "azure";
40
+ if (
41
+ (options as any).flavor === undefined &&
42
+ sdkContext.emitContext.emitterOutputDir.includes("azure")
43
+ ) {
44
+ (options as any).flavor = "azure";
63
45
  }
64
- if (options["enable-typespec-namespace"] === undefined) {
65
- options["enable-typespec-namespace"] = options.flavor !== "azure";
46
+
47
+ if (
48
+ options["package-pprint-name"] !== undefined &&
49
+ !options["package-pprint-name"].startsWith('"')
50
+ ) {
51
+ options["package-pprint-name"] = options["use-pyodide"]
52
+ ? `${options["package-pprint-name"]}`
53
+ : `"${options["package-pprint-name"]}"`;
66
54
  }
67
55
  }
68
56
 
69
- async function createPythonSdkContext<TServiceOperation extends SdkServiceOperation>(
57
+ async function createPythonSdkContext(
70
58
  context: EmitContext<PythonEmitterOptions>,
71
- ): Promise<PythonSdkContext<TServiceOperation>> {
72
- const sdkContext = await createSdkContext<PythonEmitterOptions, TServiceOperation>(
59
+ ): Promise<PythonSdkContext> {
60
+ const sdkContext = await createSdkContext<PythonEmitterOptions>(
73
61
  context,
74
62
  "@azure-tools/typespec-python",
75
63
  );
@@ -146,7 +134,7 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
146
134
  cleanAllCache();
147
135
 
148
136
  const program = context.program;
149
- const sdkContext = await createPythonSdkContext<SdkHttpOperation>(context);
137
+ const sdkContext = await createPythonSdkContext(context);
150
138
  const root = path.join(dirname(fileURLToPath(import.meta.url)), "..", "..");
151
139
  const outputDir = context.emitterOutputDir;
152
140
  addDefaultOptions(sdkContext);
@@ -173,25 +161,21 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
173
161
  commandArgs["packaging-files-config"] = keyValuePairs.join("|");
174
162
  resolvedOptions["packaging-files-config"] = undefined;
175
163
  }
176
- if (
177
- resolvedOptions["package-pprint-name"] !== undefined &&
178
- !resolvedOptions["package-pprint-name"].startsWith('"')
179
- ) {
180
- resolvedOptions["package-pprint-name"] = resolvedOptions["use-pyodide"]
181
- ? `${resolvedOptions["package-pprint-name"]}`
182
- : `"${resolvedOptions["package-pprint-name"]}"`;
183
- }
184
164
 
185
165
  for (const [key, value] of Object.entries(resolvedOptions)) {
186
166
  commandArgs[key] = value;
187
167
  }
168
+ if (resolvedOptions["generate-packaging-files"]) {
169
+ commandArgs["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane";
170
+ }
188
171
  if (sdkContext.arm === true) {
189
172
  commandArgs["azure-arm"] = "true";
190
173
  }
191
- if (resolvedOptions.flavor === "azure") {
174
+ if ((resolvedOptions as any).flavor === "azure") {
192
175
  commandArgs["emit-cross-language-definition-file"] = "true";
193
176
  }
194
177
  commandArgs["from-typespec"] = "true";
178
+ commandArgs["models-mode"] = (resolvedOptions as any)["models-mode"] ?? "dpg";
195
179
 
196
180
  if (!program.compilerOptions.noEmit && !program.hasError()) {
197
181
  // if not using pyodide and there's no venv, we try to create venv
@@ -48,7 +48,7 @@ function arrayToRecord(examples: SdkHttpOperationExample[] | undefined): Record<
48
48
  }
49
49
 
50
50
  export function emitBasicHttpMethod(
51
- context: PythonSdkContext<SdkHttpOperation>,
51
+ context: PythonSdkContext,
52
52
  rootClient: SdkClientType<SdkHttpOperation>,
53
53
  method: SdkBasicServiceMethod<SdkHttpOperation>,
54
54
  operationGroupName: string,
@@ -65,7 +65,7 @@ export function emitBasicHttpMethod(
65
65
  }
66
66
 
67
67
  function emitInitialLroHttpMethod(
68
- context: PythonSdkContext<SdkHttpOperation>,
68
+ context: PythonSdkContext,
69
69
  rootClient: SdkClientType<SdkHttpOperation>,
70
70
  method: SdkLroServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
71
71
  operationGroupName: string,
@@ -82,7 +82,7 @@ function emitInitialLroHttpMethod(
82
82
  }
83
83
 
84
84
  function addLroInformation(
85
- context: PythonSdkContext<SdkHttpOperation>,
85
+ context: PythonSdkContext,
86
86
  rootClient: SdkClientType<SdkHttpOperation>,
87
87
  method: SdkLroServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
88
88
  operationGroupName: string,
@@ -110,7 +110,7 @@ function getWireNameFromPropertySegments(segments: SdkModelPropertyType[]): stri
110
110
  }
111
111
 
112
112
  function getWireNameWithDiagnostics(
113
- context: PythonSdkContext<SdkHttpOperation>,
113
+ context: PythonSdkContext,
114
114
  segments: SdkModelPropertyType[] | undefined,
115
115
  code: "invalid-paging-items" | "invalid-next-link" | "invalid-lro-result",
116
116
  method?: SdkServiceMethod<SdkHttpOperation>,
@@ -132,7 +132,7 @@ function getWireNameWithDiagnostics(
132
132
  }
133
133
 
134
134
  function buildContinuationToken(
135
- context: PythonSdkContext<SdkHttpOperation>,
135
+ context: PythonSdkContext,
136
136
  method: SdkPagingServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
137
137
  segments: SdkModelPropertyType[],
138
138
  input: boolean = true,
@@ -166,7 +166,7 @@ function buildContinuationToken(
166
166
  }
167
167
 
168
168
  function buildAllContinuationToken(
169
- context: PythonSdkContext<SdkHttpOperation>,
169
+ context: PythonSdkContext,
170
170
  method: SdkPagingServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
171
171
  ): Record<string, any> {
172
172
  const parameterSegments = method.pagingMetadata.continuationTokenParameterSegments ?? [];
@@ -181,7 +181,7 @@ function buildAllContinuationToken(
181
181
  }
182
182
 
183
183
  function addPagingInformation(
184
- context: PythonSdkContext<SdkHttpOperation>,
184
+ context: PythonSdkContext,
185
185
  rootClient: SdkClientType<SdkHttpOperation>,
186
186
  method: SdkPagingServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
187
187
  operationGroupName: string,
@@ -223,7 +223,7 @@ function addPagingInformation(
223
223
  }
224
224
 
225
225
  export function emitLroHttpMethod(
226
- context: PythonSdkContext<SdkHttpOperation>,
226
+ context: PythonSdkContext,
227
227
  rootClient: SdkClientType<SdkHttpOperation>,
228
228
  method: SdkLroServiceMethod<SdkHttpOperation>,
229
229
  operationGroupName: string,
@@ -233,7 +233,7 @@ export function emitLroHttpMethod(
233
233
  }
234
234
 
235
235
  export function emitPagingHttpMethod(
236
- context: PythonSdkContext<SdkHttpOperation>,
236
+ context: PythonSdkContext,
237
237
  rootClient: SdkClientType<SdkHttpOperation>,
238
238
  method: SdkPagingServiceMethod<SdkHttpOperation>,
239
239
  operationGroupName: string,
@@ -243,7 +243,7 @@ export function emitPagingHttpMethod(
243
243
  }
244
244
 
245
245
  export function emitLroPagingHttpMethod(
246
- context: PythonSdkContext<SdkHttpOperation>,
246
+ context: PythonSdkContext,
247
247
  rootClient: SdkClientType<SdkHttpOperation>,
248
248
  method: SdkLroPagingServiceMethod<SdkHttpOperation>,
249
249
  operationGroupName: string,
@@ -254,7 +254,7 @@ export function emitLroPagingHttpMethod(
254
254
  }
255
255
 
256
256
  function emitHttpOperation(
257
- context: PythonSdkContext<SdkHttpOperation>,
257
+ context: PythonSdkContext,
258
258
  rootClient: SdkClientType<SdkHttpOperation>,
259
259
  operationGroupName: string,
260
260
  operation: SdkHttpOperation,
@@ -339,10 +339,7 @@ function emitFlattenedParameter(
339
339
  };
340
340
  }
341
341
 
342
- function emitHttpPathParameter(
343
- context: PythonSdkContext<SdkHttpOperation>,
344
- parameter: SdkPathParameter,
345
- ) {
342
+ function emitHttpPathParameter(context: PythonSdkContext, parameter: SdkPathParameter) {
346
343
  const base = emitParamBase(context, parameter);
347
344
  return {
348
345
  ...base,
@@ -354,7 +351,7 @@ function emitHttpPathParameter(
354
351
  };
355
352
  }
356
353
  function emitHttpHeaderParameter(
357
- context: PythonSdkContext<SdkHttpOperation>,
354
+ context: PythonSdkContext,
358
355
  parameter: SdkHeaderParameter,
359
356
  method: SdkServiceMethod<SdkHttpOperation>,
360
357
  ): Record<string, any> {
@@ -380,7 +377,7 @@ function emitHttpHeaderParameter(
380
377
  }
381
378
 
382
379
  function emitHttpQueryParameter(
383
- context: PythonSdkContext<SdkHttpOperation>,
380
+ context: PythonSdkContext,
384
381
  parameter: SdkQueryParameter,
385
382
  method: SdkServiceMethod<SdkHttpOperation>,
386
383
  ): Record<string, any> {
@@ -398,7 +395,7 @@ function emitHttpQueryParameter(
398
395
  }
399
396
 
400
397
  function emitHttpParameters(
401
- context: PythonSdkContext<SdkHttpOperation>,
398
+ context: PythonSdkContext,
402
399
  rootClient: SdkClientType<SdkHttpOperation>,
403
400
  operation: SdkHttpOperation,
404
401
  method: SdkServiceMethod<SdkHttpOperation>,
@@ -421,7 +418,7 @@ function emitHttpParameters(
421
418
  }
422
419
 
423
420
  function emitHttpBodyParameter(
424
- context: PythonSdkContext<SdkHttpOperation>,
421
+ context: PythonSdkContext,
425
422
  bodyParam?: SdkBodyParameter,
426
423
  ): Record<string, any> | undefined {
427
424
  if (bodyParam === undefined) return undefined;
@@ -438,7 +435,7 @@ function emitHttpBodyParameter(
438
435
  }
439
436
 
440
437
  function emitHttpResponse(
441
- context: PythonSdkContext<SdkHttpOperation>,
438
+ context: PythonSdkContext,
442
439
  statusCodes: HttpStatusCodeRange | number | "*",
443
440
  response: SdkHttpResponse | SdkHttpErrorResponse,
444
441
  method?: SdkServiceMethod<SdkHttpOperation>,
@@ -479,7 +476,7 @@ function emitHttpResponse(
479
476
  }
480
477
 
481
478
  function emitHttpResponseHeader(
482
- context: PythonSdkContext<SdkHttpOperation>,
479
+ context: PythonSdkContext,
483
480
  header: SdkServiceResponseHeader,
484
481
  ): Record<string, any> {
485
482
  return {
@@ -1,2 +1,2 @@
1
1
  export * from "./emitter.js";
2
- export { $lib } from "./lib.js";
2
+ export { $lib, PythonEmitterOptions, PythonEmitterOptionsSchema } from "./lib.js";
@@ -1,54 +1,75 @@
1
- import { SdkContext, SdkServiceOperation } from "@azure-tools/typespec-client-generator-core";
1
+ import {
2
+ SdkContext,
3
+ SdkEmitterOptions,
4
+ SdkEmitterOptionsSchema,
5
+ } from "@azure-tools/typespec-client-generator-core";
2
6
  import { createTypeSpecLibrary, JSONSchemaType, paramMessage } from "@typespec/compiler";
3
7
 
4
- export interface PythonEmitterOptions {
8
+ export interface PythonEmitterOptions extends SdkEmitterOptions {
5
9
  "package-version"?: string;
6
10
  "package-name"?: string;
7
- "output-dir"?: string;
8
11
  "generate-packaging-files"?: boolean;
9
12
  "packaging-files-dir"?: string;
10
13
  "packaging-files-config"?: object;
11
14
  "package-pprint-name"?: string;
12
15
  "head-as-boolean"?: boolean;
13
- "models-mode"?: string;
14
- tracing?: boolean;
15
- "company-name"?: string;
16
- "generate-test"?: boolean;
17
- debug?: boolean;
18
- flavor?: "azure";
19
- "examples-dir"?: string;
20
- // If true, package namespace will respect the typespec namespace. Otherwise,
21
- // package namespace is always aligned with package name.
22
- "enable-typespec-namespace"?: boolean;
23
16
  "use-pyodide"?: boolean;
24
17
  }
25
18
 
26
- export interface PythonSdkContext<TServiceOperation extends SdkServiceOperation>
27
- extends SdkContext<PythonEmitterOptions, TServiceOperation> {
19
+ export interface PythonSdkContext extends SdkContext<PythonEmitterOptions> {
28
20
  __endpointPathParameters: Record<string, any>[];
29
21
  }
30
22
 
31
- const EmitterOptionsSchema: JSONSchemaType<PythonEmitterOptions> = {
23
+ export const PythonEmitterOptionsSchema: JSONSchemaType<PythonEmitterOptions> = {
32
24
  type: "object",
33
25
  additionalProperties: true,
34
26
  properties: {
35
- "package-version": { type: "string", nullable: true },
36
- "package-name": { type: "string", nullable: true },
37
- "output-dir": { type: "string", nullable: true },
38
- "generate-packaging-files": { type: "boolean", nullable: true },
39
- "packaging-files-dir": { type: "string", nullable: true },
40
- "packaging-files-config": { type: "object", nullable: true },
41
- "package-pprint-name": { type: "string", nullable: true },
42
- "head-as-boolean": { type: "boolean", nullable: true },
43
- "models-mode": { type: "string", nullable: true },
44
- tracing: { type: "boolean", nullable: true },
45
- "company-name": { type: "string", nullable: true },
46
- "generate-test": { type: "boolean", nullable: true },
47
- debug: { type: "boolean", nullable: true },
48
- flavor: { type: "string", nullable: true },
49
- "examples-dir": { type: "string", nullable: true, format: "absolute-path" },
50
- "enable-typespec-namespace": { type: "boolean", nullable: true },
51
- "use-pyodide": { type: "boolean", nullable: true },
27
+ "package-version": {
28
+ type: "string",
29
+ nullable: true,
30
+ description: "The version of the package.",
31
+ },
32
+ "package-name": {
33
+ type: "string",
34
+ nullable: true,
35
+ description: "The name of the package.",
36
+ },
37
+ "generate-packaging-files": {
38
+ type: "boolean",
39
+ nullable: true,
40
+ description:
41
+ "Whether to generate packaging files. Packaging files refer to the `setup.py`, `README`, and other files that are needed to package your code.",
42
+ },
43
+ "packaging-files-dir": {
44
+ type: "string",
45
+ nullable: true,
46
+ description:
47
+ "If you are using a custom packaging files directory, you can specify it here. We won't generate with the default packaging files we have.",
48
+ },
49
+ "packaging-files-config": {
50
+ type: "object",
51
+ nullable: true,
52
+ description:
53
+ "If you are using a custom packaging files directory, and have additional configuration parameters you want to pass in during generation, you can specify it here. Only applicable if `packaging-files-dir` is set.",
54
+ },
55
+ "package-pprint-name": {
56
+ type: "string",
57
+ nullable: true,
58
+ description:
59
+ "The name of the package to be used in pretty-printing. Will be the name of the package in `README` and pprinting of `setup.py`.",
60
+ },
61
+ "head-as-boolean": {
62
+ type: "boolean",
63
+ nullable: true,
64
+ description: "Whether to return responses from HEAD requests as boolean. Defaults to `true`.",
65
+ },
66
+ "use-pyodide": {
67
+ type: "boolean",
68
+ nullable: true,
69
+ description:
70
+ "Whether to generate using `pyodide` instead of `python`. If there is no python installed on your device, we will default to using pyodide to generate the code.",
71
+ },
72
+ ...SdkEmitterOptionsSchema.properties,
52
73
  },
53
74
  required: [],
54
75
  };
@@ -63,12 +84,6 @@ const libDef = {
63
84
  default: paramMessage`Can't generate Python client code from this TypeSpec. Please open an issue on https://github.com/microsoft/typespec'.${"stack"}`,
64
85
  },
65
86
  },
66
- "invalid-models-mode": {
67
- severity: "error",
68
- messages: {
69
- default: paramMessage`Invalid value '${"inValidValue"}' for 'models-mode' of tspconfig.yaml and expected values are 'dpg'/'none'.`,
70
- },
71
- },
72
87
  "pyodide-flag-conflict": {
73
88
  severity: "error",
74
89
  messages: {
@@ -77,6 +92,12 @@ const libDef = {
77
92
  },
78
93
  },
79
94
  // warning
95
+ "no-package-name": {
96
+ severity: "warning",
97
+ messages: {
98
+ default: paramMessage`No package-name configured in tspconfig.yaml and will infer package-name '${"packageName"}' from namespace '${"namespace"}'.`,
99
+ },
100
+ },
80
101
  "no-valid-client": {
81
102
  severity: "warning",
82
103
  messages: {
@@ -109,9 +130,9 @@ const libDef = {
109
130
  },
110
131
  },
111
132
  emitter: {
112
- options: EmitterOptionsSchema as JSONSchemaType<PythonEmitterOptions>,
133
+ options: PythonEmitterOptionsSchema,
113
134
  },
114
135
  } as const;
115
136
 
116
137
  export const $lib = createTypeSpecLibrary(libDef);
117
- export const { reportDiagnostic, createStateSymbol, getTracer } = $lib;
138
+ export const { reportDiagnostic, createDiagnostic } = $lib;
@@ -11,7 +11,6 @@ import {
11
11
  SdkEnumType,
12
12
  SdkEnumValueType,
13
13
  SdkModelType,
14
- SdkServiceOperation,
15
14
  SdkType,
16
15
  SdkUnionType,
17
16
  UsageFlags,
@@ -70,8 +69,8 @@ export function getSimpleTypeResult(result: Record<string, any>): Record<string,
70
69
  return result;
71
70
  }
72
71
 
73
- export function getType<TServiceOperation extends SdkServiceOperation>(
74
- context: PythonSdkContext<TServiceOperation>,
72
+ export function getType(
73
+ context: PythonSdkContext,
75
74
  type: CredentialType | CredentialTypeUnion | Type | SdkType | MultiPartFileType,
76
75
  ): Record<string, any> {
77
76
  switch (type.kind) {
@@ -128,8 +127,8 @@ export function getType<TServiceOperation extends SdkServiceOperation>(
128
127
  }
129
128
  }
130
129
 
131
- function emitMultiPartFile<TServiceOperation extends SdkServiceOperation>(
132
- context: PythonSdkContext<TServiceOperation>,
130
+ function emitMultiPartFile(
131
+ context: PythonSdkContext,
133
132
  type: MultiPartFileType,
134
133
  ): Record<string, any> {
135
134
  if (type.type.kind === "array") {
@@ -218,8 +217,8 @@ function addDisableGenerationMap(type: SdkType): void {
218
217
  }
219
218
  }
220
219
 
221
- function emitProperty<TServiceOperation extends SdkServiceOperation>(
222
- context: PythonSdkContext<TServiceOperation>,
220
+ function emitProperty(
221
+ context: PythonSdkContext,
223
222
  model: SdkModelType,
224
223
  property: SdkBodyModelPropertyType,
225
224
  ): Record<string, any> {
@@ -254,10 +253,7 @@ function emitProperty<TServiceOperation extends SdkServiceOperation>(
254
253
  };
255
254
  }
256
255
 
257
- function emitModel<TServiceOperation extends SdkServiceOperation>(
258
- context: PythonSdkContext<TServiceOperation>,
259
- type: SdkModelType,
260
- ): Record<string, any> {
256
+ function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string, any> {
261
257
  if (isEmptyModel(type)) {
262
258
  return KnownTypes.any;
263
259
  }
@@ -320,10 +316,7 @@ function emitModel<TServiceOperation extends SdkServiceOperation>(
320
316
  return newValue;
321
317
  }
322
318
 
323
- function emitEnum<TServiceOperation extends SdkServiceOperation>(
324
- context: PythonSdkContext<TServiceOperation>,
325
- type: SdkEnumType,
326
- ): Record<string, any> {
319
+ function emitEnum(context: PythonSdkContext, type: SdkEnumType): Record<string, any> {
327
320
  if (typesMap.has(type)) {
328
321
  return typesMap.get(type)!;
329
322
  }
@@ -401,8 +394,8 @@ function emitDurationOrDateType(type: SdkDurationType | SdkDateTimeType): Record
401
394
  });
402
395
  }
403
396
 
404
- function emitArrayOrDict<TServiceOperation extends SdkServiceOperation>(
405
- context: PythonSdkContext<TServiceOperation>,
397
+ function emitArrayOrDict(
398
+ context: PythonSdkContext,
406
399
  type: SdkArrayType | SdkDictionaryType,
407
400
  ): Record<string, any> {
408
401
  const kind = type.kind === "array" ? "list" : type.kind;
@@ -470,10 +463,7 @@ function emitBuiltInType(
470
463
  });
471
464
  }
472
465
 
473
- function emitUnion<TServiceOperation extends SdkServiceOperation>(
474
- context: PythonSdkContext<TServiceOperation>,
475
- type: SdkUnionType,
476
- ): Record<string, any> {
466
+ function emitUnion(context: PythonSdkContext, type: SdkUnionType): Record<string, any> {
477
467
  return getSimpleTypeResult({
478
468
  name: type.isGeneratedName ? undefined : type.name,
479
469
  snakeCaseName: type.isGeneratedName ? undefined : camelToSnakeCase(type.name),
@@ -508,8 +498,8 @@ export const KnownTypes = {
508
498
  any: { type: "any" },
509
499
  };
510
500
 
511
- export function emitEndpointType<TServiceOperation extends SdkServiceOperation>(
512
- context: PythonSdkContext<TServiceOperation>,
501
+ export function emitEndpointType(
502
+ context: PythonSdkContext,
513
503
  type: SdkEndpointType,
514
504
  ): Record<string, any>[] {
515
505
  const params: Record<string, any>[] = [];