Commit 49ee58b
authored
fix: bridge Python environment selection to content creator commands (#2763)
## Bridge Python environment selection to content creator commands
### Problem
Content creator commands (`ansible-creator`, `ade`, etc.) were not
respecting the Python environment selected in VS Code. When users
selected a virtual environment containing these tools, the extension
would still attempt to execute them using system Python, resulting in
"command not found" errors even when the tools were correctly installed
in the selected venv.
This affected:
- Collection/Project/Role/Devfile/Devcontainer creation panels
- Execution Environment panel
- Ansible Vault operations
- All commands executed via `withInterpreter()`
### Root Cause
The `withInterpreter()` helper was a legacy synchronous function that
only set `ANSIBLE_FORCE_COLOR` and `PYTHONBREAKPOINT` environment
variables. It did not:
1. Resolve the active Python environment
2. Add the venv's `bin/` directory to `PATH`
3. Set `VIRTUAL_ENV` for tools that check it
Additionally, `PythonEnvironmentService.getEnvironment()` would return
system Python when no workspace scope was provided, even when a
workspace-specific venv was selected.
### Solution
#### 1. Enhanced `withInterpreter()` to bridge Python environment
- Made function async to support environment resolution
- Integrated `PythonEnvironmentService` to resolve interpreter path
- Added venv `bin/` directory to `PATH` before command execution
- Set `VIRTUAL_ENV` environment variable for compatibility
#### 2. Workspace scope defaulting
Added intelligent scope resolution in
`PythonEnvironmentService.getEnvironment()`:
- Defaults to first workspace folder when no scope provided
- Ensures workspace-specific Python environments are used instead of
system Python
- Maintains explicit scope behavior when caller provides one
#### 3. Configuration middleware improvements
- Added `PythonEnvironmentService.resolveInterpreterPath()` to
centralize path resolution
- Expanded tilde (`~`) and `${workspaceFolder}` in user-configured
interpreter paths
- Added error handling for configuration fetch and environment
resolution failures
- Send expanded paths to language server to avoid server-side expansion
issues
#### 4. Execution Environment webview parity
- Added requirements checking to Execution Environment panel (previously
missing)
- Added `RequirementsBanner` component to show version check results
- Aligned behavior with other content creator panels
### Changes
**Core Infrastructure:**
- `src/features/utils/commandRunner.ts` - Made `withInterpreter()` async
with venv PATH support
- `src/services/PythonEnvironmentService.ts` - Added scope defaulting
and `resolveInterpreterPath()` method
**Updated Callers (now await async `withInterpreter()`):**
- `src/extension.ts` - ansible-creator and ansible-dev-tools
installation commands
- `src/features/contentCreator/utils.ts` - `getBinDetail()` for version
checks
- `src/features/lightspeed/vue/views/ansibleCreatorUtils.ts` - Role,
plugin, collection, project creation
- `src/features/lightspeed/vue/views/webviewMessageHandlers.ts` -
Execution environment init
- `src/features/utils/buildExecutionEnvironment.ts` - EE build command
- `src/features/vault.ts` - All ansible-vault operations
**Configuration Middleware:**
- `src/extension.ts` - `makeConfigurationMiddleware()` now expands user
paths and handles errors gracefully
**UI:**
- `src/features/contentCreator/vue/views/createExecutionEnvPanel.ts` -
Added requirements check message handler
- `webviews/CreateExecutionEnvApp.vue` - Added `RequirementsBanner` and
requirements state
**Tests:**
- `test/unit/utils/commandRunner.test.ts` - New comprehensive unit tests
(10 tests)
- `test/unit/services/PythonEnvironmentService.test.ts` - Added scope
resolution tests (6 new tests)
- `test/unit/configurationMiddleware.test.ts` - Added error handling and
path expansion tests (3 new tests)
### Testing
**Unit Tests:** 56 tests (54 passing, 2 skipped)
- `commandRunner.test.ts` - Validates PATH manipulation, environment
variable setting, scope handling
- `PythonEnvironmentService.test.ts` - Tests scope resolution for
single/multi-workspace scenarios
- `configurationMiddleware.test.ts` - Validates path expansion and error
handling
**Integration Tests:**
- `utilities.test.ts` - Validates real command execution through
`getBinDetail()`
### Migration Notes
The changes are backward compatible:
- `withInterpreter()` is now async but maintains the same return
signature
- All callers updated to use `await`
- No configuration changes required from users
- Workspace scope defaulting is transparent
### Limitations
- Multi-workspace setups default to first workspace folder when no scope
provided (RFE: add workspace picker for ambiguous cases)
- Debug logging added temporarily to aid troubleshooting (can be removed
after stabilization)
## Identified Regression
In #2757, the resources for devfile and devcontainer were identified as
build artifacts, when they need to be packaged into the final .vsix. The
fixes for this were incorporated into this change due to urgency.1 parent c2baa58 commit 49ee58b
19 files changed
Lines changed: 820 additions & 130 deletions
File tree
- src
- features
- contentCreator
- vue/views
- lightspeed/vue/views
- utils
- services
- test/unit
- contentCreator
- services
- utils
- tools
- webviews
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | | - | |
| 599 | + | |
600 | 600 | | |
601 | 601 | | |
602 | 602 | | |
| |||
1032 | 1032 | | |
1033 | 1033 | | |
1034 | 1034 | | |
1035 | | - | |
| 1035 | + | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | 1038 | | |
| |||
1447 | 1447 | | |
1448 | 1448 | | |
1449 | 1449 | | |
1450 | | - | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
1451 | 1460 | | |
1452 | 1461 | | |
1453 | 1462 | | |
| |||
1467 | 1476 | | |
1468 | 1477 | | |
1469 | 1478 | | |
1470 | | - | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
1471 | 1488 | | |
1472 | 1489 | | |
1473 | | - | |
| 1490 | + | |
1474 | 1491 | | |
1475 | 1492 | | |
1476 | 1493 | | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
1477 | 1505 | | |
1478 | 1506 | | |
1479 | 1507 | | |
1480 | 1508 | | |
1481 | | - | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
1482 | 1522 | | |
1483 | 1523 | | |
1484 | 1524 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
23 | 38 | | |
24 | 39 | | |
25 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | | - | |
| 418 | + | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| |||
Lines changed: 5 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
742 | 742 | | |
743 | 743 | | |
744 | 744 | | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
| 745 | + | |
| 746 | + | |
749 | 747 | | |
750 | 748 | | |
751 | 749 | | |
| |||
872 | 870 | | |
873 | 871 | | |
874 | 872 | | |
875 | | - | |
| 873 | + | |
876 | 874 | | |
877 | 875 | | |
878 | 876 | | |
| |||
882 | 880 | | |
883 | 881 | | |
884 | 882 | | |
885 | | - | |
886 | | - | |
887 | | - | |
| 883 | + | |
888 | 884 | | |
889 | 885 | | |
890 | 886 | | |
| |||
1104 | 1100 | | |
1105 | 1101 | | |
1106 | 1102 | | |
1107 | | - | |
| 1103 | + | |
1108 | 1104 | | |
1109 | 1105 | | |
1110 | 1106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | | - | |
10 | | - | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | | - | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | | - | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
33 | 64 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
275 | | - | |
| 279 | + | |
276 | 280 | | |
277 | 281 | | |
278 | 282 | | |
| |||
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
284 | | - | |
| 288 | + | |
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
288 | | - | |
| 292 | + | |
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
292 | 296 | | |
293 | | - | |
| 297 | + | |
294 | 298 | | |
295 | 299 | | |
296 | 300 | | |
297 | | - | |
| 301 | + | |
298 | 302 | | |
299 | 303 | | |
300 | 304 | | |
| |||
305 | 309 | | |
306 | 310 | | |
307 | 311 | | |
308 | | - | |
| 312 | + | |
309 | 313 | | |
310 | 314 | | |
311 | 315 | | |
312 | 316 | | |
313 | | - | |
| 317 | + | |
314 | 318 | | |
315 | 319 | | |
316 | | - | |
| 320 | + | |
317 | 321 | | |
318 | 322 | | |
319 | 323 | | |
| |||
0 commit comments