@azure-tools/typespec-python 0.33.0 → 0.34.0

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.
Files changed (147) hide show
  1. package/dist/scripts/copy-scripts.d.ts +2 -0
  2. package/dist/scripts/copy-scripts.d.ts.map +1 -0
  3. package/dist/scripts/copy-scripts.js +24 -0
  4. package/dist/scripts/copy-scripts.js.map +1 -0
  5. package/dist/src/emitter.d.ts +0 -2
  6. package/dist/src/emitter.d.ts.map +1 -1
  7. package/dist/src/emitter.js +2 -102
  8. package/dist/src/emitter.js.map +1 -1
  9. package/dist/src/index.d.ts +1 -1
  10. package/dist/src/index.d.ts.map +1 -1
  11. package/dist/src/index.js +1 -1
  12. package/dist/src/index.js.map +1 -1
  13. package/package.json +14 -11
  14. package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
  15. package/scripts/copy-scripts.ts +26 -0
  16. package/scripts/eng/pylintrc +2 -1
  17. package/dist/src/code-model.d.ts +0 -4
  18. package/dist/src/code-model.d.ts.map +0 -1
  19. package/dist/src/code-model.js +0 -190
  20. package/dist/src/code-model.js.map +0 -1
  21. package/dist/src/external-process.d.ts +0 -20
  22. package/dist/src/external-process.d.ts.map +0 -1
  23. package/dist/src/external-process.js +0 -44
  24. package/dist/src/external-process.js.map +0 -1
  25. package/dist/src/http.d.ts +0 -7
  26. package/dist/src/http.d.ts.map +0 -1
  27. package/dist/src/http.js +0 -266
  28. package/dist/src/http.js.map +0 -1
  29. package/dist/src/types.d.ts +0 -36
  30. package/dist/src/types.d.ts.map +0 -1
  31. package/dist/src/types.js +0 -489
  32. package/dist/src/types.js.map +0 -1
  33. package/dist/src/utils.d.ts +0 -26
  34. package/dist/src/utils.d.ts.map +0 -1
  35. package/dist/src/utils.js +0 -151
  36. package/dist/src/utils.js.map +0 -1
  37. package/generator/LICENSE +0 -21
  38. package/generator/README.md +0 -1
  39. package/generator/dev_requirements.txt +0 -5
  40. package/generator/pygen/__init__.py +0 -107
  41. package/generator/pygen/_version.py +0 -7
  42. package/generator/pygen/black.py +0 -69
  43. package/generator/pygen/codegen/__init__.py +0 -338
  44. package/generator/pygen/codegen/_utils.py +0 -16
  45. package/generator/pygen/codegen/models/__init__.py +0 -204
  46. package/generator/pygen/codegen/models/base.py +0 -186
  47. package/generator/pygen/codegen/models/base_builder.py +0 -119
  48. package/generator/pygen/codegen/models/client.py +0 -430
  49. package/generator/pygen/codegen/models/code_model.py +0 -237
  50. package/generator/pygen/codegen/models/combined_type.py +0 -149
  51. package/generator/pygen/codegen/models/constant_type.py +0 -129
  52. package/generator/pygen/codegen/models/credential_types.py +0 -214
  53. package/generator/pygen/codegen/models/dictionary_type.py +0 -127
  54. package/generator/pygen/codegen/models/enum_type.py +0 -238
  55. package/generator/pygen/codegen/models/imports.py +0 -291
  56. package/generator/pygen/codegen/models/list_type.py +0 -143
  57. package/generator/pygen/codegen/models/lro_operation.py +0 -142
  58. package/generator/pygen/codegen/models/lro_paging_operation.py +0 -32
  59. package/generator/pygen/codegen/models/model_type.py +0 -362
  60. package/generator/pygen/codegen/models/operation.py +0 -530
  61. package/generator/pygen/codegen/models/operation_group.py +0 -184
  62. package/generator/pygen/codegen/models/paging_operation.py +0 -155
  63. package/generator/pygen/codegen/models/parameter.py +0 -412
  64. package/generator/pygen/codegen/models/parameter_list.py +0 -387
  65. package/generator/pygen/codegen/models/primitive_types.py +0 -659
  66. package/generator/pygen/codegen/models/property.py +0 -171
  67. package/generator/pygen/codegen/models/request_builder.py +0 -189
  68. package/generator/pygen/codegen/models/request_builder_parameter.py +0 -115
  69. package/generator/pygen/codegen/models/response.py +0 -348
  70. package/generator/pygen/codegen/models/utils.py +0 -23
  71. package/generator/pygen/codegen/serializers/__init__.py +0 -574
  72. package/generator/pygen/codegen/serializers/base_serializer.py +0 -21
  73. package/generator/pygen/codegen/serializers/builder_serializer.py +0 -1513
  74. package/generator/pygen/codegen/serializers/client_serializer.py +0 -295
  75. package/generator/pygen/codegen/serializers/enum_serializer.py +0 -15
  76. package/generator/pygen/codegen/serializers/general_serializer.py +0 -213
  77. package/generator/pygen/codegen/serializers/import_serializer.py +0 -127
  78. package/generator/pygen/codegen/serializers/metadata_serializer.py +0 -198
  79. package/generator/pygen/codegen/serializers/model_init_serializer.py +0 -33
  80. package/generator/pygen/codegen/serializers/model_serializer.py +0 -300
  81. package/generator/pygen/codegen/serializers/operation_groups_serializer.py +0 -89
  82. package/generator/pygen/codegen/serializers/operations_init_serializer.py +0 -44
  83. package/generator/pygen/codegen/serializers/parameter_serializer.py +0 -221
  84. package/generator/pygen/codegen/serializers/patch_serializer.py +0 -19
  85. package/generator/pygen/codegen/serializers/request_builders_serializer.py +0 -52
  86. package/generator/pygen/codegen/serializers/sample_serializer.py +0 -168
  87. package/generator/pygen/codegen/serializers/test_serializer.py +0 -293
  88. package/generator/pygen/codegen/serializers/types_serializer.py +0 -31
  89. package/generator/pygen/codegen/serializers/utils.py +0 -68
  90. package/generator/pygen/codegen/templates/client.py.jinja2 +0 -37
  91. package/generator/pygen/codegen/templates/client_container.py.jinja2 +0 -12
  92. package/generator/pygen/codegen/templates/config.py.jinja2 +0 -73
  93. package/generator/pygen/codegen/templates/config_container.py.jinja2 +0 -16
  94. package/generator/pygen/codegen/templates/conftest.py.jinja2 +0 -28
  95. package/generator/pygen/codegen/templates/enum.py.jinja2 +0 -13
  96. package/generator/pygen/codegen/templates/enum_container.py.jinja2 +0 -10
  97. package/generator/pygen/codegen/templates/init.py.jinja2 +0 -24
  98. package/generator/pygen/codegen/templates/keywords.jinja2 +0 -19
  99. package/generator/pygen/codegen/templates/lro_operation.py.jinja2 +0 -16
  100. package/generator/pygen/codegen/templates/lro_paging_operation.py.jinja2 +0 -18
  101. package/generator/pygen/codegen/templates/macros.jinja2 +0 -12
  102. package/generator/pygen/codegen/templates/metadata.json.jinja2 +0 -167
  103. package/generator/pygen/codegen/templates/model_base.py.jinja2 +0 -1158
  104. package/generator/pygen/codegen/templates/model_container.py.jinja2 +0 -13
  105. package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +0 -98
  106. package/generator/pygen/codegen/templates/model_init.py.jinja2 +0 -28
  107. package/generator/pygen/codegen/templates/model_msrest.py.jinja2 +0 -92
  108. package/generator/pygen/codegen/templates/operation.py.jinja2 +0 -21
  109. package/generator/pygen/codegen/templates/operation_group.py.jinja2 +0 -75
  110. package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +0 -20
  111. package/generator/pygen/codegen/templates/operation_tools.jinja2 +0 -81
  112. package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +0 -17
  113. package/generator/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +0 -6
  114. package/generator/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +0 -21
  115. package/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +0 -8
  116. package/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +0 -107
  117. package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +0 -9
  118. package/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +0 -108
  119. package/generator/pygen/codegen/templates/paging_operation.py.jinja2 +0 -21
  120. package/generator/pygen/codegen/templates/patch.py.jinja2 +0 -19
  121. package/generator/pygen/codegen/templates/pkgutil_init.py.jinja2 +0 -1
  122. package/generator/pygen/codegen/templates/request_builder.py.jinja2 +0 -28
  123. package/generator/pygen/codegen/templates/request_builders.py.jinja2 +0 -10
  124. package/generator/pygen/codegen/templates/rest_init.py.jinja2 +0 -12
  125. package/generator/pygen/codegen/templates/sample.py.jinja2 +0 -44
  126. package/generator/pygen/codegen/templates/serialization.py.jinja2 +0 -2115
  127. package/generator/pygen/codegen/templates/test.py.jinja2 +0 -50
  128. package/generator/pygen/codegen/templates/testpreparer.py.jinja2 +0 -26
  129. package/generator/pygen/codegen/templates/types.py.jinja2 +0 -8
  130. package/generator/pygen/codegen/templates/validation.py.jinja2 +0 -38
  131. package/generator/pygen/codegen/templates/vendor.py.jinja2 +0 -96
  132. package/generator/pygen/codegen/templates/version.py.jinja2 +0 -4
  133. package/generator/pygen/m2r.py +0 -65
  134. package/generator/pygen/postprocess/__init__.py +0 -183
  135. package/generator/pygen/postprocess/get_all.py +0 -19
  136. package/generator/pygen/postprocess/venvtools.py +0 -75
  137. package/generator/pygen/preprocess/__init__.py +0 -509
  138. package/generator/pygen/preprocess/helpers.py +0 -27
  139. package/generator/pygen/preprocess/python_mappings.py +0 -224
  140. package/generator/pygen/utils.py +0 -160
  141. package/generator/pygen.egg-info/PKG-INFO +0 -25
  142. package/generator/pygen.egg-info/SOURCES.txt +0 -66
  143. package/generator/pygen.egg-info/dependency_links.txt +0 -1
  144. package/generator/pygen.egg-info/requires.txt +0 -4
  145. package/generator/pygen.egg-info/top_level.txt +0 -1
  146. package/generator/requirements.txt +0 -12
  147. package/generator/setup.py +0 -55
