|
5 | 5 | import os |
6 | 6 | import shutil |
7 | 7 | import uuid |
8 | | -from pathlib import Path |
9 | 8 | from typing import Any, Dict, Optional |
10 | 9 |
|
11 | 10 | import click |
12 | 11 |
|
13 | 12 | from .._utils.constants import ENV_TELEMETRY_ENABLED |
14 | 13 | from ..telemetry import track |
15 | 14 | from ..telemetry._constants import _PROJECT_KEY, _TELEMETRY_CONFIG_FILE |
| 15 | +from ._runtime._runtime import get_user_script |
| 16 | +from ._runtime._runtime_factory import generate_runtime_factory |
16 | 17 | from ._utils._console import ConsoleLogger |
17 | | -from ._utils._input_args import generate_args |
18 | | -from ._utils._parse_ast import generate_bindings |
19 | 18 | from .middlewares import Middlewares |
20 | | -from .models.runtime_schema import Bindings, Entrypoint, RuntimeSchema |
| 19 | +from .models.runtime_schema import Bindings, RuntimeSchema |
21 | 20 |
|
22 | 21 | console = ConsoleLogger() |
23 | 22 | logger = logging.getLogger(__name__) |
@@ -126,33 +125,6 @@ def get_existing_settings(config_path: str) -> Optional[Dict[str, Any]]: |
126 | 125 | return None |
127 | 126 |
|
128 | 127 |
|
129 | | -def get_user_script(directory: str, entrypoint: Optional[str] = None) -> Optional[str]: |
130 | | - """Find the Python script to process.""" |
131 | | - if entrypoint: |
132 | | - script_path = os.path.join(directory, entrypoint) |
133 | | - if not os.path.isfile(script_path): |
134 | | - console.error( |
135 | | - f"The {entrypoint} file does not exist in the current directory." |
136 | | - ) |
137 | | - return None |
138 | | - return script_path |
139 | | - |
140 | | - python_files = [f for f in os.listdir(directory) if f.endswith(".py")] |
141 | | - |
142 | | - if not python_files: |
143 | | - console.error( |
144 | | - "No python files found in the current directory.\nPlease specify the entrypoint: `uipath init <entrypoint_path>`" |
145 | | - ) |
146 | | - return None |
147 | | - elif len(python_files) == 1: |
148 | | - return os.path.join(directory, python_files[0]) |
149 | | - else: |
150 | | - console.error( |
151 | | - "Multiple python files found in the current directory.\nPlease specify the entrypoint: `uipath init <entrypoint_path>`" |
152 | | - ) |
153 | | - return None |
154 | | - |
155 | | - |
156 | 128 | def write_config_file(config_data: Dict[str, Any] | RuntimeSchema) -> None: |
157 | 129 | existing_settings = get_existing_settings(CONFIG_PATH) |
158 | 130 | if existing_settings is not None: |
@@ -205,39 +177,28 @@ def init(entrypoint: str, infer_bindings: bool) -> None: |
205 | 177 |
|
206 | 178 | generate_agent_md_files(current_directory) |
207 | 179 | script_path = get_user_script(current_directory, entrypoint=entrypoint) |
208 | | - |
209 | 180 | if not script_path: |
210 | 181 | return |
211 | 182 |
|
212 | | - try: |
213 | | - args = generate_args(script_path) |
214 | | - |
215 | | - relative_path = Path(script_path).relative_to(current_directory).as_posix() |
216 | | - bindings = None |
217 | | - if infer_bindings: |
218 | | - try: |
219 | | - bindings = generate_bindings(script_path) |
220 | | - except Exception as e: |
221 | | - console.warning(f"Warning: Could not generate bindings: {str(e)}") |
222 | | - if bindings is None: |
| 183 | + context_args = { |
| 184 | + "runtime_dir": os.getcwd(), |
| 185 | + "entrypoint": script_path, |
| 186 | + } |
| 187 | + |
| 188 | + def initialize() -> None: |
| 189 | + try: |
| 190 | + runtime = generate_runtime_factory().new_runtime(**context_args) |
223 | 191 | bindings = Bindings( |
224 | 192 | version="2.0", |
225 | | - resources=[], |
| 193 | + resources=runtime.get_binding_resources, |
226 | 194 | ) |
227 | | - config_data = RuntimeSchema( |
228 | | - entrypoints=[ |
229 | | - Entrypoint( |
230 | | - file_path=relative_path, |
231 | | - unique_id=str(uuid.uuid4()), |
232 | | - type="agent", |
233 | | - input=args["input"], |
234 | | - output=args["output"], |
235 | | - ) |
236 | | - ], |
237 | | - bindings=bindings, |
238 | | - ) |
| 195 | + config_data = RuntimeSchema( |
| 196 | + entryPoints=[runtime.get_entrypoint], |
| 197 | + bindings=bindings, |
| 198 | + ) |
| 199 | + config_path = write_config_file(config_data) |
| 200 | + console.success(f"Created '{config_path}' file.") |
| 201 | + except Exception as e: |
| 202 | + console.error(f"Error creating configuration file:\n {str(e)}") |
239 | 203 |
|
240 | | - config_path = write_config_file(config_data) |
241 | | - console.success(f"Created '{config_path}' file.") |
242 | | - except Exception as e: |
243 | | - console.error(f"Error creating configuration file:\n {str(e)}") |
| 204 | + initialize() |
0 commit comments