Skip to content

Commit ac2e9f5

Browse files
committed
Update docfx version and move to modern template
1 parent 41123c7 commit ac2e9f5

12 files changed

Lines changed: 110 additions & 258 deletions

File tree

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"docfx": {
6+
"version": "2.75.3",
7+
"commands": [
8+
"docfx"
9+
]
10+
}
11+
}
12+
}

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docs/bonsai"]
2+
path = docs/bonsai
3+
url = https://github.com/bonsai-rx/docfx-tools

docs/articles/intro.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/articles/overview.md

Lines changed: 0 additions & 66 deletions
This file was deleted.

docs/articles/toc.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
- name: Getting Started
2-
href: intro.md
3-
items:
4-
- name: Quickstart
5-
href: intro.md
6-
- name: Dynamic Modules
7-
href: modules.md
2+
- href: ../index.md
3+
- href: modules.md

docs/bonsai

Submodule bonsai added at 81ef52f

docs/docfx.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"src": "../src"
1010
}
1111
],
12-
"dest": "api",
13-
"disableGitFeatures": false,
14-
"disableDefaultFilter": false
12+
"dest": "api"
1513
}
1614
],
1715
"build": {
@@ -41,6 +39,7 @@
4139
]
4240
}
4341
],
42+
"output": "_site",
4443
"overwrite": [
4544
{
4645
"files": [
@@ -52,33 +51,32 @@
5251
]
5352
}
5453
],
54+
"template": [
55+
"default",
56+
"modern",
57+
"bonsai/template",
58+
"template"
59+
],
5560
"globalMetadata": {
61+
"_appName": "Bonsai - Python Scripting",
62+
"_appTitle": "Bonsai.Scripting.Python",
5663
"_enableNewTab": true,
64+
"_enableSearch": true,
65+
"pdf": false,
66+
"_appFooter": "&copy; 2024 Bonsai Foundation CIC and Contributors. Made with <a href=\"https://dotnet.github.io/docfx\">docfx</a>",
5767
"_gitContribute": {
68+
"repo": "https://github.com/bonsai-rx/python-scripting",
5869
"branch": "main",
5970
"apiSpecFolder": "docs/apidoc"
6071
}
6172
},
62-
"dest": "_site",
63-
"globalMetadataFiles": [],
64-
"fileMetadataFiles": [],
65-
"template": [
66-
"default",
67-
"templates/html"
68-
],
69-
"postProcessors": [ "ExtractSearchIndex" ],
7073
"markdownEngineName": "markdig",
7174
"markdownEngineProperties": {
7275
"markdigExtensions": [
7376
"attributes",
7477
"customcontainers"
7578
]
7679
},
77-
"noLangKeyword": false,
78-
"keepFileLink": false,
79-
"cleanupCacheHistory": false,
80-
"disableGitFeatures": false,
81-
"xrefService": [ "https://xref.docs.microsoft.com/query?uid={uid}" ],
8280
"xref": [
8381
"https://bonsai-rx.org/docs/xrefmap.yml",
8482
"https://horizongir.github.io/reactive/xrefmap.yml"

docs/index.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
1-
**Bonsai - Python Scripting** Documentation
2-
===========================================
1+
# Introduction
32

4-
[!include[Overview](~/articles/overview.md)]
3+
The Python Scripting package is a [Bonsai](https://bonsai-rx.org/) interface for the [Python](https://www.python.org/) programming language. It uses [Python.NET](https://pythonnet.github.io/pythonnet/) under the hood to provide a seamless integration between the CPython runtime and data streaming in a Bonsai workflow.
4+
5+
You can use the Python Scripting package to run native Python scripts, import any module available to Python, and read or write to any variable in a named scope. The package is designed to work with any Python version from 3.7 onwards, and you can also use it in combination with [Python virtual environments](https://docs.python.org/3/tutorial/venv.html) to fully isolate your project dependencies.
6+
7+
## How to install
8+
9+
1. Download [Bonsai](https://bonsai-rx.org/).
10+
2. From the package manager, search and install the **Bonsai - Python Scripting** package.
11+
12+
## Create a Python environment
13+
14+
In addition to the Python Scripting package you need to have a version of [Python](https://www.python.org/) installed in your system. We recommend installing the official distributions and using `venv` to create virtual environments to run your specific projects.
15+
16+
To create a virtual environment you can run the following command from inside the folder where you want to install the environment:
17+
18+
```ps
19+
python -m venv example-env
20+
```
21+
22+
## Create a Python runtime
23+
24+
The [CreateRuntime](xref:Bonsai.Scripting.Python.CreateRuntime) node launches the Python kernel and creates the main global scope for running Python scripts. You must set the [PythonHome](xref:Bonsai.Scripting.Python.CreateRuntime.PythonHome) property to the environment folder (or your Python home directory) before starting the workflow:
25+
26+
:::workflow
27+
![CreateRuntime](~/workflows/create-runtime.bonsai)
28+
:::
29+
30+
Alternatively, you can activate the virtual environment *before* starting Bonsai. In this case you do not need to specify the Python home directory.
31+
32+
> [!Tip]
33+
> You can set the value of the [**ScriptPath**](xref:Bonsai.Scripting.Python.CreateRuntime.ScriptPath) property to specify a main script that will be run when the Python runtime is initialized. This script can be used to import all the main modules to be used in your workflow, or initialize any state variables to be manipulated during execution.
34+
35+
## Run Python code
36+
37+
The [Eval](xref:Bonsai.Scripting.Python.Eval) operator can be used anywhere in your workflow to interact with the Python runtime, just as if you were writing code in the Python REPL:
38+
39+
:::workflow
40+
![HelloPython](~/workflows/hello-python.bonsai)
41+
:::
42+
43+
You can also use the [Exec](xref:Bonsai.Scripting.Python.Exec) operator to run Python statements dynamically, for example to import new modules:
44+
45+
:::workflow
46+
![HelloPython](~/workflows/exec-eval.bonsai)
47+
:::
48+
49+
## Read and write state variables
50+
51+
To interface with Python state variables, you can use the [Get](xref:Bonsai.Scripting.Python.Get) and [Set](xref:Bonsai.Scripting.Python.Set) operators:
52+
53+
:::workflow
54+
![GetSet](~/workflows/get-set.bonsai)
55+
:::
56+
57+
> [!Warning]
58+
> All the operators in the Python Scripting package run under the Python [Global Interpreter Lock](https://docs.python.org/3/glossary.html#term-global-interpreter-lock). This means that although execution of Python code can be triggered asynchronously anywhere in the workflow, there will be a bottleneck when accessing the interpreter. Because of this, we currently do not recommend running large number of parallel calls to Python.
59+
60+
## Scripting Extensions
61+
62+
Custom script files can be executed when creating the Python runtime with [CreateRuntime](xref:Bonsai.Scripting.Python.CreateRuntime) or when creating a new module with [CreateModule](xref:Bonsai.Scripting.Python.CreateModule).
63+
64+
To edit script files we recommend [Visual Studio Code](https://code.visualstudio.com/) and the [Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python). If both your virtual environment and your custom Python scripts are placed relative to your main workflow, VS Code can be launched from the Bonsai IDE and will be able to correctly pick up the right environment when editing the scripts.
565

666
> [!Warning]
7-
> These docs are under active development, feel free to contribute by either [raising an issue](https://github.com/bonsai-rx/python-scripting/issues) or following the links to **Improve this Doc**.
67+
> These docs are under active development, feel free to contribute by either [raising an issue](https://github.com/bonsai-rx/python-scripting/issues) or following the links to **Edit this page**.

docs/template/public/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "workflow.css";

docs/template/public/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import WorkflowContainer from "./workflow.js"
2+
3+
export default {
4+
defaultTheme: 'light',
5+
iconLinks: [{
6+
icon: 'github',
7+
href: 'https://github.com/bonsai-rx/python-scripting',
8+
title: 'GitHub'
9+
}],
10+
start: () => {
11+
WorkflowContainer.init();
12+
}
13+
}

0 commit comments

Comments
 (0)