<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import os . path <EOL> import sys <EOL> from pip_accel . compat import configparser <EOL> from pip_accel . utils import is_root , expand_path <EOL> from coloredlogs import DEFAULT_LOG_FORMAT <EOL> from cached_property import cached_property <EOL> from humanfriendly import coerce_boolean , parse_path <EOL> logger = logging . getLogger ( __name__ ) <EOL> LOCAL_CONFIG = '<STR_LIT>' <EOL> GLOBAL_CONFIG = '<STR_LIT>' <EOL> class Config ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , load_configuration_files = True , load_environment_variables = True ) : <EOL> """<STR_LIT>""" <EOL> self . overrides = { } <EOL> self . configuration = { } <EOL> self . environment = os . environ if load_environment_variables else { } <EOL> if load_configuration_files : <EOL> for filename in self . available_configuration_files : <EOL> self . load_configuration_file ( filename ) <EOL> @ cached_property <EOL> def available_configuration_files ( self ) : <EOL> """<STR_LIT>""" <EOL> known_files = [ GLOBAL_CONFIG , LOCAL_CONFIG , self . environment . get ( '<STR_LIT>' ) ] <EOL> absolute_paths = [ parse_path ( pathname ) for pathname in known_files if pathname ] <EOL> return [ pathname for pathname in absolute_paths if os . path . isfile ( pathname ) ] <EOL> def load_configuration_file ( self , configuration_file ) : <EOL> """<STR_LIT>""" <EOL> configuration_file = parse_path ( configuration_file ) <EOL> logger . debug ( "<STR_LIT>" , configuration_file ) <EOL> parser = configparser . RawConfigParser ( ) <EOL> files_loaded = parser . read ( configuration_file ) <EOL> if len ( files_loaded ) != <NUM_LIT:1> : <EOL> msg = "<STR_LIT>" <EOL> raise Exception ( msg % configuration_file ) <EOL> elif not parser . has_section ( '<STR_LIT>' ) : <EOL> msg = "<STR_LIT>" <EOL> raise Exception ( msg % configuration_file ) <EOL> else : <EOL> self . configuration . update ( parser . items ( '<STR_LIT>' ) ) <EOL> def __setattr__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> attribute = getattr ( self , name , None ) <EOL> if isinstance ( attribute , ( property , cached_property ) ) : <EOL> self . overrides [ name ] = value <EOL> else : <EOL> self . __dict__ [ name ] = value <EOL> def get ( self , property_name = None , environment_variable = None , configuration_option = None , default = None ) : <EOL> """<STR_LIT>""" <EOL> if self . overrides . get ( property_name ) is not None : <EOL> return self . overrides [ property_name ] <EOL> elif environment_variable and self . environment . get ( environment_variable ) : <EOL> return self . environment [ environment_variable ] <EOL> elif self . configuration . get ( configuration_option ) is not None : <EOL> return self . configuration [ configuration_option ] <EOL> else : <EOL> return default <EOL> @ cached_property <EOL> def cache_format_revision ( self ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:7> <EOL> @ cached_property <EOL> def source_index ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> default = os . path . join ( self . data_directory , '<STR_LIT>' ) ) <EOL> @ cached_property <EOL> def binary_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> default = os . path . join ( self . data_directory , '<STR_LIT>' ) ) <EOL> @ cached_property <EOL> def eggs_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> default = os . path . join ( self . data_directory , '<STR_LIT>' ) ) <EOL> @ cached_property <EOL> def data_directory ( self ) : <EOL> """<STR_LIT>""" <EOL> return expand_path ( self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = '<STR_LIT>' if is_root ( ) else '<STR_LIT>' ) ) <EOL> @ cached_property <EOL> def on_debian ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> default = os . path . exists ( '<STR_LIT>' ) ) <EOL> @ cached_property <EOL> def install_prefix ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> default = '<STR_LIT>' if sys . prefix == '<STR_LIT>' and self . on_debian else sys . prefix ) <EOL> @ cached_property <EOL> def python_executable ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> default = sys . executable or os . path . join ( self . install_prefix , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ cached_property <EOL> def auto_install ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' ) <EOL> if value is not None : <EOL> return coerce_boolean ( value ) <EOL> @ cached_property <EOL> def log_format ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = DEFAULT_LOG_FORMAT ) <EOL> @ cached_property <EOL> def log_verbosity ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = '<STR_LIT>' ) <EOL> @ cached_property <EOL> def max_retries ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' ) <EOL> try : <EOL> n = int ( value ) <EOL> if n >= <NUM_LIT:0> : <EOL> return n <EOL> except : <EOL> return <NUM_LIT:3> <EOL> @ cached_property <EOL> def trust_mod_times ( self ) : <EOL> """<STR_LIT>""" <EOL> on_appveyor = coerce_boolean ( os . environ . get ( '<STR_LIT>' , '<STR_LIT:False>' ) ) <EOL> return coerce_boolean ( self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = ( not on_appveyor ) ) ) <EOL> @ cached_property <EOL> def s3_cache_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = '<STR_LIT>' ) <EOL> @ cached_property <EOL> def s3_cache_bucket ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' ) <EOL> @ cached_property <EOL> def s3_cache_create_bucket ( self ) : <EOL> """<STR_LIT>""" <EOL> return coerce_boolean ( self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = False ) ) <EOL> @ cached_property <EOL> def s3_cache_prefix ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' ) <EOL> @ cached_property <EOL> def s3_cache_readonly ( self ) : <EOL> """<STR_LIT>""" <EOL> return coerce_boolean ( self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' , <EOL> default = False ) ) <EOL> @ cached_property <EOL> def s3_cache_timeout ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' ) <EOL> try : <EOL> n = int ( value ) <EOL> if n >= <NUM_LIT:0> : <EOL> return n <EOL> except : <EOL> return <NUM_LIT> <EOL> @ cached_property <EOL> def s3_cache_retries ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . get ( property_name = '<STR_LIT>' , <EOL> environment_variable = '<STR_LIT>' , <EOL> configuration_option = '<STR_LIT>' ) <EOL> try : <EOL> n = int ( value ) <EOL> if n >= <NUM_LIT:0> : <EOL> return n <EOL> except : <EOL> return <NUM_LIT:5> </s>
