Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse(self, src):
with tempfile.NamedTemporaryFile() as f:
src = textwrap.dedent(src)
if sys.version_info[0] == 3:
src = src.encode('utf-8')
f.write(src)
f.flush()
return parsepy.get_imports(f.name, self.PYTHON_VERSION)
def get_file_deps(self, filename):
r = resolve.Resolver(self.path, filename)
resolved = []
unresolved = []
provenance = {}
for imp in parsepy.get_imports(filename, self.env.python_version):
try:
f = r.resolve_import(imp)
if not f.is_extension():
full_path = os.path.abspath(f.path)
resolved.append(full_path)
provenance[full_path] = f
except resolve.ImportException:
unresolved.append(imp)
return (resolved, unresolved, provenance)
def get_file_deps(self, filename):
resolved = []
unresolved = []
parent = self.provenance[filename]
r = resolve.Resolver(self.path, parent)
for imp in parsepy.get_imports(filename, self.env.python_version):
try:
f = r.resolve_import(imp)
if f.is_extension():
continue
full_path = os.path.abspath(f.path)
resolved.append(full_path)
self.provenance[full_path] = f
except resolve.ImportException:
unresolved.append(imp)
return (resolved, unresolved)