How to use the importlab.parsepy.get_imports 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_parsepy.py View on Github external
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)
github google / importlab / importlab / graph.py View on Github external
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)
github google / importlab / importlab / graph.py View on Github external
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)