eliminate py-env altogether (#775)

* examples use toml now

* use 0.21.2 for now

* change config in docs

* fix pre-commit
This commit is contained in:
Madhur Tandon
2022-10-04 19:00:39 +05:30
committed by GitHub
parent a4f97e6e46
commit c70e121078
27 changed files with 193 additions and 387 deletions

View File

@@ -16,10 +16,12 @@
}
}
</style>
<py-env>
- numpy
- matplotlib
</py-env>
<py-config>
packages = [
"numpy",
"matplotlib"
]
</py-config>
</head>
<body>

View File

@@ -258,9 +258,12 @@ OR in JSON like
```
If your `.whl` is not a pure Python wheel, then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added [here](https://github.com/pyodide/pyodide/tree/main/packages).
If there's enough popular demand, the pyodide team will likely work on supporting your package. Regardless, things will likely move faster if you make the PR and consult with the team to get unblocked.
For example, NumPy and Matplotlib are available. Notice here we're using `<py-script output="plot">`
as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`.
```html
<html>
<head>
@@ -290,9 +293,11 @@ as a shortcut, which takes the expression on the last line of the script and run
```
### Local modules
In addition to packages, you can declare local Python modules that will
be imported in the `<py-script>` tag. For example, we can place the random
number generation steps in a function in the file `data.py`.
```python
# data.py
import numpy as np
@@ -377,104 +382,6 @@ OR in JSON like
If this `"magic"` key is present in config supplied via `src` and also present in config supplied via `inline`, then the value in the inline config is given priority i.e. the overriding process also works for custom keys.
## The py-env tag (Deprecated)
**The <py-env> tag is deprecated as of `2022.09.1` release but you can still use the functionality explained below. It will be removed in the next release. To specify packages in the recommended way, please see the <py-config> section.**
In addition to the [Python Standard Library](https://docs.python.org/3/library/) and
the `pyscript` module, many 3rd-party OSS packages will work out-of-the-box with PyScript.
In order to use them, you will need to declare the dependencies using the `<py-env>` tag in the
HTML head. You can also link to `.whl` files directly on disk like in our [toga example](https://github.com/pyscript/pyscript/blob/main/examples/toga/freedom.html).
```
<py-env>
- './static/wheels/travertino-0.1.3-py3-none-any.whl'
</py-env>
```
If your `.whl` is not a pure Python wheel, then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added [here](https://github.com/pyodide/pyodide/tree/main/packages).
If there's enough popular demand, the pyodide team will likely work on supporting your package. Regardless, things will likely move faster if you make the PR and consult with the team to get unblocked.
For example, NumPy and Matplotlib are available. Notice here we're using `<py-script output="plot">`
as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`.
```html
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<py-env>
- numpy
- matplotlib
</py-env>
</head>
<body>
<h1>Let's plot random numbers</h1>
<div id="plot"></div>
<py-script output="plot">
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(1000)
y = np.random.randn(1000)
fig, ax = plt.subplots()
ax.scatter(x, y)
fig
</py-script>
</body>
</html>
```
### Local modules with py-env (Deprecated)
**The <py-env> tag is deprecated as of `2022.09.1` release but you can still use the functionality explained below. It will be removed in the next release. To specify local modules in the recommended way, please see the <py-config> section.**
In addition to packages, you can declare local Python modules that will
be imported in the `<py-script>` tag. For example, we can place the random
number generation steps in a function in the file `data.py`.
```python
# data.py
import numpy as np
def make_x_and_y(n):
x = np.random.randn(n)
y = np.random.randn(n)
return x, y
```
In the HTML tag `<py-env>`, paths to local modules are provided in the
`paths:` key.
```html
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<py-env>
- numpy
- matplotlib
- paths:
- ./data.py
</py-env>
</head>
<body>
<h1>Let's plot random numbers</h1>
<div id="plot"></div>
<py-script output="plot">
import matplotlib.pyplot as plt
from data import make_x_and_y
x, y = make_x_and_y(n=1000)
fig, ax = plt.subplots()
ax.scatter(x, y)
fig
</py-script>
</body>
</html>
```
## The py-repl tag
The `<py-repl>` tag creates a REPL component that is rendered to the page as a code editor, allowing you to write executable code inline.

View File

@@ -5,12 +5,12 @@
<link rel="icon" type="image/x-icon" href="./favicon.png">
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
paths = [
"./antigravity.py"
]
</py-config>
</head>
<body>
<b>Based on xkcd: antigravity https://xkcd.com/353/.</b>
<py-script>

