<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import argparse <EOL> import logging <EOL> import os <EOL> import sys <EOL> from yapf . yapflib import errors <EOL> from yapf . yapflib import file_resources <EOL> from yapf . yapflib import py3compat <EOL> from yapf . yapflib import style <EOL> from yapf . yapflib import yapf_api <EOL> __version__ = '<STR_LIT>' <EOL> def main ( argv ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> diff_inplace_group = parser . add_mutually_exclusive_group ( ) <EOL> diff_inplace_group . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> diff_inplace_group . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> lines_recursive_group = parser . add_mutually_exclusive_group ( ) <EOL> lines_recursive_group . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> lines_recursive_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store>' , <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( style . LOCAL_STYLE , style . SETUP_CONFIG ) ) ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' ) <EOL> args = parser . parse_args ( argv [ <NUM_LIT:1> : ] ) <EOL> if args . version : <EOL> print ( '<STR_LIT>' . format ( __version__ ) ) <EOL> return <NUM_LIT:0> <EOL> if args . style_help : <EOL> style . SetGlobalStyle ( style . CreateStyleFromConfig ( args . style ) ) <EOL> for option , docstring in sorted ( style . Help ( ) . items ( ) ) : <EOL> print ( option , '<STR_LIT:=>' , style . Get ( option ) , sep = '<STR_LIT>' ) <EOL> for line in docstring . splitlines ( ) : <EOL> print ( '<STR_LIT:U+0020>' , line ) <EOL> print ( ) <EOL> return <NUM_LIT:0> <EOL> if args . lines and len ( args . files ) > <NUM_LIT:1> : <EOL> parser . error ( '<STR_LIT>' ) <EOL> lines = _GetLines ( args . lines ) if args . lines is not None else None <EOL> if not args . files : <EOL> if args . in_place or args . diff : <EOL> parser . error ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> original_source = [ ] <EOL> while True : <EOL> try : <EOL> original_source . append ( py3compat . raw_input ( ) ) <EOL> except EOFError : <EOL> break <EOL> style_config = args . style <EOL> if style_config is None and not args . no_local_style : <EOL> style_config = file_resources . GetDefaultStyleForDir ( os . getcwd ( ) ) <EOL> reformatted_source , changed = yapf_api . FormatCode ( <EOL> py3compat . unicode ( '<STR_LIT:\n>' . join ( original_source ) + '<STR_LIT:\n>' ) , <EOL> filename = '<STR_LIT>' , <EOL> style_config = style_config , <EOL> lines = lines , <EOL> verify = args . verify ) <EOL> sys . stdout . write ( reformatted_source ) <EOL> return <NUM_LIT:2> if changed else <NUM_LIT:0> <EOL> files = file_resources . GetCommandLineFiles ( args . files , args . recursive , <EOL> args . exclude ) <EOL> if not files : <EOL> raise errors . YapfError ( '<STR_LIT>' ) <EOL> changed = FormatFiles ( files , <EOL> lines , <EOL> style_config = args . style , <EOL> no_local_style = args . no_local_style , <EOL> in_place = args . in_place , <EOL> print_diff = args . diff , <EOL> verify = args . verify ) <EOL> return <NUM_LIT:2> if changed else <NUM_LIT:0> <EOL> def FormatFiles ( filenames , <EOL> lines , <EOL> style_config = None , <EOL> no_local_style = False , <EOL> in_place = False , <EOL> print_diff = False , <EOL> verify = True ) : <EOL> """<STR_LIT>""" <EOL> changed = False <EOL> for filename in filenames : <EOL> logging . info ( '<STR_LIT>' , filename ) <EOL> if style_config is None and not no_local_style : <EOL> style_config = ( <EOL> file_resources . GetDefaultStyleForDir ( os . path . dirname ( filename ) ) ) <EOL> try : <EOL> reformatted_code , encoding , has_change = yapf_api . FormatFile ( <EOL> filename , <EOL> in_place = in_place , <EOL> style_config = style_config , <EOL> lines = lines , <EOL> print_diff = print_diff , <EOL> verify = verify , <EOL> logger = logging . warning ) <EOL> if has_change and reformatted_code is not None : <EOL> file_resources . WriteReformattedCode ( filename , reformatted_code , <EOL> in_place , encoding ) <EOL> changed |= has_change <EOL> except SyntaxError as e : <EOL> e . filename = filename <EOL> raise <EOL> return changed <EOL> def _GetLines ( line_strings ) : <EOL> """<STR_LIT>""" <EOL> lines = [ ] <EOL> for line_string in line_strings : <EOL> line = list ( map ( int , line_string . split ( '<STR_LIT:->' , <NUM_LIT:1> ) ) ) <EOL> if line [ <NUM_LIT:0> ] < <NUM_LIT:1> : <EOL> raise errors . YapfError ( '<STR_LIT>' % line ) <EOL> if line [ <NUM_LIT:0> ] > line [ <NUM_LIT:1> ] : <EOL> raise errors . YapfError ( '<STR_LIT>' , line ) <EOL> lines . append ( tuple ( line ) ) <EOL> return lines <EOL> def run_main ( ) : <EOL> try : <EOL> sys . exit ( main ( sys . argv ) ) <EOL> except errors . YapfError as e : <EOL> sys . stderr . write ( '<STR_LIT>' + str ( e ) + '<STR_LIT:\n>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> run_main ( ) </s>
