From 2426533807dcfaa47f71bad5ce730e743a6b95a4 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 30 Apr 2022 10:14:17 -0500 Subject: [PATCH 1/2] minified js and local modules --- GETTING-STARTED.md | 64 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md index 16721b0d..43a1d2c4 100644 --- a/GETTING-STARTED.md +++ b/GETTING-STARTED.md @@ -7,17 +7,22 @@ This page will guide you through getting started with PyScript. PyScript does not require any development environment other than a web browser. We recommend using Chrome. +If, you're using [VSCode](https://code.visualstudio.com/) the +[Live Server extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) +can be used to reload the page as you edit the HTML file. + ## Installation First, go to https://pyscript.net and download the PyScript assets. Unzip the archive to a directory where you wish to write PyScript-enabled -HTML files. You should then have three files in your directory. +HTML files. You should then have four files in your directory. ``` ├── ./ │ ├── pyscript.css │ ├── pyscript.js │ └── pyscript.js.map +│ ├── pyscript.min.js ``` ## Your first PyScript HTML file @@ -34,7 +39,7 @@ open an HTML by double clicking it in your file explorer. - + print('Hello, World!') @@ -54,7 +59,7 @@ example we can compute π. - + @@ -86,7 +91,7 @@ the `` tag write to. - + @@ -126,7 +131,7 @@ as a shortcut, which takes the expression on the last line of the script and run - + - numpy - matplotlib @@ -143,6 +148,55 @@ import numpy as np x = np.random.randn(1000) y = np.random.randn(1000) +fig, ax = plt.subplots() +ax.scatter(x, y) +fig + + + +``` + +### Local modules + +In addition to packages you can declare local Python modules that will +be imported in the `` 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 `` paths to local modules are provided in the +`paths:` key. + +```html + + + + + + - numpy + - matplotlib + - paths: + - /data.py + + + + +

Let's plot random numbers

+
+ +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 From 09631bb18c96ad4bd2993b59f4eea258eb5c275f Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 30 Apr 2022 11:05:33 -0500 Subject: [PATCH 2/2] pyscript.net --- GETTING-STARTED.md | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md index 43a1d2c4..c48b1b81 100644 --- a/GETTING-STARTED.md +++ b/GETTING-STARTED.md @@ -13,22 +13,15 @@ can be used to reload the page as you edit the HTML file. ## Installation -First, go to https://pyscript.net and download the PyScript assets. -Unzip the archive to a directory where you wish to write PyScript-enabled -HTML files. You should then have four files in your directory. +There is no installation required. In this document we'll use +the PyScript assets served on https://pyscript.net. -``` -├── ./ -│ ├── pyscript.css -│ ├── pyscript.js -│ └── pyscript.js.map -│ ├── pyscript.min.js -``` +If you want to download the source and build it yourself follow +the instructions in the README.md file. ## Your first PyScript HTML file -Here's a "Hello, world!" example using PyScript using the assets you -downloaded from https://pyscript.net. +Here's a "Hello, world!" example using PyScript Using your favorite editor create a new file called `hello.html` in the same directory as your PyScript JavaScript and CSS files with the @@ -38,8 +31,8 @@ open an HTML by double clicking it in your file explorer. ```html - - + + print('Hello, World!') @@ -58,8 +51,8 @@ example we can compute π. ```html - - + + @@ -90,8 +83,8 @@ the `` tag write to. ```html - - + + @@ -130,8 +123,8 @@ as a shortcut, which takes the expression on the last line of the script and run ```html - - + + - numpy - matplotlib @@ -178,8 +171,8 @@ In the HTML tag `` paths to local modules are provided in the ```html - - + + - numpy - matplotlib