|
4 | 4 |
|
5 | 5 | def main():
|
6 | 6 | """
|
7 |
| - Command-line interface for **Brian2Wasm**. |
8 |
| -
|
9 |
| - Usage |
10 |
| - ----- |
11 |
| - ``python -m brian2wasm <script.py> [--no-server]`` |
| 7 | + Run a Brian2Wasm simulation from the command line. |
12 | 8 |
|
13 | 9 | Parameters
|
14 | 10 | ----------
|
15 | 11 | script : str
|
16 |
| - Path to the user’s Python model. The file **must** end with |
17 |
| - ``.py`` and must not call ``set_device`` itself – the CLI inserts |
18 |
| - the appropriate ``set_device('wasm_standalone', …)`` line |
19 |
| - automatically. |
20 |
| - --no-server : flag, optional |
21 |
| - Generate the WASM/HTML output without starting the local preview |
22 |
| - web-server (sets the ``BRIAN2WASM_NO_SERVER`` environment |
23 |
| - variable for the subprocess). |
| 12 | + Path to the Python model file. Must end with ``.py`` and must not call |
| 13 | + ``set_device`` directly, as the CLI automatically inserts the required |
| 14 | + ``set_device('wasm_standalone', …)`` line. |
| 15 | + no_server : bool, optional |
| 16 | + If True, generate the WASM/HTML output without starting the local |
| 17 | + preview server (sets the ``BRIAN2WASM_NO_SERVER`` environment variable). |
24 | 18 |
|
25 |
| - Behaviour |
26 |
| - --------- |
27 |
| - 1. Validates that *script* exists and is a ``.py`` file. |
28 |
| - 2. Looks for an ``<scriptname>.html`` file in the same directory. |
29 |
| - * If found, passes the HTML file to ``set_device`` so the custom |
30 |
| - template is used. |
31 |
| - * Otherwise falls back to the default template. |
32 |
| - 3. Prepends the required ``set_device('wasm_standalone', …)`` call to |
33 |
| - the script source in-memory. |
34 |
| - 4. Executes the modified script with its own directory as working |
35 |
| - directory, so any relative paths inside the model behave as |
36 |
| - expected. |
| 19 | + Raises |
| 20 | + ------ |
| 21 | + FileNotFoundError |
| 22 | + If the given script does not exist. |
| 23 | + ValueError |
| 24 | + If the provided file is not a ``.py`` script. |
| 25 | + RuntimeError |
| 26 | + If execution of the model fails for any reason. |
37 | 27 |
|
38 |
| - Exit status |
39 |
| - ----------- |
40 |
| - * ``0`` – build finished successfully (and server started unless |
41 |
| - *--no-server* was given). |
42 |
| - * ``1`` – any error (missing file, not a ``.py`` file, exception |
43 |
| - during model execution, etc.). |
44 |
| - """ |
| 28 | + Notes |
| 29 | + ----- |
| 30 | + This command is typically invoked as:: |
| 31 | +
|
| 32 | + python -m brian2wasm <script.py> [--no-server] |
| 33 | + """ |
45 | 34 |
|
46 | 35 | parser = argparse.ArgumentParser(
|
47 | 36 | description="Brian2WASM CLI"
|
|
0 commit comments