Commit 1df317b
Refactor setup_venv.py, including adding --find-links support (ROCm#3242)
## Motivation
Progress on ROCm#1559. I'm splitting
this off from ROCm#3182.
In ROCm#3136, I'm using
[`indexer.py`](https://github.com/ROCm/TheRock/blob/main/third-party/indexer/indexer.py)
to generate an index page for a CI workflow run that can be installed
from using `--find-links` (and _not_ `--index-url`). For example:
https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/index.html.
For workflows and developers to be able to conveniently create Python
venvs and install those packages, this setup_venv.py script needed
support for `--find-links` too.
## Technical Details
Key points about the refactoring:
1. Changed scraping signature / behavior to returns the union of all
subdirs instead of a distinct list of subdirs per package index. If
someone tries to install a package from an index that doesn't have that
package, that will be a later error.
* before: `scrape_subdirs() -> dict[str, set[str]] | set[str] | None`
* after: `_scrape_rocm_index_subdirs() -> set[str] | None`
2. Reworked branching between `pip` and `uv` to make it more clear what
is being used where and why
3. Streamlined `run()` to emphasize the `create_venv` -> `update_venv`
-> `install_packages_into_venv` flow
4. Allowed setting `--packages` without `--index-url` or `--index-name`
(to install from the default pypi index)
5. Added new `--find-links` option (can be used together with
`--index-url` as they are compatible/complimentary)
Documentation for reference:
* https://pip.pypa.io/en/stable/cli/pip_install/
* https://docs.astral.sh/uv/pip/packages/
## Test Plan
* CI usage in some existing workflows
* New unit tests for helper functions
## Test Result
Manual testing:
<details><summary>With `--find-links` and pip</summary>
<p>
```
D:\scratch\therock
λ python D:\projects\TheRock\build_tools/setup_venv.py test.venv --packages rocm[libraries]==7.12.0.dev0 --find-links=https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/index.html --clean
Clearing existing venv_dir 'test.venv'
Creating venv at 'test.venv'
Dir relative to CWD: 'test.venv'
Dir fully resolved : 'D:\scratch\therock\test.venv'
++ Exec [D:\scratch\therock]$ 'C:\Users\Nod-Shark16\AppData\Local\Programs\Python\Python313\python.exe' -m venv 'D:\scratch\therock\test.venv'
++ Exec [D:\scratch\therock]$ 'test.venv\Scripts\python.exe' -m pip install --upgrade pip
Requirement already satisfied: pip in d:\scratch\therock\test.venv\lib\site-packages (25.1.1)
Collecting pip
Using cached pip-26.0-py3-none-any.whl.metadata (4.7 kB)
Using cached pip-26.0-py3-none-any.whl (1.8 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 25.1.1
Uninstalling pip-25.1.1:
Successfully uninstalled pip-25.1.1
Successfully installed pip-26.0
++ Exec [D:\scratch\therock]$ 'test.venv\Scripts\python.exe' -m pip install --find-links=https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/index.html 'rocm[libraries]==7.12.0.dev0'
Looking in links: https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/index.html
Collecting rocm==7.12.0.dev0 (from rocm[libraries]==7.12.0.dev0)
Using cached rocm-7.12.0.dev0-py3-none-any.whl
Collecting rocm-sdk-core==7.12.0.dev0 (from rocm==7.12.0.dev0->rocm[libraries]==7.12.0.dev0)
Using cached https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/rocm_sdk_core-7.12.0.dev0-py3-none-win_amd64.whl (654.1 MB)
Collecting rocm-sdk-libraries-gfx110X-all==7.12.0.dev0 (from rocm[libraries]==7.12.0.dev0)
Using cached https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/rocm_sdk_libraries_gfx110x_all-7.12.0.dev0-py3-none-win_amd64.whl (224.4 MB)
Installing collected packages: rocm-sdk-libraries-gfx110X-all, rocm-sdk-core, rocm
Successfully installed rocm-7.12.0.dev0 rocm-sdk-core-7.12.0.dev0 rocm-sdk-libraries-gfx110X-all-7.12.0.dev0
Setup complete at 'test.venv'! Activate the venv with:
test.venv\Scripts\activate.bat
```
</p>
</details>
<details><summary>With `--find-links` and uv</summary>
<p>
```
λ python D:\projects\TheRock\build_tools/setup_venv.py test_uv.venv --packages rocm[libraries]==7.12.0.dev0 --find-links=https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/index.html --clean --use-uv --pre
Clearing existing venv_dir 'test_uv.venv'
Creating venv at 'test_uv.venv'
Dir relative to CWD: 'test_uv.venv'
Dir fully resolved : 'D:\scratch\therock\test_uv.venv'
++ Exec [D:\scratch\therock]$ uv venv 'D:\scratch\therock\test_uv.venv'
Using CPython 3.13.5 interpreter at: C:\Users\Nod-Shark16\AppData\Local\Programs\Python\Python313\python.exe
Creating virtual environment at: test_uv.venv
Activate with: test_uv.venv\Scripts\activate
++ Exec [D:\scratch\therock]$ uv pip install --python 'test_uv.venv\Scripts\python.exe' --find-links=https://therock-artifacts-testing.s3.amazonaws.com/21440027240-windows/python/gfx110X-all/index.html --prerelease=allow 'rocm[libraries]==7.12.0.dev0'
Using Python 3.13.5 environment at: test_uv.venv
Resolved 3 packages in 162ms
░░░░░░░░░░░░░░░░░░░░ [0/3] Installing wheels...
warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
If the cache and target directories are on different filesystems, hardlinking may not be supported.
If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.
Installed 3 packages in 1.09s
+ rocm==7.12.0.dev0
+ rocm-sdk-core==7.12.0.dev0
+ rocm-sdk-libraries-gfx110x-all==7.12.0.dev0
Setup complete at 'test_uv.venv'! Activate the venv with:
test_uv.venv\Scripts\activate.bat
```
</p>
</details>
## Submission Checklist
- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1f9fc2e commit 1df317b
2 files changed
+310
-116
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 43 | | |
49 | 44 | | |
50 | | - | |
51 | | - | |
52 | 45 | | |
53 | 46 | | |
54 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
| |||
68 | 63 | | |
69 | 64 | | |
70 | 65 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 66 | + | |
| 67 | + | |
76 | 68 | | |
77 | 69 | | |
78 | 70 | | |
79 | 71 | | |
80 | 72 | | |
81 | 73 | | |
82 | 74 | | |
83 | | - | |
84 | | - | |
85 | | - | |
| 75 | + | |
| 76 | + | |
86 | 77 | | |
| 78 | + | |
| 79 | + | |
87 | 80 | | |
88 | 81 | | |
89 | 82 | | |
| |||
92 | 85 | | |
93 | 86 | | |
94 | 87 | | |
95 | | - | |
96 | | - | |
| 88 | + | |
| 89 | + | |
97 | 90 | | |
98 | 91 | | |
99 | 92 | | |
100 | | - | |
| 93 | + | |
101 | 94 | | |
102 | 95 | | |
103 | 96 | | |
104 | | - | |
105 | | - | |
106 | | - | |
| 97 | + | |
107 | 98 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
111 | 103 | | |
112 | 104 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
116 | 109 | | |
| 110 | + | |
117 | 111 | | |
| 112 | + | |
| 113 | + | |
118 | 114 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 115 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 116 | + | |
| 117 | + | |
129 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
130 | 122 | | |
131 | | - | |
132 | 123 | | |
133 | 124 | | |
134 | 125 | | |
| |||
154 | 145 | | |
155 | 146 | | |
156 | 147 | | |
157 | | - | |
158 | | - | |
159 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
160 | 173 | | |
161 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
162 | 181 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 182 | + | |
| 183 | + | |
173 | 184 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
178 | 188 | | |
179 | | - | |
180 | | - | |
181 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
182 | 193 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 194 | + | |
187 | 195 | | |
188 | | - | |
| 196 | + | |
| 197 | + | |
189 | 198 | | |
| 199 | + | |
| 200 | + | |
190 | 201 | | |
191 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
192 | 212 | | |
193 | 213 | | |
194 | 214 | | |
| |||
199 | 219 | | |
200 | 220 | | |
201 | 221 | | |
202 | | - | |
| 222 | + | |
203 | 223 | | |
204 | 224 | | |
205 | 225 | | |
206 | 226 | | |
207 | 227 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 228 | + | |
| 229 | + | |
217 | 230 | | |
218 | 231 | | |
219 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
220 | 243 | | |
221 | 244 | | |
222 | 245 | | |
223 | 246 | | |
224 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
225 | 276 | | |
226 | 277 | | |
227 | 278 | | |
| |||
238 | 289 | | |
239 | 290 | | |
240 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
241 | 297 | | |
242 | 298 | | |
243 | 299 | | |
244 | | - | |
| 300 | + | |
245 | 301 | | |
246 | 302 | | |
247 | 303 | | |
| |||
259 | 315 | | |
260 | 316 | | |
261 | 317 | | |
| 318 | + | |
262 | 319 | | |
263 | 320 | | |
264 | 321 | | |
265 | | - | |
| 322 | + | |
266 | 323 | | |
267 | | - | |
268 | | - | |
269 | 324 | | |
270 | | - | |
271 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
272 | 331 | | |
273 | 332 | | |
274 | | - | |
275 | | - | |
| 333 | + | |
| 334 | + | |
276 | 335 | | |
277 | | - | |
278 | | - | |
| 336 | + | |
| 337 | + | |
279 | 338 | | |
280 | | - | |
| 339 | + | |
281 | 340 | | |
282 | 341 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 342 | + | |
| 343 | + | |
294 | 344 | | |
295 | 345 | | |
296 | 346 | | |
297 | 347 | | |
298 | | - | |
299 | | - | |
| 348 | + | |
| 349 | + | |
300 | 350 | | |
301 | 351 | | |
302 | 352 | | |
303 | 353 | | |
304 | | - | |
305 | 354 | | |
306 | 355 | | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 356 | + | |
| 357 | + | |
321 | 358 | | |
322 | 359 | | |
323 | 360 | | |
| |||
0 commit comments