Skip to content

Commit e06224b

Browse files
author
minjk-bl
committed
Add ignoreWarning util function
1 parent 4fe6bd0 commit e06224b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

visualpython/js/com/com_util.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,31 @@ define([
245245
return label;
246246
}
247247

248+
/**
249+
* Pack the code with ignoring the warnings
250+
* @param {*} code
251+
*/
252+
var ignoreWarning = function(code) {
253+
var convertedCode = new com_String();
254+
convertedCode.appendLine('import warnings');
255+
convertedCode.appendLine('from IPython.display import display');
256+
convertedCode.appendLine('with warnings.catch_warnings():');
257+
convertedCode.appendLine(" warnings.simplefilter('ignore')");
258+
let codeLines = code.split('\n');
259+
codeLines.forEach((line, idx) => {
260+
if (idx > 0) {
261+
convertedCode.appendLine();
262+
}
263+
if (codeLines.length == idx + 1) {
264+
// last line
265+
convertedCode.appendFormat(" display({0})", line);
266+
} else {
267+
convertedCode.appendFormat(" {0}", line);
268+
}
269+
});
270+
return convertedCode.toString();
271+
}
272+
248273
//============================================================================
249274
// Cross-browser RegEx Split
250275
//============================================================================
@@ -377,6 +402,7 @@ define([
377402
setIsAPIListRunCode: setIsAPIListRunCode,
378403
getIsAPIListRunCode: getIsAPIListRunCode,
379404
safeString: safeString,
405+
ignoreWarning: ignoreWarning,
380406

381407
regex_split: regex_split
382408
}

0 commit comments

Comments
 (0)