View File

@@ -14,15 +14,14 @@
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-config>
packages = [
"bokeh",
"numpy"
]
</py-config>
</head>
<body>
<h1>Bokeh Example</h1>
<div id="myplot"></div>

View File

@@ -14,15 +14,14 @@
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-config>
packages = [
"bokeh",
"numpy"
]
</py-config>
</head>
<body>
<h1>Bokeh Example</h1>
<div id="myplot"></div>

View File

@@ -4,9 +4,6 @@
<link rel="icon" type="image/x-icon" href="./favicon.png">
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-config>
packages = [
"numpy",
@@ -14,6 +11,9 @@ packages = [
"matplotlib"
]
</py-config>
</head>
<body>
<py-script>
import numpy as np
import networkx as nx

View File

@@ -28,6 +28,19 @@
}
</style>
<py-config type="json">
{
"packages": [
"numpy",
"sympy"
],
"paths": [
"./palettes.py",
"./fractals.py"
]
}
</py-config>
</head>
<body>
<b>
@@ -78,19 +91,6 @@
</div>
</div>
<py-config type="json">
{
"packages": [
"numpy",
"sympy"
],
"paths": [
"./palettes.py",
"./fractals.py"
]
}
</py-config>
<py-script>
from pyodide.ffi import to_js, create_proxy

View File

