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

python sdk readme guide #10123

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Changes from 1 commit
Commits
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
219 changes: 219 additions & 0 deletions documentation/code-gen/configure-python-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# Readme Configuration Guide for Python SDK
This file describe how to configure readme files to make it avaiable for Python SDK code generation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo
"available"


## Common Configuration
Configure basic package information.

### Basic Information
Configure package title/description/tag.
~~~~
// file: readme.md

``` yaml
title: xxxxConfigurationClient
description: xxxx Configuration Client
openapi-type: arm
tag: package-xxxx-xx-xx
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a real example here?

~~~~

### tag
A tag can contains a bunch of swagger files which are used to generate the SDK. For Example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some name rule for tag to unify it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, @akning-ms , I think we can recommend it as: package-yyyy-mm-dd[-xxxx]. where the xxxx can be 'preview' or 'only'. I will add it in this PR.


~~~~
// file: readme.md


### Tag: package-2020-05-01

These settings apply only when `--tag=package-2020-05-01` is specified on the command line.

``` yaml $(tag) == 'package-2020-05-01'
input-file:
- Microsoft.Compute/stable/2019-12-01/compute.json
- Microsoft.Compute/stable/2019-12-01/runCommands.json
- Microsoft.Compute/stable/2019-12-01/gallery.json
```
~~~~


### all-api-versions
All swagger files need to be added into the all-api-version section. For Example:

~~~~
// file: readme.md


## Multi-API/Profile support for AutoRest v3 generators

AutoRest V3 generators require the use of `--tag=all-api-versions` to select api files.

This block is updated by an automatic script. Edits may be lost!

``` yaml $(tag) == 'all-api-versions' /* autogenerated */
# include the azure profile definitions from the standard location
require: $(this-folder)/../../../profiles/readme.md

# all the input files across all versions
input-file:
- Microsoft.Compute/stable/2019-12-01/compute.json
- Microsoft.Compute/stable/2019-12-01/runCommands.json
- Microsoft.Compute/stable/2019-12-01/gallery.json
- ...
~~~~


## Swagger to SDK
To make python SDK can be generated from the tag, swagger-to-sdk need to be configured:

~~~
// file: readme.md

## Swagger to SDK

This section describes what SDK should be generated by the automatic system.
This is not used by Autorest itself.

``` yaml $(swagger-to-sdk)
swagger-to-sdk:
- repo: azure-sdk-for-python
- ...


## Python

See configuration in [readme.python.md](./readme.python.md)
~~~

## Python Configuration
Python dedicated configurations are configured in readme.python.md.
A typical readme.python.md is like this:

~~~
// file: readme.python.md


## Python

These settings apply only when `--python` is specified on the command line.
Please also specify `--python-sdks-folder=<path to the root directory of your azure-sdk-for-python clone>`.
Use `--python-mode=update` if you already have a setup.py and just want to update the code itself.

``` yaml !$(track2) // For track1: basic Python package information
python-mode: create
python:
azure-arm: true
license-header: MICROSOFT_MIT_NO_VERSION
payload-flattening-threshold: 2
namespace: azure.mgmt.appconfiguration
package-name: azure-mgmt-appconfiguration
package-version: 0.1.0
clear-output-folder: true
```

These settings apply only when `--track2` is specified on the command line.

``` yaml $(track2) // For track2: basic Python package information
azure-arm: true
license-header: MICROSOFT_MIT_NO_VERSION
package-name: azure-mgmt-appconfiguration
no-namespace-folders: true
package-version: 0.1.0
```

``` yaml $(python-mode) == 'update'
// --------------- For track1 -----------------
python:
no-namespace-folders: true
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration/azure/mgmt/appconfiguration

// --------------- For track2 -----------------
no-namespace-folders: true
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration/azure/mgmt/appconfiguration
```
``` yaml $(python-mode) == 'create'
python:
basic-setup-py: true
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration
basic-setup-py: true
output-folder: $(python-sdks-folder)/appconfiguration/azure-mgmt-appconfiguration
```
~~~

## Multi-api
If a multi-api package is need to be released, 'batch' should be used in the readme.python.md.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explain a little bit about multi-api to the service team. Basically it's a package that contains the API versions?


### batch
The batch is a tag list which are used in the multi-api package. For example:
~~~
// file: readme.python.md

### Python multi-api

Generate all API versions currently shipped for this package

```yaml $(multiapi) && !$(track2) // For track1
batch:
- tag: package-2020-06-01-only
- tag: package-2020-05-01-only
```

```yaml $(multiapi) && $(track2) // For track2
clear-output-folder: true
batch:
- tag: package-2020-06-01-only
- tag: package-2020-05-01-only
- multiapiscript: true
```

``` yaml $(multiapiscript) // For track2
output-folder: $(python-sdks-folder)/compute/azure-mgmt-compute/azure/mgmt/compute/
clear-output-folder: false
perform-load: false
```
~~~

### tags of batch
Then, the output folder and namespace should be configured for each of the tag. For example:
~~~
// file: readme.python.md

### Tag: package-2020-06-01-only and python

These settings apply only when `--tag=package-2020-06-01-only --python` is specified on the command line.
Please also specify `--python-sdks-folder=<path to the root directory of your azure-sdk-for-python clone>`.

``` yaml $(tag) == 'package-2020-06-01-only'
namespace: azure.mgmt.compute.v2020_06_01
output-folder: $(python-sdks-folder)/compute/azure-mgmt-compute/azure/mgmt/compute/v2020_06_01
python:
namespace: azure.mgmt.compute.v2020_06_01
output-folder: $(python-sdks-folder)/compute/azure-mgmt-compute/azure/mgmt/compute/v2020_06_01
```
~~~


### multi-api init script
For track1, multi-api init script need to be configured in readme.md. For example:

~~~
// file: readme.md

swagger-to-sdk:
- repo: azure-sdk-for-python
after_scripts:
- python ./scripts/multiapi_init_gen.py azure-mgmt-compute
~~~


## Run codegen
After configure all the readme files, autorest can be used to generate SDK.
### Track1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe Track 1 (Based on AutoRest version xxxxx that's going to be replaced by version yyyyy)

~~~
autorest --keep-version-file --multiapi --no-async --python --python-mode=update --python-sdks-folder=C:\ZZ\projects\codegen\azure-sdk-for-python\sdk --use=@microsoft.azure/autorest.python@~4.0.71 --version=V2 ..\azure-rest-api-specs\specification\appconfiguration\resource-manager\readme.md
~~~

### Track2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track 2 is based on the latest AutoRest code generator

~~~
autorest --python --track2 --use=@autorest/python@5.1.0-preview.4 --python-sdks-folder=..\azure-sdk-for-python\sdk --multiapi --python-mode=update ..\azure-rest-api-specs\specification\appconfiguration\resource-manager\readme.md
~~~