Spaces:
Running
Running
Update src/utils.py
Browse files- 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\(
|
| 24 |
if match:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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:
|