Metadata-Version: 2.4
Name: cellgraph
Version: 0.2.0
Summary: The cell graph of a notebook or script: annotations with a host-supplied vocabulary, analysis, the DAG, and the keys that say whether a cell must run.
Author: Fangchen Li
Author-email: Fangchen Li <fangchen.li@outlook.com>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/bearing-research/cellgraph
Project-URL: Repository, https://github.com/bearing-research/cellgraph
Project-URL: Changelog, https://github.com/bearing-research/cellgraph/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# cellgraph

The cell graph of a notebook or script. A cell is source with a leading
`# @key value` block; the set of annotations is the host's, composed from the
ten effects the package implements (binds, defines, reads, keeps, after, seeds,
member, fan-out, input, no-cache). `analyze` reads every cell's names and
annotations, applies their effects, wires the DAG, says which cells can be
planned and why the others cannot, and keys each cell: a definition key from its
normalized source and the annotations that change what it computes, and an
execution key from the outputs and external inputs the host looks up. The
package has no dependencies and runs nothing; the host executes, stores and
resolves. It was factored out of Strata's notebook, its first host, whose
formats it reproduces exactly under `legacy-1`.

```bash
pip install cellgraph
```

See [the API](https://github.com/bearing-research/cellgraph/blob/main/docs/api.md).

```python
import cellgraph as cg

vocab = cg.Vocabulary.core() | cg.Vocabulary(
    [
        cg.Annotation("gpu", parse=cg.scalar(str), in_key=False),
    ]
)
analysis = cg.analyze(
    [cg.Cell("a", "x = 1\n"), cg.Cell("b", "# @gpu A100\ny = x + 1\n")],
    vocab,
)
analysis.cells["b"].annotations["gpu"]  # 'A100'
analysis.dag.topological_order  # ['a', 'b']
```

## Development

```bash
uv sync
uv run pytest
uv run pre-commit run --all-files
```
