U V.a @sdZz ddlZWnek r$YnXddlZddlZddlZddlZddlZddlm Z ddl Z ddl m Z ddl mZmZmZddlmZddlmZddlmZz ddlZWnek rddlZYnXdd lmZddlZed Zd d d d d d d d d dd ddd ddddddddddddddddddZdZdZ d Z!d!d"Z"d@d$d%Z#d&d'Z$d(d)Z%d*d+Z&d,d-Z'd.d/Z(d0d1Z)d2d3Z*d4d5Z+d6d7Z,d8d9Z-d:d;Z.Gdd?d?e0Z1dS)AaThe code in this module is mostly copy/pasted out of the distutils2 source code, as recommended by Tarek Ziade. As such, it may be subject to some change as distutils2 development continues, and will have to be kept up to date. I didn't want to use it directly from distutils2 itself, since I do not want it to be an installation dependency for our packages yet--it is still too unstable (the latest version on PyPI doesn't even install). N) defaultdict)log)DistutilsOptionErrorDistutilsModuleErrorDistutilsFileError)manifest_maker) Distribution) Extension) extra_filesz\s*(.*?)\s*\((.*)\)\s*$)metadata)r Z home_page)r Zsummary)r description)r Z classifier)r platform)r Z requires_dist)r Zsetup_requires_dist)r Z provides_dist)r Zobsoletes_dist)files packages_root)r)rmodules)globalZcommands)backwards_compatuse_2to3)rzip_safe)r tests_require)r)nameversionZauthorZ author_emailZ maintainerZmaintainer_emailZurlr keywordslong_descriptionz download-url classifiers platformslicenseinstall_requiressetup_requiresprovides obsoletes package_dirpackages package_datanamespace_packages data_filesscripts py_modulescmdclassrrrdependency_linksinclude_package_data)rrrrr r$r"r#r%r&r'r)rrr()rrr*)rc Cs|d}t|d}|d|}|d}|dkrztd||gd}WqWq*tk r|dkrh|d8}|d|}||}d}Yq*Xq*||dD]0}zt||}Wqtk rt|YqXq|S)zResolve a name like ``module.object`` to an object and return it. Raise ImportError if the module or name is not found. .Nr)fromlist)splitlen __import__join ImportErrorgetattrAttributeError)rpartsZcursor module_nameZ attr_nameZretpartr:/util.py resolve_names*     r< setup.cfgc Cst}tj|s(tdtj|||i}|D]}t | |||<q>t |dd}t |dd}|rtj|}t j d|z|r&ddt|D}|D]x}t|}z ||Wqtk rtd Yqt d }td ||fttt d YqXqtj|t|} d | d <d| d<t|t|} | rh| | d<t|} | r~| | d<t| t |dd} | rt !t| W5|rt jdX| S)aP Distutils2 to distutils1 compatibility util. This method uses an existing setup.cfg to generate a dictionary of keywords that can be used by distutils.core.setup(kwargs**). :param file: The setup.cfg path. :raises DistutilsFileError: When the setup.cfg file is not found. zfile '%s' does not existr setup_hooksrrrcSsg|]}|dkr|qS)zpbr.hooks.setup_hookr:).0hookr:r:r; szcfg_to_args..z)setup hook %s terminated the installationr,z#setup hook %s raised exception: %s Tr*Fr ext_modules entry_pointsr )" configparserZSafeConfigParserospathexistsrabspathreadZsectionsdictitemshas_get_optionsysinsertpopsplit_multiliner< SystemExitrerrorexc_info traceback format_excexitpbrhooksZ setup_hooksetup_cfg_to_setup_kwargsregister_custom_compilersget_extension_modulesget_entry_points wrap_commandsr Zset_extra_files) rFparserconfigsectionr>r!r@Zhook_fnekwargsrBrCZfiles_extra_filesr:r:r; cfg_to_argssd           rcc" Csi}i}tD]}tt|dkr0t|\}}n tt|dkrPt|d}|}t|||}|s|dkr t||d}|rt|}d}|D]0}t|} z|| d7}W5| Xq|}nq |tkrt |}|t krt|}n"|t kr| dkrd }nd }|r|d kr$d d |D}|dkrg} d} |D]<} t | | } | d}| d}| ||fq:| |d<n|dkrd|i}n|dkrbi}d }d}|D]}d|kr|dd\}}||}}||kr||}||n|}||<n&|r0td|n||d }q|dkr\|}|}n@|dkri}t}|D]"}t|}||}|||<qz|}|||<q d|kr$d} |d}|D]\}g}t||}|D]8} t | | } | d}| d}|||fq|||<qi}|D]D} || D]4\} }|rTd| |f}!n| }!||!g| q8q,|dg|d<||d<|S)zqProcesses the setup.cfg options and converts them to arguments accepted by setuptools' setup() function. r,rrdescription_filer/z )truet1ZyesyTF)rrcSsg|]}td|qS)z\1\2)_VERSION_SPEC_REsub)r?Zpredr:r:r;rAKsz-setup_cfg_to_setup_kwargs..rz6(?P[^;]*);?(?P[^#]*?)(?:\s*#.*)?$package env_markerr!)r#r%N=z1malformed package_data first line %r (misses "=")r%r(extrasz6(?P[^:]*):?(?P[^#]*?)(?:\s*#.*)?$z%s:(%s)extras_require)D1_D2_SETUP_ARGSr1rLrPopencloserIstrip CSV_FIELDS split_csv MULTI_FIELDS BOOL_FIELDSlowerrematchgroupappendr0extendrrKrr<get_command_name setdefaultrO)"r_rbZall_requirementsargr`optionZ in_cfg_valuevaluefilenamererZrequirement_patternZ requirementmZrequirement_packagermr% firstlineprevlinekeyr(distZcls_nameclscmdroZextraZextra_requirementsZ requirementsZ extras_valuerpZ req_groupZ extras_keyr:r:r;rYs                      rYcCst|dd}|rt|}|D]p}t|}t|dr:|j}n|j}t|drR|j}nd|}|j}tj j }||j|f||<t j |t j d|<qdS)zHandle custom compilers; this has no real equivalent in distutils, where additional compilers could only be added programmatically, so we have to hack it in somehow. r compilersrr zcustom compiler %sz distutils.N) rLrPr<hasattrr__name__r __module__ distutilsZ ccompilerZcompiler_classrMr)r_rZcompilerrZdescr8Zccr:r:r;rZs   rZc Cs(d}g}|D]}d|kr(|dd}n |dd}dd|D}t|dkr |dd kr i}|D]}t|||}|sxqbt|}|d krg}|D]P} | dd} t| dkr| dd f} n| d| df} || q|}|||<qb|r d |kr |d|d <|t|d f|q |S) zHandle extension modules) ZsourcesZ include_dirs define_macrosZ undef_macrosZ library_dirsZ librariesZruntime_library_dirsZ extra_objectsZextra_compile_argsZextra_link_argsZexport_symbolsZ swig_optsZdepends:r,rncSsg|] }|qSr:rt)r?lr:r:r;rAsz)get_extension_modules..rdr extensionrNr)r0r1rLrPrtr}r rO) r_ZEXTENSION_FIELDSrBr`labelsZext_argsZfieldrZmacrosZmacror:r:r;r[s>         r[cCs&d|kr iStdd|dDS)aProcess the [entry_points] section of setup.cfg to handle setuptools entry points. This is, of course, not a standard feature of distutils2/packaging, but as there is not currently a standard alternative in packaging, we provide support for them. rCcss|]\}}|t|fVqdSN)rP)r?rrr:r:r; sz#get_entry_points..)rJrK)r_r:r:r;r\s  r\c Cst}||D]\}}i}||D]H\}}|d}|dsT|dr0|dd\}}||i} || |<q0|sqd|kr||dkr|d|} n ||} t || |} | |di|<qdS)Nr,z pre_hook.z post_hook.r+r() rZparse_config_filesZget_command_listZget_option_dictrK startswithr0rZget_command_class wrap_command) rbrr_rXoptvalZ hook_typealiasZ hook_dictr(Z new_cmdclassr:r:r;r]s"    r]c Cs2|fdd}t||tf|t|d|ddS)NcSs"|d|||ddS)Npre_hook post_hook)run_command_hooksrun)selfr(r:r:r;r2s  zwrap_command..runrr)rrrr)typeobjectrget)rr(rXrr:r:r;r1s  rc Cs|dkrtd|t||d}|dkr,dS|D]}t|trz t|}Wqtk r~td}t d||fYqXn|}t |dst d|t d|||z ||Wq4td}t d ||ft ttdYq4Xq4dS) zRun hooks registered for that command and phase. *cmd_obj* is a finalized command object; *hook_kind* is either 'pre_hook' or 'post_hook'. )rrzinvalid hook kind: %rNr,zcannot find hook %s: %s__call__zhook %r is not callablezrunning %s %s for command %szhook %s raised exception: %s ) ValueErrorr5values isinstancestrr<r4rMrSrrrrinforrRrTrUrV)Zcmd_objZ hook_kindrXr@Zhook_objerrrar:r:r;r=s:          rcCsX||kr |||kr |||S||krP|dd||krP|||ddSdSdS)Nr-Freplace)r_r`rr:r:r;rLfs  rLcCs"dddd|dDD}|S)z3Special behaviour when we have a multi line optionscSsg|] }|r|qSr:r:r?Zelementr:r:r;rArsz#split_multiline..css|]}|VqdSrr)r?rr:r:r;rssz"split_multiline.. r0rr:r:r;rPosrPcCs"dddd|dDD}|S)z8Special behaviour when we have a comma separated optionscSsg|] }|r|qSr:r:rr:r:r;rA{szsplit_csv..css|]}|VqdSrr)r?chunkr:r:r;r|szsplit_csv..,rrr:r:r;rvxsrvcsfdd}|S)z[A function decorator to monkey-patch a method of the same name on the given class. cs:t|jd}|r6t|ds6t|d|t|j||S)NZ_orig)r5rrsetattr)funcZorigrr:r;wrappers  z#monkeypatch_method..wrapperr:)rrr:rr;monkeypatch_methods rcs"eZdZdZdfdd ZZS)DefaultGetDictzXLike defaultdict, but the get() method also sets and returns the default value. Ncs"|dkr|}tt|||Sr)default_factorysuperrr)rrdefault __class__r:r;rszDefaultGetDict.get)N)rr __qualname____doc__r __classcell__r:r:rr;rsrcs(eZdZdZddZfddZZS) IgnoreDictzA dictionary that ignores any insertions in which the key is a string matching any string in `ignore`. The ignore list can also contain wildcard patterns using '*'. cCs$tdddd|D|_dS)Nz(%s)|cSsg|]}|ddqS)*z.*r)r?Zpatr:r:r;rAsz'IgnoreDict.__init__..)rzcompiler3_IgnoreDict__ignore)rignorer:r:r;__init__s  zIgnoreDict.__init__cs&|j|rdStt|||dSr)rr{rr __setitem__)rrrrr:r;rs zIgnoreDict.__setitem__)rrrrrrrr:r:rr;rsr)r=)2rZmultiprocessingr4ZloggingrErzrMrT collectionsrZdistutils.ccompilerrrZdistutils.errorsrrrZsetuptools.command.egg_inforZsetuptools.distrZsetuptools.extensionr Z ConfigParserrDrWr Z pbr.hooksrrjrqrwrxrur<rcrYrZr[r\r]rrrLrPrvrrrJrr:r:r:r;.s          ' V"5 )