jac-client 0.2.9__py3-none-any.whl → 0.2.10__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.
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Jac Sidecar Entry Point
4
+
5
+ This is the entry point for the Jac backend sidecar.
6
+ It launches the Jac runtime and starts an HTTP API server.
7
+
8
+ Usage:
9
+ python -m jac_client.plugin.src.targets.desktop.sidecar.main [OPTIONS]
10
+ # Or via wrapper script: ./jac-sidecar.sh [OPTIONS]
11
+
12
+ Options:
13
+ --module-path PATH Path to the .jac module file (default: main.jac)
14
+ --port PORT Port to bind the API server (default: 8000)
15
+ --base-path PATH Base path for the project (default: current directory)
16
+ --host HOST Host to bind to (default: 127.0.0.1)
17
+ --help Show this help message
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import argparse
23
+ import sys
24
+ from pathlib import Path
25
+
26
+ from jaclang.cli.console import console
27
+
28
+
29
+ def main():
30
+ """Main entry point for the sidecar."""
31
+ parser = argparse.ArgumentParser(
32
+ description="Jac Backend Sidecar - Runs Jac API server in a bundled executable"
33
+ )
34
+ parser.add_argument(
35
+ "--module-path",
36
+ type=str,
37
+ default="main.jac",
38
+ help="Path to the .jac module file (default: main.jac)",
39
+ )
40
+ parser.add_argument(
41
+ "--port",
42
+ type=int,
43
+ default=8000,
44
+ help="Port to bind the API server (default: 8000)",
45
+ )
46
+ parser.add_argument(
47
+ "--base-path",
48
+ type=str,
49
+ default=None,
50
+ help="Base path for the project (default: current directory)",
51
+ )
52
+ parser.add_argument(
53
+ "--host",
54
+ type=str,
55
+ default="127.0.0.1",
56
+ help="Host to bind to (default: 127.0.0.1)",
57
+ )
58
+
59
+ args = parser.parse_args()
60
+
61
+ # Determine base path
62
+ if args.base_path:
63
+ base_path = Path(args.base_path).resolve()
64
+ else:
65
+ # Try to find project root (look for jac.toml)
66
+ base_path = Path.cwd()
67
+ for parent in [base_path] + list(base_path.parents):
68
+ if (parent / "jac.toml").exists():
69
+ base_path = parent
70
+ break
71
+
72
+ # Resolve module path
73
+ module_path = Path(args.module_path)
74
+ if not module_path.is_absolute():
75
+ module_path = base_path / module_path
76
+
77
+ if not module_path.exists():
78
+ console.print(f"Error: Module file not found: {module_path}", file=sys.stderr)
79
+ console.print(f" Base path: {base_path}", file=sys.stderr)
80
+ sys.exit(1)
81
+
82
+ # Extract module name (without .jac extension)
83
+ module_name = module_path.stem
84
+ module_base = module_path.parent
85
+
86
+ # Import Jac runtime and server
87
+ try:
88
+ # Import jaclang (must be installed via pip)
89
+ from jaclang.pycore.runtime import JacRuntime as Jac
90
+ except ImportError as e:
91
+ console.print(f"Error: Failed to import Jac runtime: {e}", file=sys.stderr)
92
+ console.print(
93
+ " Make sure jaclang is installed: pip install jaclang", file=sys.stderr
94
+ )
95
+ sys.exit(1)
96
+
97
+ # Initialize Jac runtime
98
+ try:
99
+ # Import the module
100
+ Jac.jac_import(target=module_name, base_path=str(module_base), lng="jac")
101
+ if Jac.program.errors_had:
102
+ console.print("Error: Failed to compile module:", file=sys.stderr)
103
+ for error in Jac.program.errors_had:
104
+ console.print(f" {error}", file=sys.stderr)
105
+ sys.exit(1)
106
+ except Exception as e:
107
+ console.print(
108
+ f"Error: Failed to load module '{module_name}': {e}", file=sys.stderr
109
+ )
110
+ import traceback
111
+
112
+ traceback.print_exc()
113
+ sys.exit(1)
114
+
115
+ # Create and start the API server
116
+ try:
117
+ # Get server class (allows plugins like jac-scale to provide enhanced server)
118
+ server_class = Jac.get_api_server_class()
119
+ server = server_class(
120
+ module_name=module_name, port=args.port, base_path=str(base_path)
121
+ )
122
+
123
+ console.print("Jac Sidecar starting...")
124
+ console.print(f" Module: {module_name}")
125
+ console.print(f" Base path: {base_path}")
126
+ console.print(f" Server: http://{args.host}:{args.port}")
127
+ console.print("\nPress Ctrl+C to stop the server\n")
128
+
129
+ # Start the server (blocks until interrupted)
130
+ server.start(dev=False)
131
+
132
+ except KeyboardInterrupt:
133
+ console.print("\nShutting down sidecar...")
134
+ sys.exit(0)
135
+ except Exception as e:
136
+ console.print(f"Error: Server failed to start: {e}", file=sys.stderr)
137
+ import traceback
138
+
139
+ traceback.print_exc()
140
+ sys.exit(1)
141
+
142
+
143
+ if __name__ == "__main__":
144
+ main()
@@ -0,0 +1,37 @@
1
+ """Desktop target implementation.
2
+
3
+ This target will be implemented in Phase 2.
4
+ """
5
+ import from pathlib { Path }
6
+ import from typing { Optional }
7
+ import from jac_client.plugin.src.targets.registry { ClientTarget }
8
+
9
+ """Desktop build target (placeholder for Phase 2)."""
10
+ class DesktopTarget(ClientTarget) {
11
+ def init(self: DesktopTarget) {
12
+ self.name = "desktop";
13
+ self.default = False;
14
+ self.requires_setup = True;
15
+ self.config_section = "desktop";
16
+ self.output_dir = Path("src-tauri/target/release/bundle");
17
+ }
18
+
19
+ """Setup desktop target - scaffold Tauri project structure."""
20
+ override def setup(self: DesktopTarget, project_dir: Path) -> None;
21
+
22
+ """Build desktop app - build web bundle first, then wrap with Tauri."""
23
+ override def build(
24
+ self: DesktopTarget,
25
+ entry_file: Path,
26
+ project_dir: Path,
27
+ platform: Optional[str] = None
28
+ ) -> Path;
29
+
30
+ """Start desktop dev server - start web dev server and launch tauri dev."""
31
+ override def dev(self: DesktopTarget, entry_file: Path, project_dir: Path) -> None;
32
+
33
+ """Start desktop app - build web bundle and launch Tauri with built bundle."""
34
+ override def start(
35
+ self: DesktopTarget, entry_file: Path, project_dir: Path
36
+ ) -> None;
37
+ }