Skip to main content

Python runner for an interactive litex terminal session.

Project description

litexpy

Python runner for an interactive litex terminal session.

Links

Prerequisites

litexpy starts the local litex command in an interactive terminal session. It does not bundle the Litex executable, so install Litex first if litex is not already available in your terminal.

If you already have Litex

If litex -version works in your terminal, install only the Python package:

pip install litexpy

If you have not installed Litex

Install Litex first locally on your machine, then install litexpy.

Setup guide: https://litexlang.com/doc/Setup

Usage

Use a runner as a context manager so the underlying Litex process is closed automatically:

import litexpy

with litexpy.Runner() as runner:
    results = runner.run("1 = 1")

    print(results[0]["result"])
    print(results[0]["stmt"])

Runner() starts litex from your PATH by default. To use another command, pass an argument list:

runner = litexpy.Runner(command=["cargo", "run", "--quiet", "--"])

For local Litex development, set a default command so plain Runner() uses the checkout you choose:

export LITEXPY_LITEX_COMMAND='cargo run --quiet --manifest-path /path/to/golitex/Cargo.toml --'

If you already built a local binary, point directly at it:

export LITEXPY_LITEX_BIN=/path/to/golitex/target/debug/litex

An explicit Runner(command=...) always wins over these environment variables.

Run multiple lines or block-style Litex code in the same session:

with litexpy.Runner() as runner:
    results = runner.run("1 = 1\n0 = 0")

    block_results = runner.run(
        """forall x R:
    x = 2
    =>:
        x + 1 = 3
        x^2 = 4"""
    )

Facts accepted by run() stay in the interactive session until you call clear():

with litexpy.Runner() as runner:
    runner.run("have a R = 1")
    runner.run("a = 1")
    runner.clear()

Use sandbox_run() for candidate code that should see the current successful context but should not modify the main session:

with litexpy.Runner() as runner:
    runner.run("have a R = 1")
    trial = runner.sandbox_run("have b R = 2\na = 1")
    still_isolated = runner.run("b = 2")  # returns an error result

Pass commit=True to preflight in a sandbox first, then run the same code in the main session only if the sandbox succeeds:

with litexpy.Runner() as runner:
    committed = runner.sandbox_run("have b R = 2", commit=True)
    now_available = runner.run("b = 2")

commit=True is a preflight-then-run workflow in Python. It is not a single kernel-level transaction, so avoid relying on it for code that reads external files that may change between the preflight and the commit run.

If you do not use a with block, call runner.quit() or runner.close() when you are done. A live Runner owns a live Litex process; relying on Python garbage collection or interpreter shutdown is not the supported lifecycle.

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

litexpy-0.0.9.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

litexpy-0.0.9-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file litexpy-0.0.9.tar.gz.

File metadata

  • Download URL: litexpy-0.0.9.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for litexpy-0.0.9.tar.gz
Algorithm Hash digest
SHA256 248a07ede0d8c482a93bc52876316cb7b8c58f94a317d3be98ef3b3ca3cf8854
MD5 ee0c96480340c47ec9056b70a07d2d48
BLAKE2b-256 59ad28ed90c0d220eff17e4bc14bb5c8b85b557b8897886f918c897402571b56

See more details on using hashes here.

File details

Details for the file litexpy-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: litexpy-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for litexpy-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a10b10bccd927dfd16b6cc1fac3ca8b7df6bd63d4a5b6c2e117f3be35d915d81
MD5 5ba4a3e462d439d2ddd856716c5c0ad1
BLAKE2b-256 adbac749d6fd6b925740f57a8b094a484c1463c5848099c6c7232529a2a7fabc

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