Skip to content

Commit c754a76

Browse files
Environment exclusion
1 parent e18e280 commit c754a76

File tree

6 files changed

+76
-28
lines changed

6 files changed

+76
-28
lines changed

.devcontainer/SETUP_SUMMARY.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This document summarizes the changes made to simplify and robustly configure the
1414
- **Before**: Manual kernel selection required, multiple kernels visible
1515
- **After**: Only the correct venv kernel is visible and auto-selected
1616
- **Implementation**:
17-
- Kernel filtering in VS Code settings (`jupyter.kernels.filter`)
17+
- Python environment exclusion (`jupyter.kernels.excludePythonEnvironments`)
1818
- Trusted kernel configuration (`jupyter.kernels.trusted`)
1919
- Automatic kernel registration during container setup
2020

@@ -81,12 +81,20 @@ python -m ipykernel install --user --name=apim-samples --display-name='APIM Samp
8181
### VS Code Jupyter Settings
8282
```json
8383
{
84-
"jupyter.kernels.filter": [
84+
"jupyter.kernels.excludePythonEnvironments": [
8585
"/usr/bin/python3",
8686
"/bin/python3",
8787
"/usr/local/bin/python3",
8888
"/opt/python/*/bin/python*",
89-
"*/site-packages/*"
89+
"*/site-packages/*",
90+
"**/miniconda3/**",
91+
"**/anaconda3/**",
92+
"**/conda/**",
93+
"/usr/bin/python",
94+
"/bin/python",
95+
"**/python3.*",
96+
"python3",
97+
"python"
9098
],
9199
"jupyter.kernels.trusted": [
92100
"/workspaces/Apim-Samples/.venv/bin/python"

.devcontainer/devcontainer.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,24 @@
6565
"jupyter.askForKernelRestart": false,
6666
"jupyter.interactiveWindow.textEditor.executeSelection": true,
6767
"jupyter.notebookFileRoot": "${workspaceFolder}",
68-
"notebook.defaultKernel": "apim-samples",
68+
"jupyter.kernels.excludePythonEnvironments": [
69+
"/usr/bin/python3",
70+
"/bin/python3",
71+
"/usr/local/bin/python3",
72+
"/opt/python/*/bin/python*",
73+
"*/site-packages/*",
74+
"**/miniconda3/**",
75+
"**/anaconda3/**",
76+
"**/conda/**",
77+
"/usr/bin/python",
78+
"/bin/python",
79+
"**/python3.*",
80+
"python3",
81+
"python"
82+
],
6983
"jupyter.kernels.trusted": [
7084
"/workspaces/Apim-Samples/.venv/bin/python"
7185
],
72-
"notebook.kernelProviderAssociations": {
73-
"**/*.ipynb": [
74-
"apim-samples"
75-
]
76-
},
7786
"files.associations": {
7887
"*.bicep": "bicep"
7988
}

.vscode/settings.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,24 @@
2222
"jupyter.askForKernelRestart": false,
2323
"jupyter.interactiveWindow.textEditor.executeSelection": true,
2424
"jupyter.notebookFileRoot": "${workspaceFolder}",
25-
"notebook.defaultKernel": "apim-samples",
25+
"jupyter.kernels.excludePythonEnvironments": [
26+
"/usr/bin/python3",
27+
"/bin/python3",
28+
"/usr/local/bin/python3",
29+
"/opt/python/*/bin/python*",
30+
"*/site-packages/*",
31+
"**/miniconda3/**",
32+
"**/anaconda3/**",
33+
"**/conda/**",
34+
"/usr/bin/python",
35+
"/bin/python",
36+
"**/python3.*",
37+
"python3",
38+
"python"
39+
],
2640
"jupyter.kernels.trusted": [
2741
"/workspaces/Apim-Samples/.venv/bin/python"
2842
],
29-
"notebook.kernelProviderAssociations": {
30-
"**/*.ipynb": [
31-
"apim-samples"
32-
]
33-
},
3443
"terminal.integrated.env.windows": {
3544
"PATH": "${env:PATH}"
3645
},

apim-samples.code-workspace

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
{
55
"path": "."
66
}
7-
],
8-
"settings": {
9-
// Default kernel for all notebooks in this workspace
10-
"notebook.defaultKernel": "apim-samples",
11-
12-
// Kernel associations to ensure our kernel is preferred
13-
"notebook.kernelProviderAssociations": {
14-
"**/*.ipynb": [
15-
"apim-samples"
16-
]
17-
},
7+
], "settings": {
8+
// Exclude all Python environments except our venv to ensure auto-selection
9+
"jupyter.kernels.excludePythonEnvironments": [
10+
"/usr/bin/python3",
11+
"/bin/python3",
12+
"/usr/local/bin/python3",
13+
"/opt/python/*/bin/python*",
14+
"*/site-packages/*",
15+
"**/miniconda3/**",
16+
"**/anaconda3/**",
17+
"**/conda/**",
18+
"/usr/bin/python",
19+
"/bin/python",
20+
"**/python3.*",
21+
"python3",
22+
"python"
23+
],
1824

1925
// Trust our venv kernel
2026
"jupyter.kernels.trusted": [

test-kernel-selection.ipynb

Whitespace-only changes.

verify-devcontainer.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,26 @@ def main():
135135
f"PYTHONPATH includes: {path}",
136136
f"PYTHONPATH missing: {path}"
137137
):
138-
issues.append(f"PYTHONPATH configuration")
139-
# 5. Check Jupyter kernel
138+
issues.append(f"PYTHONPATH configuration") # 5. Check Jupyter kernel and VS Code settings
140139
print_section("Jupyter Kernel Configuration")
141140

141+
# Check VS Code settings for kernel exclusion
142+
vscode_settings_path = Path('/workspaces/Apim-Samples/.vscode/settings.json')
143+
if vscode_settings_path.exists():
144+
try:
145+
with open(vscode_settings_path, 'r') as f:
146+
# Simple check for the exclusion setting
147+
settings_content = f.read()
148+
if 'jupyter.kernels.excludePythonEnvironments' in settings_content:
149+
print("✅ VS Code kernel exclusion settings configured")
150+
else:
151+
print("⚠️ VS Code kernel exclusion settings not found")
152+
issues.append("VS Code kernel exclusion settings")
153+
except Exception as e:
154+
print(f"⚠️ Could not read VS Code settings: {e}")
155+
else:
156+
print("⚠️ VS Code settings file not found")
157+
142158
try:
143159
# List available kernels
144160
result = subprocess.run(['jupyter', 'kernelspec', 'list', '--json'],

0 commit comments

Comments
 (0)