Skip to content

Commit cb913cb

Browse files
catalinaperaltacperaltahiscai-msftmsyyc
authored
Move m2r code into autorest.python (#3047)
* move m2r code into autorest * changelog * regenerate * regenerate * example build url * example build pnpm-lock.yaml - revert before merge * update typespec-python package.json * update lock file * remove m2r ref from typespec-python * Revert "update lock file" This reverts commit a3d179f. * Revert "example build pnpm-lock.yaml - revert before merge" This reverts commit 78ffad1. * revert package.json updates * change * black * update tests * regen * black * example build pnpm-lock.yaml - revert before merge * Update dependencies (2025-03-10 02:33:27) * Regenerate for typespec-python (2025-03-10 02:37:48) * fix ci * update * update version * update pnpm-lock --------- Co-authored-by: catalinaperalta <[email protected]> Co-authored-by: iscai-msft <[email protected]> Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython> Co-authored-by: Yuchao Yan <[email protected]>
1 parent a804517 commit cb913cb

File tree

565 files changed

+830
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+830
-205
lines changed

packages/autorest.python/CHANGELOG.md

+4

packages/autorest.python/autorest/m2r.py

+50-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,60 @@
55
# --------------------------------------------------------------------------
66
"""An autorest MD to RST plugin.
77
"""
8-
from typing import Any, Dict
8+
import logging
9+
from typing import Any, Dict, Set, Union
10+
11+
import m2r2
12+
from pygen import YamlUpdatePlugin
913

10-
from pygen.m2r import M2R
1114
from . import YamlUpdatePluginAutorest
1215

1316

17+
_LOGGER = logging.getLogger(__name__)
18+
19+
20+
class GeneratorRenderer(m2r2.RestRenderer):
21+
"""Redefine the concept of inline HTML in the renderer, we don't want to define a new format
22+
in the description/summary.
23+
"""
24+
25+
def inline_html(self, html: str) -> str:
26+
"""Do not render inline HTML with a role definition."""
27+
return r"\ :code:`{}`".format(html)
28+
29+
30+
class M2R(YamlUpdatePlugin):
31+
"""A plugin to convert any description and summary from MD to RST."""
32+
33+
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
34+
"""Convert in place the YAML str."""
35+
self._convert_docstring_no_cycles(yaml_data, set())
36+
37+
def _convert_docstring_no_cycles(self, yaml_data: Union[Dict[str, Any], str], node_list: Set[int]) -> None:
38+
"""Walk the YAML tree to convert MD to RST."""
39+
if id(yaml_data) in node_list:
40+
return
41+
node_list.add(id(yaml_data))
42+
43+
if isinstance(yaml_data, list):
44+
for elt in yaml_data:
45+
self._convert_docstring_no_cycles(elt, node_list)
46+
elif isinstance(yaml_data, dict):
47+
for key, value in yaml_data.items():
48+
if key in ["description", "summary"]:
49+
yaml_data[key] = self.convert_to_rst(value)
50+
continue
51+
self._convert_docstring_no_cycles(value, node_list)
52+
53+
@staticmethod
54+
def convert_to_rst(string_to_convert: str) -> str:
55+
"""Convert that string from MD to RST."""
56+
try:
57+
return m2r2.convert(string_to_convert, renderer=GeneratorRenderer()).strip()
58+
except Exception: # pylint: disable=broad-except
59+
return string_to_convert
60+
61+
1462
class M2RAutorest(YamlUpdatePluginAutorest, M2R):
1563
def get_options(self) -> Dict[str, Any]:
1664
return {}

packages/autorest.python/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@autorest/python",
3-
"version": "6.29.0",
3+
"version": "6.29.1",
44
"description": "The Python extension for generators in AutoRest.",
55
"scripts": {
66
"start": "node ./scripts/run-python3.js ./scripts/start.py",
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "~0.7.0",
32+
"@typespec/http-client-python": "~0.7.1",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
json-rpc==1.14.0
2+
m2r2==0.3.3.post2

packages/autorest.python/samples/specification/azure_key_credential/generated/azure/key/credential/sample/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/azure_key_credential/generated/azure/key/credential/sample/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/azure_key_credential/generated/azure/key/credential/sample/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/azure_key_credential/generated/azure/key/credential/sample/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/basic/generated/azure/basic/sample/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/basic/generated/azure/basic/sample/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/basic/generated/azure/basic/sample/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/basic/generated/azure/basic/sample/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/directives/generated/azure/directives/sample/_operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/directives/generated/azure/directives/sample/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/directives/generated/azure/directives/sample/aio/_operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/directives/generated/azure/directives/sample/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/management/generated/azure/mgmt/sample/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/management/generated/azure/mgmt/sample/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/management/generated/azure/mgmt/sample/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/management/generated/azure/mgmt/sample/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v1/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v1/models/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v2/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v2/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v2/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v2/models/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v2/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v3/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v3/models/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/bodyduration/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/bodyduration/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/bodyduration/aio/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/bodyduration/models/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/bodyduration/operations/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureParameterGrouping/azureparametergrouping/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureParameterGrouping/azureparametergrouping/aio/_patch.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
56
"""Customize generated code here.
67
78
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize

0 commit comments

Comments
 (0)