The Azure Python CLI projects sources are located on GitHub (https://github.com/Azure/azure-cli/). In order to contribute to the project, you are expected to:
- Have a GitHub account. For Microsoft contributors, follow the guidelines on https://opensourcehub.microsoft.com/ to create, configure and link your account
- Fork the https://github.com/Azure/azure-cli/ repository into your private GitHub account
- Create pull requests against the https://github.com/azure/azure-cli repository to get your code changes merged into the project repository.
-
Install Python 3.5.x or higher from http://python.org. Please note that the version of Python that comes preinstalled on OSX is 2.7.
-
Clone your repository and check out the
dev
branch. -
Create a new virtual environment “env” for Python in the root of your clone. You can do this by running:
Windows:
python -m venv <clone root>\env
OSX/Ubuntu (bash):
python -m venv <clone root>/env
-
Activate the env virtual environment by running:
Windows:
<clone root>\env\scripts\activate.bat
OSX/Ubuntu (bash):
<clone root>/env/bin/activate
-
Install the dependencies and load the command modules as local packages using pip.
python scripts/dev_setup.py
-
Add
<clone root>\src
to your PYTHONPATH environment variable:Windows:
set PYTHONPATH=<clone root>\src;%PYTHONPATH%
OSX/Ubuntu (bash):
export PYTHONPATH=<clone root>/src:${PYTHONPATH}
-
Setup tab completion (OSX/Ubuntu ONLY).
Open Bash or zsh window and run:
source <clone root>/src/azure-cli/az.completion.sh
- Install Python Tools for Visual Studio. As of 2/18/2016, the current version (PTVS 2.2) can be found at http://microsoft.github.io/PTVS/.
- Open the
azure-cli.pyproj
project You should now be able to launch your project by pressing F5/start debugging
Experimental steps – still haven’t been able to get virtual environments to work well with VSCode
- Install VS Code
- Install (one of) the python extension(s) (https://marketplace.visualstudio.com/items?itemName=donjayamanne.python)
- Put breakpoints in your code, then click on the Debug icon in the Activity Bar on the side of Visual Studio Code, and select
Azure CLI Debug
from the drop down menu. After that, press the play button to start debugging. - To add custom arguments to the command that you want to debug, press the gear icon beside the drop down menu and modify the
args
field inlaunch.json
The repo has a launch.json
file that will launch the version of Python that is first on your path.
- Activate your virtual environment if not already done:
. <clone root>/env/bin/activate
<clone root>\env\scripts\activate.bat
- Invoke the CLI using:
az
Running the dev_setup.py
file will install azdev
, a CLI that performs useful tasks for Azure CLI developers such as executing CLI tests, CLI linter, and style checking.
For a list of available azdev
commands:
azdev --help
To run the CLI tests:
azdev test [-h] [--series] [--live] [--src-file SRC_FILE]
[--dest-file DEST_FILE] [--ci] [--discover]
[--profile PROFILE]
[tests [tests ...]]
Note that to run all tests, use azdev test --ci
.
To check the CLI and command modules for style errors:
azdev style [-h] [--ci] [--pep8] [--pylint] [--module MODULES]
Click on the Debug icon in the Activity Bar on the side of Visual Studio Code, and select Azdev Scripts
from the drop down menu. To execute azdev
commands via Visual Studio Code, you will need to press the gear icon beside the drop down menu and modify the args
field in launch.json
. Make sure that any modification of launch.json
is not included in your pull requests.
Select Test > Windows > Test Explorer
and click Run All
in the Test Explorer pane.