• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights
2# reserved. Use of this source code is governed by a BSD-style license that
3# can be found in the LICENSE file
4
5from __future__ import absolute_import
6from __future__ import print_function
7from exec_util import exec_cmd
8import os
9import sys
10
11# Script directory.
12script_dir = os.path.dirname(__file__)
13root_dir = os.path.join(script_dir, os.pardir)
14
15
16def yapf_format(file_name, file_contents):
17  # Reads .style.yapf in the root_dir when specifying contents via stdin.
18  result = exec_cmd("%s %s/yapf" % (sys.executable, script_dir), root_dir,
19                    file_contents.encode('utf-8'))
20  if result['err'] != '':
21    print("yapf error: %s" % result['err'])
22  if result['out'] != '':
23    output = result['out']
24    if sys.platform == 'win32':
25      # Convert to Unix line endings.
26      output = output.replace("\r", "")
27    return output
28  return None
29