Skip to content

Generate Python SDK with Cadl (Preview)

Yuchao Yan edited this page Nov 7, 2022 · 4 revisions

Prerequisite

Install Node.js 16 or above. (Verify by node --version)

Install Python 3.7+. (Verify by python --version)

Install pnpm with cmd npm install -g pnpm

Install cadl with cmd npm install -g @cadl-lang/compiler

Clone autorest.python.

Build cadl-python locally

Step into repo autorest.python and run:

pnpm install
pnpm build

Generate SDK

  1. Step into packages/cadl-python under repo autorest.python
  2. Copy Cadl project here and run
cadl compile {your-cadl-files}/.  --emit=@azure-tools/cadl-python

The generated SDK code will be in cadl-output

How to debug cadl-python with VS code

copy following configuration in launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        { 
            "name": "authoring",
            "request": "launch",
            "cwd": "${workspaceFolder}/packages/cadl-python/authoring",
            "runtimeArgs": ["compile", ".", "--emit", "@azure-tools/cadl-python"],
            "runtimeExecutable": "cadl",
            "skipFiles": ["<node_internals>/**"],
            "type": "node",
            "outFiles": [
              "${workspaceFolder}/packages/*/dist/**/*.js",
              "${workspaceFolder}/packages/*/dist-dev/**/*.js",
              "${workspaceFolder}/core/packages/*/dist/**/*.js",
              "${workspaceFolder}/core/packages/*/dist-dev/**/*.js"
            ]
          }
    ]
}

Then you can debug in emitter.ts of cadl-python