U ja07@sdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZmZddlmZddlmZddlmZmZejZe deZerd nd Zd Zed d ddddZejejej ej!ej"fZ#ejejej fZ$e%e&Z'ddZ(ddZ)ddZ*GdddZ+dS)a Configuration management setup Some terminology: - name As written in config files. - value Value associated with a name - key Name combined with it's section (section.name) - variant A single word describing where the configuration key-value pair came from N)AnyDictIterableListNewTypeOptionalTuple)ConfigurationError!ConfigurationFileCouldNotBeLoaded)appdirs)WINDOWS) ensure_direnumKindzpip.inizpip.conf)versionhelpuserglobalsiteenvzenv-var)USERGLOBALSITEENVENV_VARcCs*|dd}|dr&|dd}|S)zFMake a name consistent regardless of source (environment or file) _-z--N)lowerreplace startswith)namer"s/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/configuration.py_normalize_name2s  r$cCs&d|krd|}t||ddS)N.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?)formatr split)r! error_messager"r"r#_disassemble_key<sr*cCstddtdD}tjtjt}tjtjdt rIsz+get_configuration_files..pip~z.pip)r site_config_dirsr+r,r-sysprefixr. expanduserr user_config_dirkindsrrr)global_config_filessite_config_filelegacy_config_filenew_config_filer"r"r#get_configuration_filesGs(  r=cseZdZdZd-fdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ e ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZZS). ConfigurationaHandles management of configuration. Provides an interface to accessing and managing configuration files. This class converts provides an API that takes "section.key-name" style keys and stores the value associated with it as "key-name" under the section "section". This allows for a clean interface wherein the both the section and the key-name are preserved in an easy to manage form in the configuration files and the data stored is also nice. Ncsjt|dk r4|tkr4tddttt||_||_ ddt D|_ ddt D|_ g|_ dS)Nz5Got invalid value for load_only - should be one of {}z, cSsi|] }|gqSr"r"r/variantr"r"r# zsz*Configuration.__init__..cSsi|] }|iqSr"r"r?r"r"r#rA}s)super__init__VALID_LOAD_ONLYr r'r-mapreprisolated load_onlyOVERRIDE_ORDER_parsers_config_modified_parsers)selfrGrH __class__r"r#rCls  zConfiguration.__init__cCs||js|dS)zELoads configuration from configuration files and environment N)_load_config_filesrG_load_environment_varsrMr"r"r#loadszConfiguration.loadcCs<|jdk stdz|dWStk r6YdSXdS)z@Returns the file with highest priority in configuration Nz)Need to be specified a file to be editingr)rHAssertionError_get_parser_to_modify IndexErrorrRr"r"r#get_file_to_edits zConfiguration.get_file_to_editcCs |jS)z`Returns key-value pairs like dict.items() representing the loaded configuration ) _dictionaryitemsrRr"r"r#rYszConfiguration.itemscCs4z |j|WStk r.td|YnXdS)z,Get a value from the configuration. No such key - N)rXKeyErrorr )rMkeyr"r"r# get_values zConfiguration.get_valuecCst||jst|\}}|dk rTt|\}}||sF||||||||j|j|<| ||dS)z-Modify a value in the configuration. N) _ensure_have_load_onlyrHrTrUr* has_section add_sectionsetrK_mark_as_modified)rMr\valuefnameparsersectionr!r"r"r# set_values     zConfiguration.set_valuecCs||jst||j|jkr0td||\}}|dk rt|\}}||rf|||sntd| |s| || |||j|j|=dS)z#Unset a value in the configuration.rZNz4Fatal Internal error [id=1]. Please report as a bug.) r^rHrTrKr rUr*r_ remove_optionrYremove_sectionrb)rMr\rdrerfr!r"r"r# unset_values"        zConfiguration.unset_valuec CsX||jD]D\}}td|ttj|t|d}| |W5QRXqdS)z*Save the current in-memory state. z Writing to %swN) r^rLloggerinfor r+r,dirnameopenwrite)rMrdrefr"r"r#saves   zConfiguration.savecCs$|jdkrtdtd|jdS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rHr rldebugrRr"r"r#r^s z$Configuration._ensure_have_load_onlycCs"i}tD]}||j|q|S)z^s.       r>),rrrloggingr+r4typingrrrrrrrpip._internal.exceptionsr r Zpip._internal.utilsr pip._internal.utils.compatr pip._internal.utils.miscr rrstrrr.rr8rrrrrrIrD getLoggerrrlr$r*r=r>r"r"r"r#s8 $