Skip to content

Commit d4943c5

Browse files
python sdk readme guide (#10123)
* python sdk readme guide * add tag name rule * address comments
1 parent 23e12a4 commit d4943c5

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# Readme Configuration Guide for Python SDK
2+
This file describe how to configure readme files to make it available for Python SDK code generation.
3+
4+
## Common Configuration
5+
Configure basic package information.
6+
7+
### Basic Information
8+
Configure package title/description/tag.
9+
~~~~
10+
// file: readme.md
11+
12+
``` yaml
13+
title: AppconfigurationConfigurationClient
14+
description: Appconfiguration Configuration Client
15+
openapi-type: arm
16+
tag: package-2019-10-01 // refer to below tag description
17+
```
18+
~~~~
19+
20+
### tag
21+
Tags are used to define what swagger files are used in specific client SDK. In Single-API client, only one tag can be used to generate SDK client.
22+
A tag can contains a bunch of swagger files which are used to generate the SDK.
23+
24+
The name of a tag should be in form of package-yyyy-mm-dd[-xxx], for example below tag names are available:
25+
- package-2020-02-03
26+
- package-2020-03-22-preview
27+
- package-2020-05-03-only
28+
29+
while those are invalid names:
30+
- 2020-03-04
31+
- package-preview-2020-03-04
32+
33+
A tag can be configured like below:
34+
~~~~
35+
// file: readme.md
36+
37+
38+
### Tag: package-2019-10-01
39+
40+
These settings apply only when `--tag=package-2020-05-01` is specified on the command line.
41+
42+
``` yaml $(tag) == 'package-2019-10-01'
43+
input-file:
44+
- Microsoft.AppConfiguration/stable/2019-10-01/appconfiguration.json
45+
- Microsoft.AppConfiguration/stable/2019-10-01/xxxx.json
46+
```
47+
~~~~
48+
49+
50+
### all-api-versions
51+
All swagger files need to be added into the all-api-version section. For Example:
52+
53+
~~~~
54+
// file: readme.md
55+
56+
57+
## Multi-API/Profile support for AutoRest v3 generators
58+
59+
AutoRest V3 generators require the use of `--tag=all-api-versions` to select api files.
60+
61+
This block is updated by an automatic script. Edits may be lost!
62+
63+
``` yaml $(tag) == 'all-api-versions' /* autogenerated */
64+
# include the azure profile definitions from the standard location
65+
require: $(this-folder)/../../../profiles/readme.md
66+
67+
# all the input files across all versions
68+
input-file:
69+
- Microsoft.AppConfiguration/stable/2019-10-01/appconfiguration.json
70+
- Microsoft.AppConfiguration/stable/2019-10-01/xxxx.json
71+
- Microsoft.AppConfiguration/stable/2018-10-01/appconfiguration.json
72+
- ...
73+
~~~~
74+
75+
76+
## Swagger to SDK
77+
To make python SDK can be generated from the tag, swagger-to-sdk need to be configured:
78+
79+
~~~
80+
// file: readme.md
81+
82+
## Swagger to SDK
83+
84+
This section describes what SDK should be generated by the automatic system.
85+
This is not used by Autorest itself.
86+
87+
``` yaml $(swagger-to-sdk)
88+
swagger-to-sdk:
89+
- repo: azure-sdk-for-python
90+
- ...
91+
92+
93+
## Python
94+
95+
See configuration in [readme.python.md](./readme.python.md)
96+
~~~
97+
98+
## Python Configuration
99+
Python dedicated configurations are configured in readme.python.md.
100+
A typical readme.python.md is like this:
101+
102+
~~~
103+
// file: readme.python.md
104+
105+
106+
## Python
107+
108+
These settings apply only when `--python` is specified on the command line.
109+
Please also specify `--python-sdks-folder=<path to the root directory of your azure-sdk-for-python clone>`.
110+
Use `--python-mode=update` if you already have a setup.py and just want to update the code itself.
111+
112+
``` yaml !$(track2) // For track1: basic Python package information
113+
python-mode: create
114+
python:
115+
azure-arm: true
116+
license-header: MICROSOFT_MIT_NO_VERSION
117+
payload-flattening-threshold: 2
118+
namespace: azure.mgmt.appconfiguration
119+
package-name: azure-mgmt-appconfiguration
120+
package-version: 0.1.0
121+
clear-output-folder: true
122+
```
123+
124+
These settings apply only when `--track2` is specified on the command line.
125+
126+
``` yaml $(track2) // For track2: basic Python package information
127+
azure-arm: true
128+
license-header: MICROSOFT_MIT_NO_VERSION
129+
package-name: azure-mgmt-appconfiguration
130+
no-namespace-folders: true
131+
package-version: 0.1.0
132+
```
133+
134+
``` yaml $(python-mode) == 'update'
135+
// --------------- For track1 -----------------
136+
python:
137+
no-namespace-folders: true
138+
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration/azure/mgmt/appconfiguration
139+
140+
// --------------- For track2 -----------------
141+
no-namespace-folders: true
142+
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration/azure/mgmt/appconfiguration
143+
```
144+
``` yaml $(python-mode) == 'create'
145+
python:
146+
basic-setup-py: true
147+
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration
148+
basic-setup-py: true
149+
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration
150+
```
151+
~~~
152+
153+
## Multi-API
154+
Multi-API SDK is a package that support multiple REST api-versions. With Python multi-api SDK, the end user can assign api-version for REST calls explicitly; nevertheless, they can also use the default api-version which is choosed as the latest stable api-version.
155+
156+
If a multi-api package is need to be released, 'batch' should be used in the readme.python.md.
157+
Typical multi-api RPs are azure-mgmt-compute, azure-mgmt-network, azure-mgmt-storage, you cam find their readme files to have a reference for multi-api.
158+
159+
### batch
160+
The batch is a tag list which are used in the multi-api package. For example:
161+
~~~
162+
// file: readme.python.md
163+
164+
### Python multi-api
165+
166+
Generate all API versions currently shipped for this package
167+
168+
```yaml $(multiapi) && !$(track2) // For track1
169+
batch:
170+
- tag: package-2020-06-01-only
171+
- tag: package-2020-05-01-only
172+
```
173+
174+
```yaml $(multiapi) && $(track2) // For track2
175+
clear-output-folder: true
176+
batch:
177+
- tag: package-2020-06-01-only
178+
- tag: package-2020-05-01-only
179+
- multiapiscript: true
180+
```
181+
182+
``` yaml $(multiapiscript) // For track2
183+
output-folder: $(python-sdks-folder)/compute/azure-mgmt-compute/azure/mgmt/compute/
184+
clear-output-folder: false
185+
perform-load: false
186+
```
187+
~~~
188+
189+
### tags of batch
190+
Then, the output folder and namespace should be configured for each of the tag. For example:
191+
~~~
192+
// file: readme.python.md
193+
194+
### Tag: package-2020-06-01-only and python
195+
196+
These settings apply only when `--tag=package-2020-06-01-only --python` is specified on the command line.
197+
Please also specify `--python-sdks-folder=<path to the root directory of your azure-sdk-for-python clone>`.
198+
199+
``` yaml $(tag) == 'package-2020-06-01-only'
200+
namespace: azure.mgmt.compute.v2020_06_01
201+
output-folder: $(python-sdks-folder)/compute/azure-mgmt-compute/azure/mgmt/compute/v2020_06_01
202+
python:
203+
namespace: azure.mgmt.compute.v2020_06_01
204+
output-folder: $(python-sdks-folder)/compute/azure-mgmt-compute/azure/mgmt/compute/v2020_06_01
205+
```
206+
~~~
207+
208+
209+
### multi-api init script
210+
For track1, multi-api init script need to be configured in readme.md. For example:
211+
212+
~~~
213+
// file: readme.md
214+
215+
swagger-to-sdk:
216+
- repo: azure-sdk-for-python
217+
after_scripts:
218+
- python ./scripts/multiapi_init_gen.py azure-mgmt-compute
219+
~~~
220+
221+
222+
## Run codegen
223+
After configure all the readme files, autorest can be used to generate SDK.
224+
225+
### Track1 (for Autorest V2)
226+
Track1 SDK is based on AutoRest version V2 that's going to be replaced by version V3.
227+
228+
~~~
229+
autorest --keep-version-file --multiapi --no-async --python --python-mode=update --python-sdks-folder=C:\ZZ\projects\codegen\azure-sdk-for-python\sdk [email protected]/autorest.python@~4.0.71 --version=V2 ..\azure-rest-api-specs\specification\appconfiguration\resource-manager\readme.md
230+
~~~
231+
232+
### Track2 (for latest Autorest)
233+
Track 2 is based on the latest AutoRest code generator
234+
235+
~~~
236+
autorest --python --track2 --use=@autorest/[email protected] --python-sdks-folder=..\azure-sdk-for-python\sdk --multiapi --python-mode=update ..\azure-rest-api-specs\specification\appconfiguration\resource-manager\readme.md
237+
~~~

0 commit comments

Comments
 (0)