mcp_source.py: remove duplicate mac-only script; keep cross-platform argparse version (auto-detect manifest/repo; supports interactive/non-interactive)

main
dsarno 2025-08-13 13:10:47 -07:00
parent cd707284d7
commit 5583327a03
1 changed files with 0 additions and 73 deletions

View File

@ -164,78 +164,5 @@ def main() -> None:
print("Tip: In Unity, open Package Manager and Refresh to re-resolve packages.")
if __name__ == "__main__":
main()
#!/usr/bin/env python3
import json
import os
import sys
import subprocess
# Defaults for your environment
UNITY_PROJECT = "/Users/davidsarno/ramble" # change if needed
MANIFEST = os.path.join(UNITY_PROJECT, "Packages", "manifest.json")
LOCAL_REPO = "/Users/davidsarno/unity-mcp" # local repo root
PKG_NAME = "com.coplaydev.unity-mcp"
def get_current_branch(repo_path: str) -> str:
result = subprocess.run(
["git", "-C", repo_path, "rev-parse", "--abbrev-ref", "HEAD"],
capture_output=True, text=True
)
if result.returncode != 0:
print("Error: unable to detect current branch from local repo.", file=sys.stderr)
sys.exit(1)
return result.stdout.strip()
def build_options(branch: str):
return [
("[1] Upstream main", "https://github.com/CoplayDev/unity-mcp.git?path=/UnityMcpBridge"),
(f"[2] Remote {branch}", f"https://github.com/dsarno/unity-mcp.git?path=/UnityMcpBridge#{branch}"),
(f"[3] Local {branch}", f"file:{os.path.join(LOCAL_REPO, 'UnityMcpBridge')}"),
]
def read_manifest(path: str):
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
def write_manifest(path: str, data: dict):
with open(path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
f.write("\n")
def main():
# Allow overrides via args: python mcp_source.py [manifest.json] [local_repo]
manifest_path = MANIFEST if len(sys.argv) < 2 else sys.argv[1]
repo_path = LOCAL_REPO if len(sys.argv) < 3 else sys.argv[2]
branch = get_current_branch(repo_path)
options = build_options(branch)
print("Select MCP package source by number:")
for label, _ in options:
print(label)
choice = input("Enter 1-3: ").strip()
if choice not in {"1", "2", "3"}:
print("Invalid selection.", file=sys.stderr)
sys.exit(1)
idx = int(choice) - 1
_, chosen = options[idx]
data = read_manifest(manifest_path)
deps = data.get("dependencies", {})
if PKG_NAME not in deps:
print(f"Error: '{PKG_NAME}' not found in manifest dependencies.", file=sys.stderr)
sys.exit(1)
print(f"\nUpdating {PKG_NAME}{chosen}")
deps[PKG_NAME] = chosen
data["dependencies"] = deps
write_manifest(manifest_path, data)
print(f"Done. Wrote to: {manifest_path}")
print("Tip: In Unity, open Package Manager and Refresh to re-resolve packages.")
if __name__ == "__main__":
main()