Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions env_service/environments/appworld/setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ conda run -n appworld pip install -r "$SCRIPT_DIR/requirements.txt"

# 5. 初始化 appworld
echo "📁 初始化 appworld..."
conda run -n appworld appworld install
conda run -n appworld python -c $'from appworld.install import install_package\ninstall_package()\n'

# 6. 下载数据
echo "📦 下载数据(失败则使用备用下载)..."
if ! conda run -n appworld appworld download data; then
if ! conda run -n appworld python -c $'import os\nfrom appworld import update_root\nfrom appworld.download import download_data\nroot = os.environ.get("APPWORLD_ROOT") or "."\nupdate_root(root)\ndownload_data()\n'; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The inline Python script here, and similarly on line 40, is quite complex. This makes the script harder to read, debug, and maintain. For better long-term code health, consider moving this logic into a dedicated helper Python script.

For example, you could create a download_helper.py in this directory:

# env_service/environments/appworld/download_helper.py
import os
import sys
from appworld import update_root
from appworld.download import download_data

root = os.environ.get("APPWORLD_ROOT")
if not root:
    print("Warning: APPWORLD_ROOT environment variable not set. Defaulting to '.'", file=sys.stderr)
    root = "."

update_root(root)
download_data()

You could then call it from this shell script like so:

if ! conda run -n appworld python "$SCRIPT_DIR/download_helper.py"; then
    # ...
fi

This approach would make the setup.sh script cleaner and the Python logic easier to manage and test independently.

echo "⚠️ 自动下载失败,尝试从备用地址获取数据..."
wget -O "$APPWORLD_ROOT/appworld_data.zip" "https://dail-wlcb.oss-accelerate.aliyuncs.com/eric.czq/appworld_data.zip"
mkdir -p /tmp/unziptemp
Expand Down
30 changes: 27 additions & 3 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import signal
import shlex
from pathlib import Path
from dotenv import load_dotenv
from agentevolver.utils.daemon import LaunchCommandWhenAbsent

Expand Down Expand Up @@ -98,9 +99,32 @@ def parse_args():
return parser.parse_args()


def _require_service_env(service_name: str):
"""Return (path, script) for the companion service, validating env vars."""
env_prefix = service_name.upper()
service_path = os.environ.get(f'{env_prefix}_PATH')
service_script = os.environ.get(f'{env_prefix}_SCRIPT')
missing = []
if not service_path:
missing.append(f'{env_prefix}_PATH')
if not service_script:
missing.append(f'{env_prefix}_SCRIPT')
if missing:
example_hint = ""
example_env = Path("example.env")
if example_env.exists():
example_hint = (
f" Copy the relevant entries from {example_env} into your .env file."
)
raise RuntimeError(
f"Missing environment variable(s) required to launch '{service_name}': "
f"{', '.join(missing)}.{example_hint}"
)
return service_path, service_script


def pty_launch(service_name: str, success_std_string="Starting server on"):
service_path = os.environ.get(f'{service_name.upper()}_PATH')
service_script = os.environ.get(f'{service_name.upper()}_SCRIPT')
service_path, service_script = _require_service_env(service_name)
companion = LaunchCommandWhenAbsent(
full_argument_list=[service_script],
dir=service_path,
Expand Down Expand Up @@ -393,4 +417,4 @@ def main():
sys.exit(1)

if __name__ == "__main__":
main()
main()