3 K]u@sdgZddlZddlZddlZddlZddlZddlZddlZddl Zddl Z ddl m Z ddl mZmZmZddlmZddlmZddlmZddlmZdd lmZmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#ddl$Z$ddl%m&Z&e'de'dddZ(ddZ)ddZ*e+e,fZ-ddZ.ddZ/ddZ0ddZ1d d!Z2d"d#Z3d$d%Z4d&d'Z5d(d)Z6d*d+Z7d,d-Z8d.d/Z9e!ej:j;ZZ parse_maprAr)rDr8rEerrrcheck_entry_pointssrfcCst|tjstddS)Nztest_suite must be a string)r`r Z string_typesr)rDr8rErrrcheck_test_suites rgc Csdt|trTxH|jD]8\}}t|ts(Py t|Wqtk rJPYqXqWdSt|ddS)z@Verify that value is a dictionary of package names to glob listsNzI must be a dictionary mapping package names to lists of wildcard patterns)r`rar2striterr@r)rDr8rEkvrrrcheck_package_datas    rlcCs,x&|D]}tjd|stjjd|qWdS)Nz \w+(\.\w+)*z[WARNING: %r not a valid package name; please use only .-separated package names in setup.py)rematchrLrMr)rDr8rEZpkgnamerrrcheck_packagess   roc@s0eZdZdZdeedZdZddZdGddZ dd Z d d Z e d d Z ddZddZdHddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Z d5d6Z!d7d8Z"d9d:Z#d;d<Z$d=d>Z%d?d@Z&dAdBZ'dCdDZ(dEdFZ)dS)IraDistribution with support for features, 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. 'features' **deprecated** -- a dictionary mapping option names to 'setuptools.Feature' objects. Features are a portion of the distribution that can be included or excluded based on user options, inter-feature dependencies, and availability on the current system. Excluded features are omitted from all setup commands, including source and binary distributions, so you can create multiple distributions from the same source tree. Feature names should be valid Python identifiers, except that they may contain the '-' (minus) sign. Features can be included or excluded via the command line options '--with-X' and '--without-X', where 'X' is the name of the feature. Whether a feature is included by default, and whether you are allowed to control this from the command line, is determined by the Feature object. See the 'Feature' class for more information. '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. They are used by the feature subsystem to configure the distribution for the included and excluded features. N)rr1rcCsp| sd|ksd|krdStjt|dj}tjjj|}|dk rl|jd rltjt|d|_ ||_ dS)NrYr7zPKG-INFO) r=Z safe_namerhlower working_setZby_keygetZ has_metadataZ safe_versionZ_version _patched_dist)r5attrskeyrDrrrpatch_missing_pkg_infoSsz#Distribution.patch_missing_pkg_infoc std}|si_|pi}d|ks,d|kr4tjg_i_g_|jdd_j ||jdg_ |jdg_ x$t j dD]}tj|jdqWtjfdd |jDx\jjD]N\}}x6jj|fD]}||kr||}PqW|r|nd}tj||qWtjjtjr>tjjj_jjdk ryHtjjjj}t|} jj| krtj d jj| f| j_Wn0tjj!t"fk rtj d jjYnXj#dS) N package_datafeaturesrequire_featuressrc_rootdependency_linkssetup_requireszdistutils.setup_keywordscs i|]\}}|jkr||qSr)_DISTUTILS_UNSUPPORTED_METADATA).0rjrk)r5rr qsz)Distribution.__init__..zNormalizing '%s' to '%s'zThe 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.)$r4rwFeaturewarn_deprecatedryrxZ dist_filespoprzrvr{r|r=iter_entry_pointsvars setdefaultrY _Distribution__init__r2r}metadata__dict__setattrr`r7numbersNumberrhr ZVersionrrZInvalidVersionr@_finalize_requires) r5rtZhave_package_datarFZoptiondefaultsourcerEZverZnormalized_versionr)r5rr`sR    zDistribution.__init__cCsjt|ddr|j|j_t|ddrVx2|jjD]$}|jdd}|r.|jjj|q.W|j|j dS)z Set `metadata.python_requires` and fix environment markers in `install_requires` and `extras_require`. rNextras_requirerVr) r rrrkeyssplitradd_convert_extras_requirements"_move_install_requirements_markers)r5r;rrrrs   zDistribution._finalize_requirescCspt|ddpi}tt|_xP|jD]D\}}|j|x0tj|D]"}|j|}|j||j|qBWq$WdS)z Convert requirements in `extras_require` of the form `"extra": ["barbazquux; {marker}"]` to `"extra:{marker}": ["barbazquux"]`. rN) r rrQ_tmp_extras_requirer2r=rX _suffix_forappend)r5Z spec_ext_reqsZsectionrkrsuffixrrrrs   z)Distribution._convert_extras_requirementscCs|jrdt|jSdS)ze For a requirement, return the 'extras_require' suffix for that requirement. rV)rZrh)reqrrrrszDistribution._suffix_forcsdd}tddpf}ttj|}t||}t||}ttt|_x&|D]}j dt|j j |qPWt fddj j D_dS)zv Move requirements in `install_requires` that are using environment markers `extras_require`. cSs|j S)N)rZ)rrrr is_simple_reqszFDistribution._move_install_requirements_markers..is_simple_reqinstall_requiresNrVc3s,|]$\}}|ddtj|DfVqdS)cSsg|] }t|qSr)rh)r~rrrr szMDistribution._move_install_requirements_markers...N)r _clean_req)r~rjrk)r5rr szBDistribution._move_install_requirements_markers..)r rQr=rXr r r rhrrrZrrar2r)r5rZspec_inst_reqsZ inst_reqsZ simple_reqsZ complex_reqsrr)r5rrs     z/Distribution._move_install_requirements_markerscCs d|_|S)zP Given a Requirement, remove environment markers and return it. N)rZ)r5rrrrrszDistribution._clean_reqFcCs*tj||dt||j|d|jdS)zYParses configuration files from various levels and loads configuration. ) filenames)ignore_option_errorsN)rparse_config_filesrcommand_optionsr)r5rrrrrrszDistribution.parse_config_filescCstj|}|jr|j|S)z3Process features after parsing command line options)rparse_command_linerx_finalize_features)r5resultrrrrs zDistribution.parse_command_linecCsd|jddS)z;Convert feature name to corresponding option attribute nameZwith_-_)replace)r5rYrrr_feature_attrnameszDistribution._feature_attrnamecCs<tjjtj||jdd}x|D]}tjj|ddq W|S)zResolve pre-setup requirementsT) installerZreplace_conflicting)r)r=rqresolverXfetch_build_eggr)r5r!Zresolved_distsrDrrrfetch_build_eggss zDistribution.fetch_build_eggscCstj||jr|jxHtjdD]:}t||jd}|dk r$|j|j d|j ||j|q$Wt|ddrdd|j D|_ ng|_ dS)Nzdistutils.setup_keywords)rconvert_2to3_doctestscSsg|]}tjj|qSr)ospathabspath)r~prrrrsz1Distribution.finalize_options..) rfinalize_optionsrx_set_global_opts_from_featuresr=rr rYrequirerloadr)r5rFrErrrrs  zDistribution.finalize_optionsc Csvtjjtjd}tjj|srtj|tj|tjj|d}t|d$}|j d|j d|j dWdQRX|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. ) rrr3curdirexistsmkdirrZ hide_fileopenr/)r5Z egg_cache_dirZreadme_txt_filenamefrrrget_egg_cache_dirs      zDistribution.get_egg_cache_dirc Csddlm}|jddgi}|jd}|j|jdd|jdjD|jr|jdd}d|krx|dd |}d |f|d<|j}||d g|d d dd d d d d d }|j |j|S)z Fetch an egg needed for buildingr) easy_installZ script_argsrcss"|]\}}|dkr||fVqdS) find_links site_dirs index_urloptimize allow_hostsN)rrrrrrr)r~rjrkrrrr1sz/Distribution.fetch_build_egg..NrrZsetupxTF) args install_dirZexclude_scriptsZ always_copyZbuild_directoryZeditableZupgradeZ multi_versionZ no_reportuser) Zsetuptools.command.easy_installr __class__get_option_dictclearupdater2r{rZensure_finalized)r5rrrDoptsZlinksrcmdrrrr*s(   zDistribution.fetch_build_eggc Csg}|jj}x|jjD]\}}|j|d|j||jr|j}d}d}|js^||}}d|dd||fd|dd||ff}|j |d||d|<qW||j |_ |_ ||_|_ dS)z;Add --with-X/--without-X options based on optional featuresNz (default)rzwith-zinclude zwithout-zexclude ) negative_optcopyrxr2 _set_featurevalidateoptional descriptioninclude_by_defaultextendglobal_optionsZfeature_optionsZfeature_negopt) r5ZgonorYfeaturedescrZincdefZexcdefnewrrrrGs"     z+Distribution._set_global_opts_from_featurescCsxJ|jjD]<\}}|j|}|s2|dkr |jr |j||j|dq Wx6|jjD](\}}|j|sX|j||j|dqXWdS)z9Add/remove features and resolve dependencies between themNrr)rxr2feature_is_includedr include_inr exclude_from)r5rYrZenabledrrrrbs    zDistribution._finalize_featurescCs`||jkr|j|Stjd|}x:|D]&}|j|jd|j|j|<}|SWtj||SdS)z(Pluggable version of get_command_class()zdistutils.commands)rN)cmdclassr=rrrrrget_command_class)r5commandZepsrFrrrrrss    zDistribution.get_command_classcCs>x2tjdD]$}|j|jkr |j}||j|j<q Wtj|S)Nzdistutils.commands)r=rrYrrrprint_commands)r5rFrrrrrs  zDistribution.print_commandscCs>x2tjdD]$}|j|jkr |j}||j|j<q Wtj|S)Nzdistutils.commands)r=rrYrrrget_command_list)r5rFrrrrrs  zDistribution.get_command_listcCst||j||dS)zSet feature's inclusion statusN)rr)r5rYZstatusrrrrszDistribution._set_featurecCst||j|S)zAReturn 1 if feature is included, 0 if excluded, 'None' if unknown)r r)r5rYrrrrsz Distribution.feature_is_includedcCsF|j|dkr&|j|j}t|d|j|j||j|ddS)z)Request inclusion of feature named 'name'rz2 is required, but was excluded or is not availablerN)rrxrrrr)r5rYrrrrinclude_features   zDistribution.include_featurecKsDx>|jD]2\}}t|d|d}|r0||q |j||q WdS)aAdd items to distribution that are named in keyword arguments For example, 'dist.exclude(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)r2r _include_misc)r5rtrjrkincluderrrrs  zDistribution.includecsfd|jr&fdd|jD|_|jrDfdd|jD|_|jrbfdd|jD|_dS)z9Remove packages, modules, and extensions in named packagerIcs$g|]}|kr|j r|qSr) startswith)r~r)packagepfxrrrsz0Distribution.exclude_package..cs$g|]}|kr|j r|qSr)r)r~r)rrrrrscs(g|] }|jkr|jj r|qSr)rYr)r~r)rrrrrsN)packages py_modules ext_modules)r5rr)rrrexclude_packageszDistribution.exclude_packagecCs4|d}x&|jD]}||ks(|j|rdSqWdS)z.)r`sequencerr rBr)r5rYrEoldr)rEr _exclude_miscs  zDistribution._exclude_miscc st|tstd||fyt||Wn tk rHtd|YnXdkr`t|||n:ttsxt|dn"fdd|D}t|||dS)zAHandle 'include()' for list/tuple attrs without a special handlerz%s: setting must be a list (%r)z %s: No such distribution settingNz4: this setting cannot be changed via include/excludecsg|]}|kr|qSrr)r~r)rrrrsz.Distribution._include_misc..)r`rrr rBr)r5rYrErr)rrrs   zDistribution._include_misccKsDx>|jD]2\}}t|d|d}|r0||q |j||q WdS)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)r2r r)r5rtrjrkexcluderrrrs  zDistribution.excludecCs,t|tstd|ftt|j|dS)Nz.packages: setting must be a list or tuple (%r))r`rrrQr r)r5rrrr_exclude_packagess  zDistribution._exclude_packagesc Cs|jj|_|jj|_|d}|jd}xB||krh||\}}||=ddl}|j|d|dd<|d}q(Wtj|||}|j|} t | ddrd|f|j|d<|dk rgS|S)NraliasesTrZcommand_consumes_argumentsz command liner) rrrrshlexrr_parse_command_optsrr ) r5parserrrrsrcaliasrnargsZ cmd_classrrrr s"        z Distribution._parse_command_optsc Csi}x|jjD]\}}x|jD]\}\}}|dkr8q"|jdd}|dkr|j|}|jj}|jt|dix<|jD]\} } | |kr|| }d}Pq|Wtdn |dkrd}||j |i|<q"WqW|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. z command linerrrrNzShouldn't be able to get herer) rr2rZget_command_objrrrr rCr) r5drroptrvalZcmdobjZneg_optnegposrrrget_cmdline_options:s(     z Distribution.get_cmdline_optionsccsx|jp fD] }|Vq Wx|jp$fD] }|Vq&WxH|jp>fD]:}t|trX|\}}n|j}|jdrt|dd}|Vq@WdS)z@Yield all packages, modules, and extension names in distributionmoduleNi)rrrr`tuplerYendswith)r5ZpkgrZextrYZ buildinforrrrbs      z$Distribution.iter_distribution_namescCsddl}tjs|jr tj||Sddl}t|j|j sBtj||S|jj j dkr^tj||S|jj }|jj }|j dkr|dp~d}|jj}|j |jjd||||_z tj||S|j |jj|||||_XdS)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. rNutf-8utf8Zwin32 )rr )sysr r0Z help_commandsrhandle_display_optionsior`stdout TextIOWrapperencodingrperrorsr:line_bufferingdetach)r5Z option_orderr r rrnewlinerrrrr ts$     z#Distribution.handle_display_options)N)NF)*__name__ __module__ __qualname____doc__rarbr}rsrvrrr staticmethodrrrrrrrrrrrrrrrrrrrrrJrrrrrrrr rrrrrsLB ;      (c@sPeZdZdZeddZdddfffddZdd Zd d Zd d Z ddZ dS)ra **deprecated** -- The `Feature` facility was never completely implemented or supported, `has reported issues `_ and will be removed in a future version. A subset of the distribution that can be excluded if unneeded/wanted Features are created using these keyword arguments: 'description' -- a short, human readable description of the feature, to be used in error messages, and option help messages. 'standard' -- if true, the feature is included by default if it is available on the current system. Otherwise, the feature is only included if requested via a command line '--with-X' option, or if another included feature requires it. The default setting is 'False'. 'available' -- if true, the feature is available for installation on the current system. The default setting is 'True'. 'optional' -- if true, the feature's inclusion can be controlled from the command line, using the '--with-X' or '--without-X' options. If false, the feature's inclusion status is determined automatically, based on 'availabile', 'standard', and whether any other feature requires it. The default setting is 'True'. 'require_features' -- a string or sequence of strings naming features that should also be included if this feature is included. Defaults to empty list. May also contain 'Require' objects that should be added/removed from the distribution. 'remove' -- a string or list of strings naming packages to be removed from the distribution if this feature is *not* included. If the feature *is* included, this argument is ignored. This argument exists to support removing features that "crosscut" a distribution, such as defining a 'tests' feature that removes all the 'tests' subpackages provided by other features. The default for this argument is an empty list. (Note: the named package(s) or modules must exist in the base distribution when the 'setup()' function is initially called.) other keywords -- any other keyword arguments are saved, and passed to the distribution's 'include()' and 'exclude()' methods when the feature is included or excluded, respectively. So, for example, you could pass 'packages=["a","b"]' to cause packages 'a' and 'b' to be added or removed from the distribution as appropriate. A feature must include at least one 'requires', 'remove', or other keyword argument. Otherwise, it can't affect the distribution in any way. Note also that you can subclass 'Feature' to create your own specialized feature types that modify the distribution in other ways when included or excluded. See the docstrings for the various methods here for more detail. Aside from the methods, the only feature attributes that distributions look at are 'description' and 'optional'. cCsd}tj|tdddS)NzrFeatures are deprecated and will be removed in a future version. See https://github.com/pypa/setuptools/issues/65.) stacklevel)rrr)msgrrrrszFeature.warn_deprecatedFTc Ks|j||_||_||_||_t|ttfr4|f}dd|D|_dd|D}|r^||d<t|trn|f}||_ ||_ | r| r| rt ddS)NcSsg|]}t|tr|qSr)r`rh)r~rrrrrsz$Feature.__init__..cSsg|]}t|ts|qSr)r`rh)r~rrrrrsryzgFeature %s: must define 'require_features', 'remove', or at least one of 'packages', 'py_modules', etc.) rrstandard availablerr`rhrryremoveextrasr) r5rrrrryrr Zerrrrrs$ zFeature.__init__cCs |jo |jS)z+Should this feature be included by default?)rr)r5rrrrszFeature.include_by_defaultcCs@|jst|jd|jf|jx|jD]}|j|q*WdS)aEnsure feature and its requirements are included in distribution You may override this in a subclass to perform additional operations on the distribution. Note that this method may be called more than once per feature, and so should be idempotent. z3 is required, but is not available on this platformN)rrrrr ryr)r5rDrrrrrs   zFeature.include_incCs2|jf|j|jr.x|jD]}|j|qWdS)a2Ensure feature is excluded from distribution You may override this in a subclass to perform additional operations on the distribution. This method will be called at most once per feature, and only after all included features have been asked to include themselves. N)rr rr)r5rDrrrrrs  zFeature.exclude_fromcCs2x,|jD]"}|j|std|j||fqWdS)aVerify that feature makes sense in context of distribution This method is called by the distribution just before it parses its command line. It checks to ensure that the 'remove' attribute, if any, contains only valid package/module names that are present in the base distribution when 'setup()' is called. You may override it in a subclass to perform any other required validation of the feature against a target distribution. zg%s wants to be able to remove %s, but the distribution doesn't contain any packages or modules under %sN)rrJrr)r5rDrrrrrs  zFeature.validateN) rrrrrrrrrrrrrrrrs7 r)>__all__rmrrrZ distutils.logrLZdistutils.coreZ distutils.cmdZdistutils.distrR collectionsrZdistutils.errorsrrrZdistutils.utilrZdistutils.versionrZsetuptools.externr r Zsetuptools.extern.six.movesr r r Zsetuptools.dependsrZ setuptoolsrZsetuptools.monkeyrZsetuptools.configrr=Z py36compatr __import__rr#r<rrQrrGrHrPrUrTr^rcrdrfrgrlroZcorerrrrrrrs`          G