<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> from colors import green <EOL> from pants . base . build_environment import get_buildroot <EOL> from pants . bin . goal_runner import GoalRunner , OptionsInitializer , ReportingInitializer <EOL> from pants . bin . repro import Reproducer <EOL> from pants . option . options_bootstrapper import OptionsBootstrapper <EOL> class LocalPantsRunner ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exiter , args , env , options_bootstrapper = None ) : <EOL> """<STR_LIT>""" <EOL> self . _exiter = exiter <EOL> self . _args = args <EOL> self . _env = env <EOL> self . _options_bootstrapper = options_bootstrapper <EOL> self . _profile_path = self . _env . get ( '<STR_LIT>' ) <EOL> def _maybe_profiled ( self , runner ) : <EOL> """<STR_LIT>""" <EOL> if self . _profile_path : <EOL> import cProfile <EOL> profiler = cProfile . Profile ( ) <EOL> try : <EOL> profiler . runcall ( runner ) <EOL> finally : <EOL> profiler . dump_stats ( self . _profile_path ) <EOL> print ( '<STR_LIT>' . format ( self . _profile_path ) ) <EOL> view_cmd = green ( '<STR_LIT>' <EOL> . format ( path = self . _profile_path ) ) <EOL> print ( '<STR_LIT>' . format ( view_cmd ) ) <EOL> else : <EOL> runner ( ) <EOL> def run ( self ) : <EOL> self . _maybe_profiled ( self . _run ) <EOL> def _run ( self ) : <EOL> options_bootstrapper = self . _options_bootstrapper or OptionsBootstrapper ( env = self . _env , <EOL> args = self . _args ) <EOL> options , build_config = OptionsInitializer ( options_bootstrapper , exiter = self . _exiter ) . setup ( ) <EOL> self . _exiter . apply_options ( options ) <EOL> for scope in options . scope_to_flags . keys ( ) : <EOL> options . for_scope ( scope ) <EOL> if options . for_global_scope ( ) . verify_config : <EOL> options_bootstrapper . verify_configs_against_options ( options ) <EOL> run_tracker , reporting = ReportingInitializer ( ) . setup ( ) <EOL> try : <EOL> root_dir = get_buildroot ( ) <EOL> repro = Reproducer . global_instance ( ) . create_repro ( ) <EOL> if repro : <EOL> repro . capture ( run_tracker . run_info . get_as_dict ( ) ) <EOL> goal_runner = GoalRunner . Factory ( root_dir , <EOL> options , <EOL> build_config , <EOL> run_tracker , <EOL> reporting , <EOL> exiter = self . _exiter ) . setup ( ) <EOL> result = goal_runner . run ( ) <EOL> if repro : <EOL> repro . log_location_of_repro_file ( ) <EOL> finally : <EOL> run_tracker . end ( ) <EOL> self . _exiter . exit ( result ) </s>
