How to use the importlab.graph.ImportGraph.create 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_output.py View on Github external
def setUp(self):
        self.tempdir = utils.Tempdir()
        self.tempdir.setup()
        filenames = [
            self.tempdir.create_file(f, FILES[f])
            for f in FILES]
        self.fs = fs.OSFileSystem(self.tempdir.path)
        env = environment.Environment(fs.Path([self.fs]), (3, 6))
        self.graph = graph.ImportGraph.create(env, filenames)
github google / importlab / tests / test_graph.py View on Github external
def test_basic(self):
        g = graph.ImportGraph.create(self.env, self.filenames)
        self.assertEqual(
                g.sorted_source_files(),
                [[self.tempdir[x]] for x in ["foo/b.py", "foo/a.py", "x.py"]])
github google / importlab / tests / test_graph.py View on Github external
def test_basic(self):
        g = graph.ImportGraph.create(self.env, self.filenames)
        self.assertEqual(
                g.sorted_source_files(),
                [[self.tempdir[x]] for x in ["foo/b.py", "foo/a.py", "x.py"]])
github google / importlab / tests / test_graph.py View on Github external
def test_trim(self):
        sources = [self.tempdir["x.py"]]
        with self.patch_resolve_import():
            # Untrimmed g1 contains foo.b, the dep of system module foo.a.
            g1 = graph.ImportGraph.create(self.env, sources, trim=False)
            self.assertEqual(
                g1.sorted_source_files(),
                [[self.tempdir[x]] for x in ["foo/b.py", "foo/a.py", "x.py"]])
            # Trimmed g2 stops at foo.a.
            g2 = graph.ImportGraph.create(self.env, sources, trim=True)
            self.assertEqual(
                g2.sorted_source_files(),
                [[self.tempdir[x]] for x in ["foo/a.py", "x.py"]])
github google / pytype / pytype / tools / analyze_project / main.py View on Github external
if args.no_cache:
    conf.output = tempfile.mkdtemp()
  if not conf.pythonpath:
    conf.pythonpath = environment.compute_pythonpath(conf.inputs)
  logging.info('\n  '.join(['Configuration:'] + str(conf).split('\n')))

  if not conf.inputs:
    parser.parser.error('Need an input.')

  # Importlab needs the python exe, so we check it as early as possible.
  environment.check_python_exe_or_die(conf.python_version)

  typeshed = environment.initialize_typeshed_or_die()
  env = analyze_project_env.create_importlab_environment(conf, typeshed)
  print('Computing dependencies')
  import_graph = importlab.graph.ImportGraph.create(env, conf.inputs, trim=True)

  if args.tree:
    print('Source tree:')
    importlab.output.print_tree(import_graph)
    sys.exit(0)

  if args.unresolved:
    print('Unresolved dependencies:')
    for imp in sorted(import_graph.get_all_unresolved()):
      print(' ', imp.name)
    sys.exit(0)

  # Main usage mode: analyze the project file by file in dependency order.

  logging.info('Source tree:\n%s',
               importlab.output.formatted_deps_list(import_graph))