<s> import os <EOL> import sys <EOL> from contextlib import contextmanager <EOL> from . common import die <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class Variables ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def process_pydoc ( cls , pydoc ) : <EOL> if pydoc is None : <EOL> return '<STR_LIT>' , '<STR_LIT>' <EOL> pydoc = pydoc . splitlines ( ) <EOL> variable_type = pydoc [ <NUM_LIT:0> ] <EOL> variable_text = '<STR_LIT:U+0020>' . join ( filter ( None , ( line . strip ( ) for line in pydoc [ <NUM_LIT:2> : ] ) ) ) <EOL> return variable_type , variable_text <EOL> @ classmethod <EOL> def iter_help ( cls ) : <EOL> for variable_name , value in sorted ( cls . __dict__ . items ( ) ) : <EOL> if not variable_name . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> variable_type , variable_text = cls . process_pydoc ( getattr ( value , '<STR_LIT>' ) ) <EOL> yield variable_name , variable_type , variable_text <EOL> def __init__ ( self , environ = None , rc = '<STR_LIT>' , use_defaults = True ) : <EOL> self . _use_defaults = use_defaults <EOL> self . _environ = environ . copy ( ) if environ else os . environ <EOL> if not self . PEX_IGNORE_RCFILES : <EOL> rc_values = self . _from_rc ( rc ) . copy ( ) <EOL> rc_values . update ( self . _environ ) <EOL> self . _environ = rc_values <EOL> def copy ( self ) : <EOL> return self . _environ . copy ( ) <EOL> def delete ( self , variable ) : <EOL> self . _environ . pop ( variable , None ) <EOL> def set ( self , variable , value ) : <EOL> self . _environ [ variable ] = str ( value ) <EOL> def _from_rc ( self , rc ) : <EOL> ret_vars = { } <EOL> for filename in [ '<STR_LIT>' , rc , os . path . join ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) ] : <EOL> try : <EOL> with open ( os . path . expanduser ( filename ) ) as fh : <EOL> rc_items = map ( self . _get_kv , fh ) <EOL> ret_vars . update ( dict ( filter ( None , rc_items ) ) ) <EOL> except IOError : <EOL> continue <EOL> return ret_vars <EOL> def _get_kv ( self , variable ) : <EOL> kv = variable . strip ( ) . split ( '<STR_LIT:=>' ) <EOL> if len ( list ( filter ( None , kv ) ) ) == <NUM_LIT:2> : <EOL> return kv <EOL> def _defaulted ( self , default ) : <EOL> return default if self . _use_defaults else None <EOL> def _get_bool ( self , variable , default = False ) : <EOL> value = self . _environ . get ( variable ) <EOL> if value is not None : <EOL> if value . lower ( ) in ( '<STR_LIT:0>' , '<STR_LIT:false>' ) : <EOL> return False <EOL> elif value . lower ( ) in ( '<STR_LIT:1>' , '<STR_LIT:true>' ) : <EOL> return True <EOL> else : <EOL> die ( '<STR_LIT>' % ( variable , value ) ) <EOL> else : <EOL> return self . _defaulted ( default ) <EOL> def _get_string ( self , variable , default = None ) : <EOL> return self . _environ . get ( variable , self . _defaulted ( default ) ) <EOL> def _get_path ( self , variable , default = None ) : <EOL> value = self . _get_string ( variable , default = default ) <EOL> if value is not None : <EOL> return os . path . realpath ( os . path . expanduser ( value ) ) <EOL> def _get_int ( self , variable , default = None ) : <EOL> try : <EOL> return int ( self . _environ [ variable ] ) <EOL> except ValueError : <EOL> die ( '<STR_LIT>' % ( variable , self . _environ [ variable ] ) ) <EOL> except KeyError : <EOL> return self . _defaulted ( default ) <EOL> def strip_defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> return Variables ( environ = self . copy ( ) , use_defaults = False ) <EOL> @ contextmanager <EOL> def patch ( self , ** kw ) : <EOL> """<STR_LIT>""" <EOL> old_environ = self . _environ <EOL> self . _environ = self . _environ . copy ( ) <EOL> self . _environ . update ( kw ) <EOL> yield <EOL> self . _environ = old_environ <EOL> @ property <EOL> def PEX_ALWAYS_CACHE ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_COVERAGE ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_COVERAGE_FILENAME ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_path ( '<STR_LIT>' , default = None ) <EOL> @ property <EOL> def PEX_FORCE_LOCAL ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_IGNORE_ERRORS ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_INHERIT_PATH ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_INTERPRETER ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_MODULE ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_string ( '<STR_LIT>' , default = None ) <EOL> @ property <EOL> def PEX_PROFILE ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_path ( '<STR_LIT>' , default = None ) <EOL> @ property <EOL> def PEX_PROFILE_FILENAME ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_path ( '<STR_LIT>' , default = None ) <EOL> @ property <EOL> def PEX_PROFILE_SORT ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_string ( '<STR_LIT>' , default = '<STR_LIT>' ) <EOL> @ property <EOL> def PEX_PYTHON ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_string ( '<STR_LIT>' , default = None ) <EOL> @ property <EOL> def PEX_ROOT ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_path ( '<STR_LIT>' , default = os . path . expanduser ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def PEX_PATH ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_string ( '<STR_LIT>' , default = '<STR_LIT>' ) <EOL> @ property <EOL> def PEX_SCRIPT ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_string ( '<STR_LIT>' , default = None ) <EOL> @ property <EOL> def PEX_TEARDOWN_VERBOSE ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> @ property <EOL> def PEX_VERBOSE ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_int ( '<STR_LIT>' , default = <NUM_LIT:0> ) <EOL> @ property <EOL> def PEX_HTTP_RETRIES ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_int ( '<STR_LIT>' , default = <NUM_LIT:5> ) <EOL> @ property <EOL> def PEX_IGNORE_RCFILES ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_bool ( '<STR_LIT>' , default = False ) <EOL> ENV = Variables ( ) </s>
