Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Mar 18, 2024
1 parent d41a679 commit 387c4ab
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 45 deletions.
34 changes: 30 additions & 4 deletions build_mkdocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ if [ ! -d "$WASM_ENV_PREFIX" ]; then
--yes \
python pybind11 nlohmann_json pybind11_json numpy \
bzip2 sqlite zlib libffi exceptiongroup \
xeus xeus-lite xeus-python xeus-javascript xtl "ipython<8.20"

xeus xeus-lite xeus-python "xeus-javascript>=0.3.1" xtl "ipython=8.22.2=py311had7285e_1" "traitlets>=5.14.2"
else
echo "Wasm env $WASM_ENV_NAME already exists"
fi




if [ ! -f "$PYJS_PROBE_FILE" ]; then
if true; then
echo "Building pyjs"

cd $THIS_DIR
Expand Down Expand Up @@ -75,7 +74,6 @@ else
fi


# PYJS_PROBE_FILE=$WASM_ENV_PREFIX/share/jupyter/kernels/xpython/kernel.json
if false; then
echo "Building xeus-python"

Expand Down Expand Up @@ -113,6 +111,34 @@ else
echo "Skipping build xeus-python"
fi

# no need to build xeus-javascript, the distributed version is fine
# if false; then
# echo "Building xeus-javascript"

# cd $THIS_DIR
# source $EMSDK_DIR/emsdk_env.sh


# cd ~/src/xeus-javascript
# mkdir -p build_wasm
# cd build_wasm

# export PREFIX=$WASM_ENV_PREFIX
# export CMAKE_PREFIX_PATH=$PREFIX
# export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX


# emcmake cmake .. \
# -DCMAKE_BUILD_TYPE=Release \
# -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
# -DCMAKE_INSTALL_PREFIX=$PREFIX \
# -DXPYT_EMSCRIPTEN_WASM_BUILD=ON\

# emmake make -j8 install
# else
# echo "Skipping build xeus-javascript"
# fi



if true ; then
Expand Down
21 changes: 21 additions & 0 deletions docs/JavaScript_API.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# JavaScript API

## `pyjs`
The main module for the JavaScript API.
### `exec`
Execute a string of Python code.
### `exec_eval`
Execute a string of Python code and return the last expression.

Example:
```javascript
pyjs.exec(`
import numpy
print(numpy.random.rand(3))
`);
```

### `eval`
Evaluate a string with a Python expression.
### `async_exec_eval`
Schedule the execution of a string of Python code and return a promise.
The last expression is returned as the result of the promise.
### `eval_file`
Evaluate a file with Python code.
### `pyobject`
A Python object exported as a JavaScript class
#### `py_call`
Call the `__call__` method of a Python object.
#### `py_apply`
Call the `__call__` method of a Python object with an array of arguments.
#### `get`
Get an attribute of a Python object.

13 changes: 4 additions & 9 deletions docs/Python_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
options:
show_submodules: true
members:
- pyjs_core
- to_js
- to_py
- register_converter
- to_py_json
- JsToPyConverterOptions
- to_py
- error_to_py
- error_to_py_and_raise
- new
- create_callable
- callable_context
- promise
- create_once_callable
- promise
- apply
- japply
- gapply
- WebLoop
- JsException
- JsGenericError
- JsError
Expand All @@ -36,8 +33,6 @@
- JsSyntaxError
- JsTypeError
- JsURIError
- WebLoop
- pyjs_core



2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- mkdocs
- mkdocstrings
- mkdocstrings-python
- mkdocs-material
- empack >=3.2.0
- jupyter_server # to enable contents
- jupyterlite
Expand All @@ -27,5 +28,4 @@ dependencies:
# pyjs_code_runner dev deps
- hatchling
- pip:
- mkdocs-dracula-theme
- JLDracula
18 changes: 10 additions & 8 deletions include/pyjs/pre_js/apply.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

function isPromise(p) {
if (
p !== null &&
typeof p === 'object' &&
typeof p.then === 'function' &&
typeof p.catch === 'function'
) {
return true;
try{
if (
p !== null &&
typeof p === 'object' &&
typeof p.then === 'function' &&
typeof p.catch === 'function'
) {
return true;
}
} catch (e) {
}

return false;
}

Expand Down
4 changes: 4 additions & 0 deletions include/pyjs/pre_js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ Module['init_phase_1'] = async function(prefix, python_version) {
return this.py_apply(args)
};

// Module['pyobject'].prototype.toString = function(...args) {
// return this.py_apply(args)
// };

Module['pyobject'].prototype.py_apply = function(args, kwargs) {

if (args === undefined) {
Expand Down
14 changes: 12 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
site_name: Pyjs docs
theme:
# name: material
name: dracula
name: material
# name: dracula

palette:

Expand Down Expand Up @@ -34,3 +34,13 @@ plugins:
allow_inspection: true
show_root_heading: true
show_source: false


markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
Loading

0 comments on commit 387c4ab

Please sign in to comment.