Metadata-Version: 2.5
Name: nkparser
Version: 0.4.0
Summary: Parse, query, and serialize Foundry Nuke .nk script files
Author-email: Virgil Sisoe <28490646+sisoe24@users.noreply.github.com>
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Provides-Extra: graphviz
Requires-Dist: graphviz>=0.20; extra == 'graphviz'
Description-Content-Type: text/markdown

# nkparser

`nkparser` parses, queries, validates, and round-trips Foundry Nuke `.nk` script files.

## Install

This project is managed with `uv`.

```bash
uv sync
```

Install the package into the current environment:

```bash
uv pip install .
```

Install with Graphviz rendering support:

```bash
uv pip install '.[graphviz]'
```

## CLI

The package exposes the `nkparser` console script:

```bash
uv run nkparser --help
```

You can also run it as a module:

```bash
uv run python -m nkparser --help
```

### Examples

```bash
uv run nkparser info tests/fixtures/minimal.nk
uv run nkparser validate tests/fixtures/malformed_unclosed.nk
uv run nkparser tree tests/fixtures/complex_groups.nk --knobs
uv run nkparser tree tests/fixtures/complex_groups.nk --knobs --format json
uv run nkparser show tests/fixtures/minimal.nk --format json
uv run nkparser nodes tests/fixtures/minimal.nk --class Grade
uv run nkparser dot tests/fixtures/minimal.nk -o graph.dot
uv run nkparser dot tests/fixtures/minimal.nk -o graph.dot --render --dot-command /opt/homebrew/bin/dot
uv run nkparser diff v012.nk v013.nk --ignore xpos,ypos,selected
```

`nkparser diff` prints one line per change and exits 0 when the scripts match, 1 when they differ:

```text
- Merge1 (Merge2)
+ Blur2 (Blur)
~ Grade1 (Grade) white: 1.2 -> 1.4
~ Merge1 (Merge2) inputs: ['Grade1', 'Read1'] -> ['Grade1', None]
```

Add `--format json` to get the raw dict from `diff_scripts`.

## Use with git

`nkparser git-diff` is a git external diff driver: `git diff` then shows node changes for `.nk` files instead of raw text.

Add to `.gitattributes` in the repository:

```text
*.nk diff=nk
```

Register the driver (once per repository, or add `--global`):

```bash
git config diff.nk.command "nkparser git-diff --ignore xpos,ypos,selected"
```

`nkparser` must be on `PATH` for git. Drop `--ignore` to also see node moves. To see the raw text diff for one command, run `git diff --no-ext-diff`.

The driver always exits 0, because git stops the whole diff when an external driver exits non-zero. Added and deleted files show every node as `+` or `-`.

## Development

Sync the dev environment:

```bash
uv sync --dev
```

Run checks:

```bash
uv run pytest
uv run ruff check .
uv run mypy
```

Build distributions:

```bash
uv build
```

## Python API

```python
import nkparser

script = nkparser.Script.from_file("comp.nk")

print(script.nuke_version)
print(len(list(script.all_nodes())))

reads = script.query().of_class("Read").all()
grade = script.find("Grade1")

if grade:
    grade.set("disable", "true")

script.write("comp_modified.nk")
```
