@@ -19,7 +19,7 @@ import { CellState, ICell, IJupyterExecution, INotebookExporter, ISysInfo } from
1919export class JupyterExporter implements INotebookExporter {
2020
2121 constructor (
22- @inject ( IJupyterExecution ) private jupyterExecution : IJupyterExecution ,
22+ @inject ( IJupyterExecution ) private jupyterExecution : IJupyterExecution ,
2323 @inject ( ILogger ) private logger : ILogger ,
2424 @inject ( IWorkspaceService ) private workspaceService : IWorkspaceService ,
2525 @inject ( IFileSystem ) private fileSystem : IFileSystem ) {
@@ -29,7 +29,7 @@ export class JupyterExporter implements INotebookExporter {
2929 noop ( ) ;
3030 }
3131
32- public async translateToNotebook ( cells : ICell [ ] , changeDirectory ?: string ) : Promise < nbformat . INotebookContent | undefined > {
32+ public async translateToNotebook ( cells : ICell [ ] , changeDirectory ?: string ) : Promise < nbformat . INotebookContent | undefined > {
3333 // If requested, add in a change directory cell to fix relative paths
3434 if ( changeDirectory ) {
3535 cells = await this . addDirectoryChangeCell ( cells , changeDirectory ) ;
@@ -95,18 +95,17 @@ export class JupyterExporter implements INotebookExporter {
9595 // When we export we want to our change directory back to the first real file that we saw run from any workspace folder
9696 private firstWorkspaceFolder = async ( cells : ICell [ ] ) : Promise < string | undefined > => {
9797 for ( const cell of cells ) {
98- const filename = cell . file ;
98+ const filename = cell . file ;
9999
100- // First check that this is an absolute file that exists (we add in temp files to run system cell)
101- if ( path . isAbsolute ( filename ) && await this . fileSystem . fileExists ( filename ) ) {
100+ // First check that this is an absolute file that exists (we add in temp files to run system cell)
101+ if ( path . isAbsolute ( filename ) && await this . fileSystem . fileExists ( filename ) ) {
102102 // We've already check that workspace folders above
103103 for ( const folder of this . workspaceService . workspaceFolders ! ) {
104- if ( filename . toLowerCase ( ) . startsWith ( folder . uri . fsPath . toLowerCase ( ) ) )
105- {
104+ if ( filename . toLowerCase ( ) . startsWith ( folder . uri . fsPath . toLowerCase ( ) ) ) {
106105 return folder . uri . fsPath ;
107106 }
108107 }
109- }
108+ }
110109 }
111110
112111 return undefined ;
@@ -134,22 +133,22 @@ export class JupyterExporter implements INotebookExporter {
134133 }
135134 }
136135
137- private pruneCells = ( cells : ICell [ ] ) : nbformat . IBaseCell [ ] => {
136+ private pruneCells = ( cells : ICell [ ] ) : nbformat . IBaseCell [ ] => {
138137 // First filter out sys info cells. Jupyter doesn't understand these
139138 return cells . filter ( c => c . data . cell_type !== 'sys_info' )
140139 // Then prune each cell down to just the cell data.
141140 . map ( this . pruneCell ) ;
142141 }
143142
144- private pruneCell = ( cell : ICell ) : nbformat . IBaseCell => {
143+ private pruneCell = ( cell : ICell ) : nbformat . IBaseCell => {
145144 // Remove the #%% of the top of the source if there is any. We don't need
146145 // this to end up in the exported ipynb file.
147- const copy = { ...cell . data } ;
146+ const copy = { ...cell . data } ;
148147 copy . source = this . pruneSource ( cell . data . source ) ;
149148 return copy ;
150149 }
151150
152- private pruneSource = ( source : nbformat . MultilineString ) : nbformat . MultilineString => {
151+ private pruneSource = ( source : nbformat . MultilineString ) : nbformat . MultilineString => {
153152
154153 if ( Array . isArray ( source ) && source . length > 0 ) {
155154 if ( RegExpValues . PythonCellMarker . test ( source [ 0 ] ) ) {
@@ -168,7 +167,7 @@ export class JupyterExporter implements INotebookExporter {
168167 private extractPythonMainVersion = async ( cells : ICell [ ] ) : Promise < number > => {
169168 let pythonVersion ;
170169 const sysInfoCells = cells . filter ( ( targetCell : ICell ) => {
171- return targetCell . data . cell_type === 'sys_info' ;
170+ return targetCell . data . cell_type === 'sys_info' ;
172171 } ) ;
173172
174173 if ( sysInfoCells . length > 0 ) {
@@ -184,6 +183,6 @@ export class JupyterExporter implements INotebookExporter {
184183
185184 // In this case, let's check the version on the active interpreter
186185 const usableInterpreter = await this . jupyterExecution . getUsableJupyterPython ( ) ;
187- return usableInterpreter ? usableInterpreter . version_info [ 0 ] : 3 ;
186+ return usableInterpreter && usableInterpreter . version ? usableInterpreter . version . major : 3 ;
188187 }
189188}
0 commit comments