a B_?`@sdgZddlZddlZddlZddlZddlZddlZddlZddl Zddl Zddl Zddl m Z ddlmZddlmZddlZddlmZddlmZddlmZmZdd l mZdd lmZdd lmZdd lmZd dl m!Z!ddl"Z"ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(Z(e)de)dddZ*ddZ+ddZ,ddZ-ddZ.e/e0fZ1ddZ2d d!Z3d"d#Z4d$d%Z5d&d'Z6d(d)Z7d*d+Z8d,d-Z9d.d/Z:d0d1Z;d2d3Zj?Z@Gd6dde@Z?Gd7d8d8e!ZAdS)9 DistributionN) strtobool)DEBUGtranslate_longopt) defaultdict)message_from_file)DistutilsOptionErrorDistutilsSetupError) rfc822_escape) StrictVersion) packaging) ordered_set)SetuptoolsDeprecationWarning)windows_support) get_unpatched)parse_configurationz&setuptools.extern.packaging.specifiersz#setuptools.extern.packaging.versioncCstdtt|S)NzDo not call this function)warningswarnDistDeprecationWarningr)clsr1/usr/lib/python3/dist-packages/setuptools/dist.py_get_unpatched)s rcCst|dd}|dur|js |jr*td}nd|jdusT|jdusTt|dddusT|jr^td}n0|js||js||j s||j s||j rtd}ntd}||_ |S)Nmetadata_versionz2.1python_requires1.21.1z1.0) getattrlong_description_content_typeprovides_extrasr maintainermaintainer_email project_urlsprovidesrequires obsoletes classifiers download_urlr)selfZmvrrrget_metadata_version.s*      r+cs t|fdd}fdd}td|_|d|_|d|_|d|_|d |_d |_|d |_d |_ |d |_ |d |_ dvr|d|_ nd |_ |d|_ |d|_dvr|dd|_|d|_|d|_|jtdkr |d|_|d|_|d|_nd |_d |_d |_d S)z-Reads the metadata values from a file object.cs|}|dkrdS|S)NZUNKNOWNr)namevaluemsgrr _read_fieldHsz"read_pkg_file.._read_fieldcs|d}|gkrdS|SN)Zget_all)r,valuesr.rr _read_listNs z!read_pkg_file.._read_listzmetadata-versionr,versionZsummaryauthorNz author-emailz home-pagelicensez download-url descriptionkeywords,platformZ classifierrr&r%r')rr rr,r4r7r5r" author_emailr#Zurlr6r)Zlong_descriptionsplitr8Z platformsr(r&r%r')r*filer0r3rr.r read_pkg_fileDs:                 r>cCs"d|vrtd|dd}|S)N z1newlines not allowed and will break in the future )rrreplace)valrrr single_lineys  rCc 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|jrt|jD]} |d| qd S)z5Write the PKG-INFO format data to a file object. csd||fdS)Nz%s: %s )write)keyr-r=rr write_fieldsz#write_pkg_file..write_fieldzMetadata-VersionNameVersionZSummaryz Home-pagerAuthor Author-email))rJr5)rKr;)Z Maintainerr")zMaintainer-emailr#NZLicensez Download-URLz Project-URLz%s, %sZ Descriptionr9ZKeywordsZPlatformZ ClassifierZRequiresZProvidesZ ObsoletesrzRequires-PythonzDescription-Content-TypezProvides-Extra)r+strZget_nameZ get_versionrCZget_descriptionZget_urlr Z get_contactZget_contact_emailrZ get_licenser)r$itemsr Zget_long_descriptionjoinZ get_keywordsZ get_platformsZ _write_listZget_classifiersZ get_requiresZ get_providesZ get_obsoleteshasattrrr r!sorted) r*r=r4rGZoptional_fieldsZfieldattrZattr_valZ project_urlZ long_descr8r:extrarrFrwrite_pkg_filesV            rSc Csbztjd|}|jrJWn>ttttfy\}ztd||f|WYd}~n d}~00dS)Nzx=z4%r must be importable 'module:attrs' string (got %r)) pkg_resources EntryPointparseZextras TypeError ValueErrorAttributeErrorAssertionErrorr )distrQr-eperrrcheck_importablesr^c Cslz(t|ttfsJd||ks&JWn>ttttfyf}ztd||f|WYd}~n d}~00dS)z"Verify that value is a string listz%%r must be a list of strings (got %r)N) isinstancelisttuplerNrWrXrYrZr r[rQr-r]rrrassert_string_lists rdcCsd|}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)rdhas_contents_forr rpartition distutilslogr)r[rQr-Z ns_packagesZnspparentsepchildrrr check_nsps   rmc 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) ra itertoolsstarmap _check_extrarMrWrXrYr rcrrr check_extrassrqcCs<|d\}}}|r*t|r*td|tt|dS)N:zInvalid environment marker: ) partitionrTZinvalid_markerr raparse_requirements)rRZreqsr,rkmarkerrrrrps 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}))rQr-N)boolr format)r[rQr-tmplrrr assert_bool s 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}rQerrorN) rarTrtr`dictsetrWrXr rwr[rQr-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)r Z specifiersZ SpecifierSetZInvalidSpecifierr rwr~rrrcheck_specifier#s rc CsDztj|Wn.ty>}zt||WYd}~n d}~00dS)z)Verify that entry_points map is parseableN)rTrUZ parse_maprXr rcrrrcheck_entry_points1srcCst|tstddS)Nztest_suite must be a string)r`rLr )r[rQr-rrrcheck_test_suite9s 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 rwrMrLrd)r[rQr-kvrrrcheck_package_data>s  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)rematchrhrir)r[rQr-Zpkgnamerrrcheck_packagesMs  rc@s:eZdZdZdeejejdZdZddZ dEddZ e dd Z e d d Z d d ZddZe ddZddZddZdFddZdGddZdHddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Z d3d4Z!d5d6Z"d7d8Z#d9d:Z$d;d<Z%d=d>Z&d?d@Z'dAdBZ(dCdDZ)dS)IraG 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. N)r r$r!Z license_filescCsl|rd|vsd|vrdStt|d}tjj|}|durh|dshtt|d|_ ||_ dS)Nr,r4zPKG-INFO) rTZ safe_namerLlower working_setZby_keygetZ has_metadataZ safe_versionZ_version _patched_dist)r*attrsrEr[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__..)rOrZ dist_filespoprrrrrTiter_entry_pointsvars setdefaultr, _Distribution__init__rMrmetadata__dict__setattr_normalize_version_validate_versionr4_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` setuptoolssicrLr r4rIrrrwlocals)r4Z 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`numbersNumberrLr r4rIZInvalidVersionrWrrrr)r4rrrrs 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) rrrrkeysr<r!add_convert_extras_requirements"_move_install_requirements_markers)r*rRrrrrs   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) rrra_tmp_extras_requirerMrTrt _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. rrr_)rurLreqrrrrszDistribution._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 Sr1rurrrr is_simple_reqszFDistribution._move_install_requirements_markers..is_simple_reqinstall_requiresNrrrc3s,|]$\}}|ddtj|DfVqdS)cSsg|] }t|qSr)rL)rrrrr %zMDistribution._move_install_requirements_markers...N)map _clean_reqrrrr $szBDistribution._move_install_requirements_markers..)rrarTrtfilterrn filterfalserrLrrrurr|rMr)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_reqc Csddlm}tjtjkrgngd}t|}|dur<|}trJ|d|}|D]}t j |dd6}tr|dj fit | |Wdn1s0Y|D]X}||}||} |D]:} | d ks| |vrq||| } | d d } || f| | <qq|qTd |jvr(dS|jd D]\} \} } |j| } | r`t|  } n| d vrrt| } zt|| p| | Wn0ty}zt||WYd}~n d}~00q6dS)z Adapted from distutils.dist.Distribution.parse_config_files, this method provides the same functionality in subtly-improved ways. r) ConfigParser) z install-basezinstall-platbasez install-libzinstall-platlibzinstall-purelibzinstall-headerszinstall-scriptsz install-dataprefixz exec-prefixhomeuserrootNz"Distribution.parse_config_files():utf-8)encodingz reading {filename}__name__-_global)verboseZdry_run)Z configparserrsysr base_prefix frozensetZfind_config_filesrannounceioopenrwrZ read_fileZsectionsoptionsget_option_dictrrArcommand_optionsrM negative_optrrrXr )r* filenamesrZignore_optionsparserfilenamereaderrrZopt_dictoptrBsrcaliasr]rrr_parse_config_files1sF  (          z Distribution._parse_config_filesc Cs\|}|dur||}tr,|d||D] \}\}}trZ|d|||fzdd|jD}Wntyg}Yn0z |j}Wntyi}Yn0z|t|t } ||vr| rt |||t | nJ||vr| rt ||t |n,t ||rt |||nt d|||fWq4tyT} zt | | WYd} ~ q4d} ~ 00q4dS)a Set the options for 'command_obj' from 'option_dict'. Basically this means copying elements of a dictionary ('option_dict') to attributes of an instance ('command'). 'command_obj' must be a Command instance. If 'option_dict' is not supplied, uses the standard option dictionary for this command (from 'self.command_options'). (Adopted from distutils.dist.Distribution._set_command_options) Nz# setting options for '%s' command:z %s = %s (from %s)cSsg|] }t|qSrr)rorrrrsz5Distribution._set_command_options..z1error in %s: command '%s' has no such option '%s')Zget_command_namerrrrMZboolean_optionsrYrr`rLrrrOr rX) r*Z command_objZ option_dictZ command_namerrr-Z bool_optsneg_optZ is_stringr]rrr_set_command_optionsrsF             z!Distribution._set_command_optionsFcCs(|j|dt||j|d|dS)zYParses configuration files from various levels and loads configuration. )r)ignore_option_errorsN)rrrr)r*rrrrrparse_config_filess  zDistribution.parse_config_filescCs8tjjt||jdd}|D]}tjj|ddq|S)zResolve pre-setup requirementsT) installerZreplace_conflicting)rA)rTrresolvertfetch_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|Sr1)load)r]rrrrz/Distribution.finalize_options..)rEN)rrTrrP)r*grouprepsr\rrrfinalize_optionss zDistribution.finalize_optionscCsJtdD]:}t||jd}|dur |j|jd|||j|q dS)Nrr)rTrrr,requirerr)r*r\r-rrr_finalize_setup_keywordss z%Distribution._finalize_setup_keywordscCs*t|ddr dd|jD|_ng|_dS)Nconvert_2to3_doctestscSsg|]}tj|qSr)ospathabspathrprrrrsz8Distribution._finalize_2to3_doctests..)rrrrrr_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. ) rrrNcurdirexistsmkdirrZ hide_filerrD)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*rrrrrrs zDistribution.fetch_build_eggcCs\||jvr|j|Std|}|D]*}|j|jd||j|<}|St||S)z(Pluggable version of get_command_class()distutils.commandsrN)cmdclassrTrrrrrget_command_class)r*commandrr\rrrrrs   zDistribution.get_command_classcCs:tdD]$}|j|jvr |}||j|j<q t|SNr)rTrr,rrrprint_commandsr*r\rrrrrs  zDistribution.print_commandscCs:tdD]$}|j|jvr |}||j|j<q t|Sr)rTrr,rrrget_command_listr rrrr 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)rMr _include_misc)r*rrrincluderrrr s  zDistribution.includecsfd|jr&fdd|jD|_|jrDfdd|jD|_|jrbfdd|jD|_dS)z9Remove packages, modules, and extensions in named packagerecs"g|]}|kr|s|qSr startswithrpackagepfxrrr#sz0Distribution.exclude_package..cs"g|]}|kr|s|qSrr rrrrr)scs&g|]}|jkr|js|qSr)r,rrrrrr/sN)packages py_modules ext_modules)r*rrrrexclude_packages   zDistribution.exclude_packagecCs2|d}|D]}||ks&||rdSqdS)z.r`sequencer rrYr)r*r,r-oldr]rrr _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)rNrcsg|]}|vr|qSrrrrrrrdrz.Distribution._include_misc..r)r*r,r-r]newrr rr Ps(   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)rMrr)r*rrrexcluderrrr"gs  zDistribution.excludecCs,t|tstd|ftt|j|dS)Nz.packages: setting must be a list or tuple (%r))r`rr rarr)r*rrrr_exclude_packages~s  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*rr&rr$rrr(nargsZ cmd_classrrrr)s"       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. r%rrrrNzShouldn't be able to get herer) rrMrAZget_command_objrcopyupdaterrZr) r*dcmdZoptsrrrBZcmdobjrnegposrrrget_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)rrrr`rbr,endswith)r*pkgr2Zextr,Z buildinforrrrs    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)rutf8Zwin32r?r)rZ help_commandsrhandle_display_optionsr`stdoutr TextIOWrapperrrerrorsr:line_bufferingdetach)r*Z option_orderrrr9newliner:rrrr6s2    z#Distribution.handle_display_options)N)N)N)NF)*r __module__ __qualname____doc__r|rZ OrderedSetrrrr staticmethodrrrrrrrrrrrrrrrrrrr r rrfrr r"r#r)r1rr6rrrrrYsT4 "    A /     (c@seZdZdZdS)rzrClass for warning about deprecations in dist in setuptools. Not ignored by default, unlike DeprecationWarning.N)rr=r>r?rrrrrsr)B__all__rrrrrrZ distutils.logrhZdistutils.coreZ distutils.cmdZdistutils.distZdistutils.utilrZdistutils.debugrZdistutils.fancy_getoptrrn collectionsrZemailrZdistutils.errorsr r r Zdistutils.versionr Zsetuptools.externr rr_rrrZsetuptools.monkeyrZsetuptools.configrrT __import__rr+r>rCrSrbrarr^rdrmrqrpryrrrrrrZcorerrrrrrrsn             5 H   (