@typespec/http-client-python 0.37.0 → 0.37.2

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.
@@ -0,0 +1,32 @@
1
+ import { expectDiagnostics, t } from "@typespec/compiler/testing";
2
+ import { expect, it } from "vitest";
3
+ import { emitCodeModel } from "./test-host.js";
4
+
5
+ it("targets the service namespace when no SDK clients are found", async () => {
6
+ const { diagnostics } = await emitCodeModel(t.code`
7
+ #suppress "@typespec/http-client-python/no-sdk-clients" "This service intentionally has no client."
8
+ @service namespace ${t.namespace("Service")} {}
9
+ `);
10
+
11
+ expectDiagnostics(diagnostics, []);
12
+ });
13
+
14
+ it("generates models when no service exists", async () => {
15
+ const { codeModel, diagnostics } = await emitCodeModel(`
16
+ import "@azure-tools/typespec-client-generator-core";
17
+ using Azure.ClientGenerator.Core;
18
+
19
+ #suppress "@typespec/http-client-python/no-sdk-clients" "This model-only package intentionally has no client."
20
+ @access(Access.public)
21
+ @usage(Usage.input | Usage.output)
22
+ @clientNamespace("Models")
23
+ model Widget {}
24
+ `);
25
+
26
+ expectDiagnostics(diagnostics, []);
27
+ // A model-only package has no clients but must still emit its models into the code model.
28
+ expect(codeModel.clients).toHaveLength(0);
29
+ expect(codeModel.types.some((type) => type.type === "model" && type.name === "Widget")).toBe(
30
+ true,
31
+ );
32
+ });
@@ -0,0 +1,83 @@
1
+ import type { Diagnostic } from "@typespec/compiler";
2
+ import { resolvePath } from "@typespec/compiler";
3
+ import { createTester, mockFile } from "@typespec/compiler/testing";
4
+ import { mkdtemp, readdir, readFile, rm } from "fs/promises";
5
+ import jsyaml from "js-yaml";
6
+ import { tmpdir } from "os";
7
+ import { join } from "path";
8
+ import { $onEmit } from "../src/emitter.js";
9
+
10
+ const PythonTester = createTester(resolvePath(import.meta.dirname, "../.."), {
11
+ libraries: ["@azure-tools/typespec-client-generator-core"],
12
+ });
13
+
14
+ export const Tester = PythonTester;
15
+
16
+ // `@typespec/http-client-python` is intentionally excluded from the pnpm workspace, so it isn't
17
+ // linked into its own `node_modules` and `.emit()` can't resolve it by name. Register a minimal
18
+ // virtual package whose entrypoint re-exports the real `$onEmit`, so the emitter under test runs.
19
+ export const EmitterTester = PythonTester.files({
20
+ "node_modules/@typespec/http-client-python/package.json": JSON.stringify({
21
+ name: "@typespec/http-client-python",
22
+ version: "0.0.0",
23
+ exports: { ".": "./index.js" },
24
+ }),
25
+ "node_modules/@typespec/http-client-python/index.js": mockFile.js({
26
+ $onEmit,
27
+ }),
28
+ }).emit("@typespec/http-client-python", {
29
+ "generate-packaging-files": false,
30
+ });
31
+
32
+ /** A type entry in the emitted code model. */
33
+ export interface CodeModelType {
34
+ type: string;
35
+ name?: string;
36
+ }
37
+
38
+ /** The subset of the emitted code model that the emitter tests assert against. */
39
+ export interface CodeModel {
40
+ clients: unknown[];
41
+ types: CodeModelType[];
42
+ }
43
+
44
+ /**
45
+ * Run the emitter's TypeScript step only (via `emit-yaml-only`) and return the code model it
46
+ * produced along with any diagnostics. This stops right after `emitCodeModel`, so it exercises the
47
+ * real emitter logic that decides what gets generated without booting the Python/Pyodide generator.
48
+ */
49
+ export async function emitCodeModel(
50
+ code: string,
51
+ ): Promise<{ codeModel: CodeModel; diagnostics: readonly Diagnostic[] }> {
52
+ const outputDir = await mkdtemp(join(tmpdir(), "typespec-python-"));
53
+ let yamlPath: string | undefined;
54
+ try {
55
+ const [, diagnostics] = await EmitterTester.compileAndDiagnose(code, {
56
+ compilerOptions: {
57
+ options: {
58
+ "@typespec/http-client-python": {
59
+ "emit-yaml-only": true,
60
+ "emitter-output-dir": outputDir,
61
+ },
62
+ },
63
+ },
64
+ });
65
+
66
+ // `emit-yaml-only` writes a `.tsp-codegen-*.json` pointer into the output dir that references
67
+ // the serialized code model YAML written to the OS temp dir.
68
+ const pointerName = (await readdir(outputDir)).find(
69
+ (name) => name.startsWith(".tsp-codegen-") && name.endsWith(".json"),
70
+ );
71
+ if (!pointerName) {
72
+ throw new Error("Emitter did not produce a code model.");
73
+ }
74
+ ({ yamlPath } = JSON.parse(await readFile(join(outputDir, pointerName), "utf-8")));
75
+ const codeModel = jsyaml.load(await readFile(yamlPath!, "utf-8")) as CodeModel;
76
+ return { codeModel, diagnostics };
77
+ } finally {
78
+ await rm(outputDir, { recursive: true, force: true });
79
+ if (yamlPath) {
80
+ await rm(yamlPath, { force: true });
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "ignorePatterns": ["**/dist/**/*", "**/node_modules/**/*"],
3
+ "rules": {
4
+ "unicorn/no-useless-spread": "off"
5
+ }
6
+ }
@@ -41,7 +41,7 @@ ${pc.bold("Description:")}
41
41
 
42
42
  ${pc.bold("Options:")}
43
43
  ${pc.cyan("-e, --emitter")}
44
- Run ESLint on TypeScript emitter code.
44
+ Run Oxlint on TypeScript emitter code.
45
45
 
46
46
  ${pc.cyan("-g, --generator")}
47
47
  Run pylint on Python generator source code (pygen).
@@ -85,7 +85,7 @@ function runCommand(
85
85
  const workingDir = cwd || root;
86
86
  const name = displayName || command;
87
87
 
88
- // Add node_modules/.bin directories to PATH so commands like eslint can be found
88
+ // Add node_modules/.bin directories to PATH so commands like oxlint can be found
89
89
  // Also set NODE_PATH so that config files can resolve packages from monorepo's node_modules
90
90
  const pathSep = process.platform === "win32" ? ";" : ":";
91
91
  const binPaths = [
@@ -134,20 +134,17 @@ function runCommand(
134
134
 
135
135
  async function lintEmitter(): Promise<boolean> {
136
136
  console.log(`\n${pc.bold("=== Linting TypeScript ===")}\n`);
137
- // Run eslint with local config to avoid dependency on monorepo's eslint.config.js
138
- // This ensures the package can be linted in CI without full monorepo dependencies
139
- // Lint both emitter/ and eng/scripts/ directories
140
137
  return runCommand(
141
- "eslint",
138
+ "oxlint",
142
139
  [
143
140
  "emitter/",
144
141
  "eng/scripts/",
145
142
  "--config",
146
- "eng/scripts/ci/config/eslint-ci.config.mjs",
147
- "--max-warnings=0",
143
+ "eng/scripts/ci/config/oxlint.json",
144
+ "--deny-warnings",
148
145
  ],
149
146
  root,
150
- "eslint emitter/ eng/scripts/ --max-warnings=0",
147
+ "oxlint emitter/ eng/scripts/ --deny-warnings",
151
148
  );
152
149
  }
153
150
 
@@ -21,7 +21,7 @@ Requires-Dist: docutils>=0.20.1
21
21
  Requires-Dist: Jinja2==3.1.6
22
22
  Requires-Dist: PyYAML==6.0.1
23
23
  Requires-Dist: tomli==2.0.1
24
- Requires-Dist: setuptools==75.3.2
24
+ Requires-Dist: setuptools==83.0.0
25
25
  Dynamic: author
26
26
  Dynamic: author-email
27
27
  Dynamic: classifier
@@ -3,4 +3,4 @@ docutils>=0.20.1
3
3
  Jinja2==3.1.6
4
4
  PyYAML==6.0.1
5
5
  tomli==2.0.1
6
- setuptools==75.3.2
6
+ setuptools==83.0.0
@@ -52,6 +52,6 @@ setup(
52
52
  "Jinja2==3.1.6",
53
53
  "PyYAML==6.0.1",
54
54
  "tomli==2.0.1",
55
- "setuptools==75.3.2",
55
+ "setuptools==83.0.0",
56
56
  ],
57
57
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.37.0",
3
+ "version": "0.37.2",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",
@@ -66,20 +66,20 @@
66
66
  "emitter"
67
67
  ],
68
68
  "peerDependencies": {
69
- "@azure-tools/typespec-autorest": ">=0.71.0 <1.0.0",
70
- "@azure-tools/typespec-azure-core": ">=0.71.0 <1.0.0",
71
- "@azure-tools/typespec-azure-resource-manager": ">=0.71.0 <1.0.0",
72
- "@azure-tools/typespec-azure-rulesets": ">=0.71.0 <1.0.0",
73
- "@azure-tools/typespec-client-generator-core": ">=0.71.0 <1.0.0",
74
- "@typespec/compiler": "^1.15.0",
75
- "@typespec/http": "^1.15.0",
76
- "@typespec/openapi": "^1.15.0",
77
- "@typespec/rest": ">=0.85.0 <1.0.0",
78
- "@typespec/versioning": ">=0.85.0 <1.0.0",
79
- "@typespec/events": ">=0.85.0 <1.0.0",
80
- "@typespec/sse": ">=0.85.0 <1.0.0",
81
- "@typespec/streams": ">=0.85.0 <1.0.0",
82
- "@typespec/xml": ">=0.85.0 <1.0.0"
69
+ "@azure-tools/typespec-autorest": ">=0.72.0 <1.0.0",
70
+ "@azure-tools/typespec-azure-core": ">=0.72.0 <1.0.0",
71
+ "@azure-tools/typespec-azure-resource-manager": ">=0.72.0 <1.0.0",
72
+ "@azure-tools/typespec-azure-rulesets": ">=0.72.0 <1.0.0",
73
+ "@azure-tools/typespec-client-generator-core": ">=0.72.0 <1.0.0",
74
+ "@typespec/compiler": "^1.16.0",
75
+ "@typespec/http": "^1.16.0",
76
+ "@typespec/openapi": "^1.16.0",
77
+ "@typespec/rest": ">=0.86.0 <1.0.0",
78
+ "@typespec/versioning": ">=0.86.0 <1.0.0",
79
+ "@typespec/events": ">=0.86.0 <1.0.0",
80
+ "@typespec/sse": ">=0.86.0 <1.0.0",
81
+ "@typespec/streams": ">=0.86.0 <1.0.0",
82
+ "@typespec/xml": ">=0.86.0 <1.0.0"
83
83
  },
84
84
  "playgroundConfig": {
85
85
  "assets": [
@@ -97,39 +97,39 @@
97
97
  ]
98
98
  },
99
99
  "dependencies": {
100
- "js-yaml": "^4.2.0",
100
+ "js-yaml": "^4.3.1",
101
101
  "marked": "^15.0.6",
102
102
  "pyodide": "0.26.2",
103
103
  "semver": "~7.6.2",
104
- "tsx": "^4.21.0"
104
+ "tsx": "^4.23.13"
105
105
  },
106
106
  "devDependencies": {
107
- "@azure-tools/typespec-autorest": "~0.71.0",
108
- "@azure-tools/typespec-azure-core": "~0.71.0",
109
- "@azure-tools/typespec-azure-resource-manager": "~0.71.0",
110
- "@azure-tools/typespec-azure-rulesets": "~0.71.0",
111
- "@azure-tools/typespec-client-generator-core": "~0.71.0",
112
- "@azure-tools/azure-http-specs": "0.1.0-alpha.44",
113
- "@typespec/compiler": "^1.15.0",
114
- "@typespec/http": "^1.15.0",
115
- "@typespec/openapi": "^1.15.0",
116
- "@typespec/rest": "~0.85.0",
117
- "@typespec/versioning": "~0.85.0",
118
- "@typespec/events": "~0.85.0",
119
- "@typespec/spector": "0.1.0-alpha.29-dev.0",
120
- "@typespec/spec-api": "0.1.0-alpha.16",
121
- "@typespec/sse": "~0.85.0",
122
- "@typespec/streams": "~0.85.0",
123
- "@typespec/xml": "~0.85.0",
124
- "@typespec/http-specs": "0.1.0-alpha.42-dev.2",
107
+ "@azure-tools/typespec-autorest": "~0.72.0",
108
+ "@azure-tools/typespec-azure-core": "~0.72.0",
109
+ "@azure-tools/typespec-azure-resource-manager": "~0.72.0",
110
+ "@azure-tools/typespec-azure-rulesets": "~0.72.0",
111
+ "@azure-tools/typespec-client-generator-core": "~0.72.0",
112
+ "@azure-tools/azure-http-specs": "0.1.0-alpha.45",
113
+ "@typespec/compiler": "^1.16.0",
114
+ "@typespec/http": "^1.16.0",
115
+ "@typespec/openapi": "^1.16.0",
116
+ "@typespec/rest": "~0.86.0",
117
+ "@typespec/versioning": "~0.86.0",
118
+ "@typespec/events": "~0.86.0",
119
+ "@typespec/spector": "0.1.0-alpha.29",
120
+ "@typespec/spec-api": "0.1.0-alpha.17",
121
+ "@typespec/sse": "~0.86.0",
122
+ "@typespec/streams": "~0.86.0",
123
+ "@typespec/xml": "~0.86.0",
124
+ "@typespec/http-specs": "0.1.0-alpha.42",
125
125
  "@types/js-yaml": "~4.0.5",
126
126
  "@types/node": "~25.0.2",
127
127
  "@types/semver": "7.5.8",
128
128
  "c8": "^10.1.3",
129
+ "oxlint": "^1.69.0",
129
130
  "picocolors": "~1.1.1",
130
131
  "rimraf": "~6.1.2",
131
132
  "typescript": "~5.9.2",
132
- "typescript-eslint": "^8.49.0",
133
133
  "vitest": "^4.0.15",
134
134
  "prettier": "^3.9.5"
135
135
  }
@@ -1,64 +0,0 @@
1
- // @ts-check
2
- // Standalone eslint config for http-client-python package
3
- // This config is used in CI where monorepo dependencies may not be available
4
- import eslint from "@eslint/js";
5
- import { dirname } from "path";
6
- import tsEslint from "typescript-eslint";
7
- import { fileURLToPath } from "url";
8
-
9
- const root = dirname(dirname(dirname(dirname(fileURLToPath(import.meta.url)))));
10
-
11
- export default [
12
- {
13
- ignores: ["**/dist/**/*", "**/node_modules/**/*"],
14
- },
15
- eslint.configs.recommended,
16
- ...tsEslint.configs.recommended,
17
- {
18
- languageOptions: {
19
- parserOptions: {
20
- tsconfigRootDir: root,
21
- },
22
- },
23
- rules: {
24
- // TypeScript plugin overrides
25
- "@typescript-eslint/no-non-null-assertion": "off",
26
- "@typescript-eslint/no-explicit-any": "off",
27
- "@typescript-eslint/no-inferrable-types": "off",
28
- "@typescript-eslint/no-empty-function": "off",
29
- "@typescript-eslint/no-empty-interface": "off",
30
- "@typescript-eslint/no-empty-object-type": "off",
31
- "@typescript-eslint/no-unused-vars": [
32
- "warn",
33
- {
34
- varsIgnorePattern: "^_",
35
- argsIgnorePattern: ".*",
36
- ignoreRestSiblings: true,
37
- caughtErrorsIgnorePattern: ".*",
38
- },
39
- ],
40
- "@typescript-eslint/no-unused-expressions": [
41
- "warn",
42
- { allowShortCircuit: true, allowTernary: true },
43
- ],
44
-
45
- // Core rules
46
- "no-inner-declarations": "off",
47
- "no-empty": "off",
48
- "no-constant-condition": "off",
49
- "no-case-declarations": "off",
50
- "no-ex-assign": "off",
51
- "no-undef": "off",
52
- "no-useless-assignment": "error",
53
- "prefer-const": [
54
- "warn",
55
- {
56
- destructuring: "all",
57
- },
58
- ],
59
- eqeqeq: ["warn", "always", { null: "ignore" }],
60
- "no-console": "warn",
61
- "symbol-description": "warn",
62
- },
63
- },
64
- ];