aboutsummaryrefslogtreecommitdiff
path: root/gazelle/parse.py
diff options
context:
space:
mode:
Diffstat (limited to 'gazelle/parse.py')
-rw-r--r--gazelle/parse.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/gazelle/parse.py b/gazelle/parse.py
index dec3a16..6b07c0e 100644
--- a/gazelle/parse.py
+++ b/gazelle/parse.py
@@ -21,15 +21,18 @@ def parse_import_statements(content, filepath):
"name": subnode.name,
"lineno": node.lineno,
"filepath": filepath,
+ "from": ""
}
modules.append(module)
elif isinstance(node, ast.ImportFrom) and node.level == 0:
- module = {
- "name": node.module,
- "lineno": node.lineno,
- "filepath": filepath,
- }
- modules.append(module)
+ for subnode in node.names:
+ module = {
+ "name": f"{node.module}.{subnode.name}",
+ "lineno": node.lineno,
+ "filepath": filepath,
+ "from": node.module
+ }
+ modules.append(module)
return modules
@@ -47,9 +50,10 @@ def parse(repo_root, rel_package_path, filename):
abs_filepath = os.path.join(repo_root, rel_filepath)
with open(abs_filepath, "r") as file:
content = file.read()
- # From simple benchmarks, 2 workers gave the best performance here.
+ # From simple benchmarks, 2 workers gave the best performance here.
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
- modules_future = executor.submit(parse_import_statements, content, rel_filepath)
+ modules_future = executor.submit(parse_import_statements, content,
+ rel_filepath)
comments_future = executor.submit(parse_comments, content)
modules = modules_future.result()
comments = comments_future.result()
@@ -69,11 +73,12 @@ def main(stdin, stdout):
filenames = parse_request["filenames"]
outputs = list()
if len(filenames) == 1:
- outputs.append(parse(repo_root, rel_package_path, filenames[0]))
+ outputs.append(parse(repo_root, rel_package_path,
+ filenames[0]))
else:
futures = [
- executor.submit(parse, repo_root, rel_package_path, filename)
- for filename in filenames
+ executor.submit(parse, repo_root, rel_package_path,
+ filename) for filename in filenames
if filename != ""
]
for future in concurrent.futures.as_completed(futures):