3 K]VF@sddlmZmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZddlmZmZddlmZdd d Zd d ZdddZGdddeZGdddeZGdddeZdS))absolute_importunicode_literalsN) defaultdict)partial) import_module)DistutilsOptionErrorDistutilsFileError) LegacyVersionparse) string_typesFc Csddlm}m}tjj|}tjj|s4td|tj}tj tjj |zJ|}|rb|j ng}||krx|j ||j ||dt||j|d}Wdtj |Xt|S)a,Read given configuration file and returns options from it as a dict. :param str|unicode filepath: Path to configuration file to get options from. :param bool find_others: Whether to search for other configuration files which could be on in various places. :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: dict r) Distribution _Distributionz%Configuration file %s does not exist.) filenames)ignore_option_errorsN)Zsetuptools.distr r ospathabspathisfilergetcwdchdirdirnameZfind_config_filesappendZparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict) filepathZ find_othersrr r Zcurrent_directoryZdistrhandlersr/usr/lib/python3.6/config.pyread_configurations$      rcCsltt}x^|D]V}|j}|j}xD|jD]:}t|d|d}|dkrNt||}n|}||||<q&WqW|S)zReturns configuration data gathered by given handlers as a dict. :param list[ConfigHandler] handlers: Handlers list, usually from parse_configuration() :rtype: dict zget_%sN)rdictsection_prefix target_obj set_optionsgetattr)rZ config_dictZhandlerZ obj_aliasr"Zoptiongettervaluerrrr=s   rcCs6t|||}|jt|j|||j}|j||fS)aPerforms additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: list )ConfigOptionsHandlerr ConfigMetadataHandlermetadata package_dir)Z distributionrroptionsmetarrrrZs rc@seZdZdZdZiZd!ddZeddZdd Z e d"d d Z e d dZ e ddZ e ddZeddZeddZe d#ddZe ddZe d$ddZddZdd ZdS)% ConfigHandlerz1Handles metadata supplied in configuration files.NFcCsbi}|j}x:|jD].\}}|j|s(q|j|djd}|||<qW||_||_||_g|_dS)N.) r!items startswithreplacestriprr"sectionsr#)selfr"r+rr4r! section_namesection_optionsrrr__init__s  zConfigHandler.__init__cCstd|jjdS)z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)NotImplementedError __class____name__)r5rrrparsersszConfigHandler.parsersc Cst}|j}|jj||}t|||}||kr6t||r>dSd}|jj|}|ry ||}Wn tk r~d}|jszYnX|rdSt|d|d}|dkrt |||n|||j j |dS)NFTzset_%s) tupler"aliasesgetr$KeyErrorr< Exceptionrsetattrr#r) r5Z option_namer&unknownr"Z current_valueZ skip_optionparsersetterrrr __setitem__s0   zConfigHandler.__setitem__,cCs8t|tr|Sd|kr |j}n |j|}dd|DS)zRepresents value as a list. Value is split either by separator (defaults to comma) or by lines. :param value: :param separator: List items separator character. :rtype: list  cSsg|]}|jr|jqSr)r3).0chunkrrr sz-ConfigHandler._parse_list..) isinstancelist splitlinessplit)clsr& separatorrrr _parse_lists   zConfigHandler._parse_listcCsTd}i}xF|j|D]8}|j|\}}}||krsz,ConfigHandler._parse_file..rGrHc3s2|]*}j|sdrtjj|rj|VqdS)TN) _assert_localrrr _read_file)rIr)rPrrr` s)rLr r1lenrOjoin)rPr&Zinclude_directivespecZ filepathsr)rPr _parse_files   zConfigHandler._parse_filecCs|jtjstd|dS)Nz#`file:` directive can not access %s)r1rrr)rrrrraszConfigHandler._assert_localc Cs"tj|dd }|jSQRXdS)Nzutf-8)encoding)ioopenread)rfrrrrbszConfigHandler._read_filec Csd}|j|s|S|j|djjd}|j}dj|}|p@d}tj}|r|d|kr||d}|jdd} t | dkrtj jtj| d}| d}q|}nd|krtj jtj|d}t j j d|zt |} t| |}Wdt j ddt _ X|S) zRepresents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:r.r/r8r/N)r1r2r3rOpoprdrrrsplitrcrsysinsertrr$) rPr&r*Zattr_directiveZ attrs_pathZ attr_nameZ module_name parent_pathZ custom_pathpartsmodulerrr _parse_attrs0        zConfigHandler._parse_attrcsfdd}|S)zReturns parser function to represents value as a list. Parses a value applying given methods one after another. :param parse_methods: :rtype: callable cs|}xD] }||}q W|S)Nr)r&parsedmethod) parse_methodsrrr Qs  z1ConfigHandler._get_parser_compound..parser)rPrxr r)rxr_get_parser_compoundHs z"ConfigHandler._get_parser_compoundcCs:i}|pdd}x$|jD]\}\}}||||<qW|S)zParses section options into a dictionary. Optionally applies a given parser to values. :param dict section_options: :param callable values_parser: :rtype: dict cSs|S)Nr)rYrrrfsz6ConfigHandler._parse_section_to_dict..)r0)rPr7Z values_parserr&rW_rYrrr_parse_section_to_dict[s  z$ConfigHandler._parse_section_to_dictc Cs@x:|jD].\}\}}y |||<Wq tk r6Yq Xq WdS)zQParses configuration file section. :param dict section_options: N)r0r@)r5r7namer{r&rrr parse_sectionks  zConfigHandler.parse_sectioncCsfx`|jjD]R\}}d}|r$d|}t|d|jddd}|dkrVtd|j|f||q WdS)zTParses configuration file items from one or more related sections. r.z_%szparse_section%sr/__Nz0Unsupported distribution option section: [%s.%s])r4r0r$r2rr!)r5r6r7Zmethod_postfixZsection_parser_methodrrrr wszConfigHandler.parse)F)rG)N)N)r; __module__ __qualname____doc__r!r>r8propertyr<rF classmethodrRrZr_rf staticmethodrarbruryr|r~r rrrrr-ts(  &     ,   r-csHeZdZdZdddddZdZdfd d Zed d Zd dZ Z S)r(r)Zurl description classifiers platforms)Z home_pageZsummaryZ classifierplatformFNcstt|j|||||_dS)N)superr(r8r*)r5r"r+rr*)r:rrr8szConfigMetadataHandler.__init__c Cs8|j}|j}|j}||||||j||||||j|d S)z.Metadata item name to parser function mapping.) rkeywordsZprovidesZrequiresZ obsoletesrlicenserZlong_descriptionversionZ project_urls)rRrfrZry_parse_version)r5 parse_listZ parse_file parse_dictrrrr<s zConfigMetadataHandler.parserscCs|j|}||kr<|j}tt|tr8td||f|S|j||j}t|rX|}t|t st |dr~dj t t |}nd|}|S)zSParses `version` option value. :param value: :rtype: str z7Version loaded from %s does not comply with PEP 440: %s__iter__r/z%s)rfr3rLr r rrur*callabler hasattrrdmapstr)r5r&rrrrrs    z$ConfigMetadataHandler._parse_version)FN) r;rrr!r>Z strict_moder8rr<r __classcell__rr)r:rr(s r(c@sTeZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ dS)r'r+cCsL|j}t|jdd}|j}|j}|||||||||||||||j|j|dS)z.Metadata item name to parser function mapping.;)rQ)Zzip_safeZuse_2to3Zinclude_package_datar*Zuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsscriptsZeager_resourcesZdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ tests_requireZpackages entry_pointsZ py_modules)rRrr_rZ_parse_packagesrf)r5rZparse_list_semicolonZ parse_boolrrrrr<s*zConfigOptionsHandler.parserscCsBd}|j|s|j|S|j|jjdi}ddlm}|f|S)zTParses `packages` option value. :param value: :rtype: list zfind:z packages.findr) find_packages)r1rRparse_section_packages__findr4r?Z setuptoolsr)r5r&Zfind_directive find_kwargsrrrrrs   z$ConfigOptionsHandler._parse_packagescsT|j||j}dddgtfdd|jD}|jd}|dk rP|d|d<|S)zParses `packages.find` configuration file section. To be used in conjunction with _parse_packages(). :param dict section_options: whereincludeZexcludecs$g|]\}}|kr|r||fqSrr)rIkv) valid_keysrrrKszEConfigOptionsHandler.parse_section_packages__find..Nr)r|rRr r0r?)r5r7Z section_datarrr)rrrs    z1ConfigOptionsHandler.parse_section_packages__findcCs|j||j}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: rN)r|rR)r5r7rvrrrparse_section_entry_points%sz/ConfigOptionsHandler.parse_section_entry_pointscCs.|j||j}|jd}|r*||d<|d=|S)N*r.)r|rRr?)r5r7rvrootrrr_parse_package_data-s  z(ConfigOptionsHandler._parse_package_datacCs|j||d<dS)z`Parses `package_data` configuration file section. :param dict section_options: Z package_dataN)r)r5r7rrrparse_section_package_data7sz/ConfigOptionsHandler.parse_section_package_datacCs|j||d<dS)zhParses `exclude_package_data` configuration file section. :param dict section_options: Zexclude_package_dataN)r)r5r7rrr"parse_section_exclude_package_data>sz7ConfigOptionsHandler.parse_section_exclude_package_datacCs"t|jdd}|j|||d<dS)zbParses `extras_require` configuration file section. :param dict section_options: r)rQZextras_requireN)rrRr|)r5r7rrrrparse_section_extras_requireFsz1ConfigOptionsHandler.parse_section_extras_requireN) r;rrr!rr<rrrrrrrrrrrr's  r')FF)F)Z __future__rrrhrrp collectionsr functoolsr importlibrZdistutils.errorsrrZ#setuptools.extern.packaging.versionr r Zsetuptools.extern.sixr rrrobjectr-r(r'rrrrs"     . M