-
Notifications
You must be signed in to change notification settings - Fork 3k
Generate Python Mgmt SDK from Typespec
Yuchao Yan edited this page Dec 12, 2024
·
9 revisions
-
Python 3.8 or later is required
- download for windows
- linux
- sudo apt install python3
- sudo apt install python3-pip
- sudo apt install python3.{?}-venv explicitly if needed
-
Node.js 18.3 LTS or later is required
- Fork and clone the azure-sdk-for-python repo (Let's call it
SDK repo
) - Fork and clone the azure-rest-api-specs repo (Let's call it
Rest repo
)
Identify the tspconfig.yaml file for your package in the Rest repo and ensure there is a configuration for the Python SDK similar to that shown below and in this example
parameters:
"service-dir":
default: "sdk/SERVICE_DIRECTORY_NAME"
options:
"@azure-tools/typespec-python":
package-dir: "azure-mgmt-PACKAGE_NAME"
package-name: "{package-dir}"
generate-test: true
generate-sample: true
flavor: "azure"
nit: please replace SERVICE_DIRECTORY_NAME
/PACKAGE_NAME
with real value as needed.
- Install
typespec-client-generator-cli
globally:
npm install -g @azure-tools/typespec-client-generator-cli
- Create Python virtual environments and activate it:
PS C:\dev\azure-sdk-for-python> python -m venv .venv
PS C:\dev\azure-sdk-for-python> .\.venv\Scripts\Activate.ps1 (Windows)
/C/dev/azure-sdk-for-python> source .venv/bin/activate (Linux)
- Install Python dependencies:
(.venv) PS C:\dev\azure-sdk-for-python> python .\scripts\dev_setup.py -p azure-core
(.venv) PS C:\dev\azure-sdk-for-python> pip install tox
- Create a local json file named
generatedInput.json
outside SDK repo with content similar to that shown below
{
"dryRun": false,
"specFolder": "LOCAL_AZURE-REST-API-SPECS_REPO_ROOT", // e.g. "C:/dev/azure-rest-api-specs"
"headSha": "SHA_OF_AZURE-REST-API-SPECS_REPO", // use ' git rev-parse HEAD ' on the local rest repo root
"repoHttpsUrl": "https://github.com/Azure/azure-rest-api-specs",
"relatedTypeSpecProjectFolder": [
"specification/SERVICE_DIRECTORY_NAME/PACKAGE_DIRECTORY_NAME/" // e.g specification/contosowidgetmanager/Contoso.Management
]
}
- Run command to generate SDK
(.venv) PS C:\dev\azure-sdk-for-python> python -m packaging_tools.sdk_package ..\generatedInput.json ..\temp.json
(.venv) PS C:\dev\azure-sdk-for-python> python -m packaging_tools.sdk_package ..\temp.json ..\generatedOutput.json
- View information about the generated SDK in
generateOutput.json
The generated code is not enough to release at once and you need to update it for better usage experience. Please follow What to do after generating the SDK code with MPG to check the code.