Exemple #1
0
def main(argv=None):
    """Apply FixMergePyi to a source file without using the 2to3 main program.

  This is necessary so we can have our own options.

  Args:
    argv: Flags and files to process.
  """

    logging.basicConfig(level=logging.DEBUG)

    if argv is None:
        argv = sys.argv
    args = parse_args(argv)

    py_src = args.py.read()
    pyi_src = args.pyi.read()

    annotated_src = merge_pyi.annotate_string(args, py_src, pyi_src)
    src_changed = annotated_src != py_src

    if args.diff:
        if src_changed:
            diff = get_diff(py_src, annotated_src)
            print(diff)
    elif args.i:
        if src_changed:
            with open(args.py.name, 'w') as f:
                f.write(annotated_src)
    else:
        sys.stdout.write(annotated_src)
  def run_test(self):
    py_input, pyi_src = [_read_file(f) for f in (self.py, self.pyi)]

    output = merge_pyi.annotate_string(self.args, py_input, pyi_src)

    if OVERWRITE_EXPECTED:
      with open(self.outfile, 'w') as f:
        f.write(output)
    else:
      expected = _read_file(self.outfile)
      self.assertEqual(expected, output, _get_diff(expected, output))
Exemple #3
0
    def regression_test(test_case):
        py_input, pyi_src = [_read_file(f) for f in (py, pyi)]

        output = merge_pyi.annotate_string(args, py_input, pyi_src)

        if OVERWRITE_EXPECTED:
            with open(outfile, 'w') as f:
                f.write(output)
        else:
            expected = _read_file(outfile)
            test_case.assertEqual(expected, output,
                                  _get_diff(expected, output))
Exemple #4
0
def main(argv=None):
    """Apply FixMergePyi to a source file without using the 2to3 main program.

  This is necessary so we can have our own options.

  Args:
    argv: Flags and files to process.
  """

    if argv is None:
        argv = sys.argv
    args = parse_args(argv)

    # Log levels range from 10 (DEBUG) to 50 (CRITICAL) in increments of 10. A
    # level >50 prevents anything from being logged.
    logging.basicConfig(level=50 - args.verbosity * 10)

    py_src = args.py.read()
    pyi_src = args.pyi.read()

    annotated_src = merge_pyi.annotate_string(args, py_src, pyi_src)
    src_changed = annotated_src != py_src

    if args.diff:
        if src_changed:
            diff = get_diff(py_src, annotated_src)
            print(diff)
    elif args.in_place:
        if src_changed:
            with open(args.py.name, 'w') as f:
                f.write(annotated_src)
            print('Merged types to %s from %s' % (args.py.name, args.pyi.name))
        else:
            print('No new types for %s in %s' % (args.py.name, args.pyi.name))
    else:
        sys.stdout.write(annotated_src)