@@ -9,7 +9,6 @@
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@holoviz/panel@0.13.1/dist/panel.min.js"></script>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
packages = [
"bokeh",
@@ -17,6 +16,7 @@ packages = [
"panel==0.13.1"
]
</py-config>
</head>
<body>
<h1>Panel Example</h1>
<div id="simple_app"></div>

View File

@@ -40,8 +40,6 @@
</style>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
packages = [
"bokeh",
@@ -50,6 +48,7 @@ packages = [
"panel==0.13.1"
]
</py-config>
</head>
<body>
<div class="container-fluid d-flex flex-column vh-100 overflow-hidden" id="container">

View File

@@ -41,8 +41,6 @@
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
packages = [
"altair",
@@ -52,6 +50,7 @@ packages = [
"panel==0.13.1"
]
</py-config>
</head>
<body>
<div class="container-fluid d-flex flex-column vh-100 overflow-hidden" id="container">

View File

@@ -32,8 +32,6 @@
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
packages = [
"bokeh",
@@ -42,6 +40,7 @@ packages = [
"panel==0.13.1"
]
</py-config>
</head>
<body>
<div class="container-fluid d-flex flex-column vh-100 overflow-hidden" id="container">

View File

@@ -9,13 +9,12 @@
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
paths = [
"./antigravity.py"
]
</py-config>
</head>
<body>
<h1><b>pyscript REPL</b></h1>

View File

@@ -11,8 +11,6 @@
<link rel="stylesheet" href="repl.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
packages = [
"bokeh",
@@ -23,6 +21,7 @@ paths = [
"./antigravity.py"
]
</py-config>
</head>
<body>
<h1 class="font-semibold text-2xl ml-5">Custom REPL</h1>

View File

@@ -16,6 +16,14 @@
<title>Loading...</title>
<link rel="icon" type="image/png" href="../favicon.png" />
<py-config>
packages = [
"./static/wheels/travertino-0.1.3-py3-none-any.whl",
"./static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl",
"./static/wheels/toga_web-0.3.0.dev33-py3-none-any.whl",
"./static/wheels/freedom-0.0.1-py3-none-any.whl"
]
</py-config>
</head>
<body>
<div id="toga-placeholder">Loading...</div>
@@ -34,14 +42,6 @@
crossorigin="anonymous">
</script>
</body>
<py-config>
packages = [
"./static/wheels/travertino-0.1.3-py3-none-any.whl",
"./static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl",
"./static/wheels/toga_web-0.3.0.dev33-py3-none-any.whl",
"./static/wheels/freedom-0.0.1-py3-none-any.whl"
]
</py-config>
<py-script>
from toga_web.dom import handle as dom_handle

View File

@@ -14,7 +14,6 @@
"@codemirror/theme-one-dark": "^0.19.1",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"codemirror": "^5.65.3",
"js-yaml": "^4.1.0",
"sirv-cli": "^1.0.0",
"svelte-fa": "^2.4.0",
"svelte-promisable-stores": "^0.1.3"
@@ -26,7 +25,6 @@
"@rollup/plugin-typescript": "^8.4.0",
"@tsconfig/svelte": "^1.0.0",
"@types/jest": "^28.1.6",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.7.11",
"@typescript-eslint/eslint-plugin": "^5.36.0",
"@typescript-eslint/parser": "^5.36.0",
@@ -1689,9 +1687,9 @@
}
},
"node_modules/@types/babel__traverse": {
"version": "7.18.1",
"resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.1.tgz",
"integrity": "sha512-FSdLaZh2UxaMuLp9lixWaHq/golWTRWOnRsAXzDTDSDOQLuZb1nsdCt6pJSPWSEQt2eFZ2YVk3oYhn+1kLMeMA==",
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.2.tgz",
"integrity": "sha512-FcFaxOr2V5KZCviw1TnutEMVUVsGt4D2hP1TAfXZAMKuHYW3xQhe3jTxNPWutgCJ3/X1c5yX8ZoGVEItxKbwBg==",
"dev": true,
"dependencies": {
"@babel/types": "^7.3.0"
@@ -1765,12 +1763,6 @@
"pretty-format": "^28.0.0"
}
},
"node_modules/@types/js-yaml": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.5.tgz",
"integrity": "sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==",
"dev": true
},
"node_modules/@types/jsdom": {
"version": "16.2.15",
"resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-16.2.15.tgz",
@@ -1795,9 +1787,9 @@
"dev": true
},
"node_modules/@types/node": {
"version": "18.7.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
"integrity": "sha512-m+6nTEOadJZuTPkKR/SYK3A2d7FZrgElol9UP1Kae90VVU4a6mxnPuLiIW1m4Cq4gZ/nWb9GrdVXJCoCazDAbg==",
"version": "18.7.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.19.tgz",
"integrity": "sha512-Sq1itGUKUX1ap7GgZlrzdBydjbsJL/NSQt/4wkAxUJ7/OS5c2WkoN6WSpWc2Yc5wtKMZOUA0VCs/j2XJadN3HA==",
"dev": true
},
"node_modules/@types/parse5": {
@@ -1807,9 +1799,9 @@
"dev": true
},
"node_modules/@types/prettier": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.0.tgz",
"integrity": "sha512-RI1L7N4JnW5gQw2spvL7Sllfuf1SaHdrZpCHiBlCXjIlufi1SMNnbu2teze3/QE67Fg2tBlH7W+mi4hVNk4p0A==",
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow==",
"dev": true
},
"node_modules/@types/pug": {
@@ -1849,9 +1841,9 @@
"dev": true
},
"node_modules/@types/yargs": {
"version": "17.0.12",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.12.tgz",
"integrity": "sha512-Nz4MPhecOFArtm81gFQvQqdV7XYCrWKx5uUt6GNHredFHn1i2mtWqXTON7EPXMtNi1qjtjEM/VCHDhcHsAMLXQ==",
"version": "17.0.13",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz",
"integrity": "sha512-9sWaruZk2JGxIQU+IhI1fhPYRcQ0UuTNuKuCW9bR5fp7qi2Llf7WDzNa17Cy7TKnh3cdxDOiyTu6gaLS0eDatg==",
"dev": true,
"dependencies": {
"@types/yargs-parser": "*"
@@ -2200,7 +2192,8 @@
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"dev": true
},
"node_modules/array-union": {
"version": "2.1.0",
@@ -2485,9 +2478,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001409",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001409.tgz",
"integrity": "sha512-V0mnJ5dwarmhYv8/MzhJ//aW68UpvnQBXv8lJ2QUsvn2pHcmAuNtu8hQEDz37XnA1iE+lRR9CIfGWWpgJ5QedQ==",
"version": "1.0.30001406",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001406.tgz",
"integrity": "sha512-bWTlaXUy/rq0BBtYShc/jArYfBPjEV95euvZ8JVtO43oQExEN/WquoqpufFjNu4kSpi5cy5kMbNvzztWDfv1Jg==",
"dev": true,
"funding": [
{
@@ -2884,9 +2877,9 @@
}
},
"node_modules/electron-to-chromium": {
"version": "1.4.256",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.256.tgz",
"integrity": "sha512-x+JnqyluoJv8I0U9gVe+Sk2st8vF0CzMt78SXxuoWCooLLY2k5VerIBdpvG7ql6GKI4dzNnPjmqgDJ76EdaAKw==",
"version": "1.4.261",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.261.tgz",
"integrity": "sha512-fVXliNUGJ7XUVJSAasPseBbVgJIeyw5M1xIkgXdTSRjlmCqBbiSTsEdLOCJS31Fc8B7CaloQ/BFAg8By3ODLdg==",
"dev": true
},
"node_modules/emittery": {
@@ -3026,13 +3019,13 @@
}
},
"node_modules/eslint": {
"version": "8.23.1",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.23.1.tgz",
"integrity": "sha512-w7C1IXCc6fNqjpuYd0yPlcTKKmHlHHktRkzmBPZ+7cvNBQuiNjx0xaMTjAJGCafJhQkrFJooREv0CtrVzmHwqg==",
"version": "8.24.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.24.0.tgz",
"integrity": "sha512-dWFaPhGhTAiPcCgm3f6LI2MBWbogMnTJzFBbhXVRQDJPkr9pGZvVjlVfXd+vyDcWPA2Ic9L2AXPIQM0+vk/cSQ==",
"dev": true,
"dependencies": {
"@eslint/eslintrc": "^1.3.2",
"@humanwhocodes/config-array": "^0.10.4",
"@humanwhocodes/config-array": "^0.10.5",
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
"@humanwhocodes/module-importer": "^1.0.1",
"ajv": "^6.10.0",
@@ -4559,6 +4552,7 @@
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
"dev": true,
"dependencies": {
"argparse": "^2.0.1"
},
@@ -5626,9 +5620,9 @@
}
},
"node_modules/rollup": {
"version": "2.79.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.0.tgz",
"integrity": "sha512-x4KsrCgwQ7ZJPcFA/SUu6QVcYlO7uRLfLAy0DSA4NS2eG8japdbpM50ToH7z4iObodRYOJ0soneF0iaQRJ6zhA==",
"version": "2.79.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz",
"integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==",
"dev": true,
"bin": {
"rollup": "dist/bin/rollup"
@@ -6759,9 +6753,9 @@
}
},
"node_modules/ws": {
"version": "8.8.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz",
"integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==",
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.9.0.tgz",
"integrity": "sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==",
"dev": true,
"engines": {
"node": ">=10.0.0"
@@ -8168,9 +8162,9 @@
}
},
"@types/babel__traverse": {
"version": "7.18.1",
"resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.1.tgz",
"integrity": "sha512-FSdLaZh2UxaMuLp9lixWaHq/golWTRWOnRsAXzDTDSDOQLuZb1nsdCt6pJSPWSEQt2eFZ2YVk3oYhn+1kLMeMA==",
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.2.tgz",
"integrity": "sha512-FcFaxOr2V5KZCviw1TnutEMVUVsGt4D2hP1TAfXZAMKuHYW3xQhe3jTxNPWutgCJ3/X1c5yX8ZoGVEItxKbwBg==",
"dev": true,
"requires": {
"@babel/types": "^7.3.0"
@@ -8244,12 +8238,6 @@
"pretty-format": "^28.0.0"
}
},
"@types/js-yaml": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.5.tgz",
"integrity": "sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==",
"dev": true
},
"@types/jsdom": {
"version": "16.2.15",
"resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-16.2.15.tgz",
@@ -8274,9 +8262,9 @@
"dev": true
},
"@types/node": {
"version": "18.7.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
"integrity": "sha512-m+6nTEOadJZuTPkKR/SYK3A2d7FZrgElol9UP1Kae90VVU4a6mxnPuLiIW1m4Cq4gZ/nWb9GrdVXJCoCazDAbg==",
"version": "18.7.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.19.tgz",
"integrity": "sha512-Sq1itGUKUX1ap7GgZlrzdBydjbsJL/NSQt/4wkAxUJ7/OS5c2WkoN6WSpWc2Yc5wtKMZOUA0VCs/j2XJadN3HA==",
"dev": true
},
"@types/parse5": {
@@ -8286,9 +8274,9 @@
"dev": true
},
"@types/prettier": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.0.tgz",
"integrity": "sha512-RI1L7N4JnW5gQw2spvL7Sllfuf1SaHdrZpCHiBlCXjIlufi1SMNnbu2teze3/QE67Fg2tBlH7W+mi4hVNk4p0A==",
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow==",
"dev": true
},
"@types/pug": {
@@ -8328,9 +8316,9 @@
"dev": true
},
"@types/yargs": {
"version": "17.0.12",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.12.tgz",
"integrity": "sha512-Nz4MPhecOFArtm81gFQvQqdV7XYCrWKx5uUt6GNHredFHn1i2mtWqXTON7EPXMtNi1qjtjEM/VCHDhcHsAMLXQ==",
"version": "17.0.13",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz",
"integrity": "sha512-9sWaruZk2JGxIQU+IhI1fhPYRcQ0UuTNuKuCW9bR5fp7qi2Llf7WDzNa17Cy7TKnh3cdxDOiyTu6gaLS0eDatg==",
"dev": true,
"requires": {
"@types/yargs-parser": "*"
@@ -8546,7 +8534,8 @@
"argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"dev": true
},
"array-union": {
"version": "2.1.0",
@@ -8748,9 +8737,9 @@
"dev": true
},
"caniuse-lite": {
"version": "1.0.30001409",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001409.tgz",
"integrity": "sha512-V0mnJ5dwarmhYv8/MzhJ//aW68UpvnQBXv8lJ2QUsvn2pHcmAuNtu8hQEDz37XnA1iE+lRR9CIfGWWpgJ5QedQ==",
"version": "1.0.30001406",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001406.tgz",
"integrity": "sha512-bWTlaXUy/rq0BBtYShc/jArYfBPjEV95euvZ8JVtO43oQExEN/WquoqpufFjNu4kSpi5cy5kMbNvzztWDfv1Jg==",
"dev": true
},
"chalk": {
@@ -9054,9 +9043,9 @@
}
},
"electron-to-chromium": {
"version": "1.4.256",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.256.tgz",
"integrity": "sha512-x+JnqyluoJv8I0U9gVe+Sk2st8vF0CzMt78SXxuoWCooLLY2k5VerIBdpvG7ql6GKI4dzNnPjmqgDJ76EdaAKw==",
"version": "1.4.261",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.261.tgz",
"integrity": "sha512-fVXliNUGJ7XUVJSAasPseBbVgJIeyw5M1xIkgXdTSRjlmCqBbiSTsEdLOCJS31Fc8B7CaloQ/BFAg8By3ODLdg==",
"dev": true
},
"emittery": {
@@ -9159,13 +9148,13 @@
}
},
"eslint": {
"version": "8.23.1",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.23.1.tgz",
"integrity": "sha512-w7C1IXCc6fNqjpuYd0yPlcTKKmHlHHktRkzmBPZ+7cvNBQuiNjx0xaMTjAJGCafJhQkrFJooREv0CtrVzmHwqg==",
"version": "8.24.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.24.0.tgz",
"integrity": "sha512-dWFaPhGhTAiPcCgm3f6LI2MBWbogMnTJzFBbhXVRQDJPkr9pGZvVjlVfXd+vyDcWPA2Ic9L2AXPIQM0+vk/cSQ==",
"dev": true,
"requires": {
"@eslint/eslintrc": "^1.3.2",
"@humanwhocodes/config-array": "^0.10.4",
"@humanwhocodes/config-array": "^0.10.5",
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
"@humanwhocodes/module-importer": "^1.0.1",
"ajv": "^6.10.0",
@@ -10326,6 +10315,7 @@
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
"dev": true,
"requires": {
"argparse": "^2.0.1"
}
@@ -11098,9 +11088,9 @@
}
},
"rollup": {
"version": "2.79.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.0.tgz",
"integrity": "sha512-x4KsrCgwQ7ZJPcFA/SUu6QVcYlO7uRLfLAy0DSA4NS2eG8japdbpM50ToH7z4iObodRYOJ0soneF0iaQRJ6zhA==",
"version": "2.79.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz",
"integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==",
"dev": true,
"requires": {
"fsevents": "~2.3.2"
@@ -11913,9 +11903,9 @@
}
},
"ws": {
"version": "8.8.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz",
"integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==",
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.9.0.tgz",
"integrity": "sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==",
"dev": true,
"requires": {}
},

