Skip to main content

Pure Python port of Meta Yoga layout engine

Project description

yoga-layout-python

yoga-layout-python is a pure Python port of Meta's Yoga layout engine.

Current Status

  • Public enums, value/config primitives, and the core layout algorithm are implemented in Python.
  • Internal module layout mirrors upstream yoga/ so translation and parity work can stay file-for-file aligned.
  • Upstream test translations pass, and a Python-vs-C++ differential parity harness is available under tools/.

Installation

pip install -e .

For development:

pip install -e ".[dev]"

API Shape

The Python package keeps Yoga's public naming style:

from yoga import *

config = YGConfigNew()
node = YGNodeNewWithConfig(config)
YGNodeStyleSetWidth(node, 100)
YGNodeStyleSetHeight(node, 50)
YGNodeCalculateLayout(node, YGUndefined, YGUndefined, YGDirectionLTR)

width = YGNodeLayoutGetWidth(node)
height = YGNodeLayoutGetHeight(node)

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=yoga --cov-report=term-missing

# Run specific test file
pytest tests/test_smoke.py -v

Differential Parity

The repository includes a differential parity runner that compares Python layout results against the vendored upstream C++ Yoga engine on the same captured tree.

# Run the default parity suite
python tools/run_differential_ci.py

# Rebuild the C++ runner first
python tools/run_differential_ci.py --force-rebuild

# Increase the random batch size
python tools/run_differential_ci.py --random-count 1000 --seed 20260317

On failure, the script writes a repro capture to build/differential_failure_capture.json.

The lower-level harness remains available if you want the raw output format:

python tools/differential_test.py

Project Structure

src/yoga/
├── algorithm/        # Core layout algorithms (CalculateLayout, FlexLine, etc.)
├── config/           # Configuration handling
├── debug/            # Debug utilities (logging, assertions)
├── event/            # Event system
├── node/             # Node class and layout results
├── numeric/          # Numeric utilities (FloatOptional, Comparison)
├── style/            # Style system (Style, StyleLength, etc.)
└── *.py              # Public API modules

tools/
├── differential_cpp_runner.cpp  # C++ capture runner used for parity checks
├── differential_test.py         # Python/C++ differential harness
└── run_differential_ci.py       # Stable CLI entrypoint for parity checks

License

This project uses the same MIT license as upstream Yoga. See LICENSE.

Contributing

Contributions are welcome! Please see the upstream Yoga repository for reference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yoga_layout_python-0.1.0.tar.gz (75.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yoga_layout_python-0.1.0-py3-none-any.whl (64.8 kB view details)

Uploaded Python 3

File details

Details for the file yoga_layout_python-0.1.0.tar.gz.

File metadata

  • Download URL: yoga_layout_python-0.1.0.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yoga_layout_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdf9573d2833d17617a79b9f17a597894d9090c41165ff862e93490caa1b55de
MD5 4bdaafd050b463d88b1ea7ffb64e19d1
BLAKE2b-256 0a41561b120ccff16ed116156e1170f07123a99854a16f87fc96d31c7b1db29f

See more details on using hashes here.

File details

Details for the file yoga_layout_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yoga_layout_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f40ecba839f4ab78e9a6c12ac93a91c4612e7a7db6feec8e3008ef6872cd78be
MD5 a793e7b90f9dce030caf24131e1ce2e3
BLAKE2b-256 384317bf72474290b1db8ea8c4cbc5e9d69120a19f5c2574897cabe3f45931d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page