Spaces:
Runtime error
Runtime error
fix parsing python_files bug
Browse files
py_code_analyzer/code_imports_analyzer.py
CHANGED
|
@@ -36,7 +36,7 @@ async def get_program_text(session, python_file):
|
|
| 36 |
if response.status == 200:
|
| 37 |
data = await response.json()
|
| 38 |
if data["encoding"] == "base64":
|
| 39 |
-
return data["content"]
|
| 40 |
else:
|
| 41 |
print(
|
| 42 |
f"WARNING: {python_file['path']}'s encoding is {data['encoding']}, not base64"
|
|
@@ -72,20 +72,20 @@ class CodeImportsAnalyzer:
|
|
| 72 |
async with aiohttp.ClientSession() as session:
|
| 73 |
tasks = []
|
| 74 |
for python_file in self.python_files:
|
| 75 |
-
self.python_imports += [
|
| 76 |
-
{
|
| 77 |
-
"file_name": python_file["path"].split("/")[-1],
|
| 78 |
-
"file_path": python_file["path"],
|
| 79 |
-
"imports": [],
|
| 80 |
-
}
|
| 81 |
-
]
|
| 82 |
tasks.append(
|
| 83 |
asyncio.ensure_future(get_program_text(session, python_file))
|
| 84 |
)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
for base64_program_text in
|
| 88 |
if base64_program_text:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
program = pybase64.b64decode(base64_program_text)
|
| 90 |
tree = ast.parse(program)
|
| 91 |
self._node_visitor.visit(tree)
|
|
|
|
| 36 |
if response.status == 200:
|
| 37 |
data = await response.json()
|
| 38 |
if data["encoding"] == "base64":
|
| 39 |
+
return data["content"], python_file["path"]
|
| 40 |
else:
|
| 41 |
print(
|
| 42 |
f"WARNING: {python_file['path']}'s encoding is {data['encoding']}, not base64"
|
|
|
|
| 72 |
async with aiohttp.ClientSession() as session:
|
| 73 |
tasks = []
|
| 74 |
for python_file in self.python_files:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
tasks.append(
|
| 76 |
asyncio.ensure_future(get_program_text(session, python_file))
|
| 77 |
)
|
| 78 |
|
| 79 |
+
results = await asyncio.gather(*tasks)
|
| 80 |
+
for base64_program_text, python_file_path in results:
|
| 81 |
if base64_program_text:
|
| 82 |
+
self.python_imports += [
|
| 83 |
+
{
|
| 84 |
+
"file_name": python_file_path.split("/")[-1],
|
| 85 |
+
"file_path": python_file_path,
|
| 86 |
+
"imports": [],
|
| 87 |
+
}
|
| 88 |
+
]
|
| 89 |
program = pybase64.b64decode(base64_program_text)
|
| 90 |
tree = ast.parse(program)
|
| 91 |
self._node_visitor.visit(tree)
|