How to use the importlab.parsepy.ParseError function in importlab

To help you get started, we’ve selected a few importlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / importlab / tests / test_graph.py View on Github external
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 ([], [])
github google / importlab / tests / test_graph.py View on Github external
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 ([], [])
github google / importlab / tests / test_parsepy.py View on Github external
def test_syntax_error(self):
        with self.assertRaises(parsepy.ParseError):
            self.parse("foo(]")
github google / importlab / importlab / parsepy.py View on Github external
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]
github google / importlab / importlab / graph.py View on Github external
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)