infinitymatter commited on
Commit
4e3cfe7
·
verified ·
1 Parent(s): 2a2caa1

Update src/utils.py

Browse files
Files changed (1) hide show
  1. src/utils.py +5 -4
src/utils.py CHANGED
@@ -20,17 +20,18 @@ def extract_code(text):
20
  # Extract file path from a code string that uses os.path.join()
21
  def extract_file_path(code_str):
22
  try:
23
- match = re.search(r'os\.path\.join\(\s*["\'](.+?)["\']\s*,\s*["\'](.+?)["\']\s*\)', code_str)
24
  if match:
25
- folder = match.group(1)
26
- filename = match.group(2)
27
- return os.path.join(folder, filename)
28
  print("No file path found.")
29
  return None
30
  except Exception as e:
31
  print(f"File path extraction error: {e}")
32
  raise
33
 
 
34
  # Execute extracted Python code in a subprocess using the given interpreter
35
  def execute_code_in_virtualenv(text, python_interpreter=sys.executable):
36
  if not python_interpreter:
 
20
  # Extract file path from a code string that uses os.path.join()
21
  def extract_file_path(code_str):
22
  try:
23
+ match = re.search(r'os\.path\.join\(([^)]+)\)', code_str)
24
  if match:
25
+ parts = re.findall(r'["\']([^"\']+)["\']', match.group(1))
26
+ if parts:
27
+ return os.path.join(*parts)
28
  print("No file path found.")
29
  return None
30
  except Exception as e:
31
  print(f"File path extraction error: {e}")
32
  raise
33
 
34
+
35
  # Execute extracted Python code in a subprocess using the given interpreter
36
  def execute_code_in_virtualenv(text, python_interpreter=sys.executable):
37
  if not python_interpreter: