Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_file_deps(self, filename):
if filename in self.unreadable:
raise parsepy.ParseError(filename)
if filename in self.deps:
resolved, unresolved, provenance = self.deps[filename]
self.provenance.update(provenance)
return (resolved, unresolved)
return ([], [])
def get_file_deps(self, filename):
if filename in self.unreadable:
raise parsepy.ParseError()
if filename in self.deps:
resolved, unresolved, provenance = self.deps[filename]
self.provenance.update(provenance)
return (resolved, unresolved)
return ([], [])
def test_syntax_error(self):
with self.assertRaises(parsepy.ParseError):
self.parse("foo(]")
else:
# Call the appropriate python version in a subprocess
f = sys.modules['importlab.import_finder'].__file__
if f.rsplit('.', 1)[-1] == 'pyc':
# In host Python 2, importlab ships with .pyc files.
f = f[:-1]
ret, stdout, stderr = utils.run_py_file(python_version, f, filename)
if not ret:
if sys.version_info[0] == 3:
stdout = stdout.decode('ascii')
imports = import_finder.read_imports(stdout)
else:
if sys.version_info[0] == 3:
stderr = stderr.decode('ascii')
logging.info(stderr)
raise ParseError(filename)
return [ImportStatement(*imp) for imp in imports]
Args:
filename: The name of the file.
trim: Whether to trim the dependencies of builtin and system files.
"""
assert not self.final, 'Trying to mutate a final graph.'
self.add_source_file(filename)
queue = collections.deque([filename])
seen = set()
while queue:
filename = queue.popleft()
self.graph.add_node(filename)
try:
deps, broken = self.get_file_deps(filename)
except parsepy.ParseError:
# Python couldn't parse `filename`. If we're sure that it is a
# Python file, we mark it as unreadable and keep the node in the
# graph so importlab's callers can do their own syntax error
# handling if desired.
if filename.endswith('.py'):
self.unreadable_files.add(filename)
else:
self.graph.remove_node(filename)
continue
for f in broken:
self.broken_deps[filename].add(f)
for f in deps:
if self.follow_file(f, seen, trim):
queue.append(f)
seen.add(f)
self.graph.add_node(f)