forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-deps.py
More file actions
executable file
·118 lines (97 loc) · 3.65 KB
/
Copy pathsync-deps.py
File metadata and controls
executable file
·118 lines (97 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
"""
CopilotKit Dependency Synchronization Script
Ensures all examples use standardized dependency versions from the main SDK.
Usage:
python sync-deps.py [example-path]
python sync-deps.py --all # Update all examples
"""
import os
import sys
import toml
from pathlib import Path
# Canonical versions from main SDK
CANONICAL_VERSIONS = {
"python": ">=3.10,<3.13", # Compatible with CopilotKit requirement
"copilotkit": "0.1.49",
"langchain": "0.3.21",
"langgraph": "0.3.18",
"langsmith": "0.3.18",
"openai": "^1.68.2",
"fastapi": "^0.115.5",
"uvicorn": "^0.29.0",
"python-dotenv": "^1.0.0",
"crewai": "0.118.0" # For CrewAI examples
}
REQUIREMENTS_TEMPLATE = """# CopilotKit standardized dependencies for pip compatibility
# Generated from pyproject.toml - keep these versions synchronized
copilotkit==0.1.49
langchain==0.3.21
langgraph==0.3.18
langsmith==0.3.18
openai>=1.68.2,<2.0.0
fastapi>=0.115.5,<1.0.0
uvicorn>=0.29.0,<1.0.0
python-dotenv>=1.0.0,<2.0.0
"""
def update_pyproject(pyproject_path):
"""Update pyproject.toml with canonical versions while preserving existing config."""
if not pyproject_path.exists():
print(f"Skipping {pyproject_path} - file not found")
return False
try:
with open(pyproject_path, 'r') as f:
data = toml.load(f)
deps = data.get('tool', {}).get('poetry', {}).get('dependencies', {})
updated = False
# Update only the canonical dependencies, preserve others
for dep, version in CANONICAL_VERSIONS.items():
if dep in deps and deps[dep] != version:
print(f"Updating {dep}: {deps[dep]} -> {version}")
deps[dep] = version
updated = True
# Preserve existing sections like scripts, dev-dependencies, etc.
# Only update the dependencies section
if updated:
with open(pyproject_path, 'w') as f:
toml.dump(data, f)
print(f"✅ Updated {pyproject_path} (preserved existing config)")
else:
print(f"✅ {pyproject_path} already up to date")
return True
except Exception as e:
print(f"❌ Error updating {pyproject_path}: {e}")
return False
def create_requirements_txt(requirements_path, has_crewai=False):
"""Create or update requirements.txt for pip compatibility."""
template = REQUIREMENTS_TEMPLATE
if has_crewai:
template += "crewai==0.118.0\n"
with open(requirements_path, 'w') as f:
f.write(template)
print(f"✅ Created {requirements_path}")
def main():
if len(sys.argv) < 2:
print("Usage: python sync-deps.py [example-path] or --all")
return
examples_root = Path("../../../examples")
if sys.argv[1] == "--all":
# Update all Python examples
for example_dir in examples_root.glob("*/agent*/"):
pyproject_path = example_dir / "pyproject.toml"
requirements_path = example_dir / "requirements.txt"
if pyproject_path.exists():
update_pyproject(pyproject_path)
has_crewai = "crewai" in example_dir.name
create_requirements_txt(requirements_path, has_crewai)
else:
# Update specific example
example_path = Path(sys.argv[1])
pyproject_path = example_path / "pyproject.toml"
requirements_path = example_path / "requirements.txt"
if pyproject_path.exists():
update_pyproject(pyproject_path)
has_crewai = "crewai" in str(example_path)
create_requirements_txt(requirements_path, has_crewai)
if __name__ == "__main__":
main()