litexpy 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
litexpy/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """Python runner for an interactive litex terminal session."""
2
+
3
+ from .runner import Runner, runner
4
+
5
+ __version__ = "0.0.2"
6
+
7
+ __all__ = ["Runner", "runner", "__version__"]
litexpy/runner.py ADDED
@@ -0,0 +1,59 @@
1
+ """Runner for interactive litex sessions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import subprocess
6
+ from collections.abc import Sequence
7
+
8
+
9
+ class Runner:
10
+ """Run commands inside an interactive ``litex`` process."""
11
+
12
+ def __init__(self, command: str | Sequence[str] = "litex") -> None:
13
+ if isinstance(command, str):
14
+ args = [command]
15
+ else:
16
+ args = list(command)
17
+
18
+ self._process = subprocess.Popen(
19
+ args,
20
+ stdin=subprocess.PIPE,
21
+ text=True,
22
+ )
23
+
24
+ def run(self, script: str) -> None:
25
+ """Send a script line to the running litex process."""
26
+ if self._process.poll() is not None:
27
+ raise RuntimeError("litex process is not running")
28
+ if self._process.stdin is None:
29
+ raise RuntimeError("litex process stdin is not available")
30
+
31
+ self._process.stdin.write(f"{script}\n")
32
+ self._process.stdin.flush()
33
+
34
+ def clear(self) -> None:
35
+ """Clear the litex terminal session."""
36
+ self.run("clear")
37
+
38
+ def quit(self) -> None:
39
+ """Stop the running litex process."""
40
+ if self._process.poll() is not None:
41
+ return
42
+
43
+ if self._process.stdin is not None:
44
+ self._process.stdin.close()
45
+
46
+ try:
47
+ self._process.wait(timeout=2)
48
+ except subprocess.TimeoutExpired:
49
+ self._process.terminate()
50
+ try:
51
+ self._process.wait(timeout=2)
52
+ except subprocess.TimeoutExpired:
53
+ self._process.kill()
54
+ self._process.wait()
55
+
56
+
57
+ def runner() -> Runner:
58
+ """Create a litex runner."""
59
+ return Runner()
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: litexpy
3
+ Version: 0.0.2
4
+ Summary: Python runner for an interactive litex terminal session.
5
+ Project-URL: Homepage, https://github.com/litexlang/litexpy
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+
11
+ # litexpy
12
+
13
+ Python runner for an interactive `litex` terminal session.
14
+
15
+ ## Usage
16
+
17
+ ```python
18
+ import litexpy
19
+
20
+ runner = litexpy.Runner()
21
+
22
+ runner.run("1 = 1")
23
+ runner.clear()
24
+ runner.quit()
25
+ ```
26
+
27
+ `litexpy.Runner()` starts the `litex` command in an interactive terminal
28
+ process. `run(script)` sends one script line to that process, `clear()` is
29
+ equivalent to `run("clear")`, and `quit()` closes the running `litex` process.
@@ -0,0 +1,6 @@
1
+ litexpy/__init__.py,sha256=zQjvMKSNtW86kmeTxKOm2_JPxEDfErgLzqmuEwwyWBc,169
2
+ litexpy/runner.py,sha256=-R3Ji14eqLuqv60PaKP9frKi6r_9BwuFekFOtNhGXHc,1667
3
+ litexpy-0.0.2.dist-info/METADATA,sha256=hYBW11oTjFNs3IwM6_u9MonEG_vdI3y8Cu310EWrU6I,760
4
+ litexpy-0.0.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ litexpy-0.0.2.dist-info/top_level.txt,sha256=gWGdARZ13Ry-1Py1zS_rx0iK1MErQmdNeMNq59agvU4,8
6
+ litexpy-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ litexpy