Esempio n. 1
0
def parse_args(argv):
    """Parse command line args.

  Arguments:
    argv: Raw command line args, typically sys.argv[1:]

  Returns:
    A tuple of (
      parsed_args: argparse.Namespace,
      kythe_args: kythe.Args,
      pytype_options: pytype.config.Options)
  """

    parser = make_parser()
    args = parser.parse_args(argv)
    cli_args = args.inputs.copy()
    # If we are passed an imports map we should look for pickled files as well.
    if args.imports_info:
        cli_args += [
            "--imports_info", args.imports_info, "--use-pickled-files"
        ]

    # We need to set this when creating Options (b/128032570)
    if args.python_version:
        cli_args += ["-V", pytype_utils.format_version(args.python_version)]

    pytype_options = pytype_config.Options(cli_args)
    pytype_options.tweak(**parser.get_pytype_kwargs(args))
    kythe_args = kythe.Args(corpus=args.kythe_corpus, root=args.kythe_root)
    return (args, kythe_args, pytype_options)
Esempio n. 2
0
 def generate_kythe(self, code, **kwargs):
     """Generate a kythe index from a code string."""
     with file_utils.Tempdir() as d:
         d.create_file("t.py", code)
         options = config.Options([d["t.py"]])
         options.tweak(pythonpath=[d.path], version=self.python_version)
         kythe_args = kythe.Args(corpus="corpus", root="root")
         ix = indexer.process_file(options, kythe_args=kythe_args)
         # Collect all the references from the kythe graph.
         kythe_index = [json.loads(x) for x in output.json_kythe_graph(ix)]
         return kythe_index
Esempio n. 3
0
 def test_kythe_args(self):
     code = textwrap.dedent("""
     def f(x):
       return 42
 """)
     with file_utils.Tempdir() as d:
         d.create_file("t.py", code)
         options = config.Options([d["t.py"]])
         options.tweak(pythonpath=[d.path], version=self.python_version)
         kythe_args = kythe.Args(corpus="corpus", root="root")
         ix = indexer.process_file(options, kythe_args=kythe_args)
         # Collect all the references from the kythe graph.
         kythe_index = [json.loads(x) for x in output.json_kythe_graph(ix)]
         k = kythe_index[0]["source"]
         self.assertEqual(k["corpus"], "corpus")
         self.assertEqual(k["root"], "root")
Esempio n. 4
0
def parse_args(argv):
    """Parse command line args.

  Arguments:
    argv: Raw command line args, typically sys.argv[1:]

  Returns:
    A tuple of (
      parsed_args: argparse.Namespace,
      kythe_args: kythe.Args,
      pytype_options: pytype.config.Options)
  """

    parser = make_parser()
    args = parser.parse_args(argv)
    pytype_options = pytype_config.Options(args.inputs)
    pytype_options.tweak(**parser.get_pytype_kwargs(args))
    kythe_args = kythe.Args(corpus=args.kythe_corpus, root=args.kythe_root)
    return (args, kythe_args, pytype_options)
Esempio n. 5
0
def parse_args(argv):
  """Parse command line args.

  Arguments:
    argv: Raw command line args, typically sys.argv[1:]

  Returns:
    A tuple of (
      parsed_args: argparse.Namespace,
      kythe_args: kythe.Args,
      pytype_options: pytype.config.Options)
  """

  parser = make_parser()
  args = parser.parse_args(argv)
  cli_args = args.inputs
  # If we are passed an imports map we should look for pickled files as well.
  if args.imports_info:
    cli_args += ["--imports_info", args.imports_info,
                 "--use-pickled-files"]
  pytype_options = pytype_config.Options(cli_args)
  pytype_options.tweak(**parser.get_pytype_kwargs(args))
  kythe_args = kythe.Args(corpus=args.kythe_corpus, root=args.kythe_root)
  return (args, kythe_args, pytype_options)