a hK@sdgZddlZddlZddlZddlZddlZddlZddlZddl Zddl Zddl Zddl m Z ddlmZddlmZddlmZddlZddlmZddlmZdd lmZmZdd l mZdd lmZdd lm Z dd lm!Z!ddl"m#Z#ddl$Z$ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*Z*e+de+dddZ,ddZ-ddZ.ddZ/ddZ0e1e2fZ3dd Z4d!d"Z5d#d$Z6d%d&Z7d'd(Z8d)d*Z9d+d,Z:d-d.Z;d/d0Zd5d6Z?e'ej@jAZBGd7ddeBZAGd8d9d9e#ZCd._read_fieldcs|d}|gkrdS|SN)Zget_all)r.valuesr0rr _read_listOs z!read_pkg_file.._read_listzmetadata-versionr.versionZsummaryauthorNz author-emailz home-pagelicensez download-url descriptionkeywords,platformZ classifierrr'r&r(z license-file)r r rr.r6r9r7r# author_emailr$urlr8r*Zlong_descriptionsplitr:Z platformsr)r'r&r( license_files)r+filer2r5rr0r read_pkg_fileEs<                 rBcCs"d|vrtd|dd}|S)N z1newlines not allowed and will break in the future )rrreplace)valrrr single_line|s  rGc s|}fdd}|dt||d||d||dt||d||tdkr|d ||d | n.d }|D]$\}}t ||}|d ur|||q|d | |j r|d|j |j D]}|dd|qt|} |d| d|} | r(|d| |tdkrR|D]} |d| q>n|d||d||d||d||d|t|dr|d|j|jr|d|j|jr|jD]} |d| q|d|jp gd S)z5Write the PKG-INFO format data to a file object. csd||fdS)Nz%s: %s )write)keyr/rArr write_fieldsz#write_pkg_file..write_fieldzMetadata-VersionNameVersionZSummaryz Home-pagerAuthor Author-email))rNr7)rOr=)Z Maintainerr#)zMaintainer-emailr$NZLicensez Download-URLz Project-URLz%s, %sZ Descriptionr;ZKeywordsZPlatformZ ClassifierZRequiresZProvidesZ ObsoletesrzRequires-PythonzDescription-Content-TypezProvides-Extraz License-File)r-strZget_nameZ get_versionrGZget_descriptionZget_urlr Z get_contactZget_contact_emailr Z get_licenser*r%itemsr Zget_long_descriptionjoinZ get_keywordsZ get_platformsZ _write_listZget_classifiersZ get_requiresZ get_providesZ get_obsoleteshasattrrr!r"r@) r+rAr6rKZoptional_fieldsZfieldattrZattr_valZ project_urlZ long_descr:r<extrarrJrwrite_pkg_filesX             rVc CsXztjd|}Wn>ttttfyR}ztd||f|WYd}~n d}~00dS)Nzx=z4%r must be importable 'module:attrs' string (got %r)) pkg_resources EntryPointparse TypeError ValueErrorAttributeErrorAssertionErrorr )distrTr/eperrrcheck_importablesrac CsHzWn>ttttfyB}ztd||f|WYd}~n d}~00dS)z"Verify that value is a string listz%%r must be a list of strings (got %r)N)rZr[r\r]r r^rTr/r`rrrassert_string_lists rccCsd|}t||||D]J}||s2tdd||d\}}}|r||vrtjd||qdS)z(Verify that namespace packages are validz1Distribution contains no modules or packages for znamespace package %r.z^WARNING: %r is declared as a package namespace, but %r is not: please correct this in setup.pyN)rchas_contents_forr rpartition distutilslogr)r^rTr/Z ns_packagesZnspparentsepchildrrr check_nsps   rlc CsRzttt|Wn4tttfyL}ztd|WYd}~n d}~00dS)z+Verify that extras_require mapping is validz'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.N) list itertoolsstarmap _check_extrarQrZr[r\r rbrrr check_extrassrqcCs<|d\}}}|r*t|r*td|tt|dS)N:zInvalid environment marker: ) partitionrWZinvalid_markerr rmparse_requirements)rUZreqsr.rjmarkerrrrrp s rpcCs&t||kr"d}t|j||ddS)z)Verify that value is True, False, 0, or 1z0{attr!r} must be a boolean value (got {value!r}))rTr/N)boolr format)r^rTr/tmplrrr assert_bools ryc Csnz(tt|t|ttfr&tdWn@ttfyh}z$d}t|j ||d|WYd}~n d}~00dS)z9Verify that install_requires is a valid requirements listzUnordered types are not allowedzm{attr!r} must be a string or list of strings containing valid project/version requirement specifiers; {error}rTerrorN) rmrWrt isinstancedictsetrZr[r rwr^rTr/r{rxrrrcheck_requirementss  rc CsVztj|Wn@tjjyP}z$d}t|j||d|WYd}~n d}~00dS)z.Verify that value is a valid version specifierzF{attr!r} must be a string containing valid version specifiers; {error}rzN)rZ specifiersZ SpecifierSetZInvalidSpecifierr rwrrrrcheck_specifier's rc CsDztj|Wn.ty>}zt||WYd}~n d}~00dS)z)Verify that entry_points map is parseableN)rWrXZ parse_mapr[r rbrrrcheck_entry_points5srcCst|tstddS)Nztest_suite must be a string)r|rPr )r^rTr/rrrcheck_test_suite=s rcCsZt|tstd||D]4\}}t|tsBtd||t|d||q dS)z@Verify that value is a dictionary of package names to glob listszT{!r} must be a dictionary mapping package names to lists of string wildcard patternsz,keys of {!r} dict must be strings (got {!r})zvalues of {!r} dictN)r|r}r rwrQrPrc)r^rTr/kvrrrcheck_package_dataBs  rcCs(|D]}td|stjd|qdS)Nz \w+(\.\w+)*z[WARNING: %r not a valid package name; please use only .-separated package names in setup.py)rematchrgrhr)r^rTr/Zpkgnamerrrcheck_packagesQs  rc@sVeZdZdZdeejdddddZdZddZ dLd d Z e d d Z e d dZ ddZddZe ddZddZddZddZe ddZdMddZdNdd ZdOd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Z d6d7Z!d8d9Z"d:d;Z#dd?Z%d@dAZ&dBdCZ'dDdEZ(dFdGZ)dHdIZ*dJdKZ+dS)PraG Distribution with support for tests and package data This is an enhanced version of 'distutils.dist.Distribution' that effectively adds the following new optional keyword arguments to 'setup()': 'install_requires' -- a string or sequence of strings specifying project versions that the distribution requires when installed, in the format used by 'pkg_resources.require()'. They will be installed automatically when the package is installed. If you wish to use packages that are not available in PyPI, or want to give your users an alternate download location, you can add a 'find_links' option to the '[easy_install]' section of your project's 'setup.cfg' file, and then setuptools will scan the listed web pages for links that satisfy the requirements. 'extras_require' -- a dictionary mapping names of optional "extras" to the additional requirement(s) that using those extras incurs. For example, this:: extras_require = dict(reST = ["docutils>=0.3", "reSTedit"]) indicates that the distribution can optionally provide an extra capability called "reST", but it can only be used if docutils and reSTedit are installed. If the user installs your package using EasyInstall and requests one of your extras, the corresponding additional requirements will be installed if needed. 'test_suite' -- the name of a test suite to run for the 'test' command. If the user runs 'python setup.py test', the package will be installed, and the named test suite will be run. The format is the same as would be used on a 'unittest.py' command line. That is, it is the dotted name of an object to import and call to generate a test suite. 'package_data' -- a dictionary mapping package names to lists of filenames or globs to use to find data files contained in the named packages. If the dictionary has filenames or globs listed under '""' (the empty string), those names will be searched for in every package, in addition to any names for the specific package. Data files found using these names/globs will be installed along with the package, in the same location as the package. Note that globs are allowed to reference the contents of non-package subdirectories, as long as you use '/' as a path separator. (Globs are automatically converted to platform-specific paths at runtime.) In addition to these new keywords, this class also has several new methods for manipulating the distribution's contents. For example, the 'include()' and 'exclude()' methods can be thought of as in-place add and subtract commands that add or remove packages, modules, extensions, and so on from the distribution. NcCsdSr3rrrrrzDistribution.cCsdSr3rrrrrrr)r!r%r" license_filer@cCsl|rd|vsd|vrdStt|d}tjj|}|durh|dshtt|d|_ ||_ dS)Nr.r6zPKG-INFO) rWZ safe_namerPlower working_setZby_keygetZ has_metadataZ safe_version_version _patched_dist)r+attrsrIr^rrrpatch_missing_pkg_infosz#Distribution.patch_missing_pkg_infocstd}|si_|pi}g_|dd_||dg_|dg_t dD]}t  |j dq`t fdd|DjD]J\}}jj|fD]}||vr||}qq|r|nd}tj||qjjj_dS)N package_datasrc_rootdependency_linkssetup_requiresdistutils.setup_keywordscs i|]\}}|jvr||qSr)_DISTUTILS_UNSUPPORTED_METADATA.0rrr+rr s z)Distribution.__init__..)rSrZ dist_filespoprrrrrWiter_entry_pointsvars setdefaultr. _Distribution__init__rQrmetadata__dict__setattr_normalize_version_validate_versionr6_finalize_requires)r+rZhave_package_datar_optiondefaultsourcer/rrrrs2   zDistribution.__init__cCsTt|tjs|dur|Sttj|}||krPd}t|j fit |S|S)Nz)Normalizing '{version}' to '{normalized}') r| setuptoolssicrPrr6rMrrrwlocals)r6Z normalizedrxrrrrszDistribution._normalize_versionc Csdt|tjrt|}|dur`ztj|Wn2tjjtfy^t d|t |YS0|S)NzThe version specified (%r) is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.) r|numbersNumberrPrr6rMZInvalidVersionrZrrrr)r6rrrrs zDistribution._validate_versioncCsft|ddr|j|j_t|ddrR|jD]$}|dd}|r,|jj|q,|| dS)z Set `metadata.python_requires` and fix environment markers in `install_requires` and `extras_require`. rNextras_requirerrr) r rrrkeysr?r"add_convert_extras_requirements"_move_install_requirements_markers)r+rUrrrrs   zDistribution._finalize_requirescCsht|ddpi}tt|_|D]@\}}|j|t|D]"}||}|j|||q>q"dS)z Convert requirements in `extras_require` of the form `"extra": ["barbazquux; {marker}"]` to `"extra:{marker}": ["barbazquux"]`. rN) r rrm_tmp_extras_requirerQrWrt _suffix_forappend)r+Z spec_ext_reqssectionrrsuffixrrrrs   z)Distribution._convert_extras_requirementscCs|jrdt|jSdS)ze For a requirement, return the 'extras_require' suffix for that requirement. rr)rurPreqrrrr szDistribution._suffix_forcsdd}tddpd}tt|}t||}t||}ttt|_ |D]}j dt|j  |qPt fddj D_dS) zv Move requirements in `install_requires` that are using environment markers `extras_require`. cSs|j Sr3rurrrr is_simple_reqszFDistribution._move_install_requirements_markers..is_simple_reqinstall_requiresNrrrc3s,|]$\}}|ddtj|DfVqdS)cSsg|] }t|qSr)rP)rrrrr *rzMDistribution._move_install_requirements_markers...N)map _clean_reqrrrr )szBDistribution._move_install_requirements_markers..)r rmrWrtfilterrn filterfalserrPrrrurr}rQr)r+rZspec_inst_reqsZ inst_reqsZ simple_reqsZ complex_reqsrrrrrs    z/Distribution._move_install_requirements_markerscCs d|_|S)zP Given a Requirement, remove environment markers and return it. Nr)r+rrrrr.szDistribution._clean_reqcCs`|jj}|r|ng}|jj}|r2||vr2|||durF|durFd}tt|||j_dS)z.r)rrrrrGszDistribution._expand_patternsc Csddlm}tjtjkrgngd}t|}|dur<|}trJ|d|}t |_ |D]}t j |dd6}tr|dj fit||Wdn1s0Y|D]X}||}||} |D]:} | d ks| |vrq||| } | d d } || f| | <qq|qZd |jvr.dS|jd D]\} \} } |j| } | rft|  } n| d vrxt| } zt|| p| | Wn0ty}zt||WYd}~n d}~00q.z1error in %s: command '%s' has no such option '%s')Zget_command_namerrrrQZboolean_optionsr\rr|rPrrrSr r[) r+Z command_objZ option_dictZ command_namerrr/Z bool_optsneg_optZ is_stringr`rrr_set_command_optionssF             z!Distribution._set_command_optionsFcCs0|j|dt||j|d||dS)zYParses configuration files from various levels and loads configuration. )r)ignore_option_errorsN)rrrrr)r+rrrrrparse_config_filess  zDistribution.parse_config_filescCs8tjjt||jdd}|D]}tjj|ddq|S)zResolve pre-setup requirementsT) installerZreplace_conflicting)rE)rWrresolvertfetch_build_eggr)r+r'Zresolved_distsr^rrrfetch_build_eggsszDistribution.fetch_build_eggscCs>d}dd}tddt|}t||dD] }||q,dS)z Allow plugins to apply arbitrary operations to the distribution. Each hook may optionally define a 'order' to influence the order of execution. Smaller numbers go first and the default is 0. z(setuptools.finalize_distribution_optionscSs t|ddS)Norderr)r )hookrrrby_ordersz/Distribution.finalize_options..by_ordercSs|Sr3)load)r`rrrrrz/Distribution.finalize_options..)rIN)rrWrsorted)r+grouprepsr_rrrfinalize_optionss zDistribution.finalize_optionscCsJtdD]:}t||jd}|dur |j|jd|||j|q dS)Nrr)rWrr r.requirerr)r+r_r/rrr_finalize_setup_keywordss z%Distribution._finalize_setup_keywordscCs*t|ddr dd|jD|_ng|_dS)Nconvert_2to3_doctestscSsg|]}tj|qSr)rrabspathrprrrrsz8Distribution._finalize_2to3_doctests..)r rrrrr_finalize_2to3_doctestss   z$Distribution._finalize_2to3_doctestscCstjtjd}tj|st|t|tj|d}t|d.}| d| d| dWdn1s|0Y|S)Nz.eggsz README.txtwzcThis directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. zAThis directory caches those eggs to prevent repeated downloads. z/However, it is safe to delete this directory. ) rrrRcurdirexistsmkdirrZ hide_filerrH)r+Z egg_cache_dirZreadme_txt_filenamefrrrget_egg_cache_dirs      (zDistribution.get_egg_cache_dircCsddlm}|||S)z Fetch an egg needed for buildingr)r)Zsetuptools.installerr)r+rrrrrr s zDistribution.fetch_build_eggcCs\||jvr|j|Std|}|D]*}|j|jd||j|<}|St||S)z(Pluggable version of get_command_class()distutils.commandsrN)cmdclassrWrrrrrget_command_class)r+commandrr_rrrrrs   zDistribution.get_command_classcCs:tdD]$}|j|jvr |}||j|j<q t|SNr)rWrr.rrrprint_commandsr+r_rrrrrs  zDistribution.print_commandscCs:tdD]$}|j|jvr |}||j|j<q t|Sr)rWrr.rrrget_command_listrrrrr#s  zDistribution.get_command_listcKs@|D]2\}}t|d|d}|r.||q|||qdS)aAdd items to distribution that are named in keyword arguments For example, 'dist.include(py_modules=["x"])' would add 'x' to the distribution's 'py_modules' attribute, if it was not already there. Currently, this method only supports inclusion for attributes that are lists or tuples. If you need to add support for adding to other attributes in this or a subclass, you can add an '_include_X' method, where 'X' is the name of the attribute. The method will be called with the value passed to 'include()'. So, 'dist.include(foo={"bar":"baz"})' will try to call 'dist._include_foo({"bar":"baz"})', which can then handle whatever special inclusion logic is needed. Z _include_N)rQr _include_misc)r+rrrincluderrrr+s  zDistribution.includecsfd|jr&fdd|jD|_|jrDfdd|jD|_|jrbfdd|jD|_dS)z9Remove packages, modules, and extensions in named packagerdcs"g|]}|kr|s|qSr startswithrpackagepfxrrrFsz0Distribution.exclude_package..cs"g|]}|kr|s|qSrrrrrrrLscs&g|]}|jkr|js|qSr)r.rrrrrrRsN)packages py_modules ext_modules)r+rrrrexclude_packageAs   zDistribution.exclude_packagecCs2|d}|D]}||ks&||rdSqdS)z.r|sequencer r r\r)r+r.r/oldr`rr)r _exclude_misc`s$  zDistribution._exclude_miscc st|tstd||fzt||Wn2tyZ}ztd||WYd}~n d}~00durrt|||n:ttst|dn"fdd|D}t|||dS)zAHandle 'include()' for list/tuple attrs without a special handlerz%s: setting must be a list (%r)r%Nr&csg|]}|vr|qSrrr'r,rrrrz.Distribution._include_misc..r*)r+r.r/r`newrr.rrss(   zDistribution._include_misccKs@|D]2\}}t|d|d}|r.||q|||qdS)aRemove items from distribution that are named in keyword arguments For example, 'dist.exclude(py_modules=["x"])' would remove 'x' from the distribution's 'py_modules' attribute. Excluding packages uses the 'exclude_package()' method, so all of the package's contained packages, modules, and extensions are also excluded. Currently, this method only supports exclusion from attributes that are lists or tuples. If you need to add support for excluding from other attributes in this or a subclass, you can add an '_exclude_X' method, where 'X' is the name of the attribute. The method will be called with the value passed to 'exclude()'. So, 'dist.exclude(foo={"bar":"baz"})' will try to call 'dist._exclude_foo({"bar":"baz"})', which can then handle whatever special exclusion logic is needed. Z _exclude_N)rQr r-)r+rrrexcluderrrr0s  zDistribution.excludecCs,t|tstd|ftt|j|dS)Nz.packages: setting must be a list or tuple (%r))r|r+r rmrr#)r+r rrr_exclude_packagess  zDistribution._exclude_packagesc Cs|jj|_|jj|_|d}|d}||vrf||\}}||=ddl}||d|dd<|d}q&t|||}||} t | ddrd|f||d<|durgS|S)NraliasesTrZcommand_consumes_arguments command lineargs) __class__Zglobal_optionsrrshlexr?r_parse_command_optsrr ) r+rr4rr2rrr6nargsZ cmd_classrrrr7s"       z Distribution._parse_command_optsc Csi}|jD]\}}|D]\}\}}|dkr4q|dd}|dkr||}|j}|t|di|D]\} } | |krv| }d}qqvtdn |dkrd}|| |i|<qq|S) ahReturn a '{cmd: {opt:val}}' map of all command-line options Option names are all long, but do not include the leading '--', and contain dashes rather than underscores. If the option doesn't take an argument (e.g. '--quiet'), the 'val' is 'None'. Note that options provided by config files are intentionally excluded. r3rrrrNzShouldn't be able to get herer) rrQrEZget_command_objrcopyupdater r]r) r+dcmdZoptsrrrFZcmdobjrnegposrrrget_cmdline_optionss(     z Distribution.get_cmdline_optionsccsv|jpdD] }|Vq |jpdD] }|Vq |jp4dD]:}t|trN|\}}n|j}|drj|dd}|Vq6dS)z@Yield all packages, modules, and extension names in distributionrmoduleNi)r r!r"r|tupler.r)r+pkgr@extr.Z buildinforrrr$s    z$Distribution.iter_distribution_namesc Csddl}|jrt||St|jtjs4t||S|jj dvrPt||S|jj}|jj }|j dkrndppd}|jj }t|j d||||_z(t||Wt|j |||||_St|j |||||_0dS)zIf there were any non-global "display-only" options (--help-commands or the metadata display options) on the command line, display the requested info and return true; else return false. rN)rutf8win32rCr)rZ help_commandsrhandle_display_optionsr|stdoutr TextIOWrapperrrerrorsr<line_bufferingdetach)r+Z option_orderrrrInewlinerJrrrrFs2    z#Distribution.handle_display_options)N)N)N)NF),r __module__ __qualname____doc__r}rZ OrderedSetrrrr staticmethodrrrrrrrrrrrrrrrr rrrrrrr#rer-rr0r1r7r?r$rFrrrrr]s\4 "    B /     (c@seZdZdZdS)rzrClass for warning about deprecations in dist in setuptools. Not ignored by default, unlike DeprecationWarning.N)rrMrNrOrrrrrsrccsdt}|j}|dur8t|j|D]}|||Vq"n(|D]"}||}||vr<|||Vqsr              7 I   G