Merge branch 'main' into docs

This commit is contained in:
Mark Saroufim
2022-05-02 09:27:02 -07:00
committed by GitHub
7 changed files with 68 additions and 5 deletions

4
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,4 @@
# Code of Conduct
The Code of Conduct is available in the pyscript Governance repo.
See https://github.com/pyscript/governance/blob/main/CODE-OF-CONDUCT.md

View File

@@ -67,6 +67,7 @@ pi = wallis(100000)
s = f"π is approximately {pi:.3f}"
print(s)
</py-script>
</body>
</html>
```
@@ -113,6 +114,7 @@ pyscript.write('pi', f'π is approximately {pi:.3f}')
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 delcare the dependencies using the `<py-env>` 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/pyscriptjs/examples/toga/freedom.html)
@@ -122,7 +124,10 @@ HTML head. You can also link to `.whl` files directly on disk like in our [toga
</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 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.
In order to use them you will need to declare the dependencies using the `<py-env>` in the
HTML head.
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)`.

View File

@@ -10,7 +10,7 @@ To get started see [GETTING-STARTED][GETTING-STARTED.md]
For examples see [the pyscript folder](pyscriptjs/README.md).
### Longer Version
PyScript is a meta project that aims to combine multiple open technologies to create a framework for users to use Python (and other languages) to create sophisticated applications in the browser. It highly integrate with the way the DOM works in the browser and allows users to add logic, in Python, in a way that feel natural to web as well as Python developers.
PyScript is a meta project that aims to combine multiple open technologies to create a framework for users to use Python (and other languages) to create sophisticated applications in the browser. It highly integrates with the way the DOM works in the browser and allows users to add logic, in Python, in a way that feels natural to web as well as Python developers.
## Try PyScript

View File

@@ -0,0 +1,53 @@
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-env>
- numpy
- networkx
- matplotlib
</py-env>
<py-script>
import numpy as np
import networkx as nx
</py-script>
<p>Message passing with linear algebra: a demo.</p>
<p>Imagine we have a chain graph that looks like this:</p>
<pre><code>O --> 1 --> 2 --> 3</code></pre>
<p>In NetworkX this graph would look like the following:</p>
<pre>
<py-script>
G = nx.Graph()
nodes = list(range(4))
G.add_edges_from(zip(nodes[0:-1], nodes[1:]))
print(G.edges())
</py-script></pre>
<p>This chain graph has the following adjacency matrix:</p>
<pre>
<py-script>
adj_mat = np.eye(4, k=1)
print(f"A: {adj_mat}")
</py-script>
</pre>
<p>And imagine that we have a message that lives on the graph:</p>
<pre>
<py-script>
message = np.array([1.0, 0.0, 0.0, 0.0])
print(f"message: {message}")
</py-script>
</pre>
<p>Try out message passing below by doing any one of the following steps:</p>
<pre><code>message @ adj_mat</code></pre>
<pre><code>message @ adj_mat @ adj_mat</code></pre>
<pre><code>message @ adj_mat @ adj_mat @ adj_mat</code></pre>
<div>
<py-repl id="my-repl" auto-generate="true"> </py-repl>
</div>
</body>
</html>

View File

@@ -7,7 +7,7 @@ def now(fmt = "%m/%d/%Y, %H:%M:%S"):
return format_date(dt.now(), fmt)
def remove_class(element, className):
element.element.classList.remove("line-through")
element.element.classList.remove(className)
def add_class(element, className):
element.element.classList.add("line-through")
element.element.classList.add(className)

View File

@@ -0,0 +1 @@

View File

@@ -54,7 +54,7 @@ export class PyBox extends HTMLElement {
this.widths.forEach((width, index)=>{
const node: ChildNode = mainDiv.childNodes[index];
addClasses(node, [width, 'mx-1'])
addClasses(node as HTMLElement, [width, 'mx-1'])
})