package/dist/src/utils.js DELETED
@@ -1,151 +0,0 @@
1
- import { getSimpleTypeResult, getType } from "./types.js";
2
- import { getNamespaceFullName } from "@typespec/compiler";
3
- function IsFullyUpperCase(identifier, maxUppercasePreserve) {
4
- const len = identifier.length;
5
- if (len > 1) {
6
- if (len <= maxUppercasePreserve && identifier === identifier.toUpperCase()) {
7
- return true;
8
- }
9
- if (len <= maxUppercasePreserve + 1 && identifier.endsWith("s")) {
10
- const i = identifier.substring(0, len - 1);
11
- if (i.toUpperCase() === i) {
12
- return true;
13
- }
14
- }
15
- }
16
- return false;
17
- }
18
- function deconstruct(identifier, maxUppercasePreserve) {
19
- if (Array.isArray(identifier)) {
20
- return [...identifier.flatMap((each) => deconstruct(each, maxUppercasePreserve))];
21
- }
22
- return `${identifier}`
23
- .replace(/([a-z]+)([A-Z])/g, "$1 $2") // Add a space in between camelCase words(e.g. fooBar => foo Bar)
24
- .replace(/(\d+)/g, " $1 ") // Adds a space after numbers(e.g. foo123 => foo123 bar)
25
- .replace(/\b([A-Z]+)([A-Z])s([^a-z])(.*)/g, "$1$2« $3$4") // Add a space after a plural uppper cased word(e.g. MBsFoo => MBs Foo)
26
- .replace(/\b([A-Z]+)([A-Z])([a-z]+)/g, "$1 $2$3") // Add a space between an upper case word(2 char+) and the last captial case.(e.g. SQLConnection -> SQL Connection)
27
- .replace(/«/g, "s")
28
- .trim()
29
- .split(/[\W|_]+/)
30
- .map((each) => (IsFullyUpperCase(each, maxUppercasePreserve) ? each : each.toLowerCase()));
31
- }
32
- function isEqual(s1, s2) {
33
- // when s2 is undefined and s1 is the string 'undefined', it returns 0, making this true.
34
- // To prevent that, first we need to check if s2 is undefined.
35
- return s2 !== undefined && !!s1 && !s1.localeCompare(s2, undefined, { sensitivity: "base" });
36
- }
37
- function removeSequentialDuplicates(identifier) {
38
- const ids = [...identifier].filter((each) => !!each);
39
- for (let i = 0; i < ids.length; i++) {
40
- while (isEqual(ids[i], ids[i - 1])) {
41
- ids.splice(i, 1);
42
- }
43
- while (isEqual(ids[i], ids[i - 2]) && isEqual(ids[i + 1], ids[i - 1])) {
44
- ids.splice(i, 2);
45
- }
46
- }
47
- return ids;
48
- }
49
- function normalize(identifier, removeDuplicates = true, maxUppercasePreserve = 0) {
50
- if (!identifier || identifier.length === 0) {
51
- return [""];
52
- }
53
- return typeof identifier === "string"
54
- ? normalize(deconstruct(identifier, maxUppercasePreserve), removeDuplicates, maxUppercasePreserve)
55
- : removeDuplicates
56
- ? removeSequentialDuplicates(identifier)
57
- : identifier;
58
- }
59
- export function camelToSnakeCase(name) {
60
- if (!name)
61
- return name;
62
- const words = normalize(name, false, 6);
63
- const result = words.join("_").toLowerCase();
64
- const result_final = result.replace(/([^\d])_(\d+)/g, "$1$2");
65
- return result_final;
66
- }
67
- export function removeUnderscoresFromNamespace(name) {
68
- // needed because of the _specs_ tests
69
- return (name || "").replace(/_/g, "");
70
- }
71
- export function getImplementation(context, parameter) {
72
- if (parameter.onClient)
73
- return "Client";
74
- return "Method";
75
- }
76
- export function isAbstract(method) {
77
- return (method.operation.bodyParam?.contentTypes.length ?? 0) > 1 && method.access !== "internal";
78
- }
79
- export function getDelimiterAndExplode(parameter) {
80
- if (parameter.type.kind !== "array")
81
- return [undefined, false];
82
- let delimiter = undefined;
83
- let explode = parameter.kind === "query" && parameter.explode;
84
- if (parameter.collectionFormat === "csv" || parameter.collectionFormat === "simple") {
85
- delimiter = "comma";
86
- }
87
- else if (parameter.collectionFormat === "ssv") {
88
- delimiter = "space";
89
- }
90
- else if (parameter.collectionFormat === "tsv") {
91
- delimiter = "tab";
92
- }
93
- else if (parameter.collectionFormat === "pipes") {
94
- delimiter = "pipe";
95
- }
96
- else {
97
- explode = true;
98
- }
99
- return [delimiter, explode];
100
- }
101
- export function getAddedOn(context, type) {
102
- // since we do not support multi-service for now, we can just check the root client's api version
103
- // if type is added in the first version of the client, we do not need to add the versioning info
104
- if (type.apiVersions[0] ===
105
- context.sdkPackage.clients.find((c) => c.initialization.access === "public")?.apiVersions[0])
106
- return undefined;
107
- return type.apiVersions[0];
108
- }
109
- export function emitParamBase(context, parameter) {
110
- let type = getType(context, parameter.type);
111
- if (parameter.isApiVersionParam) {
112
- if (parameter.clientDefaultValue) {
113
- type = getSimpleTypeResult({ type: "constant", value: parameter.clientDefaultValue, valueType: type });
114
- }
115
- }
116
- return {
117
- optional: parameter.optional,
118
- description: parameter.description || "",
119
- addedOn: getAddedOn(context, parameter),
120
- clientName: camelToSnakeCase(parameter.name),
121
- inOverload: false,
122
- isApiVersion: parameter.isApiVersionParam,
123
- type,
124
- };
125
- }
126
- export function isAzureCoreErrorResponse(t) {
127
- if (!t)
128
- return false;
129
- const tspType = t.__raw;
130
- if (!tspType)
131
- return false;
132
- return (tspType.kind === "Model" &&
133
- tspType.namespace !== undefined &&
134
- ["Azure.Core", "Azure.Core.Foundations"].includes(getNamespaceFullName(tspType.namespace)) &&
135
- tspType.name === "ErrorResponse");
136
- }
137
- export function getDescriptionAndSummary(method) {
138
- if (method.details) {
139
- return {
140
- description: method.details,
141
- summary: method.description,
142
- };
143
- }
144
- return {
145
- description: method.description ?? "",
146
- };
147
- }
148
- export function capitalize(name) {
149
- return name[0].toUpperCase() + name.slice(1);
150
- }
151
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,SAAS,gBAAgB,CAAC,UAAkB,EAAE,oBAA4B;IACtE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;IAC9B,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACV,IAAI,GAAG,IAAI,oBAAoB,IAAI,UAAU,KAAK,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC;YACzE,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,GAAG,IAAI,oBAAoB,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;YAC3C,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;gBACxB,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,WAAW,CAAC,UAAkC,EAAE,oBAA4B;IACjF,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,OAAO,GAAG,UAAU,EAAE;SACjB,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,CA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AO,CAAC,SAAS,KAAK,SAAS;QAC/B,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1F,OAAO,CAAC,IAAI,KAAK,eAAe,CACnC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,wBAAwB,CACpC,MAAoC;IAEpC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,OAAO;YACH,WAAW,EAAE,MAAM,CAAC,OAAO;YAC3B,OAAO,EAAE,MAAM,CAAC,WAAW;SAC9B,CAAC;IACN,CAAC;IACD,OAAO;QACH,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;KACxC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
package/generator/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation. All rights reserved.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
@@ -1 +0,0 @@
1
- # Core Library for Python Generation
@@ -1,5 +0,0 @@
1
- -e ./generator
2
- -r ../../../eng/requirements.txt
3
- -r ../../../eng/dev_requirements.txt
4
- ptvsd==4.3.2
5
- types-PyYAML==6.0.12.8
@@ -1,107 +0,0 @@
1
- # -------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # Licensed under the MIT License. See License.txt in the project root for
4
- # license information.
5
- # --------------------------------------------------------------------------
6
- import logging
7
- from pathlib import Path
8
- import json
9
- from abc import ABC, abstractmethod
10
- from typing import Any, Dict, Union, List
11
-
12
- import yaml
13
-
14
- from ._version import VERSION
15
-
16
-
17
- __version__ = VERSION
18
- _LOGGER = logging.getLogger(__name__)
19
-
20
-
21
- class ReaderAndWriter:
22
- def __init__(self, *, output_folder: Union[str, Path], **kwargs: Any) -> None:
23
- self.output_folder = Path(output_folder)
24
- self._list_file: List[str] = []
25
- try:
26
- with open(
27
- Path(self.output_folder) / Path("..") / Path("python.json"),
28
- "r",
29
- encoding="utf-8-sig",
30
- ) as fd:
31
- python_json = json.load(fd)
32
- except Exception: # pylint: disable=broad-except
33
- python_json = {}
34
- self.options = kwargs
35
- if python_json:
36
- _LOGGER.warning("Loading python.json file. This behavior will be depreacted")
37
- self.options.update(python_json)
38
-
39
- def read_file(self, path: Union[str, Path]) -> str:
40
- """Directly reading from disk"""
41
- # make path relative to output folder
42
- try:
43
- with open(self.output_folder / Path(path), "r", encoding="utf-8-sig") as fd:
44
- return fd.read()
45
- except FileNotFoundError:
46
- return ""
47
-
48
- def write_file(self, filename: Union[str, Path], file_content: str) -> None:
49
- """Directly writing to disk"""
50
- file_folder = Path(filename).parent
51
- if not Path.is_dir(self.output_folder / file_folder):
52
- Path.mkdir(self.output_folder / file_folder, parents=True)
53
- with open(self.output_folder / Path(filename), "w", encoding="utf-8") as fd:
54
- fd.write(file_content)
55
-
56
- def list_file(self) -> List[str]:
57
- return [str(f.relative_to(self.output_folder)) for f in self.output_folder.glob("**/*") if f.is_file()]
58
-
59
-
60
- class Plugin(ReaderAndWriter, ABC):
61
- """A base class for autorest plugin.
62
-
63
- :param autorestapi: An autorest API instance
64
- """
65
-
66
- @abstractmethod
67
- def process(self) -> bool:
68
- """The plugin process.
69
-
70
- :rtype: bool
71
- :returns: True if everything's ok, False optherwise
72
- :raises Exception: Could raise any exception, stacktrace will be sent to autorest API
73
- """
74
- raise NotImplementedError()
75
-
76
-
77
- class YamlUpdatePlugin(Plugin):
78
- """A plugin that update the YAML as input."""
79
-
80
- def get_yaml(self) -> Dict[str, Any]:
81
- # cadl file doesn't have to be relative to output folder
82
- with open(self.options["cadl_file"], "r", encoding="utf-8-sig") as fd:
83
- return yaml.safe_load(fd.read())
84
-
85
- def write_yaml(self, yaml_string: str) -> None:
86
- with open(self.options["cadl_file"], "w", encoding="utf-8-sig") as fd:
87
- fd.write(yaml_string)
88
-
89
- def process(self) -> bool:
90
- # List the input file, should be only one
91
- yaml_data = self.get_yaml()
92
-
93
- self.update_yaml(yaml_data)
94
-
95
- yaml_string = yaml.safe_dump(yaml_data)
96
-
97
- self.write_yaml(yaml_string)
98
- return True
99
-
100
- @abstractmethod
101
- def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
102
- """The code-model-v4-no-tags yaml model tree.
103
-
104
- :rtype: updated yaml
105
- :raises Exception: Could raise any exception, stacktrace will be sent to autorest API
106
- """
107
- raise NotImplementedError()
@@ -1,7 +0,0 @@
1
- # -------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # Licensed under the MIT License. See License.txt in the project root for
4
- # license information.
5
- # --------------------------------------------------------------------------
6
-
7
- VERSION = "0.1.0"
@@ -1,69 +0,0 @@
1
- # -------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # Licensed under the MIT License. See License.txt in the project root for
4
- # license information.
5
- # --------------------------------------------------------------------------
6
- import logging
7
- from pathlib import Path
8
- import os
9
- import black
10
- from black.report import NothingChanged
11
-
12
- from . import Plugin
13
- from .utils import parse_args
14
-
15
- _LOGGER = logging.getLogger("blib2to3")
16
-
17
- _BLACK_MODE = black.Mode() # pyright: ignore [reportPrivateImportUsage]
18
- _BLACK_MODE.line_length = 120
19
-
20
-
21
- class BlackScriptPlugin(Plugin):
22
- def __init__(self, **kwargs):
23
- super().__init__(**kwargs)
24
- output_folder = self.options.get("output_folder", str(self.output_folder))
25
- if output_folder.startswith("file:"):
26
- output_folder = output_folder[5:]
27
- if os.name == "nt" and output_folder.startswith("///"):
28
- output_folder = output_folder[3:]
29
- self.output_folder = Path(output_folder)
30
-
31
- def process(self) -> bool:
32
- # apply format_file on every .py file in the output folder
33
- list(
34
- map(
35
- self.format_file,
36
- [
37
- Path(f)
38
- for f in self.list_file()
39
- if Path(f).parts[0]
40
- not in (
41
- "__pycache__",
42
- "node_modules",
43
- "venv",
44
- "env",
45
- )
46
- and not Path(f).parts[0].startswith(".")
47
- and Path(f).suffix == ".py"
48
- ],
49
- )
50
- )
51
- return True
52
-
53
- def format_file(self, file: Path) -> None:
54
- try:
55
- file_content = self.read_file(file)
56
- file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)
57
- except NothingChanged:
58
- pass
59
- except:
60
- _LOGGER.error("Error: failed to format %s", file)
61
- raise
62
- else:
63
- self.write_file(file, file_content)
64
-
65
-
66
- if __name__ == "__main__":
67
- # CADL pipeline will call this
68
- args, unknown_args = parse_args(need_cadl_file=False)
69
- BlackScriptPlugin(output_folder=args.output_folder, **unknown_args).process()