Skip to content

Commit 4ada810

Browse files
authored
Default cell language for native notebooks (#14314)
For #13522 , #13520 * Do not prompt to install ipykernel for non-python kernels * Default the cell of the next blank notebook to language of last saved/used notebook. * Ability to search for kernels based on language (even if kernel spec is not available) * Added Julia language, so users can install this extension and run Julia kernels (remember, they need to select a `Jualia` language in the cell of a VSCode native editor. However Jualia is not a built in language. Will need to submit a PR upstream). * Added tests
1 parent bc1d780 commit 4ada810

36 files changed

+1019
-189
lines changed

.github/workflows/pr_datascience.yml

Lines changed: 300 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# We're not running CI on macOS for now because it's one less matrix entry to lower the number of runners used,
3333
# macOS runners are expensive, and we assume that Ubuntu is enough to cover the UNIX case.
3434
os: [ubuntu-latest]
35-
python: [3.8]
35+
python: [3.8]
3636
test-suite: [group1, group2, group3, group4]
3737
steps:
3838
- name: Checkout
@@ -149,8 +149,305 @@ jobs:
149149
- name: Publish Test Report
150150
uses: scacap/action-surefire-report@v1
151151
with:
152-
github_token: ${{ secrets.GITHUB_TOKEN }}
153-
report_paths: ${{ env.TEST_RESULTS_GLOB }}
152+
github_token: ${{ secrets.GITHUB_TOKEN }}
153+
report_paths: ${{ env.TEST_RESULTS_GLOB }}
154154
check_name: Functional Test Report
155155
if: steps.test_functional_group.outcome == 'failure' && failure()
156156

157+
testsInVSCode:
158+
name: Tests in VS Code
159+
runs-on: ${{ matrix.os }}
160+
if: github.repository == 'microsoft/vscode-python'
161+
strategy:
162+
fail-fast: false
163+
matrix:
164+
# We're not running CI on macOS for now because it's one less matrix entry to lower the number of runners used,
165+
# macOS runners are expensive, and we assume that Ubuntu is enough to cover the UNIX case.
166+
os: [ubuntu-latest]
167+
python: [3.8]
168+
steps:
169+
- name: Checkout
170+
uses: actions/checkout@v2
171+
172+
- name: Use Python ${{matrix.python}}
173+
uses: actions/setup-python@v2
174+
with:
175+
python-version: ${{matrix.python}}
176+
177+
- name: Upgrade pip
178+
run: python -m pip install -U pip
179+
180+
- name: Use Node ${{env.NODE_VERSION}}
181+
uses: actions/[email protected]
182+
with:
183+
node-version: ${{env.NODE_VERSION}}
184+
185+
# Start caching
186+
187+
# Cache Python Dependencies.
188+
# Caching (https://github.com/actions/cache/blob/main/examples.md#python---pip
189+
- name: Cache pip on linux
190+
uses: actions/cache@v2
191+
if: matrix.os == 'ubuntu-latest'
192+
with:
193+
path: ~/.cache/pip
194+
key: ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-${{ hashFiles('requirements.txt') }}-${{hashFiles('build/debugger-install-requirements.txt')}}-${{hashFiles('test-requirements.txt')}}-${{hashFiles('ipython-test-requirements.txt')}}-${{hashFiles('functional-test-requirements.txt')}}-${{hashFiles('conda-functional-requirements.txt')}}
195+
restore-keys: |
196+
${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-
197+
198+
- name: Cache pip on mac
199+
uses: actions/cache@v2
200+
if: matrix.os == 'macos-latest'
201+
with:
202+
path: ~/Library/Caches/pip
203+
key: ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-${{ hashFiles('requirements.txt') }}-${{hashFiles('build/debugger-install-requirements.txt')}}-${{hashFiles('test-requirements.txt')}}-${{hashFiles('ipython-test-requirements.txt')}}-${{hashFiles('functional-test-requirements.txt')}}-${{hashFiles('conda-functional-requirements.txt')}}
204+
restore-keys: |
205+
${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-
206+
207+
- name: Cache pip on windows
208+
uses: actions/cache@v2
209+
if: matrix.os == 'windows-latest'
210+
with:
211+
path: ~\AppData\Local\pip\Cache
212+
key: ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-${{ hashFiles('requirements.txt') }}-${{hashFiles('build/debugger-install-requirements.txt')}}-${{hashFiles('test-requirements.txt')}}-${{hashFiles('ipython-test-requirements.txt')}}-${{hashFiles('functional-test-requirements.txt')}}-${{hashFiles('conda-functional-requirements.txt')}}
213+
restore-keys: |
214+
${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-
215+
216+
# Caching of npm packages (https://github.com/actions/cache/blob/main/examples.md#node---npm)
217+
- name: Cache npm on linux/mac
218+
uses: actions/cache@v2
219+
if: matrix.os != 'windows-latest'
220+
with:
221+
path: ~/.npm
222+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
223+
restore-keys: |
224+
${{ runner.os }}-node-
225+
226+
- name: Get npm cache directory
227+
if: matrix.os == 'windows-latest'
228+
id: npm-cache
229+
run: |
230+
echo "::set-output name=dir::$(npm config get cache)"
231+
- name: Cache npm on windows
232+
uses: actions/cache@v2
233+
if: matrix.os == 'windows-latest'
234+
with:
235+
path: ${{ steps.npm-cache.outputs.dir }}
236+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
237+
restore-keys: |
238+
${{ runner.os }}-node-
239+
240+
- name: Cache compiled TS files
241+
id: out-cache
242+
uses: actions/cache@v2
243+
with:
244+
path: ./out
245+
key: ${{runner.os}}-${{env.CACHE_OUT_DIRECTORY}}-${{hashFiles('src/**')}}
246+
247+
# For faster/better builds of sdists.
248+
- run: python -m pip install wheel
249+
shell: bash
250+
251+
# debugpy is not shipped, only installed for local tests.
252+
# In production, we get debugpy from python extension.
253+
- name: Install functional test requirements
254+
run: |
255+
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r ./requirements.txt
256+
python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
257+
python ./pythonFiles/install_debugpy.py
258+
python -m pip install numpy
259+
python -m pip install --upgrade jupyter
260+
python -m pip install --upgrade -r build/test-requirements.txt
261+
python -m pip install --upgrade -r ./build/ipython-test-requirements.txt
262+
python -m pip install --upgrade -r ./build/conda-functional-requirements.txt
263+
python -m ipykernel install --user
264+
# This step is slow.
265+
266+
- name: Install dependencies (npm ci)
267+
run: npm ci --prefer-offline
268+
# This step is slow.
269+
270+
- name: Compile if not cached
271+
run: npx gulp prePublishNonBundle
272+
273+
274+
- name: Install Julia
275+
uses: julia-actions/setup-julia@v1
276+
with:
277+
version: 1.5.2
278+
279+
- name: Install Jualia Kernel
280+
run: |
281+
julia -e '
282+
using Pkg
283+
Pkg.add("IJulia")'
284+
285+
- name: Run VSCode tests
286+
uses: GabrielBB/[email protected]
287+
with:
288+
run: npm run testDataScienceInVSCode
289+
env:
290+
DISPLAY: 10
291+
VSCODE_PYTHON_ROLLING: 1
292+
VSC_PYTHON_FORCE_LOGGING: 1
293+
VSC_PYTHON_CI_NON_PYTHON_NB_TEST: 1
294+
VSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE: 'true'
295+
id: test_functional
296+
297+
- name: Publish Test Report
298+
uses: scacap/action-surefire-report@v1
299+
with:
300+
github_token: ${{ secrets.GITHUB_TOKEN }}
301+
report_paths: ${{ env.TEST_RESULTS_GLOB }}
302+
check_name: VSCode Test Report
303+
if: steps.test_functional.outcome == 'failure' && failure()
304+
305+
306+
# testsInVSCodeInsiders:
307+
# name: Tests in VS Code Insiders
308+
# runs-on: ${{ matrix.os }}
309+
# if: github.repository == 'microsoft/vscode-python'
310+
# strategy:
311+
# fail-fast: false
312+
# matrix:
313+
# # We're not running CI on macOS for now because it's one less matrix entry to lower the number of runners used,
314+
# # macOS runners are expensive, and we assume that Ubuntu is enough to cover the UNIX case.
315+
# os: [ubuntu-latest]
316+
# python: [3.8]
317+
# steps:
318+
# - name: Checkout
319+
# uses: actions/checkout@v2
320+
321+
# - name: Use Python ${{matrix.python}}
322+
# uses: actions/setup-python@v2
323+
# with:
324+
# python-version: ${{matrix.python}}
325+
326+
# - name: Upgrade pip
327+
# run: python -m pip install -U pip
328+
329+
# - name: Use Node ${{env.NODE_VERSION}}
330+
# uses: actions/[email protected]
331+
# with:
332+
# node-version: ${{env.NODE_VERSION}}
333+
334+
# # Start caching
335+
336+
# # Cache Python Dependencies.
337+
# # Caching (https://github.com/actions/cache/blob/main/examples.md#python---pip
338+
# - name: Cache pip on linux
339+
# uses: actions/cache@v2
340+
# if: matrix.os == 'ubuntu-latest'
341+
# with:
342+
# path: ~/.cache/pip
343+
# key: ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-${{ hashFiles('requirements.txt') }}-${{hashFiles('build/debugger-install-requirements.txt')}}-${{hashFiles('test-requirements.txt')}}-${{hashFiles('ipython-test-requirements.txt')}}-${{hashFiles('functional-test-requirements.txt')}}-${{hashFiles('conda-functional-requirements.txt')}}
344+
# restore-keys: |
345+
# ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-
346+
347+
# - name: Cache pip on mac
348+
# uses: actions/cache@v2
349+
# if: matrix.os == 'macos-latest'
350+
# with:
351+
# path: ~/Library/Caches/pip
352+
# key: ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-${{ hashFiles('requirements.txt') }}-${{hashFiles('build/debugger-install-requirements.txt')}}-${{hashFiles('test-requirements.txt')}}-${{hashFiles('ipython-test-requirements.txt')}}-${{hashFiles('functional-test-requirements.txt')}}-${{hashFiles('conda-functional-requirements.txt')}}
353+
# restore-keys: |
354+
# ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-
355+
356+
# - name: Cache pip on windows
357+
# uses: actions/cache@v2
358+
# if: matrix.os == 'windows-latest'
359+
# with:
360+
# path: ~\AppData\Local\pip\Cache
361+
# key: ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-${{ hashFiles('requirements.txt') }}-${{hashFiles('build/debugger-install-requirements.txt')}}-${{hashFiles('test-requirements.txt')}}-${{hashFiles('ipython-test-requirements.txt')}}-${{hashFiles('functional-test-requirements.txt')}}-${{hashFiles('conda-functional-requirements.txt')}}
362+
# restore-keys: |
363+
# ${{ runner.os }}-pip-${{env.PYTHON_VERSION}}-
364+
365+
# # Caching of npm packages (https://github.com/actions/cache/blob/main/examples.md#node---npm)
366+
# - name: Cache npm on linux/mac
367+
# uses: actions/cache@v2
368+
# if: matrix.os != 'windows-latest'
369+
# with:
370+
# path: ~/.npm
371+
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
372+
# restore-keys: |
373+
# ${{ runner.os }}-node-
374+
375+
# - name: Get npm cache directory
376+
# if: matrix.os == 'windows-latest'
377+
# id: npm-cache
378+
# run: |
379+
# echo "::set-output name=dir::$(npm config get cache)"
380+
# - name: Cache npm on windows
381+
# uses: actions/cache@v2
382+
# if: matrix.os == 'windows-latest'
383+
# with:
384+
# path: ${{ steps.npm-cache.outputs.dir }}
385+
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
386+
# restore-keys: |
387+
# ${{ runner.os }}-node-
388+
389+
# - name: Cache compiled TS files
390+
# id: out-cache
391+
# uses: actions/cache@v2
392+
# with:
393+
# path: ./out
394+
# key: ${{runner.os}}-${{env.CACHE_OUT_DIRECTORY}}-${{hashFiles('src/**')}}
395+
396+
# # For faster/better builds of sdists.
397+
# - run: python -m pip install wheel
398+
# shell: bash
399+
400+
# # debugpy is not shipped, only installed for local tests.
401+
# # In production, we get debugpy from python extension.
402+
# - name: Install functional test requirements
403+
# run: |
404+
# python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r ./requirements.txt
405+
# python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
406+
# python ./pythonFiles/install_debugpy.py
407+
# python -m pip install numpy
408+
# python -m pip install --upgrade jupyter
409+
# python -m pip install --upgrade -r build/test-requirements.txt
410+
# python -m pip install --upgrade -r ./build/ipython-test-requirements.txt
411+
# python -m pip install --upgrade -r ./build/conda-functional-requirements.txt
412+
# python -m ipykernel install --user
413+
# # This step is slow.
414+
415+
# - name: Install dependencies (npm ci)
416+
# run: npm ci --prefer-offline
417+
# # This step is slow.
418+
419+
# - name: Compile if not cached
420+
# run: npx gulp prePublishNonBundle
421+
422+
# - name: Install Julia
423+
# uses: julia-actions/setup-julia@v1
424+
# with:
425+
# version: 1.5.2
426+
427+
# - name: Install Jualia Kernel
428+
# run: |
429+
# julia -e '
430+
# using Pkg
431+
# Pkg.add("IJulia")'
432+
433+
# - name: Run VSCode tests
434+
# uses: GabrielBB/[email protected]
435+
# with:
436+
# run: npm run testDataScience
437+
# env:
438+
# DISPLAY: 10
439+
# VSCODE_PYTHON_ROLLING: 1
440+
# VSC_PYTHON_FORCE_LOGGING: 1
441+
# VSC_PYTHON_CI_NON_PYTHON_NB_TEST: 1
442+
# VSC_PYTHON_CI_TEST_VSC_CHANNEL: 'insiders'
443+
# VSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE: 'true'
444+
# id: test_functional
445+
446+
# - name: Publish Test Report
447+
# uses: scacap/action-surefire-report@v1
448+
# with:
449+
# github_token: ${{ secrets.GITHUB_TOKEN }}
450+
# report_paths: ${{ env.TEST_RESULTS_GLOB }}
451+
# check_name: VSCode Test Report
452+
# if: steps.test_functional.outcome == 'failure' && failure()
453+

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,16 @@
33443344
"extensions": [
33453345
".ipynb"
33463346
]
3347+
},
3348+
{
3349+
"id": "julia",
3350+
"aliases": [
3351+
"Julia",
3352+
"julia"
3353+
],
3354+
"extensions": [
3355+
".jl"
3356+
]
33473357
}
33483358
],
33493359
"grammars": [

src/client/common/application/notebook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export class VSCodeNotebook implements IVSCodeNotebook {
5252
? this.notebook.onDidCloseNotebookDocument
5353
: new EventEmitter<NotebookDocument>().event;
5454
}
55+
public get onDidSaveNotebookDocument(): Event<NotebookDocument> {
56+
return this.canUseNotebookApi
57+
? this.notebook.onDidSaveNotebookDocument
58+
: new EventEmitter<NotebookDocument>().event;
59+
}
5560
public get notebookDocuments(): ReadonlyArray<NotebookDocument> {
5661
return this.canUseNotebookApi ? this.notebook.notebookDocuments : [];
5762
}

src/client/common/application/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,7 @@ export interface IVSCodeNotebook {
15401540
readonly notebookDocuments: ReadonlyArray<NotebookDocument>;
15411541
readonly onDidOpenNotebookDocument: Event<NotebookDocument>;
15421542
readonly onDidCloseNotebookDocument: Event<NotebookDocument>;
1543+
readonly onDidSaveNotebookDocument: Event<NotebookDocument>;
15431544
readonly onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>;
15441545
readonly onDidChangeNotebookDocument: Event<NotebookCellChangedEvent>;
15451546
readonly notebookEditors: Readonly<NotebookEditor[]>;

src/client/datascience/common.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ export function traceCellResults(prefix: string, results: ICell[]) {
131131
}
132132

133133
export function translateKernelLanguageToMonaco(kernelLanguage: string): string {
134-
// The only known translation is C# to csharp at the moment
135-
if (kernelLanguage === 'C#' || kernelLanguage === 'c#') {
136-
return 'csharp';
134+
// At the moment these are the only translations.
135+
// python, julia, r, javascript, powershell, etc can be left as is.
136+
switch (kernelLanguage.toLowerCase()) {
137+
case 'c#':
138+
return 'csharp';
139+
case 'f#':
140+
return 'fsharp';
141+
default:
142+
return kernelLanguage.toLowerCase();
137143
}
138-
return kernelLanguage.toLowerCase();
139144
}
140145

141146
export function generateNewNotebookUri(

0 commit comments

Comments
 (0)