-
Notifications
You must be signed in to change notification settings - Fork 47
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 #92 from cameronmoreau/poc/package-breakup
- Loading branch information
Showing
32 changed files
with
14,395 additions
and
1,588 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
lib/* | ||
packages/**/lib/* | ||
example-nextjs |
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ node_modules | |
/example-nextjs/.next | ||
|
||
/lib | ||
/packages/**/lib | ||
|
||
.eslintcache | ||
yarn-*.log* |
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
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
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
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
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
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,4 @@ | ||
{ | ||
"packages": ["packages/*"], | ||
"version": "0.0.0" | ||
} |
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
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,20 @@ | ||
{ | ||
"name": "@run-wasm/python", | ||
"version": "1.0.0", | ||
"main": "./lib/cjs/index.js", | ||
"module": "./lib/esm/index.js", | ||
"types": "./lib/esm/index.d.ts", | ||
"devDependencies": { | ||
"typescript": "^4.4.3" | ||
}, | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"check-types": "tsc", | ||
"build": "yarn build:esm && yarn build:cjs", | ||
"build:esm": "tsc", | ||
"build:cjs": "tsc --module commonjs --outDir lib/cjs" | ||
}, | ||
"dependencies": { | ||
"pyodide": "^0.18.0" | ||
} | ||
} |
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,39 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
export class PythonClient { | ||
// <- [reference](https://stackoverflow.com/a/59571016/1375972) | ||
// We redirect stdout to an IO string buffer so that it can be read later | ||
private readonly setStdoutToOutput = ` | ||
import sys | ||
import io | ||
sys.stdout = io.StringIO() | ||
` | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
public constructor(protected pyodide: any) { | ||
pyodide.runPython(this.setStdoutToOutput) | ||
} | ||
|
||
public async run({ code }: { code: string }): Promise<string> { | ||
await this.loadPackages(code) | ||
const output: string = this.pyodide.runPython(code) ?? '' | ||
// Prepend the value of stdout before returning | ||
const stdout: string = this.pyodide.runPython('sys.stdout.getvalue()') | ||
console.log(stdout + output) | ||
return stdout + output | ||
} | ||
|
||
private loadPackages(code: string): Promise<any> { | ||
if (typeof this.pyodide.loadPackagesFromImports === 'function') { | ||
console.log('Loading Python dependencies from code') | ||
return this.pyodide.loadPackagesFromImports(code) | ||
} | ||
return this.pyodide.loadPackage([]) | ||
} | ||
} | ||
|
||
const createPythonClient = (pyodide: string): PythonClient => { | ||
return new PythonClient(pyodide) | ||
} | ||
|
||
export { createPythonClient } |
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,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./lib" | ||
}, | ||
"include": ["./src"] | ||
} |
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,46 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
base-64@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/base-64/-/base-64-1.0.0.tgz#09d0f2084e32a3fd08c2475b973788eee6ae8f4a" | ||
integrity sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg== | ||
|
||
node-fetch@^2.6.1: | ||
version "2.6.5" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd" | ||
integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ== | ||
dependencies: | ||
whatwg-url "^5.0.0" | ||
|
||
pyodide@^0.18.0: | ||
version "0.18.1" | ||
resolved "https://registry.yarnpkg.com/pyodide/-/pyodide-0.18.1.tgz#9b987de7dc30de261aeabea64052bb7ab3f1fef7" | ||
integrity sha512-QgkdYXu0nkWoJ5Ein2GAgpsT6gfuRCdmiR5C3JSTUEyHnMY0MqU0hx7hpD0/ZVXNSalG7ytVQ+9SgCL2RtVcqg== | ||
dependencies: | ||
base-64 "^1.0.0" | ||
node-fetch "^2.6.1" | ||
|
||
tr46@~0.0.3: | ||
version "0.0.3" | ||
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" | ||
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= | ||
|
||
typescript@^4.4.3: | ||
version "4.4.3" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" | ||
integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== | ||
|
||
webidl-conversions@^3.0.0: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" | ||
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= | ||
|
||
whatwg-url@^5.0.0: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" | ||
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= | ||
dependencies: | ||
tr46 "~0.0.3" | ||
webidl-conversions "^3.0.0" |
3 changes: 1 addition & 2 deletions
3
__tests__/tsClient.test.ts → ...es/run-wasm-ts/__tests__/tsClient.test.ts
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
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,3 @@ | ||
const base = require('../../jest.config') | ||
|
||
module.exports = base |
Oops, something went wrong.
e9b5cf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: