@rookiestar/eng-lang-tutor 1.0.1 → 1.2.2
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.
- package/CHANGELOG.md +5 -0
- package/README.md +18 -6
- package/package.json +3 -3
- package/scripts/setup.py +160 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -37,10 +37,21 @@ sudo apt-get install ffmpeg python3 python3-venv
|
|
|
37
37
|
**方式一:npm 安装(推荐)**
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
+
# 1. Install the npm package
|
|
40
41
|
npm install -g @rookiestar/eng-lang-tutor
|
|
41
|
-
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
# 2. Install Python dependencies (choose one method)
|
|
44
|
+
|
|
45
|
+
# Option A: Using virtual environment (recommended)
|
|
46
|
+
eng-lang-tutor-setup --venv
|
|
47
|
+
# Then activate before using: source ~/.venvs/eng-lang-tutor/bin/activate
|
|
48
|
+
|
|
49
|
+
# Option B: Install to user directory
|
|
50
|
+
eng-lang-tutor-setup --user
|
|
51
|
+
|
|
52
|
+
# Option C: Check if dependencies are already installed
|
|
53
|
+
eng-lang-tutor-setup --check
|
|
54
|
+
```
|
|
44
55
|
|
|
45
56
|
**方式二:从源码安装**
|
|
46
57
|
|
|
@@ -57,12 +68,13 @@ pip install -r eng-lang-tutor/requirements.txt
|
|
|
57
68
|
**手动安装依赖(如需要):**
|
|
58
69
|
|
|
59
70
|
```bash
|
|
60
|
-
#
|
|
71
|
+
# 使用 setup 脚本(推荐)
|
|
72
|
+
eng-lang-tutor-setup --venv ~/.venvs/eng-lang-tutor
|
|
73
|
+
|
|
74
|
+
# 或手动创建虚拟环境
|
|
61
75
|
python3 -m venv ~/.venvs/eng-lang-tutor
|
|
62
76
|
source ~/.venvs/eng-lang-tutor/bin/activate # Linux/macOS
|
|
63
|
-
|
|
64
|
-
# 安装依赖
|
|
65
|
-
pip install -r ~/.openclaw/skills/eng-lang-tutor/requirements.txt
|
|
77
|
+
pip install -r $(npm root -g)/@rookiestar/eng-lang-tutor/requirements.txt
|
|
66
78
|
```
|
|
67
79
|
|
|
68
80
|
**验证安装:**
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rookiestar/eng-lang-tutor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "地道美式英语导师 - OpenClaw Skill for learning authentic American English",
|
|
5
5
|
"main": "scripts/cli/cli.py",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"bin": {
|
|
7
|
+
"eng-lang-tutor-setup": "scripts/setup.py"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"english",
|
package/scripts/setup.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Setup script for eng-lang-tutor skill.
|
|
4
|
+
Installs Python dependencies with support for virtual environments.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
eng-lang-tutor-setup # Install dependencies
|
|
8
|
+
eng-lang-tutor-setup --venv # Create venv and install
|
|
9
|
+
eng-lang-tutor-setup --check # Check dependencies only
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import os
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_package_dir() -> Path:
|
|
20
|
+
"""Get the package directory containing requirements.txt."""
|
|
21
|
+
# When installed via npm, the script is symlinked in node_modules/.bin/
|
|
22
|
+
# We need to find the actual package directory
|
|
23
|
+
script_path = Path(__file__).resolve()
|
|
24
|
+
|
|
25
|
+
# Check if we're in a typical npm global install location
|
|
26
|
+
if "node_modules" in str(script_path):
|
|
27
|
+
# Navigate to the package root
|
|
28
|
+
parts = script_path.parts
|
|
29
|
+
for i, part in enumerate(parts):
|
|
30
|
+
if part == "node_modules":
|
|
31
|
+
# Find the package directory (usually @scope/package or just package)
|
|
32
|
+
remaining = parts[i + 1 :]
|
|
33
|
+
if remaining and remaining[0].startswith("@"):
|
|
34
|
+
# Scoped package: @rookiestar/eng-lang-tutor
|
|
35
|
+
pkg_dir = Path(*parts[: i + 3])
|
|
36
|
+
else:
|
|
37
|
+
# Unscoped package
|
|
38
|
+
pkg_dir = Path(*parts[: i + 2])
|
|
39
|
+
return pkg_dir
|
|
40
|
+
|
|
41
|
+
# Fallback: assume script is in scripts/ directory
|
|
42
|
+
return script_path.parent.parent
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def check_dependencies() -> tuple[bool, list[str]]:
|
|
46
|
+
"""Check if all required dependencies are installed."""
|
|
47
|
+
missing = []
|
|
48
|
+
required = ["websocket", "certifi", "aiohttp", "edge_tts"]
|
|
49
|
+
|
|
50
|
+
for module in required:
|
|
51
|
+
try:
|
|
52
|
+
__import__(module)
|
|
53
|
+
except ImportError:
|
|
54
|
+
missing.append(module)
|
|
55
|
+
|
|
56
|
+
return len(missing) == 0, missing
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def install_dependencies(
|
|
60
|
+
requirements_path: Path, venv_path: Path | None = None, user: bool = False
|
|
61
|
+
) -> bool:
|
|
62
|
+
"""Install dependencies from requirements.txt."""
|
|
63
|
+
if not requirements_path.exists():
|
|
64
|
+
print(f"Error: requirements.txt not found at {requirements_path}")
|
|
65
|
+
return False
|
|
66
|
+
|
|
67
|
+
pip_cmd = [sys.executable, "-m", "pip", "install", "-r", str(requirements_path)]
|
|
68
|
+
|
|
69
|
+
if venv_path:
|
|
70
|
+
pip_cmd = [str(venv_path / "bin" / "pip"), "install", "-r", str(requirements_path)]
|
|
71
|
+
elif user:
|
|
72
|
+
pip_cmd.append("--user")
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
print(f"Installing dependencies from {requirements_path}...")
|
|
76
|
+
subprocess.run(pip_cmd, check=True)
|
|
77
|
+
return True
|
|
78
|
+
except subprocess.CalledProcessError as e:
|
|
79
|
+
print(f"Error installing dependencies: {e}")
|
|
80
|
+
return False
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def create_venv(venv_path: Path) -> bool:
|
|
84
|
+
"""Create a virtual environment."""
|
|
85
|
+
try:
|
|
86
|
+
print(f"Creating virtual environment at {venv_path}...")
|
|
87
|
+
subprocess.run([sys.executable, "-m", "venv", str(venv_path)], check=True)
|
|
88
|
+
return True
|
|
89
|
+
except subprocess.CalledProcessError as e:
|
|
90
|
+
print(f"Error creating virtual environment: {e}")
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def main():
|
|
95
|
+
parser = argparse.ArgumentParser(
|
|
96
|
+
description="Setup script for eng-lang-tutor skill"
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"--venv",
|
|
100
|
+
metavar="PATH",
|
|
101
|
+
nargs="?",
|
|
102
|
+
const="~/.venvs/eng-lang-tutor",
|
|
103
|
+
help="Create a virtual environment and install dependencies (default: ~/.venvs/eng-lang-tutor)",
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"--check",
|
|
107
|
+
action="store_true",
|
|
108
|
+
help="Check if dependencies are installed without installing",
|
|
109
|
+
)
|
|
110
|
+
parser.add_argument(
|
|
111
|
+
"--user",
|
|
112
|
+
action="store_true",
|
|
113
|
+
help="Install dependencies to user directory (use with --break-system-packages if needed)",
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
args = parser.parse_args()
|
|
117
|
+
|
|
118
|
+
pkg_dir = get_package_dir()
|
|
119
|
+
requirements_path = pkg_dir / "requirements.txt"
|
|
120
|
+
|
|
121
|
+
# Check mode
|
|
122
|
+
if args.check:
|
|
123
|
+
ok, missing = check_dependencies()
|
|
124
|
+
if ok:
|
|
125
|
+
print("All dependencies are installed.")
|
|
126
|
+
sys.exit(0)
|
|
127
|
+
else:
|
|
128
|
+
print(f"Missing dependencies: {', '.join(missing)}")
|
|
129
|
+
print("Run this script without --check to install them.")
|
|
130
|
+
sys.exit(1)
|
|
131
|
+
|
|
132
|
+
# Venv mode
|
|
133
|
+
if args.venv:
|
|
134
|
+
venv_path = Path(args.venv).expanduser().resolve()
|
|
135
|
+
|
|
136
|
+
if not (venv_path / "bin" / "python").exists():
|
|
137
|
+
if not create_venv(venv_path):
|
|
138
|
+
sys.exit(1)
|
|
139
|
+
|
|
140
|
+
if install_dependencies(requirements_path, venv_path=venv_path):
|
|
141
|
+
print(f"\nSuccess! Virtual environment created at {venv_path}")
|
|
142
|
+
print(f"To activate it, run: source {venv_path}/bin/activate")
|
|
143
|
+
sys.exit(0)
|
|
144
|
+
else:
|
|
145
|
+
sys.exit(1)
|
|
146
|
+
|
|
147
|
+
# Direct install mode
|
|
148
|
+
if install_dependencies(requirements_path, user=args.user):
|
|
149
|
+
print("\nDependencies installed successfully!")
|
|
150
|
+
sys.exit(0)
|
|
151
|
+
else:
|
|
152
|
+
print("\nInstallation failed. Try one of these alternatives:")
|
|
153
|
+
print(" 1. Create a virtual environment: eng-lang-tutor-setup --venv")
|
|
154
|
+
print(" 2. Install to user directory: eng-lang-tutor-setup --user")
|
|
155
|
+
print(" 3. If you understand the risks: pip install -r requirements.txt --break-system-packages")
|
|
156
|
+
sys.exit(1)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if __name__ == "__main__":
|
|
160
|
+
main()
|