Skip to content

Commit 6d067b3

Browse files
JennyPngCopilotscbedd
authored
Add Documentation on UV and Tool Usage (#42854)
* start draft of uv docs * revise * minor fix * edits * minor edits * uv venv edit * revisions from review * add check table and word to cspell * typo * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * Update .vscode/cspell.json Co-authored-by: Scott Beddall <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Scott Beddall <[email protected]>
1 parent 1329ed1 commit 6d067b3

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@
197197
"avroencoder",
198198
"Avs",
199199
"azcmagent",
200+
"azpysdk",
201+
"pyenv",
200202
"azsdk",
201203
"azurecr",
202204
"azuremgmtcore",

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ We utilize a variety of tools to ensure smooth development, testing, and code qu
1515

1616
- Virtualenv: [Virtualenv](https://virtualenv.pypa.io/en/latest/) is leveraged by Tox to create isolated environments for each test suite, ensuring consistent dependencies and reducing conflicts.
1717

18+
- UV: [UV](https://docs.astral.sh/uv/) is a fast package manager that can manage Python versions, run and install Python packages, and be used instead of pip, virtualenv, and more.
19+
1820
- Pytest: [Pytest](https://docs.pytest.org/en/stable/) is the test framework we use for writing and running our unit tests. It supports fixtures, parameterized tests, and other features that make testing more powerful and flexible.
1921

2022
- Pylint: [Pylint](https://pylint.readthedocs.io/en/stable/) is used for code linting to enforce coding standards and catch potential issues early. Maintaining a consistent code style is important, and Pylint helps achieve that goal.

doc/tool_usage_guide.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)