def _is_relative_import(module_name, path):
"""Checks if import is relative. Returns True if relative, False if
absolute, and None if import could not be found."""
try:
# Check within the restricted path of a (sub-)package
imp.find_module(module_name, [path])
except ImportError:
pass
else:
return True
try:
# Check across all of sys.path
imp.find_module(module_name)
except ImportError:
pass
else:
return False
# Module could not be found on system due to:
# 1. Import that doesn't exist. "Bad import".
# 2. Since we're only scanning the AST, there's a good chance the
# import's inclusion is conditional, and would never be triggered.
# For example, an import specific to an OS.
return None
评论列表
文章目录