<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> import subprocess <EOL> from pants . base . exceptions import TaskError <EOL> from pants . contrib . go . tasks . go_workspace_task import GoWorkspaceTask <EOL> class GoFmt ( GoWorkspaceTask ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def register_options ( cls , register ) : <EOL> super ( GoFmt , cls ) . register_options ( register ) <EOL> register ( '<STR_LIT>' , type = bool , fingerprint = True , help = '<STR_LIT>' ) <EOL> _GO_SOURCE_EXTENSION = '<STR_LIT>' <EOL> def _is_checked ( self , target ) : <EOL> return target . has_sources ( self . _GO_SOURCE_EXTENSION ) and not target . is_synthetic <EOL> def execute ( self ) : <EOL> if self . get_options ( ) . skip : <EOL> return <EOL> targets = self . context . targets ( self . _is_checked ) <EOL> with self . invalidated ( targets ) as invalidation_check : <EOL> invalid_targets = [ vt . target for vt in invalidation_check . invalid_vts ] <EOL> sources = self . calculate_sources ( invalid_targets ) <EOL> if sources : <EOL> args = [ os . path . join ( self . go_dist . goroot , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ] + list ( sources ) <EOL> try : <EOL> output = subprocess . check_output ( args ) <EOL> except subprocess . CalledProcessError as e : <EOL> raise TaskError ( '<STR_LIT>' . format ( args , e . returncode ) , exit_code = e . returncode ) <EOL> if output : <EOL> raise TaskError ( '<STR_LIT>' . format ( args , output ) ) <EOL> def calculate_sources ( self , targets ) : <EOL> sources = set ( ) <EOL> for target in targets : <EOL> sources . update ( source for source in target . sources_relative_to_buildroot ( ) <EOL> if source . endswith ( self . _GO_SOURCE_EXTENSION ) ) <EOL> return sources </s>
