Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception handle in dependency analysis to use regex if ast can't be used due to version #2241

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions augur/tasks/git/dependency_tasks/dependency_util/python_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ def get_files(path):


def get_deps_for_file(path):
try:
return get_deps_for_file_ast(path)
except Exception:
return get_deps_for_file_simple_regex(path)

def get_deps_for_file_simple_regex(path):
f = open(path, 'r',encoding="utf-8")

matches = re.findall("import\s*(\w*)", f.read())
f.close()
return matches


def get_deps_for_file_ast(path):
with open(path, "r", encoding="utf-8") as f:

imports = set()
Expand Down