Skip to content

Generation using autorest for Python v5 dev mode

Laurent Mazuel edited this page May 5, 2020 · 6 revisions

Requirements

Python 3.6 is required to run this new autorest

Install autorest

npm install -g autorest

If you already have autorest, be sure to execute autorest --reset and at any sign of weird behavior to be sure it's not using anything that was pulled from before from npm.

Clone, create a venv and install deps

  1. Clone the autorestv3 branch of autorest.python
git clone --single-branch --branch autorestv3 https://github.com/Azure/autorest.python.git
  1. Go to the root of the installed autorest.python repo and run npm install. This should generate a virtual environment with name venv at the root, which is essential for generating tests and making code changes. All generation must be done with this venv loaded.

Debugging

See https://github.com/Azure/autorest.python/wiki/Autorest-v3-based-generator-cheatsheet#vscode-debug

Testing

Generating test swaggers

  1. Activate your venv
  2. Call inv regenerate from the repo root if you want to regenerate all of the test server swaggers
  3. To generate a specific test server swagger, say BodyComplex, call inv regenerate --swagger-name bodycomplex

For a complete mapping of swagger names to autorest test server swaggers, see the various mappings

Testing your generated code

  1. Recommend making two separate testing environments, one for vanilla tests and one for azure tests
  2. Install the requirements.txt for azure and vanilla in your respective virtual environments
  3. Run pytest from either test/azure or test/vanilla in your repo

Generate

It's actually as usual. Be sure --use points to the folder where you cloned autorest, and that your venv is loaded.

Example:

autorest ..\azure-rest-api-specs\specification\storage\resource-manager\readme.md --use=. --python-sdks-folder=$SDK_FOLDER --python --multiapi --python-mode=update --keep-version-file