MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / open_project

Method open_project

unity_cli/hub/service.py:21–79  ·  view source on GitHub ↗

Open a Unity project with the appropriate editor. Flow: 1. Validate project path 2. Read ProjectVersion.txt to get required version 3. Find matching installed editor 4. If not found, prompt user (or fail in non-interactive mode) 5. Launch editor

(
        self,
        project_path: Path,
        editor_override: str | None = None,
        non_interactive: bool = False,
        wait: bool = False,
    )

Source from the content-addressed store, hash-verified

19 """High-level service for Unity Hub operations."""
20
21 def open_project(
22 self,
23 project_path: Path,
24 editor_override: str | None = None,
25 non_interactive: bool = False,
26 wait: bool = False,
27 ) -> bool:
28 """Open a Unity project with the appropriate editor.
29
30 Flow:
31 1. Validate project path
32 2. Read ProjectVersion.txt to get required version
33 3. Find matching installed editor
34 4. If not found, prompt user (or fail in non-interactive mode)
35 5. Launch editor
36
37 Args:
38 project_path: Path to Unity project.
39 editor_override: Override editor version (skip version detection).
40 non_interactive: If True, fail instead of prompting.
41 wait: If True, wait for editor to close.
42
43 Returns:
44 True if editor was launched successfully.
45
46 Raises:
47 ProjectError: If project path is invalid.
48 EditorNotFoundError: If required editor not installed and can't resolve.
49 """
50 project_path = project_path.resolve()
51
52 if not is_unity_project(project_path):
53 raise ProjectError(
54 f"Not a valid Unity project: {project_path}",
55 code="INVALID_PROJECT",
56 )
57
58 # Determine required version
59 if editor_override:
60 required_version = editor_override
61 else:
62 project_version = ProjectVersion.from_file(project_path)
63 required_version = project_version.version
64
65 # Resolve editor
66 editor = self.resolve_editor(
67 required_version=required_version,
68 non_interactive=non_interactive,
69 )
70
71 if editor is None:
72 raise EditorNotFoundError(
73 f"Unity {required_version} is not installed and no alternative selected",
74 code="EDITOR_NOT_RESOLVED",
75 )
76
77 # Launch
78 launch_editor(editor.path, project_path, wait=wait)

Callers 1

open_projectFunction · 0.95

Calls 6

resolve_editorMethod · 0.95
is_unity_projectFunction · 0.90
ProjectErrorClass · 0.90
EditorNotFoundErrorClass · 0.90
launch_editorFunction · 0.90
from_fileMethod · 0.45

Tested by

no test coverage detected