Skip to content

Commit

Permalink
release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bugzpodder committed Sep 23, 2023
1 parent f549c68 commit 6ed76e7
Show file tree
Hide file tree
Showing 34 changed files with 691 additions and 372 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
12 changes: 7 additions & 5 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Version 0.3.1
==========================
# Version 0.4

- bumped polyscript to 0.4
- code running in restricted mode no longer have document access

# Version 0.3.1

- docs
- auto import pysandbox.display in code blocks


Version 0.3.0
==========================
# Version 0.3.0

- `PyMainThreadSandbox` + `PyWorkerSandbox`
3 changes: 3 additions & 0 deletions docs/lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
"*.{astro,js,json,md,mdx,mjs,ts,html}": "prettier -w",
};
5 changes: 2 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"format": "prettier -w src src/**/*.astro astro.config.mjs"
"format": "prettier -w src src/**/*.astro"
},
"dependencies": {
"@astrojs/starlight": "^0.10.0",
"@codemirror/lang-python": "^6.1.3",
"astro": "^3.0.6",
"codemirror": "^6.0.1",
"pysandbox": "^0.3.1",
"sharp": "^0.32.5"
"pysandbox": "^0.4.0"
},
"devDependencies": {
"prettier": "^3.0.3",
Expand Down
18 changes: 9 additions & 9 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3113,10 +3113,10 @@ plain-tag@^0.1.3:
resolved "https://registry.yarnpkg.com/plain-tag/-/plain-tag-0.1.3.tgz#d20c0fdf8fa80c170bc1d12d6c9ab38e27922836"
integrity sha512-yyVAOFKTAElc7KdLt2+UKGExNYwYb/Y/WE9i+1ezCQsJE8gbKSjewfpRqK2nQgZ4d4hhAAGgDCOcIZVilqE5UA==

polyscript@^0.3.8:
version "0.3.8"
resolved "https://registry.yarnpkg.com/polyscript/-/polyscript-0.3.8.tgz#4b9e19c2ea48f51f8d0e85756e5df69796b02707"
integrity sha512-LXf1WQxhXiCud4VFCl4TUNFqTHghhpUYxSAAlCdb5XbxQs+0HSaC+1PuyrfsKDEM0WSZXa3xCH1LOxQl2aHDbg==
polyscript@^0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/polyscript/-/polyscript-0.4.2.tgz#e59b18136aae7d8f3dd314f84b1b34cd40485a2f"
integrity sha512-3mM5Y/DdpYND8/INAUmgF5VL4InVc04xADB+of129t8RjXi3eZK4xoGRPZdTYzW+wM56WNptnC8fC9Zt7jKLoA==
dependencies:
"@ungap/structured-clone" "^1.2.0"
"@ungap/with-resolvers" "^0.1.0"
Expand Down Expand Up @@ -3210,12 +3210,12 @@ pump@^3.0.0:
end-of-stream "^1.1.0"
once "^1.3.1"

pysandbox@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/pysandbox/-/pysandbox-0.3.1.tgz#7b6926d42e8ac4e7b621d1d4f4ccf83f88015fae"
integrity sha512-640nHFL9Hw146+JyBGXiyfQIDK/2V1lbp4UgYoJ2rkZ35TxWP6Ch0aHJVeiYPQ26VF52lLtWpb0jVLHkHS9xkg==
pysandbox@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/pysandbox/-/pysandbox-0.4.0.tgz#d366d49962327eedb94573fd538342088c2f0b91"
integrity sha512-xDeb2nyiusYZZrQFIvcJvcjhG/uhwcQn3DFLRKnqLjx44DskCbeXgDWnGPRcYpG4iHQ7TKupRkv3gXb7GuAdzw==
dependencies:
polyscript "^0.3.8"
polyscript "^0.4.2"

queue-microtask@^1.2.2:
version "1.2.3"
Expand Down
45 changes: 25 additions & 20 deletions examples/MainThread/autoimport.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<html>
<head>
<script type="importmap">
{ "imports": {
"polyscript": "https://esm.sh/polyscript@0.3.8"
} }
</script>
</head>
<body>
<script type="module">
import {PyMainThreadSandbox} from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({packages: ["matplotlib", "numpy"], restricted: true});
await sandbox.init();
const code = `import numpy as np
<head>
<script type="importmap">
{
"imports": {
"polyscript": "https://esm.sh/polyscript@0.4.2"
}
}
</script>
</head>
<body>
<script type="module">
import { PyMainThreadSandbox } from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({
packages: ["matplotlib", "numpy"],
restricted: true,
});
await sandbox.init();
const code = `import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -57,10 +62,10 @@
g.despine(bottom=True, left=True)
display(plt, target=current_target())
`;
const packages = await sandbox.findImports(code);
await sandbox.installPackages(packages, { keep_going: true });
await sandbox.exec(code, "out");
</script>
<div id="out"></div>
</body>
</html>
const packages = await sandbox.findImports(code);
await sandbox.installPackages(packages, { keep_going: true });
await sandbox.exec(code, "out");
</script>
<div id="out"></div>
</body>
</html>
46 changes: 28 additions & 18 deletions examples/MainThread/input.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
<html>
<head>
<script type="importmap">
{ "imports": {
"polyscript": "https://esm.sh/polyscript@0.3.8"
} }
</script>
</head>
<body>
<script type="module">
import {PyMainThreadSandbox} from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({ jsApi: { getJsValue: () => 'value from js' }, modules: { "foo.py": `
<head>
<script type="importmap">
{
"imports": {
"polyscript": "https://esm.sh/polyscript@0.4.2"
}
}
</script>
</head>
<body>
<script type="module">
import { PyMainThreadSandbox } from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({
jsApi: { getJsValue: () => "success" },
modules: {
"foo.py": `
import js
import pysandbox
def custom_display(target):
pysandbox.display(js.getJsValue(), target)
` }});
await sandbox.init();
await sandbox.exec("import foo\nfoo.custom_display(current_target())", 'out');
</script>
<div id="out"></div>
</body>
</html>
`,
},
});
await sandbox.init();
await sandbox.exec(
"import foo\nfoo.custom_display(current_target())",
"out",
);
</script>
<div id="out"></div>
</body>
</html>
44 changes: 26 additions & 18 deletions examples/MainThread/matplotlib-restricted.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<html>
<head>
<script type="importmap">
{ "imports": {
"polyscript": "https://esm.sh/polyscript@0.3.8"
} }
</script>
</head>
<body>
<script type="module">
import {PyMainThreadSandbox} from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({packages: ["matplotlib", "numpy"], restricted: true});
await sandbox.init();
await sandbox.exec(`import matplotlib.pyplot as plt
<head>
<script type="importmap">
{
"imports": {
"polyscript": "https://esm.sh/polyscript@0.4.2"
}
}
</script>
</head>
<body>
<script type="module">
import { PyMainThreadSandbox } from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({
packages: ["matplotlib", "numpy"],
restricted: true,
});
await sandbox.init();
await sandbox.exec(
`import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
Expand All @@ -29,8 +35,10 @@
ylim=(0, 8), yticks=np.arange(1, 8))
display(plt, target=current_target())
`, "out");
</script>
<div id="out"></div>
</body>
</html>
`,
"out",
);
</script>
<div id="out"></div>
</body>
</html>
43 changes: 25 additions & 18 deletions examples/MainThread/matplotlib.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<html>
<head>
<script type="importmap">
{ "imports": {
"polyscript": "https://esm.sh/polyscript@0.3.8"
} }
</script>
</head>
<body>
<script type="module">
import {PyMainThreadSandbox} from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({packages: ["matplotlib", "numpy"]});
await sandbox.init();
await sandbox.exec(`import matplotlib.pyplot as plt
<head>
<script type="importmap">
{
"imports": {
"polyscript": "https://esm.sh/polyscript@0.4.2"
}
}
</script>
</head>
<body>
<script type="module">
import { PyMainThreadSandbox } from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({
packages: ["matplotlib", "numpy"],
});
await sandbox.init();
await sandbox.exec(
`import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
Expand All @@ -29,8 +34,10 @@
ylim=(0, 8), yticks=np.arange(1, 8))
display(plt, target=current_target())
`, "out");
</script>
<div id="out"></div>
</body>
</html>
`,
"out",
);
</script>
<div id="out"></div>
</body>
</html>
50 changes: 29 additions & 21 deletions examples/MainThread/restricted.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<html>
<head>
<script type="importmap">
{ "imports": {
"polyscript": "https://esm.sh/polyscript@0.3.8"
} }
</script>
</head>
<body>
<script type="module">
import {PyMainThreadSandbox} from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({restricted: true});
await sandbox.init();
try {
await sandbox.exec("import js\njs.document.getElementById('out').innerText = 'fail';", "out");
} catch (e) {
await sandbox.exec("display('success', target=current_target())", 'out');
}
</script>
<div id="out"></div>
</body>
</html>
<head>
<script type="importmap">
{
"imports": {
"polyscript": "https://esm.sh/polyscript@0.4.2"
}
}
</script>
</head>
<body>
<script type="module">
import { PyMainThreadSandbox } from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox({ restricted: true });
await sandbox.init();
try {
await sandbox.exec(
"import js\njs.document.getElementById('out').innerText = 'fail';",
"out",
);
} catch (e) {
await sandbox.exec(
"display('success', target=current_target())",
"out",
);
}
</script>
<div id="out"></div>
</body>
</html>
38 changes: 21 additions & 17 deletions examples/MainThread/simple.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<html>
<head>
<script type="importmap">
{ "imports": {
"polyscript": "https://esm.sh/polyscript@0.3.8"
} }
</script>
</head>
<body>
<script type="module">
import {PyMainThreadSandbox} from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox();
await sandbox.init();
await sandbox.exec("import js\njs.document.getElementById('out').innerText = 'success'");
</script>
<div id="out"></div>
</body>
</html>
<head>
<script type="importmap">
{
"imports": {
"polyscript": "https://esm.sh/polyscript@0.4.2"
}
}
</script>
</head>
<body>
<script type="module">
import { PyMainThreadSandbox } from "/dist/index.esm.js";
const sandbox = new PyMainThreadSandbox();
await sandbox.init();
await sandbox.exec(
"import js\njs.document.getElementById('out').innerText = 'success'",
);
</script>
<div id="out"></div>
</body>
</html>
Loading

0 comments on commit 6ed76e7

Please sign in to comment.