Metadata-Version: 2.4
Name: moso
Version: 0.0.1
Author-email: Dien Hoa <dienhoa.t@gmail.com>
License: Apache-2.0
Project-URL: Repository, https://github.com/dienhoa/moso
Project-URL: Documentation, https://dienhoa.github.io/moso/
Keywords: nbdev
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: nbdev; extra == "dev"
Requires-Dist: twine>=6.2.0; extra == "dev"
Dynamic: license-file

# moso


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

`moso` provides a `%%moso` cell magic that lets you build up a Mojo
program across multiple notebook cells. All `%%moso` cells are
collected, compiled, and run together as a single Mojo script. The last
collected cell is wrapped in `def main() raises:`.

`moso` primarily supports SolveIt (from Answer.ai) because it allows the
tool to identify which cell is currently executing. In a standard
Jupyter Notebook environment, the magic simply collects all cells
containing `%%moso`.

## Install

``` sh
pip install -e .
```

## Usage

### SolveIt

``` python
from moso.core import *
setup_moso()
```

### Jupyter Notebook

``` python
from moso.core import *
setup_moso(nb_path='path/to/your/notebook.ipynb')
```

Then write Mojo code in `%%moso` cells:

``` python
%%moso
def add(a: Int, b: Int) -> Int:
    return a + b
```

``` python
%%moso
print(add(40, 2))
```

## Remote execution

Pass an SSH host and command template if Mojo runs on another machine:

``` python
setup_moso(host="user@host", cmd="cd ~/mojo-gpu-puzzles && /root/.pixi/bin/pixi run mojo run {path}")
```

## How it works

[`filter_moso`](https://dienhoa.github.io/moso/core.html#filter_moso)
strips the `%%moso` lines, concatenates previous cells, and wraps the
current cell in a `main()` (or the last cell in standard Jupyter
Notebook).
[`setup_moso`](https://dienhoa.github.io/moso/core.html#setup_moso)
registers the IPython cell magic and runs the generated source either
locally or over SSH.
