<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from pex . pex_info import PexInfo <EOL> from six import string_types <EOL> from twitter . common . collections import maybe_list <EOL> from pants . backend . python . targets . python_target import PythonTarget <EOL> from pants . base . exceptions import TargetDefinitionException <EOL> class PythonBinary ( PythonTarget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> source = None , <EOL> entry_point = None , <EOL> inherit_path = False , <EOL> zip_safe = True , <EOL> always_write_cache = False , <EOL> repositories = None , <EOL> indices = None , <EOL> ignore_errors = False , <EOL> platforms = ( ) , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> sources = [ ] if source is None else [ source ] <EOL> super ( PythonBinary , self ) . __init__ ( sources = sources , ** kwargs ) <EOL> if source is None and entry_point is None : <EOL> raise TargetDefinitionException ( self , <EOL> '<STR_LIT>' ) <EOL> if not isinstance ( platforms , ( list , tuple ) ) and not isinstance ( platforms , string_types ) : <EOL> raise TargetDefinitionException ( self , '<STR_LIT>' ) <EOL> self . _entry_point = entry_point <EOL> self . _inherit_path = bool ( inherit_path ) <EOL> self . _zip_safe = bool ( zip_safe ) <EOL> self . _always_write_cache = bool ( always_write_cache ) <EOL> self . _repositories = maybe_list ( repositories or [ ] ) <EOL> self . _indices = maybe_list ( indices or [ ] ) <EOL> self . _ignore_errors = bool ( ignore_errors ) <EOL> self . _platforms = tuple ( maybe_list ( platforms or [ ] ) ) <EOL> if source and entry_point : <EOL> entry_point_module = entry_point . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> entry_source = list ( self . sources_relative_to_source_root ( ) ) [ <NUM_LIT:0> ] <EOL> source_entry_point = self . _translate_to_entry_point ( entry_source ) <EOL> if entry_point_module != source_entry_point : <EOL> raise TargetDefinitionException ( self , <EOL> '<STR_LIT>' . format ( <EOL> source_entry_point , entry_point_module ) ) <EOL> @ property <EOL> def platforms ( self ) : <EOL> return self . _platforms <EOL> @ property <EOL> def repositories ( self ) : <EOL> return self . _repositories <EOL> @ property <EOL> def indices ( self ) : <EOL> return self . _indices <EOL> def _translate_to_entry_point ( self , source ) : <EOL> source_base , _ = os . path . splitext ( source ) <EOL> return source_base . replace ( os . path . sep , '<STR_LIT:.>' ) <EOL> @ property <EOL> def entry_point ( self ) : <EOL> if self . _entry_point : <EOL> return self . _entry_point <EOL> elif self . payload . sources . source_paths : <EOL> assert len ( self . payload . sources . source_paths ) == <NUM_LIT:1> <EOL> entry_source = list ( self . sources_relative_to_source_root ( ) ) [ <NUM_LIT:0> ] <EOL> return self . _translate_to_entry_point ( entry_source ) <EOL> else : <EOL> return None <EOL> @ property <EOL> def pexinfo ( self ) : <EOL> info = PexInfo . default ( ) <EOL> for repo in self . _repositories : <EOL> info . add_repository ( repo ) <EOL> for index in self . _indices : <EOL> info . add_index ( index ) <EOL> info . zip_safe = self . _zip_safe <EOL> info . always_write_cache = self . _always_write_cache <EOL> info . inherit_path = self . _inherit_path <EOL> info . entry_point = self . entry_point <EOL> info . ignore_errors = self . _ignore_errors <EOL> return info </s>
