Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,24 +34,35 @@ class ErrorReporter(Reporter):
|
|
| 34 |
def check_code_with_pyflakes(code_str: str) -> str:
|
| 35 |
"""
|
| 36 |
Analyzes a string of Python code using pyflakes and returns a formatted error report.
|
| 37 |
-
|
|
|
|
| 38 |
"""
|
| 39 |
reporter = ErrorReporter()
|
| 40 |
check(code_str, "scene.py", reporter=reporter)
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
return "" # No errors found
|
| 44 |
|
| 45 |
-
# Format the error list into a user-friendly string
|
| 46 |
error_report = "Static analysis found potential errors:\n"
|
| 47 |
-
for err in
|
| 48 |
-
#
|
| 49 |
match = re.search(r'scene\.py:(\d+):.*(undefined name.*)', str(err))
|
| 50 |
if match:
|
| 51 |
line_num = match.group(1)
|
| 52 |
error_msg = match.group(2)
|
| 53 |
error_report += f"- Line {line_num}: {error_msg}\n"
|
| 54 |
else:
|
|
|
|
| 55 |
error_report += f"- {err}\n"
|
| 56 |
|
| 57 |
return error_report
|
|
|
|
| 34 |
def check_code_with_pyflakes(code_str: str) -> str:
|
| 35 |
"""
|
| 36 |
Analyzes a string of Python code using pyflakes and returns a formatted error report.
|
| 37 |
+
Crucially, it filters out warnings related to star imports (`from manim import *`).
|
| 38 |
+
Returns an empty string if no definite errors are found.
|
| 39 |
"""
|
| 40 |
reporter = ErrorReporter()
|
| 41 |
check(code_str, "scene.py", reporter=reporter)
|
| 42 |
|
| 43 |
+
# --- START: New Filtering Logic ---
|
| 44 |
+
filtered_errors = []
|
| 45 |
+
for err in reporter.errors:
|
| 46 |
+
err_str = str(err)
|
| 47 |
+
# This is the key: we ignore the specific warnings about star imports.
|
| 48 |
+
if "may be undefined, or defined from star imports" not in err_str:
|
| 49 |
+
filtered_errors.append(err_str)
|
| 50 |
+
# --- END: New Filtering Logic ---
|
| 51 |
+
|
| 52 |
+
if not filtered_errors:
|
| 53 |
return "" # No errors found
|
| 54 |
|
| 55 |
+
# Format the filtered error list into a user-friendly string
|
| 56 |
error_report = "Static analysis found potential errors:\n"
|
| 57 |
+
for err in filtered_errors:
|
| 58 |
+
# We now process the filtered list, not the original one.
|
| 59 |
match = re.search(r'scene\.py:(\d+):.*(undefined name.*)', str(err))
|
| 60 |
if match:
|
| 61 |
line_num = match.group(1)
|
| 62 |
error_msg = match.group(2)
|
| 63 |
error_report += f"- Line {line_num}: {error_msg}\n"
|
| 64 |
else:
|
| 65 |
+
# Add a catch-all for other potential errors like syntax errors
|
| 66 |
error_report += f"- {err}\n"
|
| 67 |
|
| 68 |
return error_report
|