mrmd-python 0.1.0__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.
- mrmd_python/__init__.py +16 -0
- mrmd_python/cli.py +119 -0
- mrmd_python/server.py +609 -0
- mrmd_python/types.py +245 -0
- mrmd_python/worker.py +1525 -0
- mrmd_python-0.1.0.dist-info/METADATA +77 -0
- mrmd_python-0.1.0.dist-info/RECORD +9 -0
- mrmd_python-0.1.0.dist-info/WHEEL +4 -0
- mrmd_python-0.1.0.dist-info/entry_points.txt +2 -0
mrmd_python/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mrmd-python: Python runtime server implementing the MRMD Runtime Protocol (MRP)
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
mrmd-python [--host HOST] [--port PORT] [--cwd DIR]
|
|
6
|
+
|
|
7
|
+
Or programmatically:
|
|
8
|
+
from mrmd_python import create_app
|
|
9
|
+
app = create_app()
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .server import create_app, MRPServer
|
|
13
|
+
from .worker import IPythonWorker
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
__all__ = ["create_app", "MRPServer", "IPythonWorker", "__version__"]
|
mrmd_python/cli.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mrmd-python CLI
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
mrmd-python [--host HOST] [--port PORT] [--cwd DIR] [--assets-dir DIR]
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
description="Python runtime server implementing the MRMD Runtime Protocol (MRP)"
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"--host",
|
|
18
|
+
default="localhost",
|
|
19
|
+
help="Host to bind to (default: localhost)",
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--port",
|
|
23
|
+
type=int,
|
|
24
|
+
default=8000,
|
|
25
|
+
help="Port to bind to (default: 8000)",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--cwd",
|
|
29
|
+
default=None,
|
|
30
|
+
help="Working directory (default: current directory)",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--assets-dir",
|
|
34
|
+
default=None,
|
|
35
|
+
help="Directory for saving assets (default: .mrmd-assets in cwd)",
|
|
36
|
+
)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--reload",
|
|
39
|
+
action="store_true",
|
|
40
|
+
help="Enable auto-reload for development",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--venv",
|
|
44
|
+
default=None,
|
|
45
|
+
help="Path to virtual environment to use for code execution",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
args = parser.parse_args()
|
|
49
|
+
|
|
50
|
+
# Import here to avoid slow startup for --help
|
|
51
|
+
import uvicorn
|
|
52
|
+
from .server import create_app
|
|
53
|
+
|
|
54
|
+
cwd = args.cwd or os.getcwd()
|
|
55
|
+
assets_dir = args.assets_dir or os.path.join(cwd, ".mrmd-assets")
|
|
56
|
+
venv = args.venv
|
|
57
|
+
|
|
58
|
+
venv_display = venv[:43] if venv else "System Python"
|
|
59
|
+
print(
|
|
60
|
+
f"""
|
|
61
|
+
╔═══════════════════════════════════════════════════════════════╗
|
|
62
|
+
║ mrmd-python MRP Server ║
|
|
63
|
+
╠═══════════════════════════════════════════════════════════════╣
|
|
64
|
+
║ Running on: http://{args.host}:{args.port}/mrp/v1{' ' * (26 - len(args.host) - len(str(args.port)))}║
|
|
65
|
+
║ ║
|
|
66
|
+
║ Endpoints: ║
|
|
67
|
+
║ GET /mrp/v1/capabilities ║
|
|
68
|
+
║ GET /mrp/v1/sessions ║
|
|
69
|
+
║ POST /mrp/v1/execute ║
|
|
70
|
+
║ POST /mrp/v1/execute/stream ║
|
|
71
|
+
║ POST /mrp/v1/complete ║
|
|
72
|
+
║ POST /mrp/v1/inspect ║
|
|
73
|
+
║ POST /mrp/v1/hover ║
|
|
74
|
+
║ POST /mrp/v1/variables ║
|
|
75
|
+
║ ║
|
|
76
|
+
║ Working directory: {cwd[:43]:<43}║
|
|
77
|
+
║ Assets directory: {assets_dir[:43]:<43}║
|
|
78
|
+
║ Virtual env: {venv_display:<43}║
|
|
79
|
+
║ ║
|
|
80
|
+
║ Press Ctrl+C to stop ║
|
|
81
|
+
╚═══════════════════════════════════════════════════════════════╝
|
|
82
|
+
"""
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Create app factory for uvicorn
|
|
86
|
+
def app_factory():
|
|
87
|
+
return create_app(cwd=cwd, assets_dir=assets_dir, venv=venv)
|
|
88
|
+
|
|
89
|
+
if args.reload:
|
|
90
|
+
global _cwd, _assets_dir, _venv
|
|
91
|
+
_cwd = cwd
|
|
92
|
+
_assets_dir = assets_dir
|
|
93
|
+
_venv = venv
|
|
94
|
+
uvicorn.run(
|
|
95
|
+
"mrmd_python.cli:_create_app_for_reload",
|
|
96
|
+
host=args.host,
|
|
97
|
+
port=args.port,
|
|
98
|
+
reload=True,
|
|
99
|
+
access_log=False, # Disable access log to prevent it leaking into execution output
|
|
100
|
+
)
|
|
101
|
+
else:
|
|
102
|
+
app = create_app(cwd=cwd, assets_dir=assets_dir, venv=venv)
|
|
103
|
+
uvicorn.run(app, host=args.host, port=args.port, access_log=False)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# For reload mode
|
|
107
|
+
_cwd = None
|
|
108
|
+
_assets_dir = None
|
|
109
|
+
_venv = None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _create_app_for_reload():
|
|
113
|
+
from .server import create_app
|
|
114
|
+
|
|
115
|
+
return create_app(cwd=_cwd, assets_dir=_assets_dir, venv=_venv)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|