3 Bu_#7@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZddlmZerdd lmZmZmZmZmZmZmZejZed eZeje Z!d d Z"d dZ#eddddddZ$e rdndZ%ddZ&Gddde'Z(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) configparser)ConfigurationError!ConfigurationFileCouldNotBeLoaded)appdirs)WINDOWS expanduser) ensure_direnum)MYPY_CHECK_RUNNING)AnyDictIterableListNewTypeOptionalTupleKindcCs*|jjdd}|jdr&|dd}|S)zFMake a name consistent regardless of source (environment or file) _-z--N)lowerreplace startswith)namer/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/configuration.py_normalize_name*s  rcCs&d|krdj|}t||jddS)N.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?)formatrsplit)r error_messagerrr_disassemble_key4s r"userglobalsiteenvzenv-var)USERGLOBALSITEENVENV_VARzpip.inizpip.confcCspddtjdD}tjjtjt}tjjtdt r8dndt}tjjtj dt}t j |t j |gt j||giS)NcSsg|]}tjj|tqSr)ospathjoinCONFIG_BASENAME).0r-rrr Osz+get_configuration_files..pip~z.pip)rsite_config_dirsr,r-r.sysprefixr/rruser_config_dirkindsr(r)r')global_config_filessite_config_filelegacy_config_filenew_config_filerrrget_configuration_filesLs 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. Ncstt|jtjtjtjdg}||krJtdjdj t t |dd ||_ ||_ tjtjtjtjtjg|_ddg|_dd|jD|_dd|jD|_g|_dS) Nz5Got invalid value for load_only - should be one of {}z, rversionhelpcSsi|] }g|qSrr)r0variantrrr sz*Configuration.__init__..cSsi|] }i|qSrr)r0rArrrrBs)superr>__init__r8r'r(r)rrr.mapreprisolated load_onlyr*r+_override_order_ignore_env_names_parsers_config_modified_parsers)selfrHrI_valid_load_only) __class__rrrEqs   zConfiguration.__init__cCs|j|js|jdS)zELoads configuration from configuration files and environment N)_load_config_filesrH_load_environment_vars)rOrrrloadszConfiguration.loadc Cs8|jdk stdy |jdStk r2dSXdS)z@Returns the file with highest priority in configuration Nz)Need to be specified a file to be editingr)rIAssertionError_get_parser_to_modify IndexError)rOrrrget_file_to_edits   zConfiguration.get_file_to_editcCs |jjS)z`Returns key-value pairs like dict.items() representing the loaded configuration ) _dictionaryitems)rOrrrrZszConfiguration.itemsc Cs2y |j|Stk r,tdj|YnXdS)z,Get a value from the configuration. zNo such key - {}N)rYKeyErrorrr)rOkeyrrr get_values zConfiguration.get_valuecCst|j|jst|j\}}|dk rTt|\}}|j|sF|j||j|||||j|j|<|j ||dS)z-Modify a value in the configuration. N) _ensure_have_load_onlyrIrUrVr" has_section add_sectionsetrM_mark_as_modified)rOr\valuefnameparsersectionrrrr set_values     zConfiguration.set_valuecCs|j|jst||j|jkr0tdj||j\}}|dk rt|\}}|j|od|j ||sntd|j |s|j ||j |||j|j|=dS)z#Unset a value in the configuration.zNo such key - {}Nz4Fatal Internal error [id=1]. Please report as a bug.) r^rIrUrMrrrVr"r_ remove_optionrZremove_sectionrb)rOr\rdrerfrrrr unset_values        zConfiguration.unset_valuec Cs\|jxN|jD]D\}}tjd|ttjj|t|d}|j |WdQRXqWdS)z*Save the current in-memory state. z Writing to %swN) r^rNloggerinforr,r-dirnameopenwrite)rOrdrefrrrsaves   zConfiguration.savecCs$|jdkrtdtjd|jdS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rIrrldebug)rOrrrr^s z$Configuration._ensure_have_load_onlycCs(i}x|jD]}|j|j|q W|S)zWdS)z5Loads configuration from configuration files rrzZSkipping loading configuration files due to environment's PIP_CONFIG_FILE being os.devnullNz Skipping file '%s' (variant: %s)) dictiter_config_filesr8r*r,devnullrlrsrZrI _load_filerLappend)rO config_filesrAfilesrdrerrrrR s    z Configuration._load_config_filescCsPtjd|||j|}x2|jD]&}|j|}|j|j|j||q"W|S)Nz'For variant '%s', will try loading '%s')rlrs_construct_parsersectionsrZrMrt_normalized_keys)rOrArdrerfrZrrrry$s   zConfiguration._load_filecCstj}tjj|r|y|j|WnXtk rNtdjt j d|dYn.tj k rz}zt|dWYdd}~XnX|S)Nzcontains invalid {} charactersF)reasonrd)error) rRawConfigParserr,r-existsreadUnicodeDecodeErrorrrlocalegetpreferredencodingError)rOrdrerrrrr}/s   zConfiguration._construct_parsercCs"|jtjj|jd|jdS)z7Loads configuration from environment variables z:env:N)rMr8r+rtrget_environ_vars)rOrrrrSFs z$Configuration._load_environment_varscCs2i}x(|D] \}}|dt|}|||<q W|S)zNormalizes items to construct a dictionary with normalized keys. This routine is where the names become keys and are made the same regardless of source - configuration files or environment. r)r)rOrfrZ normalizedrvalr\rrrrNs  zConfiguration._normalized_keysccsVxPtjjD]B\}}|jdo2|ddj|jk}|r |ddj|fVq WdS)z@Returns a generator with all environmental vars with prefix PIP_PIP_N)r,environrZrrrK)rOr\rshould_be_yieldedrrrr[s  zConfiguration.get_environ_varsccstjjdd}|dk r&tj|gfVn tjgfVt}tj|tjfV|j ob|o`tjj | }|rztj |tj fVtj |tj fVdS)zYields variant and configuration files associated with it. This should be treated like items of a dictionary. PIP_CONFIG_FILEN) r,rgetr8r*r=r(rHr-rr'r))rO config_filer{should_load_user_configrrrrwgs  zConfiguration.iter_config_filescCs |j|S)z#Get values present in a config file)rM)rOrArrrget_values_in_configsz"Configuration.get_values_in_configcCs*|js t|j|j}|s"td|dS)Nz4Fatal Internal error [id=2]. Please report as a bug.rrC)rIrUrLr)rOparsersrrrrVs   z#Configuration._get_parser_to_modifycCs"||f}||jkr|jj|dS)N)rNrz)rOrdrefile_parser_tuplerrrrbs zConfiguration._mark_as_modifiedcCsdj|jj|jS)Nz{}({!r}))rrQ__name__rY)rOrrr__repr__szConfiguration.__repr__)N)r __module__ __qualname____doc__rErTrXrZr]rgrjrrr^propertyrYrRryr}rSrrrwrrVrbr __classcell__rr)rQrr>cs,       r>))rrloggingr,r5pip._vendor.six.movesrpip._internal.exceptionsrrZpip._internal.utilsrpip._internal.utils.compatrrpip._internal.utils.miscrr pip._internal.utils.typingr typingr r r rrrrrstrr getLoggerrrlrr"r8r/r=objectr>rrrr s4   $