-
Notifications
You must be signed in to change notification settings - Fork 60
Contributing to autorest.python
iscai-msft edited this page Nov 11, 2021
·
10 revisions
First off, we want to thank all of the autorest.python contributors. We are an open-source project, so all are welcome to contribute, and we greatly appreciate the help we receive from contributors!
In this doc, we outline all the steps needed to create a PR and contribute to this repo
- Cloning and Setting Up the Repo
- Writing Code
- Generating AutoRest with your code changes
- Testing your generated code
- Making your PR
- Run
npm install -g autorestto install autorest on your computer if you don't have it. - Make sure your Python version is
3.6and above. - Clone our
autorest.pythonrepo. You may choose to fork theautorest.pythonrepo and clone your fork instead. Our default branch, and the branch that contains the code we publish isautorestv3. - Run
npm installat the root of your cloned repo. - Activate the virtual environment
venvthat the previous step created at the root of your repo. This virtual environment has all of the dependencies needed to write and generate code in the repo code.
- Make sure the
venvvirtual environment is activated - Create your own feature branch from the default
autorestv3branch and put all of your code in here. - There are 6 submodules in the autorest folder. However, you are almost guaranteed to be writing code in the
codegensubmodule. This handles all of the code that generates an SDK. There is a small chance you may be also writing code in themultiapisubmodule, which handles the multiapiscript we run to generate a MultiApi SDK. - Make sure all of the new files you add have the Microsoft MIT license header
You have a couple options when generating code. We use the invoke library to generate
| Command | Output Description | Output Folder |
|---|---|---|
inv regenerate |
Regenerates all test swaggers with both our legacy (current published) generator and our low level generator. | All of the Expected/AcceptanceTests folders in the test folder. For example: Vanilla low level generates in test/vanilla/llc/Expected/AcceptanceTests
|
inv regenerate --version-tolerant |
Regenerate all of the test swaggers with our version tolerant generator. |
test/azure/version-tolerant/Expected/AcceptanceTests etc |
inv regenerate --legacy |
Regenerate all of the test swaggers with our legacy (current published) generator. |
test/azure/legacy/Expected/AcceptanceTests, test/vanilla/legacy/Expected/AcceptanceTests and test/multiapi/Expected/AcceptanceTests
|
inv regenerate --llc |
Regenerate all of the test swaggers with our LLC generation |
test/azure/llc/Expected/AcceptanceTests, test/vanilla/llc/Expected/AcceptanceTests
|
These flags can also be added to your command for debugging and more specialized generation
| Flag | Output |
|---|---|
--swagger-name={} |
Regenerate only a specific swagger. For example, if you only want to generate the BodyComplex swagger, include --swagger-name=BodyComplex to your command line |
--debug |
Debug your generation. If debugging in VSCode, add this to your launch configuration first |
You can find all of our tests of the generated code in folders that start with Acceptance.
| Test Type | Folder |
|---|---|
| Vanilla Legacy | test/vanilla/legacy/AcceptanceTests |
| Vanilla Low Level | test/vanilla/llc/AcceptanceTests |
| Azure Legacy | test/azure/legacy/AcceptanceTests |
| Azure Low Level | test/azure/llc/AcceptanceTests |
| Multiapi | test/multiapi/AcceptanceTests |
| Unittests | test/unittests |
- If adding a new test file, make sure you mark it with the Microsoft MIT license header
- In vast majority of cases, if you are adding a test, you will need to add it's async counterpart as well. Sync tests reside at the root of the
AcceptanceTestsfolder, whil async tests reside inAcceptanceTests/asynctests - Use fixtures where possible to decompose and organize your test work
- Create a new and activate a virtual environment inside every test folder. For example, create virtual environment
vanilla_legacy_test_venvintest/vanilla/legacy. Note: Do not use the rootvenvas your test virtual environment. You should be creating a new virtual environment for every test folder. Each virtual environment should only have the requirements for testing. -
pip install -r requirements.txtto get all of the specific requirements for that test folder - Run with
pytest - You can also debug with your editor of choice. Just make sure your python interpreter is the virtual environment you created in step 1
- Run
pylint autorestandmypy autorestfrom the root folder, to make sure your code is linted and typed well - Run
inv regenerateagain to make sure all of the test swaggers are regenerated with your fix - Run the tests in our various test folders
- If your change is a bug fix / new feature, add it to the Changelog. Please include the PR number in your description, and make sure the min version table is present. Additionally, tag yourself as fixing this issue! You deserve all the credit!
- If you have to bump any of the dependencies of the generator or the generated code, please edit the min version table, and the Minimum Dependencies of Your Client documentation
- Push to either
autorest.pythonor your fork ofautorest.pythonand create your PR! Tag @iscai-msft, @lmazuel, and / or @msyyc for review - Once pushed, our CI will start running. If you have to make any changes to fix the CI or because of PR comments, make sure you repeat steps 1-3 before pushing you changes.
And on a final note, thank you so much again for your contribution! It really means a lot to us!