View File

@@ -23,7 +23,6 @@
"@rollup/plugin-typescript": "^8.4.0",
"@tsconfig/svelte": "^1.0.0",
"@types/jest": "^28.1.6",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.7.11",
"@typescript-eslint/eslint-plugin": "^5.36.0",
"@typescript-eslint/parser": "^5.36.0",
@@ -54,7 +53,6 @@
"@codemirror/theme-one-dark": "^0.19.1",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"codemirror": "^5.65.3",
"js-yaml": "^4.1.0",
"sirv-cli": "^1.0.0",
"svelte-fa": "^2.4.0",
"svelte-promisable-stores": "^0.1.3"

View File

@@ -1,82 +0,0 @@
import * as jsyaml from 'js-yaml';
import { runtimeLoaded, addInitializer } from '../stores';
import { handleFetchError } from '../utils';
import type { Runtime } from '../runtime';
import { getLogger } from '../logger';
const logger = getLogger('py-env');
// Premise used to connect to the first available runtime (can be pyodide or others)
let runtime: Runtime;
runtimeLoaded.subscribe(value => {
runtime = value;
});
export class PyEnv extends HTMLElement {
shadow: ShadowRoot;
wrapper: HTMLElement;
code: string;
environment: unknown;
runtime: Runtime;
env: string[];
paths: string[];
constructor() {
super();
this.shadow = this.attachShadow({ mode: 'open' });
this.wrapper = document.createElement('slot');
}
connectedCallback() {
logger.info("The <py-env> tag is deprecated, please use <py-config> instead.")
this.code = this.innerHTML;
this.innerHTML = '';
const env: string[] = [];
const paths: string[] = [];
this.environment = jsyaml.load(this.code);
if (this.environment === undefined) return;
for (const entry of Array.isArray(this.environment) ? this.environment : []) {
if (typeof entry == 'string') {
env.push(entry);
} else if (entry && typeof entry === 'object') {
const obj = <Record<string, unknown>>entry;
for (const path of Array.isArray(obj.paths) ? obj.paths : []) {
if (typeof path === 'string') {
paths.push(path);
}
}
}
}
this.env = env;
this.paths = paths;
async function loadEnv() {
logger.info("Loading env: ", env);
await runtime.installPackage(env);
}
async function loadPaths() {
logger.info("Paths to load: ", paths)
for (const singleFile of paths) {
logger.info(` loading path: ${singleFile}`);
try {
await runtime.loadFromFile(singleFile);
} catch (e) {
//Should we still export full error contents to console?
handleFetchError(<Error>e, singleFile);
}
}
logger.info("All paths loaded");
}
addInitializer(loadEnv);
addInitializer(loadPaths);
}
}

