|
| 1 | +# Tool Usage Guide |
| 2 | + |
| 3 | +As part of shipping SDKs that can be trusted by customers, the azure-sdk-for-python dev team maintains a suite of `checks` that can be utilized by developers to ensure predictable quality measures. These checks help determine whether a package meets the required quality standards for release or needs further work before it can be shipped. These `checks` are implemented in a single entrypoint within the local development package `eng/tools/azure-sdk-tools`. This package provides: |
| 4 | + |
| 5 | + - Templated package generation for mgmt packages |
| 6 | + - The test-framework that all packages within this monorepo use (including record/playback integration) |
| 7 | + - A ton of CI related tasks and boilerplate |
| 8 | + - Static analysis code |
| 9 | + |
| 10 | +A `tool` in this context is merely a single entrypoint provided by the `azpysdk` entrypoint in the `eng/tools/azure-sdk-tools` package. |
| 11 | + |
| 12 | +## Available Tools |
| 13 | + |
| 14 | +This repo is currently migrating all checks from a slower `tox`-based framework, to a lightweight implementation that uses `asyncio` to simultaneously run checks. This tools list is the current set that has been migrated from `tox` to the `azpysdk` entrypoint. |
| 15 | + |
| 16 | +|tool|description|invocation| |
| 17 | +|---|---|---| |
| 18 | +|`pylint`| Runs `pylint` checks or `next-pylint` checks. (based on presence of `--next` argument) | `azpysdk pylint .` | |
| 19 | +|`mypy`| Runs `mypy` checks or `next-mypy` checks. (based on presence of `--next` argument) | `azpysdk mypy --next=True .` | |
| 20 | +|`sphinx`| Generates a documentation website for the targeted packages. Runs `sphinx` or `next-sphinx` (based on presence of `--next` argument). | `azpysdk sphinx .` | |
| 21 | +|`black`| Runs `black` checks. | `azpysdk black .` | |
| 22 | +|`import_all`| Installs the package w/ default dependencies, then attempts to `import *` from the base namespace. Ensures that all imports will resolve after a base install and import. | `azpysdk import_all .` | |
| 23 | + |
| 24 | +## Common arguments |
| 25 | + |
| 26 | +### Globbing |
| 27 | +The azpysdk is intended to be used from within the azure-sdk-for-python repository. A user can invoke |
| 28 | + |
| 29 | +``` |
| 30 | +/azure-sdk-for-python/> azpysdk import_all azure-storage* # will run import_all for all packages starting with `azure-storage` |
| 31 | +
|
| 32 | +/azure-sdk-for-python/> azpysdk import_all azure-storage-blob,azure-core # invoke import_all for two packages |
| 33 | +
|
| 34 | +/azure-sdk-for-python/sdk/core/azure-core/> azpysdk import_all . # invoke import_all for the local package only |
| 35 | +``` |
| 36 | + |
| 37 | +### Automatically isolating the environment |
| 38 | + |
| 39 | +The targeted tool should be able to run in an isolated environment for a couple reasons: |
| 40 | +- When attempting to diagnose an issue, sometimes a user is best served by completely wiping their `venv` and starting over from scratch. Issues may stem from having additional deps downloaded that normally wouldn't be installed with the package. |
| 41 | +- In `CI`, we _have_ to run in isolated virtual environments for some checks to allow processes like `multiple pytest` runs to invoke without accidentally stomping on each other's progress or hitting file contention errors. CI passes this flag by default from `dispatch_checks.py`. |
| 42 | + |
| 43 | +To utilize this feature, add `--isolate` to any `azpysdk` invocation: |
| 44 | + |
| 45 | +```bash |
| 46 | +/> azpysdk import_all azure-storage-blob --isolate |
| 47 | +# will install and run within a venv in `sdk/storage/azure-storage-blob/.venv_import_all/ |
| 48 | +``` |
| 49 | + |
| 50 | +## Prerequisite |
| 51 | + |
| 52 | +- You need to have Python installed |
| 53 | +- The monorepo requires a minimum of `python 3.9`, but `>=3.11` is required for the `sphinx` check due to compatibility constraints with external processes. |
| 54 | +- You may optionally use the ["uv"](https://docs.astral.sh/uv/) tool, which is fast and handles Python version and venv creation automatically. |
| 55 | + |
| 56 | +## Initial setup |
| 57 | + |
| 58 | +- Go to the folder of the package you're working on, for instance `sdk/contoso/azure-contoso` |
| 59 | + |
| 60 | +### Setup with uv |
| 61 | + |
| 62 | +`uv venv` |
| 63 | + |
| 64 | +```bash |
| 65 | +# for WSL |
| 66 | +source .venv/bin/activate |
| 67 | + |
| 68 | +# for Windows |
| 69 | +.venv\Scripts\activate |
| 70 | +``` |
| 71 | + |
| 72 | +`uv pip install -r dev_requirements.txt` |
| 73 | + |
| 74 | +### Setup with pip/python |
| 75 | + |
| 76 | +`python -m venv .venv` |
| 77 | + |
| 78 | +```bash |
| 79 | +# for WSL |
| 80 | +source .venv/bin/activate |
| 81 | + |
| 82 | +# for Windows |
| 83 | +.venv\Scripts\activate |
| 84 | +``` |
| 85 | + |
| 86 | +`pip install -r dev_requirements.txt` |
| 87 | + |
| 88 | +## Using the CLI |
| 89 | + |
| 90 | +```bash |
| 91 | +# You can call the command directly if you activated the venv |
| 92 | +azpysdk <tool_name> |
| 93 | +``` |
| 94 | + |
| 95 | +## Advanced scenario |
| 96 | + |
| 97 | +### Using different Python version |
| 98 | + |
| 99 | +You can locally test different Python versions to check compatibility with all the required Python versions. |
| 100 | + |
| 101 | +Note that this is optional, and you can rely on CI to test python versions. |
| 102 | + |
| 103 | +#### With uv |
| 104 | + |
| 105 | +You can specify a Python version upon venv creation: |
| 106 | +`uv venv --python 3.11` |
| 107 | + |
| 108 | +#### With Python |
| 109 | + |
| 110 | +You need to install [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation), which lets you easily switch between multiple versions of Python. |
| 111 | + |
| 112 | +To switch Python versions: |
| 113 | +``` |
| 114 | +pyenv install 3.10 |
| 115 | +pyenv global 3.10 |
| 116 | +``` |
0 commit comments