Notebook Parameterization - Papermill Compatibility (#13034)

* Parameterization papermill fix

* Utilize isParameter instead

* Address PR comments, and fix tests

* Address comment
This commit is contained in:
Vasu Bhog
2020-10-23 20:32:55 -05:00
committed by GitHub
parent bf9fd5a3b8
commit cb30dd1893
5 changed files with 28 additions and 14 deletions

View File

@@ -53,10 +53,10 @@ export class CellModel extends Disposable implements ICellModel {
private _cellUri: URI;
private _connectionManagementService: IConnectionManagementService;
private _stdInHandler: nb.MessageHandler<nb.IStdinMessage>;
private _metadata: { language?: string; tags?: string[]; cellGuid?: string; };
private _onCellLoaded = new Emitter<string>();
private _loaded: boolean;
private _stdInVisible: boolean;
private _metadata: { language?: string; tags?: string[]; cellGuid?: string; };
private _isCollapsed: boolean;
private _onCollapseStateChanged = new Emitter<boolean>();
private _modelContentChangedEvent: IModelContentChangedEvent;
@@ -355,6 +355,12 @@ export class CellModel extends Disposable implements ICellModel {
if (this.cellType !== CellTypes.Code) {
return;
}
/**
* The value will not be updated if there is already a parameter cell in the Notebook.
**/
value = this.notebookModel?.cells?.find(cell => cell.isParameter) ? false : value;
let stateChanged = this._isParameter !== value;
this._isParameter = value;
@@ -801,11 +807,10 @@ export class CellModel extends Disposable implements ICellModel {
this.executionCount = cell.execution_count;
this._source = this.getMultilineSource(cell.source);
this._metadata = cell.metadata || {};
if (this._metadata.tags && this._metadata.tags.some(x => x === HideInputTag || x === ParametersTag || x === InjectedParametersTag) && this._cellType === CellTypes.Code) {
this._isCollapsed = true;
this._isParameter = true;
this._isInjectedParameter = true;
if (this._metadata.tags && this._cellType === CellTypes.Code) {
this._isCollapsed = this._metadata.tags.some(x => x === HideInputTag);
this._isParameter = this._metadata.tags.some(x => x === ParametersTag);
this._isInjectedParameter = this._metadata.tags.some(x => x === InjectedParametersTag);
} else {
this._isCollapsed = false;
this._isParameter = false;

View File

@@ -359,6 +359,16 @@ export class NotebookModel extends Disposable implements INotebookModel {
if (contents.cells && contents.cells.length > 0) {
this._cells = contents.cells.map(c => {
let cellModel = factory.createCell(c, { notebook: this, isTrusted: isTrusted });
/*
In a parameterized notebook there will be an injected parameter cell.
Papermill originally inserts the injected parameter with the comment "# Parameters"
which would make it confusing to the user between the difference between this cell and the tagged parameters cell.
So to make it clear we edit the injected parameters comment to indicate it is the Injected-Parameters cell.
*/
if (cellModel.isInjectedParameter) {
cellModel.source = cellModel.source.slice(1);
cellModel.source = '# Injected-Parameters\n' + cellModel.source;
}
this.trackMarkdownTelemetry(<nb.ICellContents>c, cellModel);
return cellModel;
});