If you would like to become an active contributor to this project please follow the instructions provided in Microsoft Azure Projects Contribution Guidelines.
If you want to contribute to a file that is generated (header contains Code generated by Microsoft (R) AutoRest Code Generator.
), the best approach to open a PR on the initial Swagger specification, as we can NOT merge a PR on generated code (it would be replaced by next generation). See https://github.com/Azure/azure-rest-api-specs/ for details.
The Azure SDK team's Python CI leverages the tool tox
to distribute tests to virtual environments, handle test dependency installation, and coordinate tooling reporting during PR/CI builds. This means that a dev working locally can reproduce exactly what the build machine is doing.
Traditionally, the tox.ini
file for a package sits alongside the setup.py in source code. The azure-sdk-for-python
necessarily does not adhere to this policy. There are over one-hundred packages contained here-in. That's a lot of tox.ini
files to maintain!
Instead, the CI system leverages an tox plugin called tox-monorepo
. This plugin allows tox
to act as if the tox.ini
is located in whatever directory you executed tox in!
A given tox.ini
works on the concept of test environments
. A given test environment is a combination of:
- An identifier (or identifiers)
- A targeted Python version
tox
will default to base python executing thetox
command if no Python environment is specified
- (optionally) an OS platform
Internally tox
leverages virtualenv
to create each test environment's virtual environment.
This means that once the tox
workflow is in place, all tests will be executed within a virtual environment.
To see the default environments from a specific tox.ini
file, use the command tox -l
in the same directory as the file itself.
sdk-for-python/eng/tox> tox -l
whl
sdist
Unfortunately, the command tox -l
only returns the default test builds. The common tox.ini
file also supports pylint
and mypy
environments.
Basic usage of tox
within this monorepo is:
pip install tox<4 tox-monorepo
cd
to target package folder- run
tox -c path/to/tox.ini
The common tox.ini
location is eng/tox/tox.ini
within the repository.
If at any time you want to blow away the tox created virtual environments and start over, simply append -r
to any tox invocation!
cd
tosdk/core/azure-core
- Run
tox -e mypy -c ../../../eng/tox/tox.ini
cd
tosdk/storage/azure-storage-blob
- Execute
tox -c ../../../eng/tox/tox.ini
Note that we didn't provide an environment
argument for this example. Reason here is that the default environment selected by our common tox.ini
file is one that runs pytest
.
Used for test execution across the spectrum of all the platforms we want to support. Maintained at a platform specific
level just in case we run into platform-specific bugs.
- Installs the wheel, runs tests using the wheel
\> tox -e whl -c <path to tox.ini>
Used for the local dev loop.
- Installs package in editable mode
- Runs tests using the editable mode installation, not the wheel
\> tox -e sdist -c <path to tox.ini>
Pylint install and run.
\> tox -e pylint -c <path to tox.ini>
Mypy install and run.
\> tox -e mypy -c <path to tox.ini>
Generate sphinx doc for this package.
\> tox -e sphinx -c <path to tox.ini>
tox
supports custom arguments, and the defined pytest environments within the common tox.ini
also allow these. Essentially, separate the arguments you want passed to pytest
by a --
in your tox invocation.
Tox Documentation on Positional Arguments
Example: Invoke tox, breaking into the debugger on failure
tox -e whl -c ../../../eng/tox/tox.ini -- --pdb
SDK performance testing is supported via the custom perfstress
framework. For full details on this framework, and how to write and run tests for an SDK - see the perfstress tests documentation.
We maintain an additional document that has a ton of detail as to what is actually happening in these executions.
Daily dev build version of Azure sdk packages for python are available and are uploaded to Azure devops feed daily. We have also created a tox environment to test a package against dev built version of dependent packages. Below is the link to Azure devops feed.
https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python
pip install <package-name> --extra-index-url https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple --pre
For e.g.
pip install azure-appconfiguration==1.0.0b6.dev20191205001 --extra-index-url https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple
To test a package being developed against latest dev build version of dependent packages: a. cd to package root folder b. run tox environment devtest
\> tox -e devtest -c <path to tox.ini>
This tox test( devtest) will fail if installed dependent packages are not dev build version.
Third party libraries should only be included in samples when necessary to demonstrate usage of an Azure SDK package; they should not be suggested or endorsed as alternatives to the Azure SDK.
When code samples take dependencies, readers should be able to use the material without significant license burden or research on terms. This goal requires restricting dependencies to certain types of open source or commercial licenses.
Samples may take the following categories of dependencies:
-
Open-source : Open source offerings that use an Open Source Initiative (OSI) approved license. Any component whose license isn't OSI-approved is considered a commercial offering. Prefer OSS projects that are members of any of the OSS foundations that Microsoft is part of. Prefer permissive licenses for libraries, like MIT and Apache 2. Copy-left licenses like GPL are acceptable for tools, and OSs. Kubernetes, Linux, and Newtonsoft.Json are examples of this license type. Links to open source components should be to where the source is hosted, including any applicable license, such as a GitHub repository (or similar).
-
Commercial: Commercial offerings that enable readers to learn from our content without unnecessary extra costs. Typically, the offering has some form of a community edition, or a free trial sufficient for its use in content. A commercial license may be a form of dual-license, or tiered license. Links to commercial components should be to the commercial site for the software, even if the source software is hosted publicly on GitHub (or similar).
-
Dual licensed: Commercial offerings that enable readers to choose either license based on their needs. For example, if the offering has an OSS and commercial license, readers can choose between them. MySql is an example of this license type.
-
Tiered licensed: Offerings that enable readers to use the license tier that corresponds to their characteristics. For example, tiers may be available for students, hobbyists, or companies with defined revenue thresholds. For offerings with tiered licenses, strive to limit our use in tutorials to the features available in the lowest tier. This policy enables the widest audience for the article. Docker, IdentityServer, ImageSharp, and Visual Studio are examples of this license type.
In general, we prefer taking dependencies on licensed components in the order of the listed categories. In cases where the category may not be well known, we'll document the category so that readers understand the choice that they're making by using that dependency.
This project's code of conduct can be found in the CODE_OF_CONDUCT.md file (v1.4.0 of the https://contributor-covenant.org/ CoC).