View File

@@ -4,7 +4,6 @@ import { loadConfigFromElement } from './pyconfig';
import type { AppConfig } from './pyconfig';
import type { Runtime } from './runtime';
import { PyScript } from './components/pyscript';
import { PyEnv } from './components/pyenv';
import { PyLoader } from './components/pyloader';
import { PyodideRuntime } from './pyodide';
import { getLogger } from './logger';
@@ -31,7 +30,6 @@ class PyScriptApp {
/* eslint-disable @typescript-eslint/no-unused-vars */
const xPyScript = customElements.define('py-script', PyScript);
const xPyLoader = customElements.define('py-loader', PyLoader);
const xPyEnv = customElements.define('py-env', PyEnv);
/* eslint-disable @typescript-eslint/no-unused-vars */
// add loader to the page body

View File

@@ -99,7 +99,7 @@ export class PyodideRuntime extends Runtime {
try:
response = await pyfetch("${path}")
except Exception as err:
console.warn("PyScript: Access to local files (using 'paths:' in py-env) is not available when directly opening a HTML file; you must use a webserver to serve the additional files. See https://github.com/pyscript/pyscript/issues/257#issuecomment-1119595062 on starting a simple webserver with Python.")
console.warn("PyScript: Access to local files (using 'paths:' in py-config) is not available when directly opening a HTML file; you must use a webserver to serve the additional files. See https://github.com/pyscript/pyscript/issues/257#issuecomment-1119595062 on starting a simple webserver with Python.")
raise(err)
content = await response.bytes()
with open("${filename}", "wb") as f:

View File

@@ -68,7 +68,7 @@ function handleFetchError(e: Error, singleFile: string) {
let errorContent: string;
if (e.message.includes('TypeError: Failed to fetch')) {
errorContent = `<p>PyScript: Access to local files
(using "Paths:" in &lt;py-env&gt;)
(using "Paths:" in &lt;py-config&gt;)
is not available when directly opening a HTML file;
you must use a webserver to serve the additional files.
See <a style="text-decoration: underline;" href="https://github.com/pyscript/pyscript/issues/257#issuecomment-1119595062">this reference</a>