Skip to content
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

Replace m2r with new typescript-based method #6091

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4cbe321
remove m2r + add initial code
cperaltah Feb 12, 2025
4153894
remove m2r
cperaltah Feb 12, 2025
e0ce90e
add marked dep
cperaltah Feb 13, 2025
2534a05
fix md2rst
cperaltah Feb 14, 2025
4233e21
call method on description+summary fields
cperaltah Feb 14, 2025
031bb51
update node walking method
cperaltah Feb 14, 2025
943c411
Merge branch 'main' of https://github.com/microsoft/typespec into fea…
cperaltah Feb 14, 2025
7ccf1df
add link support
cperaltah Feb 14, 2025
680f126
add list support
cperaltah Feb 14, 2025
0040b7a
update parsing
cperaltah Feb 15, 2025
b9cab7d
cleanup
cperaltah Feb 15, 2025
474f7ed
update node walking logic
cperaltah Feb 21, 2025
a4cb26e
revert individual md2rst calls
cperaltah Feb 21, 2025
b5748e4
cleanup
cperaltah Feb 21, 2025
44634bb
check for null values before adding to the set
cperaltah Feb 21, 2025
0cc4f21
Merge branch 'main' of https://github.com/microsoft/typespec into fea…
cperaltah Feb 21, 2025
660e8ab
Create feature-md2rst-2025-1-21-1-49-22.md
catalinaperalta Feb 21, 2025
10f123b
Merge branch 'main' of https://github.com/microsoft/typespec into fea…
cperaltah Feb 21, 2025
5c6a308
format
cperaltah Feb 21, 2025
fa4637d
Merge branch 'feature/md2rst' of https://github.com/catalinaperalta/t…
cperaltah Feb 21, 2025
6ee8627
more m2r clean up
cperaltah Feb 26, 2025
209e34c
move m2r test to typescript and use md2rst
cperaltah Feb 26, 2025
0ed61b7
Merge branch 'main' of https://github.com/microsoft/typespec into fea…
cperaltah Feb 26, 2025
9f5b4c5
Merge branch 'main' of https://github.com/microsoft/typespec into fea…
cperaltah Mar 6, 2025
23a0669
make change report internal
cperaltah Mar 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update node walking logic
  • Loading branch information
cperaltah committed Feb 21, 2025
commit 474f7ed720f0ec8716748d44c51d9707e65b4805
50 changes: 48 additions & 2 deletions packages/http-client-python/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import { emitCodeModel } from "./code-model.js";
import { saveCodeModelAsYaml } from "./external-process.js";
import { PythonEmitterOptions, PythonSdkContext, reportDiagnostic } from "./lib.js";
import { runPython3 } from "./run-python3.js";
import { removeUnderscoresFromNamespace } from "./utils.js";
import { md2Rst, removeUnderscoresFromNamespace } from "./utils.js";
export function getModelsMode(context: SdkContext): "dpg" | "none" {
const specifiedModelsMode = context.emitContext.options["models-mode"];
if (specifiedModelsMode) {
@@ -75,6 +75,49 @@ async function createPythonSdkContext<TServiceOperation extends SdkServiceOperat
};
}

function arrayWalkThroughNodes(item: any) {
if (item !== undefined && typeof item === "object") {
return walkThroughNodes(item);
}
return item;
}

function walkThroughNodes(yamlMap: Record<string, any>): Record<string, any> {
const stack = [yamlMap];
const seen = new WeakSet();

while (stack.length > 0) {
const current = stack.pop();

if (seen.has(current!)) {
continue;
}
seen.add(current!);

if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
if (current[i] !== undefined && typeof current[i] === "object") {
stack.push(current[i]);
}
}
} else {
for (const key in current) {
if (key === "description" || key === "summary") {
if (current[key] !== undefined) {
current[key] = md2Rst(current[key]);
}
} else if (Array.isArray(current[key])) {
stack.push(current[key]);
} else if (current[key] !== undefined && typeof current[key] === "object") {
stack.push(current[key]);
}
}
}
}

return yamlMap;
}

export async function $onEmit(context: EmitContext<PythonEmitterOptions>) {
const program = context.program;
const sdkContext = await createPythonSdkContext<SdkHttpOperation>(context);
@@ -89,7 +132,10 @@ export async function $onEmit(context: EmitContext<PythonEmitterOptions>) {
});
return;
}
const yamlPath = await saveCodeModelAsYaml("python-yaml-path", yamlMap);

const parsedYamlMap = walkThroughNodes(yamlMap);

const yamlPath = await saveCodeModelAsYaml("python-yaml-path", parsedYamlMap);
const resolvedOptions = sdkContext.emitContext.options;
const commandArgs: Record<string, string> = {};
if (resolvedOptions["packaging-files-config"]) {
1 change: 1 addition & 0 deletions packages/http-client-python/emitter/src/utils.ts
Original file line number Diff line number Diff line change
@@ -289,6 +289,7 @@ export function md2Rst(text?: string): string | undefined {

tokens.forEach((token: Token) => {
if (token.type === "heading") {
// Heading tokens are block level, so we should check if there are additional tokens inside
const parsedHeadingText = md2Rst(token.text);
rst += `${"=".repeat(
parsedHeadingText!.length,