4.0 KiB
Setting up your development environment
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.
Preparing your machine
- Install Python 3.5.x 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 master branch.
- Create a new virtual environment “env” for Python 3.5 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 az.completion.sh
Configuring your IDE
Visual Studio (Windows only)
- 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
Visual Studio Code (Any platform)
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) Debugging should now work (including stepping and setting breakpoints).
The repo has a launch.json file that will launch the version of Python that is first on your path.
Running CLI
Command line
- Activate your virtual environment if not already done
OSX/Ubuntu (bash):
source <clone root>/env/scripts/activate
Windows:
<clone root>\env\scripts\activate.bat
- Invoke the CLI using:
OSX/Ubuntu (bash):
az
Windows:
<clone root>\az.bat [commands]
which is equivalent to the following:
<clone root>\src\python -m azure.cli [commands]
Running Tests:
Command line
Windows:
Provided your PYTHONPATH was set correctly, you can run the tests from your <root clone>
directory.
To test the core of the CLI:
python -m unittest discover -s src/azure-cli/azure/cli/tests
To test the command modules:
python scripts/command_modules/test.py
To check or pylint errors in the core of the CLI:
pylint src/azure
To check the command modules for pylint errors:
python scripts/command_modules/pylint.py
Additionally, you can run pylint tests for the core CLI and all command modules using the lintall.bat
script, and run tests for the core CLI and all command modules using the testall.bat
script.
VS Code
Under construction...
Visual Studio
Select Test > Windows > Test Explorer
and click Run All
in the Test Explorer pane.