-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from makebrainwaves/dano-pyodide-install
Automatic pyodide installation
- Loading branch information
Showing
4 changed files
with
310 additions
and
514 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// mkdir app/utils/pyodide/src | ||
// && cd app/utils/pyodide/src | ||
// curl -LJO https://github.com/iodide-project/pyodide/releases/download/0.12.0/pyodide-build-0.12.0.tar.bz2 | ||
// tar xjf pyodide-build-0.12.0.tar.bz2 | ||
// rm pyodide-build-0.12.0.tar.bz2", | ||
|
||
import chalk from 'chalk'; | ||
import fs from 'fs'; | ||
import https from 'https'; | ||
import mkdirp from 'mkdirp'; | ||
import tar from 'tar-fs'; | ||
import url from 'url'; | ||
import bz2 from 'unbzip2-stream'; | ||
|
||
const PYODIDE_VERSION = '0.12.0'; | ||
const TAR_NAME = `pyodide-build-${PYODIDE_VERSION}.tar.bz2`; | ||
const TAR_URL = `https://github.com/iodide-project/pyodide/releases/download/${PYODIDE_VERSION}/pyodide-build-${PYODIDE_VERSION}.tar.bz2`; | ||
const PYODIDE_DIR = 'app/utils/pyodide/src/'; | ||
|
||
const writeAndUnzipFile = response => { | ||
const filePath = `${PYODIDE_DIR}${TAR_NAME}`; | ||
const writeStream = fs.createWriteStream(filePath); | ||
response.pipe(writeStream); | ||
|
||
writeStream.on('finish', () => { | ||
console.log(`${chalk.green.bold(`Unzipping pyodide`)}`); | ||
|
||
const readStream = fs.createReadStream(filePath); | ||
try { | ||
readStream.pipe(bz2()).pipe(tar.extract(PYODIDE_DIR)); | ||
} catch (e) { | ||
throw new Error('Error in unzip:', e); | ||
} | ||
|
||
readStream.on('end', () => { | ||
console.log(`${chalk.green.bold(`Unzip successful`)}`); | ||
}); | ||
}); | ||
}; | ||
|
||
const downloadFile = response => { | ||
if ( | ||
response.statusCode > 300 && | ||
response.statusCode < 400 && | ||
response.headers.location | ||
) { | ||
if (url.parse(response.headers.location).hostname) { | ||
https.get(response.headers.location, writeAndUnzipFile); | ||
} else { | ||
https.get( | ||
url.resolve(url.parse(TAR_URL).hostname, response.headers.location), | ||
writeAndUnzipFile | ||
); | ||
} | ||
} else { | ||
writeAndUnzipFile(response); | ||
} | ||
}; | ||
|
||
(() => { | ||
console.log( | ||
`${chalk.green.bold(`Downloading pyodide ${PYODIDE_VERSION}...`)}` | ||
); | ||
mkdirp.sync(`app/utils/pyodide/src`); | ||
https.get(TAR_URL, downloadFile); | ||
})(); |
Oops, something went wrong.