jens-l commited on
Commit
7c71035
Β·
1 Parent(s): 8f63e88

Replace uv with pip in install_package tool for Docker compatibility

Browse files
Files changed (2) hide show
  1. kiss_agent.py +7 -33
  2. start.sh +0 -2
kiss_agent.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import re
3
- import socket
4
  import subprocess
5
  from pathlib import Path
6
 
@@ -121,8 +120,8 @@ def create_new_file(whole_edit: str) -> str:
121
  @tool
122
  def install_package(package_name: str) -> str:
123
  """
124
- Install a Python package using uv when encountering ModuleNotFoundError.
125
- This tool adds the package to the project's dependencies and installs it.
126
 
127
  Args:
128
  package_name: Name of the package to install (e.g., 'requests', 'pandas==2.0.0')
@@ -131,22 +130,17 @@ def install_package(package_name: str) -> str:
131
  Status message indicating success or failure
132
  """
133
  try:
134
- # Store original working directory
135
- original_cwd = os.getcwd()
136
-
137
- # Change to the project root directory (where pyproject.toml is)
138
- os.chdir(Path(__file__).parent)
139
-
140
- # Run uv add command
141
  result = subprocess.run(
142
- ["uv", "add", package_name],
143
  capture_output=True,
144
  text=True,
145
  timeout=60, # 60 second timeout for package installation
146
  )
147
 
148
  if result.returncode == 0:
149
- return f"βœ… Successfully installed {package_name} using uv"
150
  else:
151
  error_msg = result.stderr or result.stdout
152
  return f"❌ Failed to install {package_name}:\n{error_msg}"
@@ -154,29 +148,9 @@ def install_package(package_name: str) -> str:
154
  except subprocess.TimeoutExpired:
155
  return f"❌ Installation of {package_name} timed out after 60 seconds"
156
  except FileNotFoundError:
157
- return "❌ Error: uv command not found. Please make sure uv is installed."
158
  except Exception as e:
159
  return f"❌ Error installing {package_name}: {str(e)}"
160
- finally:
161
- # Change back to original directory
162
- try:
163
- os.chdir(original_cwd)
164
- except NameError:
165
- pass
166
-
167
-
168
- def _find_free_port(start_port=7860, max_ports=100):
169
- """Find an available TCP port, starting from a given port."""
170
- for port in range(start_port, start_port + max_ports):
171
- try:
172
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
173
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
174
- sock.bind(("127.0.0.1", port))
175
- return port
176
- except OSError:
177
- # This port is in use, try the next one
178
- continue
179
- return None
180
 
181
 
182
  @tool
 
1
  import os
2
  import re
 
3
  import subprocess
4
  from pathlib import Path
5
 
 
120
  @tool
121
  def install_package(package_name: str) -> str:
122
  """
123
+ Install a Python package using pip when encountering ModuleNotFoundError.
124
+ This tool installs the package to the user's local directory.
125
 
126
  Args:
127
  package_name: Name of the package to install (e.g., 'requests', 'pandas==2.0.0')
 
130
  Status message indicating success or failure
131
  """
132
  try:
133
+ # Run pip install with --user flag to install to user's local directory
134
+ # This matches the Docker container setup with /home/user/.local/bin in PATH
 
 
 
 
 
135
  result = subprocess.run(
136
+ ["pip", "install", "--user", package_name],
137
  capture_output=True,
138
  text=True,
139
  timeout=60, # 60 second timeout for package installation
140
  )
141
 
142
  if result.returncode == 0:
143
+ return f"βœ… Successfully installed {package_name} using pip"
144
  else:
145
  error_msg = result.stderr or result.stdout
146
  return f"❌ Failed to install {package_name}:\n{error_msg}"
 
148
  except subprocess.TimeoutExpired:
149
  return f"❌ Installation of {package_name} timed out after 60 seconds"
150
  except FileNotFoundError:
151
+ return "❌ Error: pip command not found. Please make sure pip is installed."
152
  except Exception as e:
153
  return f"❌ Error installing {package_name}: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
 
156
  @tool
start.sh CHANGED
@@ -1,7 +1,5 @@
1
  #!/bin/bash
2
 
3
- echo "===== Application Startup at $(date) ====="
4
-
5
  # Create necessary directories
6
  mkdir -p /var/run/nginx /var/lib/nginx/body /var/lib/nginx/proxy /var/lib/nginx/fastcgi /var/lib/nginx/uwsgi /var/lib/nginx/scgi /var/log/nginx
7
 
 
1
  #!/bin/bash
2
 
 
 
3
  # Create necessary directories
4
  mkdir -p /var/run/nginx /var/lib/nginx/body /var/lib/nginx/proxy /var/lib/nginx/fastcgi /var/lib/nginx/uwsgi /var/lib/nginx/scgi /var/log/nginx
5