<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> import subprocess <EOL> import sys <EOL> from textwrap import dedent <EOL> from pants . base . cmd_line_spec_parser import CmdLineSpecParser <EOL> from pants . binaries import binary_util <EOL> from pants . engine . exp . engine import LocalSerialEngine <EOL> from pants . engine . exp . examples . planners import setup_json_scheduler <EOL> from pants . engine . exp . fs import Files , PathGlobs <EOL> from pants . util . contextutil import temporary_file_path <EOL> def visualize_execution_graph ( scheduler , storage , request ) : <EOL> with temporary_file_path ( cleanup = False , suffix = '<STR_LIT>' ) as dot_file : <EOL> scheduler . visualize_graph_to_file ( request . roots , dot_file ) <EOL> print ( '<STR_LIT>' . format ( dot_file ) ) <EOL> with temporary_file_path ( cleanup = False , suffix = '<STR_LIT>' ) as image_file : <EOL> subprocess . check_call ( '<STR_LIT>' . format ( image_file , dot_file ) , shell = True ) <EOL> print ( '<STR_LIT>' . format ( image_file ) ) <EOL> binary_util . ui_open ( image_file ) <EOL> def visualize_build_request ( build_root , goals , subjects ) : <EOL> scheduler , storage = setup_json_scheduler ( build_root ) <EOL> execution_request = scheduler . build_request ( goals , subjects ) <EOL> engine = LocalSerialEngine ( scheduler , storage ) <EOL> engine . start ( ) <EOL> try : <EOL> engine . reduce ( execution_request ) <EOL> visualize_execution_graph ( scheduler , storage , execution_request ) <EOL> finally : <EOL> engine . close ( ) <EOL> def pop_build_root_and_goals ( description , args ) : <EOL> def usage ( error_message ) : <EOL> print ( error_message , file = sys . stderr ) <EOL> print ( dedent ( """<STR_LIT>""" . format ( sys . argv [ <NUM_LIT:0> ] ) ) , file = sys . stderr ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> usage ( '<STR_LIT>' ) <EOL> build_root = args . pop ( <NUM_LIT:0> ) <EOL> if not os . path . isdir ( build_root ) : <EOL> usage ( '<STR_LIT>' . format ( build_root ) ) <EOL> build_root = os . path . realpath ( build_root ) <EOL> def is_goal ( arg ) : return os . path . sep not in arg <EOL> goals = [ arg for arg in args if is_goal ( arg ) ] <EOL> if not goals : <EOL> usage ( '<STR_LIT>' ) <EOL> return build_root , goals , [ arg for arg in args if not is_goal ( arg ) ] <EOL> def main_addresses ( ) : <EOL> build_root , goals , args = pop_build_root_and_goals ( '<STR_LIT>' , sys . argv [ <NUM_LIT:1> : ] ) <EOL> cmd_line_spec_parser = CmdLineSpecParser ( build_root ) <EOL> spec_roots = [ cmd_line_spec_parser . parse_spec ( spec ) for spec in args ] <EOL> visualize_build_request ( build_root , goals , spec_roots ) <EOL> def main_filespecs ( ) : <EOL> build_root , goals , args = pop_build_root_and_goals ( '<STR_LIT>' , sys . argv [ <NUM_LIT:1> : ] ) <EOL> path_globs = [ PathGlobs . create ( Files , '<STR_LIT>' , globs = [ arg ] ) for arg in args ] <EOL> visualize_build_request ( build_root , goals , path_globs ) </s>
