-
Notifications
You must be signed in to change notification settings - Fork 388
Allow suppressing Python no-client warnings #11823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yuchao Yan (msyyc)
wants to merge
11
commits into
main
Choose a base branch
from
fix/python-no-sdk-clients-suppression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e58dbf5
Fix Python no-client warning suppression
msyyc e44febc
Address no-client warning review feedback
msyyc 7fab879
refactor(emitter): inline no-client diagnostic target
eaa15e8
fix(emitter): remove unused program import
4fed492
fix(emitter): address diagnostic review feedback
f6cedca
Potential fix for pull request finding
iscai-msft e8db650
test(emitter): cover model-only generation
09c7c72
fix(python): test model-only generation
f49c7fc
test(python): assert code model instead of running generator
80e05f0
fix(python): target first SDK model for no-sdk-clients diagnostic
516407f
chore(python): format emitter changes
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/fix-python-no-sdk-clients-suppression-2026-09-02.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: fix | ||
| packages: | ||
| - "@typespec/http-client-python" | ||
| --- | ||
|
|
||
| Allow `no-sdk-clients` warnings to be suppressed by reporting them on the TypeSpec service namespace. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { expectDiagnostics, t } from "@typespec/compiler/testing"; | ||
| import { expect, it } from "vitest"; | ||
| import { emitCodeModel } from "./test-host.js"; | ||
|
|
||
| it("targets the service namespace when no SDK clients are found", async () => { | ||
| const { diagnostics } = await emitCodeModel(t.code` | ||
| #suppress "@typespec/http-client-python/no-sdk-clients" "This service intentionally has no client." | ||
| @service namespace ${t.namespace("Service")} {} | ||
| `); | ||
|
|
||
| expectDiagnostics(diagnostics, []); | ||
| }); | ||
|
|
||
| it("generates models when no service exists", async () => { | ||
| const { codeModel, diagnostics } = await emitCodeModel(` | ||
| import "@azure-tools/typespec-client-generator-core"; | ||
| using Azure.ClientGenerator.Core; | ||
|
|
||
| #suppress "@typespec/http-client-python/no-sdk-clients" "This model-only package intentionally has no client." | ||
| @access(Access.public) | ||
| @usage(Usage.input | Usage.output) | ||
| @clientNamespace("Models") | ||
| model Widget {} | ||
| `); | ||
|
|
||
| expectDiagnostics(diagnostics, []); | ||
| // A model-only package has no clients but must still emit its models into the code model. | ||
| expect(codeModel.clients).toHaveLength(0); | ||
| expect(codeModel.types.some((type) => type.type === "model" && type.name === "Widget")).toBe( | ||
| true, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import type { Diagnostic } from "@typespec/compiler"; | ||
| import { resolvePath } from "@typespec/compiler"; | ||
| import { createTester, mockFile } from "@typespec/compiler/testing"; | ||
| import { mkdtemp, readdir, readFile, rm } from "fs/promises"; | ||
| import jsyaml from "js-yaml"; | ||
| import { tmpdir } from "os"; | ||
| import { join } from "path"; | ||
| import { $onEmit } from "../src/emitter.js"; | ||
|
|
||
| const PythonTester = createTester(resolvePath(import.meta.dirname, "../.."), { | ||
| libraries: ["@azure-tools/typespec-client-generator-core"], | ||
| }); | ||
|
|
||
| export const Tester = PythonTester; | ||
|
|
||
| // `@typespec/http-client-python` is intentionally excluded from the pnpm workspace, so it isn't | ||
| // linked into its own `node_modules` and `.emit()` can't resolve it by name. Register a minimal | ||
| // virtual package whose entrypoint re-exports the real `$onEmit`, so the emitter under test runs. | ||
| export const EmitterTester = PythonTester.files({ | ||
| "node_modules/@typespec/http-client-python/package.json": JSON.stringify({ | ||
| name: "@typespec/http-client-python", | ||
| version: "0.0.0", | ||
| exports: { ".": "./index.js" }, | ||
| }), | ||
| "node_modules/@typespec/http-client-python/index.js": mockFile.js({ | ||
| $onEmit, | ||
| }), | ||
| }).emit("@typespec/http-client-python", { | ||
| "generate-packaging-files": false, | ||
| }); | ||
|
|
||
| /** A type entry in the emitted code model. */ | ||
| export interface CodeModelType { | ||
| type: string; | ||
| name?: string; | ||
| } | ||
|
|
||
| /** The subset of the emitted code model that the emitter tests assert against. */ | ||
| export interface CodeModel { | ||
| clients: unknown[]; | ||
| types: CodeModelType[]; | ||
| } | ||
|
|
||
| /** | ||
| * Run the emitter's TypeScript step only (via `emit-yaml-only`) and return the code model it | ||
| * produced along with any diagnostics. This stops right after `emitCodeModel`, so it exercises the | ||
| * real emitter logic that decides what gets generated without booting the Python/Pyodide generator. | ||
| */ | ||
| export async function emitCodeModel( | ||
| code: string, | ||
| ): Promise<{ codeModel: CodeModel; diagnostics: readonly Diagnostic[] }> { | ||
| const outputDir = await mkdtemp(join(tmpdir(), "typespec-python-")); | ||
| let yamlPath: string | undefined; | ||
| try { | ||
| const [, diagnostics] = await EmitterTester.compileAndDiagnose(code, { | ||
| compilerOptions: { | ||
| options: { | ||
| "@typespec/http-client-python": { | ||
| "emit-yaml-only": true, | ||
| "emitter-output-dir": outputDir, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // `emit-yaml-only` writes a `.tsp-codegen-*.json` pointer into the output dir that references | ||
| // the serialized code model YAML written to the OS temp dir. | ||
| const pointerName = (await readdir(outputDir)).find( | ||
| (name) => name.startsWith(".tsp-codegen-") && name.endsWith(".json"), | ||
| ); | ||
| if (!pointerName) { | ||
| throw new Error("Emitter did not produce a code model."); | ||
| } | ||
| ({ yamlPath } = JSON.parse(await readFile(join(outputDir, pointerName), "utf-8"))); | ||
| const codeModel = jsyaml.load(await readFile(yamlPath!, "utf-8")) as CodeModel; | ||
| return { codeModel, diagnostics }; | ||
| } finally { | ||
| await rm(outputDir, { recursive: true, force: true }); | ||
| if (yamlPath) { | ||
| await rm(yamlPath, { force: true }); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.