ó â\e[c @s_dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZddlmZmZddlmZerýdd lmZmZmZmZmZmZmZejZed eƒZnej e!ƒZ"d „Z#d „Z$ed dddddddddƒZ%de&fd„ƒYZ'dS(s 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 iÿÿÿÿN(tsix(t configparser(tConfigurationError(tlegacy_config_filetnew_config_filetrunning_under_virtualenvtsite_config_filestvenv_config_file(t ensure_dirtenum(tMYPY_CHECK_RUNNING(tAnytDicttIterabletListtNewTypetOptionaltTupletKindcCs8|jƒjddƒ}|jdƒr4|d}n|S(sFMake a name consistent regardless of source (environment or file) t_t-s--i(tlowertreplacet startswith(tname((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyt_normalize_name)s cCs|jddƒS(Nt.i(tsplit(R((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyt_disassemble_key3stUSERtusertGLOBALtglobaltVENVtvenvtENVtenvtENV_VARsenv-vart ConfigurationcBsÂeZdZdd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z e d „ƒZd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„ZRS(sâHandles 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. cCsétt|ƒjƒtjtjtjdg}||krhtdj dj t t |d ƒƒƒƒ‚n||_ ||_tjtjtjtjtjg|_ddg|_d„|jDƒ|_d„|jDƒ|_g|_dS(Ns5Got invalid value for load_only - should be one of {}s, iÿÿÿÿtversionthelpcSsi|]}g|“qS(((t.0tvariant((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pys gs cSsi|]}i|“qS(((R)R*((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pys js (tsuperR&t__init__tkindsRRR!tNoneRtformattjointmaptreprtisolatedt load_onlyR#R%t_override_ordert_ignore_env_namest_parserst_configt_modified_parsers(tselfR3R4t_valid_load_only((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyR,Ps %  'cCs$|jƒ|js |jƒndS(sELoads configuration from configuration files and environment N(t_load_config_filesR3t_load_environment_vars(R:((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pytloadns  cCsF|jdk stdƒ‚y|jƒdSWntk rAdSXdS(s@Returns the file with highest priority in configuration s)Need to be specified a file to be editingiN(R4R.tAssertionErrort_get_parser_to_modifyt IndexError(R:((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pytget_file_to_editvs   cCs |jjƒS(s`Returns key-value pairs like dict.items() representing the loaded configuration (t _dictionarytitems(R:((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyRD‚scCs<y|j|SWn&tk r7tdj|ƒƒ‚nXdS(s,Get a value from the configuration. sNo such key - {}N(RCtKeyErrorRR/(R:tkey((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyt get_value‰s cCs—|jƒ|jƒ\}}|dk rot|ƒ\}}|j|ƒsY|j|ƒn|j|||ƒn||j|j|<|j ||ƒdS(s-Modify a value in the configuration. N( t_ensure_have_load_onlyR@R.Rt has_sectiont add_sectiontsetR8R4t_mark_as_modified(R:RFtvaluetfnametparsertsectionR((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyt set_value’s  c Cs-|jƒ||j|jkr8tdj|ƒƒ‚n|jƒ\}}|dk rt|ƒ\}}t}|j |ƒr’|j ||ƒ}n|r t |j |ƒƒ}yt j|ƒ}Wntk rÙd}nX|dkrö|j|ƒn|j||ƒqtdƒ‚n|j|j|=dS(s,Unset a value in the configuration. sNo such key - {}s4Fatal Internal error [id=1]. Please report as a bug.N(RHR8R4RR/R@R.RtFalseRIt remove_optiontiterRDRtnextt StopIterationtremove_sectionRL( R:RFRNRORPRtmodified_somethingt section_itertval((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyt unset_value¥s*      cCss|jƒxb|jD]W\}}tjd|ƒttjj|ƒƒt|dƒ}|j |ƒWdQXqWdS(s)Save the currentin-memory state. s Writing to %stwN( RHR9tloggertinfoRtostpathtdirnametopentwrite(R:RNROtf((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pytsaveÌs  cCs5|jdkrtdƒ‚ntjd|jƒdS(Ns'Needed a specific file to be modifying.s$Will be working with %s variant only(R4R.RR]tdebug(R:((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyRHßscCs2i}x%|jD]}|j|j|ƒqW|S(s<A dictionary representing the loaded configuration. (R5tupdateR8(R:tretvalR*((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyRCåscCsØt|jƒƒ}|tjdd!tjgkrCtjdƒdSxŽ|jƒD]€\}}xq|D]i}|j dk r ||j kr tjd||ƒqcn|j ||ƒ}|j |j ||fƒqcWqPWdS(s5Loads configuration from configuration files iisZSkipping loading configuration files due to environment's PIP_CONFIG_FILE being os.devnullNs Skipping file '%s' (variant: %s)(tdictt_iter_config_filesR-R#R_tdevnullR]RfRDR4R.t _load_fileR7tappend(R:t config_filesR*tfilesRNRO((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyR<ós   cCsltjd||ƒ|j|ƒ}xC|jƒD]5}|j|ƒ}|j|j|j||ƒƒq/W|S(Ns'For variant '%s', will try loading '%s'(R]Rft_construct_parsertsectionsRDR8Rgt_normalized_keys(R:R*RNRORPRD((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyRls $cCsitjƒ}tjj|ƒrey|j|ƒWqetk ratdtj t ƒ|fƒ‚qeXn|S(NsgERROR: Configuration file contains invalid %s characters. Please fix your configuration, located at %s ( RtRawConfigParserR_R`texiststreadtUnicodeDecodeErrorRtlocaletgetpreferredencodingRR(R:RNRO((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyRps   cCs-|jtjj|jd|jƒƒƒdS(s7Loads configuration from environment variables s:env:N(R8R-R%RgRrt_get_environ_vars(R:((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyR=+scCs?i}x2|D]*\}}|dt|ƒ}|||RBRDRGRQR[ReRHtpropertyRCR<RlRpR=RrRyRjR@RL(((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyR&Bs(      '       ((R‡RwtloggingR_t pip._vendorRtpip._vendor.six.movesRtpip._internal.exceptionsRtpip._internal.locationsRRRRRtpip._internal.utils.miscRR tpip._internal.utils.typingR ttypingR R R RRRRRststrRt getLoggerR…R]RRR-tobjectR&(((s:/tmp/pip-install-0xiv62/pip/pip/_internal/configuration.pyt s.   (4