Skip to content

Commit 516407f

Browse files
Copilotmsyyc
andauthored
chore(python): format emitter changes
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
1 parent 80e05f0 commit 516407f

3 files changed

Lines changed: 16 additions & 37 deletions

File tree

packages/http-client-python/emitter/src/emitter.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
22
import type { EmitContext } from "@typespec/compiler";
3-
import {
4-
emitFile,
5-
joinPaths,
6-
listServices,
7-
NoTarget,
8-
} from "@typespec/compiler";
3+
import { emitFile, joinPaths, listServices, NoTarget } from "@typespec/compiler";
94
import pkgJson from "../../package.json" with { type: "json" };
105
import { emitCodeModel } from "./code-model.js";
116
import {
@@ -97,10 +92,7 @@ function walkThroughNodes(yamlMap: Record<string, any>): Record<string, any> {
9792
}
9893
} else if (Array.isArray(current[key])) {
9994
stack.push(current[key]);
100-
} else if (
101-
current[key] !== undefined &&
102-
typeof current[key] === "object"
103-
) {
95+
} else if (current[key] !== undefined && typeof current[key] === "object") {
10496
stack.push(current[key]);
10597
}
10698
}
@@ -172,9 +164,7 @@ export async function $onEmit(context: EmitContext<PythonEmitterOptions>) {
172164
"========================================= error stack start ================================================";
173165
const errStackEnd =
174166
"========================================= error stack end ================================================";
175-
const errStack = error.stack
176-
? `\n${errStackStart}\n${error.stack}\n${errStackEnd}`
177-
: "";
167+
const errStack = error.stack ? `\n${errStackStart}\n${error.stack}\n${errStackEnd}` : "";
178168
reportDiagnostic(context.program, {
179169
code: "unknown-error",
180170
target: NoTarget,
@@ -205,19 +195,17 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
205195
const resolvedOptions = sdkContext.emitContext.options;
206196
const commandArgs: Record<string, string> = {};
207197
if (resolvedOptions["packaging-files-config"]) {
208-
const keyValuePairs = Object.entries(
209-
resolvedOptions["packaging-files-config"],
210-
).map(([key, value]) => {
211-
return `${key}:${value}`;
212-
});
198+
const keyValuePairs = Object.entries(resolvedOptions["packaging-files-config"]).map(
199+
([key, value]) => {
200+
return `${key}:${value}`;
201+
},
202+
);
213203
commandArgs["packaging-files-config"] = keyValuePairs.join("|");
214204
resolvedOptions["packaging-files-config"] = undefined;
215205
}
216206
if (resolvedOptions["keep-pyproject-fields"]) {
217207
// Flatten the object of enabled fields into a comma-separated list for the generator.
218-
const enabledFields = Object.entries(
219-
resolvedOptions["keep-pyproject-fields"],
220-
)
208+
const enabledFields = Object.entries(resolvedOptions["keep-pyproject-fields"])
221209
.filter(([, value]) => value === true)
222210
.map(([key]) => key);
223211
commandArgs["keep-pyproject-fields"] = enabledFields.join(",");
@@ -229,11 +217,8 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
229217
commandArgs[key] = value;
230218
}
231219
if (resolvedOptions["generate-packaging-files"]) {
232-
commandArgs["package-mode"] = sdkContext.arm
233-
? "azure-mgmt"
234-
: "azure-dataplane";
235-
commandArgs["keep-setup-py"] =
236-
resolvedOptions["keep-setup-py"] === true ? "true" : "false";
220+
commandArgs["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane";
221+
commandArgs["keep-setup-py"] = resolvedOptions["keep-setup-py"] === true ? "true" : "false";
237222
}
238223
if (sdkContext.arm === true) {
239224
commandArgs["azure-arm"] = "true";

packages/http-client-python/emitter/test/emitter.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ it("generates models when no service exists", async () => {
2626
expectDiagnostics(diagnostics, []);
2727
// A model-only package has no clients but must still emit its models into the code model.
2828
expect(codeModel.clients).toHaveLength(0);
29-
expect(
30-
codeModel.types.some(
31-
(type) => type.type === "model" && type.name === "Widget",
32-
),
33-
).toBe(true);
29+
expect(codeModel.types.some((type) => type.type === "model" && type.name === "Widget")).toBe(
30+
true,
31+
);
3432
});

packages/http-client-python/emitter/test/test-host.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ export async function emitCodeModel(
7171
if (!pointerName) {
7272
throw new Error("Emitter did not produce a code model.");
7373
}
74-
({ yamlPath } = JSON.parse(
75-
await readFile(join(outputDir, pointerName), "utf-8"),
76-
));
77-
const codeModel = jsyaml.load(
78-
await readFile(yamlPath!, "utf-8"),
79-
) as CodeModel;
74+
({ yamlPath } = JSON.parse(await readFile(join(outputDir, pointerName), "utf-8")));
75+
const codeModel = jsyaml.load(await readFile(yamlPath!, "utf-8")) as CodeModel;
8076
return { codeModel, diagnostics };
8177
} finally {
8278
await rm(outputDir, { recursive: true, force: true });

0 commit comments

Comments
 (0)