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. To use another command, pass an argument list:

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

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.8.tar.gz (6.8 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.8-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: litexpy-0.0.8.tar.gz
  • Upload date:
  • Size: 6.8 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.8.tar.gz
Algorithm Hash digest
SHA256 62cb53a2d54c41a8844a7738ff87307a813752a24269d0108ad496730aacc083
MD5 f5fc47484c340e7524be9d3fe9dfd537
BLAKE2b-256 7c8236bd94a723c621a76aac47da73b69f917dec35de296e034671843837b4b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: litexpy-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f87166a742e80ed7d570da5dfb588e1d4c21b26aab07c389461f2034aefee5b9
MD5 eddf96e26bb66c8837b02f9678f83109
BLAKE2b-256 e05554b44accd65e71e21451b5f5c0cb5fe8be7b4f81d67b139f2131a1eb9cb1

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