-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add Documentation on UV and Tool Usage #42854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c01edf
start draft of uv docs
JennyPng b27cece
revise
JennyPng 1e1ff6f
minor fix
JennyPng 4b2ebf1
edits
JennyPng c7eca26
minor edits
JennyPng ffb6081
uv venv edit
JennyPng 22cfbb1
revisions from review
JennyPng f274d47
add check table and word to cspell
JennyPng 0cb43fe
typo
JennyPng eaf40f7
Apply suggestions from code review
JennyPng dd87ca6
Update .vscode/cspell.json
JennyPng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,8 @@ | |
| "avroencoder", | ||
| "Avs", | ||
| "azcmagent", | ||
| "azpysdk", | ||
| "pyenv", | ||
| "azsdk", | ||
| "azurecr", | ||
| "azuremgmtcore", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Tool Usage Guide | ||
|
|
||
|
JennyPng marked this conversation as resolved.
|
||
| 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: | ||
|
|
||
| - Templated package generation for mgmt packages | ||
| - The test-framework that all packages within this monorepo use (including record/playback integration) | ||
| - A ton of CI related tasks and boilerplate | ||
| - Static analysis code | ||
|
|
||
| A `tool` in this context is merely a single entrypoint provided by the `azpysdk` entrypoint in the `eng/tools/azure-sdk-tools` package. | ||
|
|
||
| ## Available Tools | ||
|
|
||
|
JennyPng marked this conversation as resolved.
|
||
| 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. | ||
|
|
||
| |tool|description|invocation| | ||
| |---|---|---| | ||
| |`pylint`| Runs `pylint` checks or `next-pylint` checks. (based on presence of `--next` argument) | `azpysdk pylint .` | | ||
| |`mypy`| Runs `mypy` checks or `next-mypy` checks. (based on presence of `--next` argument) | `azpysdk mypy --next=True .` | | ||
| |`sphinx`| Generates a documentation website for the targeted packages. Runs `sphinx` or `next-sphinx` (based on presence of `--next` argument). | `azpysdk sphinx .` | | ||
| |`black`| Runs `black` checks. | `azpysdk black .` | | ||
| |`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 .` | | ||
|
|
||
| ## Common arguments | ||
|
|
||
| ### Globbing | ||
| The azpysdk is intended to be used from within the azure-sdk-for-python repository. A user can invoke | ||
|
|
||
| ``` | ||
| /azure-sdk-for-python/> azpysdk import_all azure-storage* # will run import_all for all packages starting with `azure-storage` | ||
|
|
||
| /azure-sdk-for-python/> azpysdk import_all azure-storage-blob,azure-core # invoke import_all for two packages | ||
|
|
||
|
JennyPng marked this conversation as resolved.
|
||
| /azure-sdk-for-python/sdk/core/azure-core/> azpysdk import_all . # invoke import_all for the local package only | ||
| ``` | ||
|
|
||
| ### Automatically isolating the environment | ||
|
|
||
| The targeted tool should be able to run in an isolated environment for a couple reasons: | ||
| - 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. | ||
| - 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`. | ||
|
|
||
| To utilize this feature, add `--isolate` to any `azpysdk` invocation: | ||
|
|
||
| ```bash | ||
| /> azpysdk import_all azure-storage-blob --isolate | ||
| # will install and run within a venv in `sdk/storage/azure-storage-blob/.venv_import_all/ | ||
| ``` | ||
|
|
||
| ## Prerequisite | ||
|
|
||
| - You need to have Python installed | ||
| - 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. | ||
| - You may optionally use the ["uv"](https://docs.astral.sh/uv/) tool, which is fast and handles Python version and venv creation automatically. | ||
|
|
||
| ## Initial setup | ||
|
|
||
| - Go to the folder of the package you're working on, for instance `sdk/contoso/azure-contoso` | ||
|
|
||
| ### Setup with uv | ||
|
|
||
| `uv venv` | ||
|
|
||
| ```bash | ||
| # for WSL | ||
| source .venv/bin/activate | ||
|
|
||
| # for Windows | ||
| .venv\Scripts\activate | ||
| ``` | ||
|
|
||
| `uv pip install -r dev_requirements.txt` | ||
|
|
||
| ### Setup with pip/python | ||
|
|
||
| `python -m venv .venv` | ||
|
|
||
| ```bash | ||
| # for WSL | ||
| source .venv/bin/activate | ||
|
|
||
| # for Windows | ||
| .venv\Scripts\activate | ||
| ``` | ||
|
|
||
| `pip install -r dev_requirements.txt` | ||
|
|
||
| ## Using the CLI | ||
|
|
||
| ```bash | ||
| # You can call the command directly if you activated the venv | ||
| azpysdk <tool_name> | ||
| ``` | ||
|
|
||
| ## Advanced scenario | ||
|
|
||
| ### Using different Python version | ||
|
|
||
|
JennyPng marked this conversation as resolved.
|
||
| You can locally test different Python versions to check compatibility with all the required Python versions. | ||
|
|
||
| Note that this is optional, and you can rely on CI to test python versions. | ||
|
|
||
| #### With uv | ||
|
|
||
| You can specify a Python version upon venv creation: | ||
| `uv venv --python 3.11` | ||
|
|
||
| #### With Python | ||
|
|
||
| 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. | ||
|
|
||
| To switch Python versions: | ||
| ``` | ||
| pyenv install 3.10 | ||
| pyenv global 3.10 | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.