dynra 0.1.1__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.
- dynra/__init__.py +6 -0
- dynra/__main__.py +5 -0
- dynra/client.py +69 -0
- dynra/core.py +1334 -0
- dynra/mcp.py +123 -0
- dynra/project.py +166 -0
- dynra/runtime.py +191 -0
- dynra-0.1.1.dist-info/METADATA +294 -0
- dynra-0.1.1.dist-info/RECORD +13 -0
- dynra-0.1.1.dist-info/WHEEL +5 -0
- dynra-0.1.1.dist-info/entry_points.txt +4 -0
- dynra-0.1.1.dist-info/licenses/LICENSE +201 -0
- dynra-0.1.1.dist-info/top_level.txt +1 -0
dynra/__init__.py
ADDED
dynra/__main__.py
ADDED
dynra/client.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import socket
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def send_code(code, host="127.0.0.1", port=9999, module=None, create=False):
|
|
9
|
+
if module is not None:
|
|
10
|
+
header = json.dumps(
|
|
11
|
+
{"module": module, "create": create}, separators=(",", ":")
|
|
12
|
+
)
|
|
13
|
+
code = f"DYNRA {header}\n{code}"
|
|
14
|
+
try:
|
|
15
|
+
with socket.create_connection((host, port)) as connection:
|
|
16
|
+
connection.sendall(code.encode("utf-8"))
|
|
17
|
+
connection.shutdown(socket.SHUT_WR)
|
|
18
|
+
response_data = bytearray()
|
|
19
|
+
while chunk := connection.recv(4096):
|
|
20
|
+
response_data.extend(chunk)
|
|
21
|
+
except ConnectionRefusedError:
|
|
22
|
+
print(
|
|
23
|
+
f"Error: Could not connect to Dynra at {host}:{port}.",
|
|
24
|
+
file=sys.stderr,
|
|
25
|
+
)
|
|
26
|
+
return 1
|
|
27
|
+
except Exception as error:
|
|
28
|
+
print(f"Error: {error}", file=sys.stderr)
|
|
29
|
+
return 1
|
|
30
|
+
|
|
31
|
+
response = json.loads(response_data.decode("utf-8"))
|
|
32
|
+
if response["stdout"]:
|
|
33
|
+
print(response["stdout"], end="")
|
|
34
|
+
if response["stderr"]:
|
|
35
|
+
print(response["stderr"], file=sys.stderr, end="")
|
|
36
|
+
if response["result"] and response["result"] != "None":
|
|
37
|
+
print(f"Result: {response['result']}")
|
|
38
|
+
return 0 if response["success"] else 1
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main():
|
|
42
|
+
parser = argparse.ArgumentParser(description="Send code to a running Dynra REPL.")
|
|
43
|
+
parser.add_argument("code", nargs="?", help="Python code to execute")
|
|
44
|
+
parser.add_argument("-f", "--file", help="File containing Python code to execute")
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"-p", "--port", type=int, default=9999, help="Port Dynra is listening on"
|
|
47
|
+
)
|
|
48
|
+
parser.add_argument("-m", "--module", help="Existing module to enter atomically")
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"--create",
|
|
51
|
+
action="store_true",
|
|
52
|
+
help="Create --module as a synthetic REPL namespace",
|
|
53
|
+
)
|
|
54
|
+
args = parser.parse_args()
|
|
55
|
+
|
|
56
|
+
if args.create and not args.module:
|
|
57
|
+
parser.error("--create requires --module")
|
|
58
|
+
if args.file:
|
|
59
|
+
code = Path(args.file).read_text(encoding="utf-8")
|
|
60
|
+
elif args.code:
|
|
61
|
+
code = args.code
|
|
62
|
+
else:
|
|
63
|
+
parser.print_help()
|
|
64
|
+
return 1
|
|
65
|
+
return send_code(code, port=args.port, module=args.module, create=args.create)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
raise SystemExit(main())
|