diff --git a/.gitignore b/.gitignore index e05d4c22..396b0deb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ jupyternotebook/visualpython colab/visualpython test/ .gitignore +visualpython/js/com/com_Config.js diff --git a/jupyterlab/.jupyterlite.doit.db b/jupyterlab/.jupyterlite.doit.db index 54f9b6a8..e60d75e0 100644 Binary files a/jupyterlab/.jupyterlite.doit.db and b/jupyterlab/.jupyterlite.doit.db differ diff --git a/visualpython/js/com/com_Config.js b/visualpython/js/com/com_Config.js index f23a1864..cf33bd8c 100644 --- a/visualpython/js/com/com_Config.js +++ b/visualpython/js/com/com_Config.js @@ -296,6 +296,7 @@ define([ * - automatically restart on jupyter kernel restart (loadVisualpython.js) */ readKernelFunction() { + let that = this; // CHROME: change method to load py files ($.get -> require) return new Promise(function(resolve, reject) { var libraryList = [ @@ -314,7 +315,26 @@ define([ libraryList.forEach(libCode => { promiseList.push(vpKernel.execute(libCode, true)); }); - + + if (that.extensionType === 'lite') { + let preInstallCode = ''; + let preInstallPackList = [ + 'seaborn', + 'plotly', + 'scikit-learn', + 'scipy', + 'statsmodels' + ]; + preInstallPackList.forEach((packName, idx) => { + preInstallCode += '%pip install ' + packName + if (idx < preInstallPackList.length - 1) { + preInstallCode += '\n'; + } + }); + // pre-install packages + promiseList.push(vpKernel.execute(preInstallCode, true)); + } + // run all promises let failed = false; Promise.all(promiseList).then(function(resultObj) { @@ -918,7 +938,7 @@ define([ '- Save VP Note before refreshing the page.' ]; com_interface.insertCell('markdown', info.join('\n')); - com_interface.insertCell('code', "import piplite\npiplite.install('jupyterlab-visualpython==" + latestVersion + "')"); + com_interface.insertCell('code', "%pip install jupyterlab-visualpython==" + latestVersion); } // update version_timestamp diff --git a/visualpython/js/com/component/PackageManager.js b/visualpython/js/com/component/PackageManager.js index f98af4f3..95b7cb5f 100644 --- a/visualpython/js/com/component/PackageManager.js +++ b/visualpython/js/com/component/PackageManager.js @@ -64,6 +64,28 @@ define([ 'PyMuPDF': { pipName: 'PyMuPDF' }, 'sweetviz': { pipName: 'sweetviz' }, } + + if (vpConfig.extensionType === 'lite') { + this.packageLibTemplate = { + 'numpy': { pipName: 'numpy' }, + 'pandas': { pipName: 'pandas' }, + 'matplotlib': { pipName: 'matplotlib' }, + 'seaborn': { pipName: 'seaborn' }, + 'plotly': { pipName: 'plotly' }, + 'sklearn': { pipName: 'scikit-learn' }, + 'scikit-posthocs': { pipName: 'scikit-posthocs' }, + 'scipy': { pipName: 'scipy' }, + 'statsmodels': { pipName: 'statsmodels' }, + 'factor-analyzer': { pipName: 'factor-analyzer' }, + 'category_encoders': { pipName: 'category_encoders' }, + 'imblearn': { pipName: 'imblearn' }, + 'xgboost': { pipName: 'xgboost' }, + 'lightgbm': { pipName: 'lightgbm' }, + 'catboost': { pipName: 'catboost' }, + 'auto-sklearn': { pipName: 'auto-sklearn' }, + 'sweetviz': { pipName: 'sweetviz' }, + } + } } _bindEvent() { @@ -148,7 +170,7 @@ define([ var pipName = that.packageLib[key].pipName; var code = com_util.formatString("!pip uninstall -y {0}", pipName); if (vpConfig.extensionType === 'lite') { - code = com_util.formatString("import piplite\npiplite.uninstall('{0}')", pipName); + code = com_util.formatString("%pip uninstall {0}", pipName); } // create block and run it $('#vp_wrapper').trigger({ @@ -162,7 +184,7 @@ define([ var pipName = that.packageLib[key].pipName; var code = com_util.formatString("!pip install --upgrade {0}", pipName); if (vpConfig.extensionType === 'lite') { - code = com_util.formatString("%pip install --upgrade {0}", pipName); + code = com_util.formatString("%pip install {0}", pipName); } // create block and run it $('#vp_wrapper').trigger({ @@ -269,7 +291,7 @@ define([ var pipName = this.packageLib[this.state.selected].pipName; var code = com_util.formatString("!pip install {0}", pipName); if (vpConfig.extensionType === 'lite') { - code = com_util.formatString("import piplite\npiplite.install('{0}')", pipName); + code = com_util.formatString("%pip install {0}", pipName); } if (versionType === 'specified') { // specified version @@ -277,7 +299,7 @@ define([ if (version && version !== '') { code = com_util.formatString("!pip install {0}=={1}", pipName, version); if (vpConfig.extensionType === 'lite') { - code = com_util.formatString("import piplite\npiplite.install('{0}=={1}')", pipName, version); + code = com_util.formatString("%pip install {0}=={1}", pipName, version); } } else { $(this.wrapSelector('.vp-inner-popup-version')).focus(); diff --git a/visualpython/js/m_apps/PDF.js b/visualpython/js/m_apps/PDF.js index c4ea125b..e5fdf2ce 100644 --- a/visualpython/js/m_apps/PDF.js +++ b/visualpython/js/m_apps/PDF.js @@ -21,9 +21,9 @@ define([ 'vp_base/js/com/component/FileNavigation' ], function(pdfHtml, pdfCss, com_String, com_interface, PopupComponent, FileNavigation) { - const PDF_SHOW = '!pip show PyMuPDF nltk' - const PDF_INSTALL1 = '!pip install PyMuPDF' - const PDF_INSTALL2 = '!pip install nltk' + var PDF_SHOW = '!pip show PyMuPDF nltk' + var PDF_INSTALL1 = '!pip install PyMuPDF' + var PDF_INSTALL2 = '!pip install nltk' const PDF_IMPORT = `import pandas as pd import fitz @@ -80,6 +80,12 @@ nltk.download('punkt')`; vp_pdfReturn: '', ...this.state } + + if (vpConfig.extensionType === 'lite') { + PDF_SHOW = PDF_SHOW.replace('!', '%'); + PDF_INSTALL1 = PDF_INSTALL1.replace('!', '%'); + PDF_INSTALL2 = PDF_INSTALL2.replace('!', '%'); + } } _bindEvent() { diff --git a/visualpython/js/m_stats/Anova.js b/visualpython/js/m_stats/Anova.js index 9edc8752..191ed0f7 100644 --- a/visualpython/js/m_stats/Anova.js +++ b/visualpython/js/m_stats/Anova.js @@ -252,7 +252,11 @@ define([ } if (tukey === true || scheffe === true || duncan === true) { - codeList.push("!pip install scikit-posthocs"); + if (vpConfig.extensionType === 'lite') { + codeList.push("%pip install scikit-posthocs"); + } else { + codeList.push("!pip install scikit-posthocs"); + } // Post hoc analysis - Tukey if (tukey === true) { @@ -379,7 +383,11 @@ define([ } if (tukey === true || scheffe === true || duncan === true) { // Add installation code - codeList.push("!pip install scikit-posthocs"); + if (vpConfig.extensionType === 'lite') { + codeList.push("%pip install scikit-posthocs"); + } else { + codeList.push("!pip install scikit-posthocs"); + } // Post hoc analysis - Tukey if (tukey === true) { @@ -445,7 +453,11 @@ define([ } // Add installation code : # pip install pingouin - codeList.push("!pip install pingouin"); + if (vpConfig.extensionType === 'lite') { + codeList.push("%pip install pingouin"); + } else { + codeList.push("!pip install pingouin"); + } code.appendLine(); code.appendLine(); diff --git a/visualpython/js/m_stats/FactorAnalysis.js b/visualpython/js/m_stats/FactorAnalysis.js index c9bcb1e0..be875252 100644 --- a/visualpython/js/m_stats/FactorAnalysis.js +++ b/visualpython/js/m_stats/FactorAnalysis.js @@ -167,6 +167,13 @@ define([ let codeList = []; let code = new com_String(); + // Add installation code FIXME: + if (vpConfig.extensionType === 'lite') { + codeList.push(that.generateInstallCode().replace('!', '%')); + } else { + codeList.push(that.generateInstallCode()); + } + // data declaration code.appendFormat("vp_df = {0}", data); if (this.columnSelector) {