3 M(Y^@sndZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZy ddlZWnek rddlZYnXddlmZddl m!Z!m"Z"m#Z#ddlm$Z$yddlm%Z%m&Z&m'Z'd Z(Wnek rXd Z(YnXdd lm)Z*dd l+m,Z,m-Z-yddl.j/Z0e0j1Wnek rdZ0YnXd dl2m3Z3ddlm4Z4ddlm5Z5e6de6de6de6ddej7kodknre8dej9r$dZ:dZ;dZZ?Gddde@ZAGdddeAe5jBjCZDGdddeAe5jBjEZFdd ZGiZHd!d"ZId#d$ZJd%d&ZKd'd(ZLd)d*ZMd+d,ZNd-d.ZOd/d0ZPZQd1d2ZRd3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRddSd dTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvgFZSGdwdNdNeTZUGdxdOdOeUZVGdydzdzeVZWGd{dPdPeUZXGd|dQdQeUZYiZZejBddZ[dZ\d}Z]d Z^dZ_dZ`d~drZadd5ZbgfddZcddZdddZeejfdZgejfdZheeZiddWZjdd4ZkekZldd6Zmdd7Znddd8Zodd9ZpGddedeZqGddfdfeqZrGddIdIe@ZsGdddetZuGddHdHe@ZvevZwGddRdRe8ZxGddJdJZyddGZzddTZ{ddUZ|ddZZ}dd[Z~dd\Zddd]ZGddldlZeae@eGddmdmeZGddndneZejGddjdjeZeZGdddetZGdddeZGddde jZGddodoeZeae jeGddgdgeZGddhdheZGddidieZeIdidddpZdddDZdddZee jedddZee@eddZdddZddZGdddZddZddZddZdd„Zeejeee0dÃree0jeeIdidčeIdidōddqZddȄZddʄZddAZd ddsZdd΄Zeejeee jeee0dÃr ee0jeddЄZee@edd_ZifddӄZddՄZddׄZddلZddXZejfdۃjZejfdejejBjZGddMdMe@Zdd߄ZddZGddKdKe@ZGdddeZGdddeZeeedZddZGdddeZddSZGddLdLe5jjZddZddZdd^ZddZddYZddZe jde?d dddZeeƃfddZeddZdS( aZ Package resource API -------------------- A resource is a logical file contained within a package, or a logical subdirectory thereof. The package resource API expects resource names to have their path parts separated with ``/``, *not* whatever the local path separator is. Do not use os.path operations to manipulate resource names being passed into the API. The package resource API is designed to work with normal filesystem packages, .egg files, and unpacked .egg files. It can also work in a limited way with .zip files and with custom PEP 302 loaders that support the ``get_data()`` method. )absolute_importN) get_importer)six)urllibmapfilter)utime)mkdirrenameunlinkTF)open)isdirsplit) py31compat)appdirs) packagingz&pkg_resources.extern.packaging.versionz)pkg_resources.extern.packaging.specifiersz+pkg_resources.extern.packaging.requirementsz&pkg_resources.extern.packaging.markerszPython 3.3 or later is requiredc@seZdZdZdS) PEP440Warningza Used when there is an issue with a version or specifier not complying with PEP 440. N)__name__ __module__ __qualname____doc__rrD/private/tmp/pip-build-nl73fm5q/setuptools/pkg_resources/__init__.pyr_srcsteZdZfddZfddZfddZfddZfd d Zfd d Zfd dZ ddZ ddZ Z S)_SetuptoolsVersionMixincstt|jS)N)superr__hash__)self) __class__rrrgsz _SetuptoolsVersionMixin.__hash__cs*t|trt||kStt|j|SdS)N) isinstancetuplerr__lt__)rother)rrrr"js  z_SetuptoolsVersionMixin.__lt__cs*t|trt||kStt|j|SdS)N)r r!rr__le__)rr#)rrrr$ps  z_SetuptoolsVersionMixin.__le__cs*t|trt||kStt|j|SdS)N)r r!rr__eq__)rr#)rrrr%vs  z_SetuptoolsVersionMixin.__eq__cs*t|trt||kStt|j|SdS)N)r r!rr__ge__)rr#)rrrr&|s  z_SetuptoolsVersionMixin.__ge__cs*t|trt||kStt|j|SdS)N)r r!rr__gt__)rr#)rrrr's  z_SetuptoolsVersionMixin.__gt__cs*t|trt||kStt|j|SdS)N)r r!rr__ne__)rr#)rrrr(s  z_SetuptoolsVersionMixin.__ne__cCs t||S)N)r!)rkeyrrr __getitem__sz#_SetuptoolsVersionMixin.__getitem__c#sjtjdtjddddddjfddfdd }tjd td d x|t|D] }|VqXWdS) Nz(\d+ | [a-z]+ | \.| -)czfinal-@)prepreview-rcdevc3s`xTj|D]F}||}| s |dkr*q |dddkrH|jdVq d|Vq WdVdS)N.r 0123456789*z*final)rzfill)spart) component_rereplacerr_parse_version_partss z>_SetuptoolsVersionMixin.__iter__.._parse_version_partscszg}xl|jD]\}|jdrd|dkrFx|rD|ddkrD|jq*Wx|rb|ddkrb|jqHW|j|qWt|S)Nr5z*finalrz*final-00000000r=)lower startswithpopappendr!)r7partsr8)r;rrold_parse_versions   z;_SetuptoolsVersionMixin.__iter__..old_parse_versionaYou have iterated over the result of pkg_resources.parse_version. This is a legacy behavior which is inconsistent with the new version class introduced in setuptools 8.0. In most cases, conversion to a tuple is unnecessary. For comparison of versions, sort the Version instances directly. If you have another use case requiring the tuple, please file a bug with the setuptools project describing that need.r) stacklevel)recompileVERBOSEgetwarningswarnRuntimeWarningstr)rrCr8r)r;r9r:r__iter__s  z _SetuptoolsVersionMixin.__iter__) rrrrr"r$r%r&r'r(r*rM __classcell__rr)rrrfs       rc@s eZdZdS)SetuptoolsVersionN)rrrrrrrrOsrOc@s eZdZdS)SetuptoolsLegacyVersionN)rrrrrrrrPsrPc Cs*yt|Stjjk r$t|SXdS)N)rOrversionInvalidVersionrP)vrrr parse_versionsrTcKs"tj|tjtj||dS)N)globalsupdate _state_varsdictfromkeys)vartypekwrrr_declare_states r\cCs<i}t}x,tjD] \}}|d|||||<qW|S)N_sget_)rUrWitems)stategkrSrrr __getstate__s rbcCs<t}x0|jD]$\}}|dt|||||qW|S)N_sset_)rUr^rW)r_r`rarSrrr __setstate__s rdcCs|jS)N)copy)valrrr _sget_dictsrgcCs|j|j|dS)N)clearrV)r)obr_rrr _sset_dictsrjcCs|jS)N)rb)rfrrr _sget_objectsrkcCs|j|dS)N)rd)r)rir_rrr _sset_objectsrlcGsdS)Nr)argsrrrsrnc Csbt}tj|}|dk r^tjdkr^y&ddjtdd|jdf}Wntk r\YnX|S)aZReturn this platform's maximum compatible version. distutils.util.get_platform() normally reports the minimum version of Mac OS X that would be required to *use* extensions produced by distutils. But what we want when checking compatibility is to know the version of Mac OS X that we are *running*. To allow usage of packages that explicitly require a newer version of Mac OS X, we must also know the current version of the OS. If this condition occurs for any other platform with a version in its platform strings, this function should be extended accordingly. Ndarwinz macosx-%s-%sr2r) get_build_platformmacosVersionStringmatchsysplatformjoin _macosx_versgroup ValueError)platmrrrget_supported_platforms  &r|require run_script get_providerget_distributionload_entry_point get_entry_mapget_entry_infoiter_entry_pointsresource_stringresource_streamresource_filenameresource_listdirresource_existsresource_isdirdeclare_namespace working_setadd_activation_listenerfind_distributionsset_extraction_pathcleanup_resourcesget_default_cache Environment WorkingSetResourceManager Distribution Requirement EntryPointResolutionErrorVersionConflictDistributionNotFound UnknownExtraExtractionErrorparse_requirements safe_name safe_version get_platformcompatible_platforms yield_linessplit_sections safe_extra to_filenameinvalid_markerevaluate_markerensure_directorynormalize_pathEGG_DIST BINARY_DIST SOURCE_DIST CHECKOUT_DIST DEVELOP_DISTIMetadataProviderIResourceProvider FileMetadata PathMetadata EggMetadata EmptyProviderempty_provider NullProvider EggProviderDefaultProvider ZipProviderregister_finderregister_namespace_handlerregister_loader_typefixup_namespace_packagesrrun_mainAvailableDistributionsc@seZdZdZddZdS)rz.Abstract base for dependency resolution errorscCs|jjt|jS)N)rrreprrm)rrrr__repr__MszResolutionError.__repr__N)rrrrrrrrrrJsc@s<eZdZdZdZeddZeddZddZd d Z d S) rz An already-installed version conflicts with the requested version. Should be initialized with the installed Distribution and the requested Requirement. z3{self.dist} is installed but {self.req} is requiredcCs |jdS)Nr)rm)rrrrdist[szVersionConflict.distcCs |jdS)Nr)rm)rrrrreq_szVersionConflict.reqcCs|jjftS)N) _templateformatlocals)rrrrreportcszVersionConflict.reportcCs|s|S|j|f}t|S)zt If required_by is non-empty, return a version of self that is a ContextualVersionConflict. )rmContextualVersionConflict)r required_byrmrrr with_contextfs zVersionConflict.with_contextN) rrrrrpropertyrrrrrrrrrQs   c@s&eZdZdZejdZeddZdS)rz A VersionConflict that accepts a third parameter, the set of the requirements that required the installed Distribution. z by {self.required_by}cCs |jdS)Nrp)rm)rrrrrysz%ContextualVersionConflict.required_byN)rrrrrrrrrrrrrqs rc@sHeZdZdZdZeddZeddZeddZd d Z d d Z d S)rz&A requested distribution was not foundzSThe '{self.req}' distribution was not found and is required by {self.requirers_str}cCs |jdS)Nr)rm)rrrrrszDistributionNotFound.reqcCs |jdS)Nr)rm)rrrr requirersszDistributionNotFound.requirerscCs|js dSdj|jS)Nzthe applicationz, )rrv)rrrr requirers_strsz"DistributionNotFound.requirers_strcCs|jjftS)N)rrr)rrrrrszDistributionNotFound.reportcCs|jS)N)r)rrrr__str__szDistributionNotFound.__str__N) rrrrrrrrrrrrrrrr~s   c@seZdZdZdS)rz>Distribution doesn't have an "extra feature" of the given nameN)rrrrrrrrrsrpcCs |t|<dS)aRegister `provider_factory` to make providers for `loader_type` `loader_type` is the type or class of a PEP 302 ``module.__loader__``, and `provider_factory` is a function that, passed a *module* object, returns an ``IResourceProvider`` for that module. N)_provider_factories) loader_typeprovider_factoryrrrrsc Cstt|tr$tj|p"tt|dSytj|}Wn&tk rXt |tj|}YnXt |dd}t t ||S)z?Return an IResourceProvider for the named module or requirementr __loader__N) r rrfindr}rLrtmodulesKeyError __import__getattr _find_adapterr) moduleOrReqmoduleloaderrrrrs  cCsd|s\tjd}|dkrLd}tjj|rLttdrLtj|}d|krL|d}|j|j d|dS)Nrz0/System/Library/CoreServices/SystemVersion.plist readPlistProductVersionr2) rumac_verospathexistshasattrplistlibrrAr)_cacherQplist plist_contentrrrrws    rwcCsdddj||S)Nppc)PowerPCPower_Macintosh)rH)machinerrr _macosx_archsrcCsyddlm}Wn tk r0ddlm}YnX|}tjdkr|jd ryIs the named metadata a directory? (like ``os.path.isdir()``)Nr)rrrrmetadata_isdirTsz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nr)rrrrmetadata_listdirWsz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r namespacerrrr~ZszIMetadataProvider.run_scriptN) rrrrrrr r r~rrrrrGs c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)rz3An object that provides access to package resourcescCsdS)zdReturn a true filesystem path for `resource_name` `manager` must be an ``IResourceManager``Nr)manager resource_namerrrget_resource_filenameasz'IResourceProvider.get_resource_filenamecCsdS)ziReturn a readable file-like object for `resource_name` `manager` must be an ``IResourceManager``Nr)r r rrrget_resource_streamfsz%IResourceProvider.get_resource_streamcCsdS)zmReturn a string containing the contents of `resource_name` `manager` must be an ``IResourceManager``Nr)r r rrrget_resource_stringksz%IResourceProvider.get_resource_stringcCsdS)z,Does the package contain the named resource?Nr)r rrr has_resourcepszIResourceProvider.has_resourcecCsdS)z>Is the named resource a directory? (like ``os.path.isdir()``)Nr)r rrrrssz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nr)r rrrrvsz"IResourceProvider.resource_listdirN) rrrrrrrrrrrrrrr^sc@seZdZdZd'ddZeddZeddZd d Zd d Z d dZ d(ddZ ddZ ddZ d)ddZd*ddZd+ddZddZd,dd Zd!d"Zd#d$Zd%d&ZdS)-rzDA collection of active distributions on sys.path (or a similar list)NcCsBg|_i|_i|_g|_|dkr&tj}x|D]}|j|q,WdS)z?Create working set from list of path entries (default=sys.path)N)entries entry_keysby_key callbacksrtr add_entry)rrentryrrr__init__}s zWorkingSet.__init__cCsZ|}yddlm}Wntk r*|SXy|j|Wntk rT|j|SX|S)z1 Prepare the master working set. r) __requires__)__main__rrr}r_build_from_requirements)clswsrrrr _build_masters zWorkingSet._build_mastercCsn|g}t|}|j|t}x|D]}|j|q$Wx"tjD]}||jkr>|j|q>W|jtjdd<|S)zQ Build a working set from a requirement spec. Rewrites sys.path. N)rresolveraddrtrrr)rreq_specrreqsdistsrrrrrrs   z#WorkingSet._build_from_requirementscCs@|jj|g|jj|x t|dD]}|j||dq&WdS)aAdd a path item to ``.entries``, finding any distributions on it ``find_distributions(entry, True)`` is used to find distributions corresponding to the path entry, and they are added. `entry` is always appended to ``.entries``, even if it is already present. (This is because ``sys.path`` can contain the same value more than once, and the ``.entries`` of the ``sys.path`` WorkingSet should always equal ``sys.path``.) TFN)r setdefaultrrArr )rrrrrrrs  zWorkingSet.add_entrycCs|jj|j|kS)z9True if `dist` is the active distribution for its project)rrHr))rrrrr __contains__szWorkingSet.__contains__cCs,|jj|j}|dk r(||kr(t|||S)aFind a distribution matching requirement `req` If there is an active distribution for the requested project, this returns it as long as it meets the version requirement specified by `req`. But, if there is an active distribution for the project and it does *not* meet the `req` requirement, ``VersionConflict`` is raised. If there is no active distribution for the requested project, ``None`` is returned. N)rrHr)r)rrrrrrrs  zWorkingSet.findccsPxJ|D]B}|j|}|dkr6x*|jD] }|Vq&Wq||kr||VqWdS)aYield entry point objects from `group` matching `name` If `name` is None, yields all entry points in `group` from all distributions in the working set, otherwise only ones matching both `group` and `name` are yielded (in distribution order). N)rvalues)rrxrrreprrrrs   zWorkingSet.iter_entry_pointscCs>tjdj}|d}|j||d<|j|dj||dS)z?Locate distribution for `requires` and run `script_name` scriptrrrN)rtrrrhr}r~)rrequiresrrrrrrr~s  zWorkingSet.run_scriptccsTi}xJ|jD]@}||jkrq x.|j|D] }||kr(d||<|j|Vq(Wq WdS)zYield distributions for non-duplicate projects in the working set The yield order is the order in which the items' path entries were added to the working set. rN)rrr)rseenitemr)rrrrMs  zWorkingSet.__iter__TFcCs|r|j|j||d|dkr$|j}|jj|g}|jj|jg}| rX|j|jkrXdS||j|j<|j|krz|j|j|j|kr|j|j|j|dS)aAdd `dist` to working set, associated with `entry` If `entry` is unspecified, it defaults to the ``.location`` of `dist`. On exit from this routine, `entry` is added to the end of the working set's ``.entries`` (if it wasn't already present). `dist` is only added to the working set if it's for a project that doesn't already have a distribution in the set, unless `replace=True`. If it's added, any callbacks registered with the ``subscribe()`` method will be called. )r:N) insert_onrlocationrr$r)rrA _added_new)rrrinsertr:keyskeys2rrrr s      zWorkingSet.addcCst|ddd}i}i}g}t} tjt} xP|r|jd} | |krLq2| j| |sZq2|j| j} | dkr |j j| j} | dks| | ko|r|} |dkr| dkrt |j }nt g}t g} |j | | ||d} || j<| dkr| j| d}t| ||j| | | kr,| | }t| | j|| j| jddd}|j|x(|D] }| |j| j| j| |<qRWd|| <q2W|S)aList all distributions needed to (recursively) meet `requirements` `requirements` must be a sequence of ``Requirement`` objects. `env`, if supplied, should be an ``Environment`` instance. If not supplied, it defaults to all distributions available within any entry or distribution in the working set. `installer`, if supplied, will be invoked with each requirement that cannot be met by an already-installed distribution; it should return a ``Distribution`` or ``None``. Unless `replace_conflicting=True`, raises a VersionConflict exception if any requirements are found on the path that have the correct name but the wrong version. Otherwise, if an `installer` is supplied it will be invoked to obtain the correct version of the requirement and activate it. `extras` is a list of the extras to be used with these requirements. This is important because extra requirements may look like `my_req; extra = "my_extra"`, which would otherwise be interpreted as a purely optional requirement. Instead, we want to be able to assert that these requirements are truly required. Nrr)replace_conflictingTr=r=)list _ReqExtras collections defaultdictsetr@ markers_passrHr)rrrr best_matchrrArrr(extrasextendr  project_name)r requirementsenv installerr1r9 processedbest to_activate req_extrasrrrrr dependent_reqnew_requirementsnew_requirementrrrrsN               zWorkingSet.resolvecCst|}|ji}i}|dkr4t|j}||7}n||}|jg} tt| j|x|D]} x|| D]x} | jg} y| j| ||} Wn4t k r}z||| <|rwjnPWYdd}~XqjXtt| j| |j t j | PqjWq\Wt|}|j||fS)asFind all activatable distributions in `plugin_env` Example usage:: distributions, errors = working_set.find_plugins( Environment(plugin_dirlist) ) # add plugins+libs to sys.path map(working_set.add, distributions) # display errors print('Could not load', errors) The `plugin_env` should be an ``Environment`` instance that contains only distributions that are in the project's "plugin directory" or directories. The `full_env`, if supplied, should be an ``Environment`` contains all currently-available distributions. If `full_env` is not supplied, one is created automatically from the ``WorkingSet`` this method is called on, which will typically mean that every directory on ``sys.path`` will be scanned for distributions. `installer` is a standard installer callback as used by the ``resolve()`` method. The `fallback` flag indicates whether we should attempt to resolve older versions of a plugin if the newest version cannot be resolved. This method returns a 2-tuple: (`distributions`, `error_info`), where `distributions` is a list of the distributions found in `plugin_env` that were loadable, along with any other distributions that are needed to resolve their dependencies. `error_info` is a dictionary mapping unloadable plugin distributions to an exception instance describing the error that occurred. Usually this will be a ``DistributionNotFound`` or ``VersionConflict`` instance. N) r2sortrrrrr as_requirementrrrVrXrY)r plugin_envfull_envr>fallbackplugin_projects error_info distributionsr= shadow_setr;rr resolveesrSrrr find_pluginsxs4$      zWorkingSet.find_pluginscGs*|jt|}x|D]}|j|qW|S)aEnsure that distributions matching `requirements` are activated `requirements` must be a string or a (possibly-nested) sequence thereof, specifying the distributions and versions required. The return value is a sequence of the distributions that needed to be activated to fulfill the requirements; all relevant distributions are included, even if they were already activated in this working set. )rrr )rr<neededrrrrr}s  zWorkingSet.requirecCs<||jkrdS|jj||s"dSx|D] }||q(WdS)zInvoke `callback` for all distributions If `existing=True` (default), call on all existing ones, as well. N)rrA)rcallbackexistingrrrr subscribes   zWorkingSet.subscribecCsx|jD] }||qWdS)N)r)rrrRrrrr-s zWorkingSet._added_newcCs,|jdd|jj|jj|jddfS)N)rrrerr)rrrrrbszWorkingSet.__getstate__cCs@|\}}}}|dd|_|j|_|j|_|dd|_dS)N)rrerrr)re_k_b_crr/rrrrrrds    zWorkingSet.__setstate__)N)N)NTF)NNFN)NNT)T)rrrrr classmethodrrrr%rrr~rMr rrPr}rTr-rbrdrrrrrzs(     Z S c@seZdZdZdddZdS)r3z> Map each requirement to the extras that demanded it. Ncs2fdd|jf|pdD}j p0t|S)z Evaluate markers for req against each extra that demanded it. Return False if the req has a marker and fails evaluation. Otherwise, return True. c3s|]}jjd|iVqdS)extraN)markerevaluate).0rW)rrr sz*_ReqExtras.markers_pass..N)N)rHrXany)rrr9 extra_evalsr)rrr7s z_ReqExtras.markers_pass)N)rrrrr7rrrrr3sr3c@sxeZdZdZdeefddZddZddZdd d Z d d Z d dZ dddZ dddZ ddZddZddZdS)rz5Searchable snapshot of distributions on a search pathNcCs i|_||_||_|j|dS)a!Snapshot distributions available on a search path Any distributions found on `search_path` are added to the environment. `search_path` should be a sequence of ``sys.path`` items. If not supplied, ``sys.path`` is used. `platform` is an optional string specifying the name of the platform that platform-specific distributions must be compatible with. If unspecified, it defaults to the current platform. `python` is an optional string naming the desired version of Python (e.g. ``'3.3'``); it defaults to the current version. You may explicitly set `platform` (and/or `python`) to ``None`` if you wish to map *all* distributions, not just those compatible with the running platform or Python version. N)_distmaprupythonscan)r search_pathrur_rrrrszEnvironment.__init__cCs.|jdks |jdks |j|jko,t|j|jS)zIs distribution `dist` acceptable for this environment? The distribution must match the platform and python version requirements specified when this environment was created, or False is returned. N)r_ py_versionrru)rrrrrcan_add*s zEnvironment.can_addcCs|j|jj|dS)z"Remove `dist` from the environmentN)r^r)remove)rrrrrrd5szEnvironment.removecCs<|dkrtj}x(|D] }xt|D]}|j|q"WqWdS)adScan `search_path` for distributions usable in this environment Any distributions found are added to the environment. `search_path` should be a sequence of ``sys.path`` items. If not supplied, ``sys.path`` is used. Only distributions conforming to the platform/python version defined at initialization are added. N)rtrrr )rrar*rrrrr`9s  zEnvironment.scancCs|j}|jj|gS)aReturn a newest-to-oldest list of distributions for `project_name` Uses case-insensitive `project_name` comparison, assuming all the project's distributions use their project's name converted to all lowercase as their key. )r>r^rH)rr;distribution_keyrrrr*HszEnvironment.__getitem__cCsL|j|rH|jrH|jj|jg}||krH|j||jtjddddS)zLAdd `dist` if we ``can_add()`` it and it has not already been added hashcmpT)r)reverseN) rc has_versionr^r$r)rArFoperator attrgetter)rrr#rrrr Ss  zEnvironment.addFc Csfy|j|}Wntk r,|s$d}YnX|dk r:|Sx||jD]}||krF|SqFW|j||S)aFind distribution best matching `req` and usable on `working_set` This calls the ``find(req)`` method of the `working_set` to see if a suitable distribution is already active. (This may raise ``VersionConflict`` if an unsuitable version of the project is already active in the specified `working_set`.) If a suitable distribution isn't active, this method returns the newest distribution in the environment that meets the ``Requirement`` in `req`. If no suitable distribution is found, and `installer` is supplied, then the result of calling the environment's ``obtain(req, installer)`` method will be returned. N)rrr)obtain)rrrr>r1rrrrr8\s  zEnvironment.best_matchcCs|dk r||SdS)aObtain a distribution matching `requirement` (e.g. via download) Obtain a distro that matches requirement (e.g. via download). In the base ``Environment`` class, this routine just returns ``installer(requirement)``, unless `installer` is None, in which case None is returned instead. This method is a hook that allows subclasses to attempt other ways of obtaining a distribution before falling back to the `installer` argument.Nr)r requirementr>rrrrkws zEnvironment.obtainccs&x |jjD]}||r |Vq WdS)z=Yield the unique project names of the available distributionsN)r^r/)rr)rrrrMszEnvironment.__iter__cCs^t|tr|j|nDt|trLx8|D] }x||D]}|j|q4Wq&Wntd|f|S)z2In-place addition of a distribution or environmentzCan't add %r to environment)r rr rr)rr#projectrrrr__iadd__s    zEnvironment.__iadd__cCs.|jgddd}x||fD] }||7}qW|S)z4Add an environment or distribution to an environmentN)rur_)r)rr#newr=rrr__add__s zEnvironment.__add__)N)NF)N)rrrrr|PY_MAJORrrcrdr`r*r r8rkrMrnrprrrrrs       c@seZdZdZdS)raTAn error occurred extracting a resource The following attributes are available from instances of this exception: manager The resource manager that raised this exception cache_path The base directory for resource extraction original_error The exception instance that caused extraction to fail N)rrrrrrrrrs c@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ffddZ eddZddZddZdddZdS)rz'Manage resource extraction and packagesNcCs i|_dS)N) cached_files)rrrrrszResourceManager.__init__cCst|j|S)zDoes the named resource exist?)rr)rpackage_or_requirementr rrrrszResourceManager.resource_existscCst|j|S)z,Is the named resource an existing directory?)rr)rrsr rrrrszResourceManager.resource_isdircCst|j||S)z4Return a true filesystem path for specified resource)rr)rrsr rrrrsz!ResourceManager.resource_filenamecCst|j||S)z9Return a readable file-like object for specified resource)rr)rrsr rrrrszResourceManager.resource_streamcCst|j||S)z%Return specified resource as a string)rr)rrsr rrrrszResourceManager.resource_stringcCst|j|S)z1List the contents of the named resource directory)rr)rrsr rrrrsz ResourceManager.resource_listdircCsRtjd}|jpt}tjdj}t|jft }||_ ||_ ||_ |dS)z5Give an error message for problems extracting file(s)ra Can't extract file(s) to egg cache The following error occurred while trying to extract file(s) to the Python egg cache: {old_exc} The Python egg cache directory is currently set to: {cache_path} Perhaps your account does not have write access to this directory? You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory. N) rtexc_infoextraction_pathrtextwrapdedentlstriprrrr  cache_pathoriginal_error)rold_excrytmplerrrrrextraction_errors   z ResourceManager.extraction_errorc Cs^|jp t}tjj||df|}y t|Wn|jYnX|j|d|j|<|S)aReturn absolute location in cache for `archive_name` and `names` The parent directory of the resulting path will be created if it does not already exist. `archive_name` should be the base filename of the enclosing egg (which may not be the name of the enclosing zipfile!), including its ".egg" extension. `names`, if provided, should be a sequence of path name parts "under" the egg's extraction location. This method should only be called by resource providers that need to obtain an extraction location, and only for names they intend to extract, as it tracks the generated names for possible cleanup later. z-tmpr) rurrrrv_bypass_ensure_directoryr~_warn_unsafe_extraction_pathrr)r archive_namenames extract_path target_pathrrrget_cache_paths    zResourceManager.get_cache_pathcCsXtjdkr |jtjd r dStj|j}|tj@s@|tj@rTd|}tj |t dS)aN If the default extraction path is overridden and set to an insecure location, such as /tmp, it opens up an opportunity for an attacker to replace an extracted file with an unauthorized payload. Warn the user if a known insecure location is used. See Distribute #375 for more details. ntwindirNz%s is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).) rrr?environstatst_modeS_IWOTHS_IWGRPrIrJ UserWarning)rmodemsgrrrrs  z,ResourceManager._warn_unsafe_extraction_pathcCs.tjdkr*tj|jdBd@}tj||dS)a4Perform any platform-specific postprocessing of `tempname` This is where Mac header rewrites should be done; other platforms don't have anything special they should do. Resource providers should call this method ONLY after successfully extracting a compressed resource. They must NOT call it on resources that are already in the filesystem. `tempname` is the current (temporary) name of the file, and `filename` is the name it will be renamed to by the caller after this routine returns. posiximiN)rrrrchmod)rtempnamefilenamerrrr postprocess's zResourceManager.postprocesscCs|jrtd||_dS)aSet the base path where resources will be extracted to, if needed. If you do not call this routine before any extractions take place, the path defaults to the return value of ``get_default_cache()``. (Which is based on the ``PYTHON_EGG_CACHE`` environment variable, with various platform-specific fallbacks. See that routine's documentation for more details.) Resources are extracted to subdirectories of this path based upon information given by the ``IResourceProvider``. You may set this to a temporary directory, but then you must call ``cleanup_resources()`` to delete the extracted files when done. There is no guarantee that ``cleanup_resources()`` will be able to remove all extracted files. (Note: you may not change the extraction path for a given resource manager once resources have been extracted, unless you first call ``cleanup_resources()``.) z5Can't change extraction path, files already extractedN)rrryru)rrrrrr;sz#ResourceManager.set_extraction_pathFcCsdS)aB Delete all extracted resource files and directories, returning a list of the file and directory names that could not be successfully removed. This function does not have any concurrency protection, so it should generally only be called when the extraction path is a temporary directory exclusive to a single process. This method is not automatically called; you must call it explicitly or register it as an ``atexit`` function if you wish to ensure cleanup of a temporary directory used for extractions. Nr)rforcerrrrUsz!ResourceManager.cleanup_resources)F)rrrrrurrrrrrrr~r staticmethodrrrrrrrrrs  cCstjjdptjddS)z Return the ``PYTHON_EGG_CACHE`` environment variable or a platform-relevant user cache dir for an app named "Python-Eggs". PYTHON_EGG_CACHEz Python-Eggs)appname)rrrHruser_cache_dirrrrrrcs cCstjdd|S)zConvert an arbitrary string to a standard distribution name Any runs of non-alphanumeric/. characters are replaced with a single '-'. z[^A-Za-z0-9.]+r/)rEsub)rrrrrosc CsDyttjj|Stjjk r>|jdd}tjdd|SXdS)zB Convert an arbitrary string to a standard version string rr2z[^A-Za-z0-9.]+r/N)rLrrQVersionrRr:rEr)rQrrrrws  cCstjdd|jS)zConvert an arbitrary string to a standard 'extra' name Any runs of non-alphanumeric characters are replaced with a single '_', and the result is always lowercased. z[^A-Za-z0-9.-]+r)rErr>)rWrrrrscCs |jddS)z|Convert a project or version name to its filename-escaped form Any '-' characters are currently replaced with '_'. r/r)r:)rrrrrscCs>y t|Wn,tk r8}zd|_d|_|Sd}~XnXdS)zo Validate text as a PEP 508 environment marker; return an exception if invalid or False otherwise. NF)r SyntaxErrorrlineno)texterrrrs cCsHytjj|}|jStjjk rB}zt|WYdd}~XnXdS)z Evaluate a PEP 508 environment marker. Return a boolean indicating the marker result in this environment. Raise SyntaxError if marker is invalid. This implementation uses the 'pyparsing' module. N)rmarkersMarkerrY InvalidMarkerr)rrWrXrrrrrs  c@seZdZdZdZdZdZddZddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZdS)'rzETry to implement resources and metadata for arbitrary PEP 302 loadersNcCs(t|dd|_tjjt|dd|_dS)Nr__file__r)rrrrdirname module_path)rrrrrrszNullProvider.__init__cCs|j|j|S)N)_fnr)rr r rrrrsz"NullProvider.get_resource_filenamecCstj|j||S)N)ioBytesIOr)rr r rrrrsz NullProvider.get_resource_streamcCs|j|j|j|S)N)_getrr)rr r rrrrsz NullProvider.get_resource_stringcCs|j|j|j|S)N)_hasrr)rr rrrrszNullProvider.has_resourcecCs|jo|j|j|j|S)N)egg_inforr)rrrrrrszNullProvider.has_metadatacCs2|js dS|j|j|j|}tjr.|jdS|S)Nrzutf-8)rrrrPY3decode)rrvaluerrrrszNullProvider.get_metadatacCst|j|S)N)rr)rrrrrrszNullProvider.get_metadata_linescCs|j|j|j|S)N)_isdirrr)rr rrrrszNullProvider.resource_isdircCs|jo|j|j|j|S)N)rrr)rrrrrr szNullProvider.metadata_isdircCs|j|j|j|S)N)_listdirrr)rr rrrrszNullProvider.resource_listdircCs|jr|j|j|j|SgS)N)rrr)rrrrrr szNullProvider.metadata_listdirc Csd|}|j|std||j|jdd}|jdd}|j|j|}||d<tjj|rt |j }t ||d}t |||n>dd l m}t|d|jd|f||<t ||d} t | ||dS) Nzscripts/zNo script named %rz   rexecr)cache)rrrr:rrrrrr readrFr linecacherlenr) rrr script script_textscript_filenamesourcecoder script_coderrrr~s        zNullProvider.run_scriptcCs tddS)Nz9Can't perform this operation for unregistered loader type)NotImplementedError)rrrrrrszNullProvider._hascCs tddS)Nz9Can't perform this operation for unregistered loader type)r)rrrrrrszNullProvider._isdircCs tddS)Nz9Can't perform this operation for unregistered loader type)r)rrrrrrszNullProvider._listdircCs |rtjj|f|jdS|S)N/)rrrvr)rbaser rrrrszNullProvider._fncCs$t|jdr|jj|StddS)Nget_dataz=Can't perform this operation for loaders without 'get_data()')rrrr)rrrrrr s  zNullProvider._get)rrrregg_namerrrrrrrrrrrr rr r~rrrrrrrrrrs,c@s eZdZdZddZddZdS)rz&Provider based on a virtual filesystemcCstj|||jdS)N)rr _setup_prefix)rrrrrrs zEggProvider.__init__cCs^|j}d}xN||krXt|rBtjj||_tjj|d|_||_P|}tjj |\}}q WdS)NzEGG-INFO) r _is_egg_pathrrbasenamerrvregg_rootr)rroldrrrrrs zEggProvider._setup_prefixN)rrrrrrrrrrrsc@sDeZdZdZddZddZddZdd Zd d Ze d d Z dS)rz6Provides access to package resources in the filesystemcCs tjj|S)N)rrr)rrrrrr.szDefaultProvider._hascCs tjj|S)N)rrr )rrrrrr1szDefaultProvider._isdircCs tj|S)N)rlistdir)rrrrrr4szDefaultProvider._listdircCst|j|j|dS)Nrb)r rr)rr r rrrr7sz#DefaultProvider.get_resource_streamc Cst|d }|jSQRXdS)Nr)r r)rrstreamrrrr:s zDefaultProvider._getcCsttdtd}t||dS)NSourceFileLoader)rimportlib_machinerytyper)r loader_clsrrr _register>s zDefaultProvider._registerN) rrrrrrrrrrVrrrrrr+sc@s8eZdZdZddZZddZddZdZddZ dS) rz.Provider that returns nothing for all requestscCsdS)NFr)rrrrrrnKszEmptyProvider.cCsdS)Nrr)rrrrrrnLscCsgS)Nr)rrrrrrnMsNcCsdS)Nr)rrrrrPszEmptyProvider.__init__) rrrrrrrrrrrrrrrHs  c@s eZdZdZeddZeZdS) ZipManifestsz zip manifest builder c s2t| fddjD}t|SQRXdS)a Build a dictionary similar to the zipimport directory caches, except instead of tuples, store ZipInfo objects. Use a platform-specific path separator (os.sep) for the path keys for compatibility with pypy on Windows. c3s&|]}|jdtjj|fVqdS)rN)r:rsepgetinfo)rZr)zfilerrr[gsz%ZipManifests.build..N)ContextualZipFilenamelistrX)rrr^r)rrbuild\s   zZipManifests.buildN)rrrrrVrloadrrrrrWs rc@s$eZdZdZejddZddZdS)MemoizedZipManifestsz% Memoized zipfile manifests. manifest_modzmanifest mtimecCsRtjj|}tj|j}||ks.||j|krH|j|}|j||||<||jS)zW Load a manifest at path or return a suitable manifest already loaded. ) rrnormpathrst_mtimemtimerrmanifest)rrrrrrrrxs    zMemoizedZipManifests.loadN)rrrrr4 namedtuplerrrrrrrrs rcs0eZdZdZddZddZfddZZS)rzL Supplement ZipFile class to support context manager for Python 2.6 cCs|S)Nr)rrrr __enter__szContextualZipFile.__enter__cCs |jdS)N)close)rrr tracebackrrr__exit__szContextualZipFile.__exit__cs(ttjdrtj||Stt|j|S)zI Construct a ZipFile or ContextualZipFile as appropriate r)rzipfileZipFilerr__new__)rrmkwargs)rrrrs  zContextualZipFile.__new__)rrrrrrrrNrr)rrrsrc@seZdZdZdZeZddZddZddZ e d d Z d d Z e d dZddZddZddZddZddZddZddZddZdd ZdS)!rz"Resource support for zips and eggsNcCs tj|||jjtj|_dS)N)rrrarchiverrzip_pre)rrrrrrs zZipProvider.__init__cCs4|j|jr|t|jdStd||jfdS)Nz%s is not a subpath of %s)r?rrAssertionError)rfspathrrr _zipinfo_names zZipProvider._zipinfo_namecCsP|j|}|j|jtjr:|t|jddjtjStd||jfdS)Nrz%s is not a subpath of %s)rr?rrrrrr)rzip_pathrrrr_partss  zZipProvider._partscCs|jj|jjS)N)_zip_manifestsrrr)rrrrzipinfoszZipProvider.zipinfocCs`|jstd|j|}|j}dj|j||krTx|D]}|j||j|q:W|j||S)Nz5resource_filename() only supported for .egg, not .zipr)rr_resource_to_zip_get_eager_resourcesrvr_extract_resource _eager_to_zip)rr r reagersrrrrrs  z!ZipProvider.get_resource_filenamecCs"|j}|jd}tj|}||fS)Nrrr=)rrr=) file_size date_timetimemktime)zip_statsizer timestamprrr_get_date_and_sizes  zZipProvider._get_date_and_sizec Csn||jkrDx*|j|D]}|j|tjj||}qWtjj|S|j|j|\}}tsdt dy|j |j |j |}|j ||r|Stdtjj|d\}} tj||jj|tj|t| ||f|j| |yt| |Wn\tjk rDtjj|r>|j ||r|Stjdkr>t|t| ||SYnXWn tjk rh|jYnX|S)Nz>"os.rename" and "os.unlink" are not supported on this platformz .$extract)dirr)_indexrrrrvrrr WRITE_SUPPORTIOErrorrrr _is_current_mkstempwriterrrrrr errorisfilerr r~) rr rrlastrr real_pathoutftmpnamrrrrs@        zZipProvider._extract_resourcec Csx|j|j|\}}tjj|s$dStj|}|j|ksB|j|krFdS|jj |}t |d}|j }WdQRX||kS)zK Return True if the file_path is current for this zip_path FrN) rrrrrrst_sizerrrr r) r file_pathrrrr zip_contentsf file_contentsrrrrs    zZipProvider._is_currentcCsB|jdkrr from_location)rrr rsubitemsubpathrZsubmetarrrr$s"   r$cCsfS)Nr)rrr rrr find_nothingsr*cCsdd}t||ddS)aL Given a list of filenames, return them in descending order by version number. >>> names = 'bar', 'foo', 'Python-2.7.10.egg', 'Python-2.7.2.egg' >>> _by_version_descending(names) ['Python-2.7.10.egg', 'Python-2.7.2.egg', 'foo', 'bar'] >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.egg' >>> _by_version_descending(names) ['Setuptools-1.2.3.egg', 'Setuptools-1.2.3b1.egg'] >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.post1.egg' >>> _by_version_descending(names) ['Setuptools-1.2.3.post1.egg', 'Setuptools-1.2.3b1.egg'] cSs2tjj|\}}tj|jd|g}dd|DS)z6 Parse each component of the filename r/cSsg|]}tjj|qSr)rrQr)rZr8rrr sz?_by_version_descending.._by_version..)rrsplitext itertoolschainr)rextrBrrr _by_versionsz+_by_version_descending.._by_versionT)r)rg)sorted)rr0rrr_by_version_descendingsr2c #sttr4tjttjjddVdSt}fdd|D}t |}x>|D]6}tjj|}t |}x||D] } | VqWq^WdS)z6Yield distributions accessible on a sys.path directoryzEGG-INFO)rNc3s|]}t|r|VqdS)N) dist_factory)rZr)r rrrr[szfind_on_path..) _normalize_cached_is_unpacked_eggrr#rrrrv safe_listdirr2r3) rrr rfilteredpath_item_entriesrfullpathfactoryrr)r rr find_on_paths   r;cCsL|j}tt|jd}|r tS| r2t|r2tS| rF|jdrFtStS)z9 Return a dist_factory for a path_item and entry .egg-info .dist-infoz .egg-link)r<r=) r>r\rr"distributions_from_metadatarrresolve_egg_linkNoDists)rrr r>Zis_metarrrr3s r3c@s*eZdZdZddZejreZddZdS)r@zS >>> bool(NoDists()) False >>> list(NoDists()('anything')) [] cCsdS)NFr)rrrr__bool__szNoDists.__bool__cCstfS)N)iter)rr9rrr__call__#szNoDists.__call__N) rrrrrArPY2 __nonzero__rCrrrrr@s r@cCsty tj|Sttfk r"YnNtk rn}z2|jtjtjtjfkpVt |dddk}|s^WYdd}~XnXfS)zI Attempt to list contents of path, but suppress some exceptions. winerrorNi ) rrPermissionErrorNotADirectoryErrorOSErrorerrnoENOTDIRZEACCESENOENTr)rrZ ignorablerrrr6's r6ccsftjj|}tjj|r:ttj|dkr.dSt||}nt|}tjj|}t j |||t dVdS)Nr) precedence) rrrr rrrrrrr'r)rrootrrrrrr><s    r>cCsddt|DS)z1 Yield non-empty lines from file at path css|]}|jr|jVqdS)N)striprstrip)rZlinerrrr[Osz"non_empty_lines..)r )rrrrnon_empty_linesKsrRcs.t}fdd|D}tt|}t|fS)za Given a path to an .egg-link, resolve distributions present in the referenced path. c3s$|]}tjjtjj|VqdS)N)rrrvr)rZref)rrrr[Ysz#resolve_egg_link..)rRrrnext)rZreferenced_pathsZresolved_pathsZ dist_groupsr)rrr?Rs   r? FileFinder)_namespace_handlers)_namespace_packagescCs |t|<dS)aRegister `namespace_handler` to declare namespace packages `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item handler), and `namespace_handler` is a callable like this:: def namespace_handler(importer, path_entry, moduleName, module): # return a path_entry to use for child packages Namespace handlers are only called if the importer object has already agreed that it can handle the relevant path item, and they should only return a subpath if the module __path__ does not already contain an equivalent subpath. For an example namespace handler, see ``pkg_resources.file_ns_handler``. N)rV)rnamespace_handlerrrrriscCst|}|dkrdS|j|}|dkr*dStjj|}|dkrbtj|}tj|<g|_t|nt |dsvt d|t t |}|||||}|dk r|j}|j ||j|t||||S)zEEnsure that named package includes a subpath of path_item (if needed)N__path__zNot a package:)r find_modulertrrHtypes ModuleTyperY_set_parent_nsrrrrVrA load_module_rebuild_mod_path) packageNamerrrrhandlerr)rrrr _handle_ns{s*         rbcs`ddtjDfddfdd}t|ts8dS|j|dd d|D|jdd<dS) zq Rebuild module.__path__ ensuring that all entries are ordered corresponding to their sys.path order cSsg|] }t|qSr)r4)rZprrrr+sz%_rebuild_mod_path..c s(y j|Stk r"tdSXdS)z/ Workaround for #520 and #513. infN)indexryfloat)r)sys_pathrrsafe_sys_path_indexs z._rebuild_mod_path..safe_sys_path_indexcs<|jtj}jdd}|d| }ttjj|S)zR Return the ordinal of the path based on its position in sys.path r2rN)rrrcountr4rv)r path_parts module_partsrB) package_namerhrrposition_in_sys_paths z/_rebuild_mod_path..position_in_sys_pathN)r)cSsg|] }t|qSr)r4)rZrcrrrr+s)rtrr r2rFrY) orig_pathrlrrmr)rlrhrgrr_s   r_cCstjz|tkrdStjd}}d|krdj|jddd}t||tkrZt|ytj |j }Wnt k rt d|YnXtj |gj|tj |gx|D]}t||qWWdtjXdS)z9Declare that package 'packageName' is a namespace packageNr2rzNot a package:r=)_imp acquire_lockrWrtrrvrrrrrYrrr$rArb release_lock)r`rrrrrrrs&   c CsJtjz2x,tj|fD]}t||}|rt||qWWdtjXdS)zDEnsure that previously-declared namespace packages include path_itemN)rorprWrHrbrrq)rrpackager)rrrrs cCsFtjj||jdd}t|}x |jD]}t||kr(Pq(W|SdS)zBCompute an ns-package subpath for a filesystem or zipfile importerr2rNr=)rrrvrr4rY)rrr`rr) normalizedr*rrrfile_ns_handlers   rtcCsdS)Nr)rrr`rrrrnull_ns_handlersrucCstjjtjj|S)z1Normalize a file/dir name for comparison purposes)rrnormcaserealpath)rrrrrsc Cs2y||Stk r,t|||<}|SXdS)N)rr)rrresultrrrr4 s r4cCs|jjdS)z7 Determine if given path appears to be an egg. z.egg)r>r")rrrrr srcCs t|otjjtjj|ddS)z@ Determine if given path appears to be an unpacked egg. zEGG-INFOzPKG-INFO)rrrrrv)rrrrr5 sr5cCs<|jd}|j}|r8dj|}ttj||tj|dS)Nr2)rr@rvsetattrrtr)r`rBrrrrrr] s   r]ccsht|tjr>xV|jD]"}|j}|r|jd r|VqWn&x$|D]}xt|D] }|VqRWqDWdS)z9Yield non-empty/non-comment lines of a string or sequence#N)r rr splitlinesrOr?r)strsr7ssrrrr$ s   z \w+(\.\w+)*$z (?P[^-]+) ( -(?P[^-]+) ( -py(?P[^-]+) ( -(?P.+) )? )? )? c@seZdZdZffdfddZddZddZdd d Zd d ZdddZ e j dZ e dddZe ddZe dddZe dddZdS)rz3Object representing an advertised importable objectNcCsJt|std|||_||_t||_tjddj|j |_ ||_ dS)NzInvalid module namezx[%s],) MODULEryr module_namer!attrsrrrvr9r)rrrrr9rrrrrD s  zEntryPoint.__init__cCsHd|j|jf}|jr*|ddj|j7}|jrD|ddj|j7}|S)Nz%s = %s:r2z [%s]r~)rrrrvr9)rr7rrrrM s zEntryPoint.__str__cCs dt|S)NzEntryPoint.parse(%r))rL)rrrrrU szEntryPoint.__repr__TcOs6| s|s|rtjdtdd|r.|j|||jS)zH Require packages for this EntryPoint, then resolve it. zJParameters to load are deprecated. Call .resolve and .require separately.rp)rD)rIrJDeprecationWarningr}r)rr}rmrrrrrX s zEntryPoint.loadcCsVt|jdgdd}ytjt|j|Stk rP}ztt|WYdd}~XnXdS)zD Resolve the entry point from its module and attrs. rr)fromlistlevelN) rr functoolsreducerrrrrL)rrexcrrrrg s zEntryPoint.resolvecCsN|jr|j rtd||jj|j}tj||||jd}tttj|dS)Nz&Can't require() without a distribution)r9) r9rrr(rrr2rr )rr=r>r"r^rrrr}q s  zEntryPoint.requirez]\s*(?P.+?)\s*=\s*(?P[\w.]+)\s*(:\s*(?P[\w.]+))?\s*(?P\[.*\])?\s*$cCsf|jj|}|sd}t|||j}|j|d}|drJ|djdnf}||d|d|||S)aParse a single entry point from string `src` Entry point syntax follows the form:: name = some.module:some.attr [extra1, extra2] The entry name and module name are required, but the ``:attrs`` and ``[extras]`` parts are optional z9EntryPoint must be in 'name=module:attrs [extras]' formatr9attrr2rr)patternrsry groupdict _parse_extrasr)rsrcrr{rresr9rrrrr s  zEntryPoint.parsecCs(|sfStjd|}|jr"t|jS)Nx)rrspecsryr9)r extras_specrrrrr s zEntryPoint._parse_extrascCsZt|std|i}x>t|D]2}|j||}|j|krHtd||j|||j<q W|S)zParse an entry point groupzInvalid group namezDuplicate entry point)rryrrr)rrxlinesrthisrQr'rrr parse_group s   zEntryPoint.parse_groupcCsxt|tr|j}nt|}i}xR|D]J\}}|dkrD|s|sdStjj|}|djdr:tjj|dddS|S)Nrrzmd5=r=r=)r)rrurlparser? urlunparse)r,parsedrrr_remove_md5_fragment s  rcCs@dd}t||}tt|d}|jd\}}}t|jp>dS)z Given an iterable of lines from a Metadata file, return the value of the Version field, if present, or None otherwise. cSs|jjdS)Nzversion:)r>r?)rQrrrrn sz$_version_from_file..rrN)rrTrB partitionrrO)ris_version_line version_linesrQrrrrr_version_from_file s  rc@sZeZdZdZdZddddedefddZedGddZ dd Z e d d Z d d Z ddZddZddZddZddZddZe ddZe ddZddZe d d!Ze d"d#Zffd$d%Zd&d'ZdHd)d*Zd+d,Zd-d.Zd/d0Zd1d2ZedId3d4Z d5d6Z!d7d8Z"dJd9d:Z#d;d<Z$dKd=d>Z%d?d@Z&dAdBZ'dCdDZ(e dEdFZ)dS)Lrz5Wrap an actual or potential sys.path entry w/metadatazPKG-INFONcCsFt|pd|_|dk r t||_||_||_||_||_|p>t|_ dS)NUnknown) rr;r_versionrbrur,rMr _provider)rr,rr;rQrbrurMrrrr s zDistribution.__init__c Ks~dgd\}}}}tjj|\}} | jtkr^t| j}t|} | r^| jdddd\}}}}|||f||||d|jS)Nrrverpyverrz)r;rQrbru)rrr,r>_distributionImplEGG_NAMErx_reload_version) rr,rrr[r;rQrbrur/rsrrrr' s   zDistribution.from_locationcCs|S)Nr)rrrrr szDistribution._reload_versioncCs(|j|j|jt|j|jpd|jp$dfS)Nr)parsed_versionrMr)rr,rbru)rrrrrf s zDistribution.hashcmpcCs t|jS)N)hashrf)rrrrr szDistribution.__hash__cCs |j|jkS)N)rf)rr#rrrr" szDistribution.__lt__cCs |j|jkS)N)rf)rr#rrrr$ szDistribution.__le__cCs |j|jkS)N)rf)rr#rrrr' szDistribution.__gt__cCs |j|jkS)N)rf)rr#rrrr& szDistribution.__ge__cCst||jsdS|j|jkS)NF)r rrf)rr#rrrr% s zDistribution.__eq__cCs ||k S)Nr)rr#rrrr( szDistribution.__ne__c Cs0y|jStk r*|jj|_}|SXdS)N)_keyrr;r>)rr)rrrr)% s zDistribution.keycCst|dst|j|_|jS)N_parsed_version)rrTrQr)rrrrr- s  zDistribution.parsed_versioncCsXtjj}t|j|}|sdS|js&dStjdjjdd}t j |j ft |t dS)Na> '{project_name} ({version})' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommended to migrate to PEP 440 compatible versions. rr)rrQ LegacyVersionr rrvrwrOr:rIrJrvarsr)rLV is_legacyr|rrr_warn_legacy_version4 s z!Distribution._warn_legacy_versionc CsLy|jStk rFt|j|j}|dkrBd}t||j||SXdS)Nz(Missing 'Version:' header and/or %s file)rrr _get_metadataPKG_INFOry)rrQr|rrrrQN szDistribution.versionc Csy|jStk rdgi}|_xdD]x}xrt|j|D]`\}}|rd|kr||jdd\}}t|rpg}n t|s|g}t|pd}|j|gj t |q>Wq*W|SXdS)N requires.txt depends.txtrr)rr) _Distribution__dep_maprrrrrrrr$r:r)rdmrrWr"rXrrr_dep_mapY s   zDistribution._dep_mapc Csj|j}g}|j|jdfxH|D]@}y|j|t|Wq"tk r`td||fYq"Xq"W|S)z@List of Requirements needed for this distro if `extras` are usedNz%s has no such extra feature %r)rr:rHrrr)rr9rdepsr/rrrr(m s zDistribution.requiresccs(|j|r$x|j|D] }|VqWdS)N)rr)rrrQrrrr{ s zDistribution._get_metadataFcCsZ|dkrtj}|j||d|tjkrVt|jx$|jdD]}|tjkrEnsure distribution is importable on `path` (default=sys.path)N)r:znamespace_packages.txt)rtrr+rr,rrr)rrr:pkgrrractivate s   zDistribution.activatecCs8dt|jt|j|jptf}|jr4|d|j7}|S)z@Return what this distribution's standard .egg filename should bez %s-%s-py%sr/)rr;rQrbrqru)rrrrrr s zDistribution.egg_namecCs |jrd||jfSt|SdS)Nz%s (%s))r,rL)rrrrr szDistribution.__repr__c Cs@yt|dd}Wntk r(d}YnX|p0d}d|j|fS)NrQz[unknown version]z%s %s)rryr;)rrQrrrr s  zDistribution.__str__cCs|jdrt|t|j|S)zADelegate all unrecognized public attributes to .metadata providerr)r?rrr)rrrrr __getattr__ s zDistribution.__getattr__cKs|jt|tjj||f|S)N)r'r4rrr)rrrr[rrrr# szDistribution.from_filenamecCs<t|jtjjr"d|j|jf}nd|j|jf}tj|S)z?Return a ``Requirement`` that matches this distribution exactlyz%s==%sz%s===%s)r rrrQrr;rr)rspecrrrrG szDistribution.as_requirementcCs.|j||}|dkr&td||ff|jS)z=Return the `name` entry point of `group` or raise ImportErrorNzEntry point %r not found)rrr)rrxrr'rrrr s zDistribution.load_entry_pointc CsPy |j}Wn,tk r6tj|jd|}|_YnX|dk rL|j|iS|S)z=Return the entry point map for `group`, or the full entry mapzentry_points.txtN)_ep_maprrrrrH)rrxep_maprrrr s  zDistribution.get_entry_mapcCs|j|j|S)z||kr>|jtkr>| r|||dkrdS|tjkr|j |j |||j ||Pq>W|tjkr|j |r|j d|n |j |dSxBy|j ||d} Wnt k rPYqX|| =|| =| }qWdS)aEnsure self.location is on path If replace=False (default): - If location is already in path anywhere, do nothing. - Else: - If it's an egg and its parent directory is on path, insert just ahead of the parent. - Else: add to the end of path. If replace=True: - If location is already on path anywhere (not eggs) or higher priority than its parent (eggs) do nothing. - Else: - If it's an egg and its parent directory is on path, insert just ahead of the parent, removing any lower-priority entries. - Else: add it to the front of path. NcSsg|]}|rt|p|qSr)r4)rZrcrrrr+ sz*Distribution.insert_on..rr)r,r4rrr enumeraterMrrtcheck_version_conflictr.rArery) rrlocr:nlocbdirnpathrcr*nprrrr+ sB        zDistribution.insert_oncCs|jdkrdStj|jd}t|j}x~|jdD]p}|tjks4||ks4|tkrTq4|dkr^q4t tj|dd}|rt|j |s4|j |jrq4t d|||jfq4WdS) N setuptoolsznamespace_packages.txtz top_level.txt pkg_resourcessiterzIModule %s was already imported from %s, but %s is being added to sys.path)rrr) r)rXrYrrr,rtrrWrr? issue_warning)rnsprmodnamefnrrrr s"   z#Distribution.check_version_conflictc Cs4y |jWn$tk r.tdt|dSXdS)NzUnbuilt egg for FT)rQryrr)rrrrrh* s  zDistribution.has_versioncKsDd}x$|jD]}|j|t||dqW|jd|j|jf|S)z@Copy this distribution, substituting in any changed keyword argsz.)r)rrrrr9: szDistribution.extras)N)NF)N)N)NF)*rrrrrrqrrrVr'rrrfrr"r$r'r&r%r(r)rrrQrr(rrrrrrr#rGrrrr+rrhrr9rrrrr sN             Cc@seZdZddZdS)EggInfoDistributioncCst|j|j}|r||_|S)a Packages installed by distutils (e.g. numpy or scipy), which uses an old safe_version, and so their version numbers can get mangled when converted to filenames (e.g., 1.11.0.dev0+2329eae to 1.11.0.dev0_2329eae). These distributions will not be parsed properly downstream by Distribution and safe_version, so take an extra step and try to get the version number from the metadata file itself instead of the filename. )rrrr)r md_versionrrrr@ s z#EggInfoDistribution._reload_versionN)rrrrrrrrr? src@s>eZdZdZdZejdZeddZ eddZ dd Z d S) DistInfoDistributionzGWrap an actual or potential sys.path entry w/metadata, .dist-info styleMETADATAz([\(,])\s*(\d.*?)\s*([,\)])c Cs@y|jStk r:|j|j}tjjj||_|jSXdS)zParse and cache metadataN) _pkg_inforrremailparserParserparsestr)rrrrr_parsed_pkg_infoW s  z%DistInfoDistribution._parsed_pkg_infoc Cs,y|jStk r&|j|_|jSXdS)N)_DistInfoDistribution__dep_mapr_compute_dependencies)rrrrra s  zDistInfoDistribution._dep_mapcsdgi}|_gx&|jjdp"gD]}jt|q$Wfdd}t|d}|dj|x<|jjdppgD](}t|j}tt|||||<qrW|S)z+Recompute this distribution's dependencies.Nz Requires-Distc3s0x*D]"}|j s"|jjd|ir|VqWdS)NrW)rXrY)rWr)r"rrreqs_for_extrar s zBDistInfoDistribution._compute_dependencies..reqs_for_extrazProvides-Extra) rrget_allr:r frozensetrrOr2)rrrrcommonrWs_extrar)r"rri s   z*DistInfoDistribution._compute_dependenciesN) rrrrrrErFEQEQrrrrrrrrrR s   r)z.eggz .egg-infoz .dist-infoc Os^d}t}y"xtj|j|kr(|d7}qWWntk r@YnXtj|d|di|dS)NrrD)rUrtrrryrIrJ)rmr[rr`rrrr src@seZdZddZdS)RequirementParseErrorcCs dj|jS)Nr)rvrm)rrrrr szRequirementParseError.__str__N)rrrrrrrrr srccshtt|}xV|D]N}d|kr0|d|jd}|jdrV|ddj}|t|7}t|VqWdS)zYield ``Requirement`` objects for each specification in `strs` `strs` must be a string, or a (possibly-nested) iterable thereof. z #N\rp)rBrrr"rOrTr)r|rrQrrrr s    csPeZdZfddZddZddZddZd d Zd d Ze d dZ Z S)rcsytt|j|Wn2tjjk rF}ztt|WYdd}~XnX|j|_ t |j}||j |_ |_ dd|jD|_ttt|j|_|j |jt|j|jrt|jndf|_t|j|_dS)z>DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!NcSsg|]}|j|jfqSr)rirQ)rZrrrrr+ sz(Requirement.__init__..)rrrrr<InvalidRequirementrrLr unsafe_namerr>r;r) specifierrr!rrr9rrXhashCmpr_Requirement__hash)rrequirement_stringrr;)rrrr s zRequirement.__init__cCst|to|j|jkS)N)r rr)rr#rrrr% s zRequirement.__eq__cCs ||k S)Nr)rr#rrrr( szRequirement.__ne__cCs0t|tr |j|jkrdS|j}|jj|ddS)NFT) prereleases)r rr)rQrcontains)rr*rrrr% s   zRequirement.__contains__cCs|jS)N)r)rrrrr szRequirement.__hash__cCs dt|S)NzRequirement.parse(%r))rL)rrrrr szRequirement.__repr__cCst|\}|S)N)r)r7rrrrr s zRequirement.parse) rrrrr%r(r%rrrrrNrr)rrr s  cCst|kr|tfS|S)zJ Ensure object appears in the mro even for old-style classes. )object)classesrrr_always_object s rcCs<ttjt|dt|}x|D]}||kr ||Sq WdS)z2Return an adapter factory for `ob` from `registry`rN)rinspectZgetmrorr)registryrir[trrrr s rcCstjj|}tj|dddS)z1Ensure that the parent directory of `path` existsT)exist_okN)rrrrmakedirs)rrrrrr s cCs@ts tdt|\}}|r<|r.N)rrVr)r`r)r r _initialize6 s  rcCs|tj}td|d|j}|j}|j}|j}|}tdd|D|ddddg|_t t |j t j tjtd S) aE Prepare the master working set and make the ``require()`` API available. This function has explicit effects on the global state of pkg_resources. It is intended to be invoked once at the initialization of this module. Invocation by other packages is unsupported and done at their own risk. r)rcss|]}|jddVqdS)F)r:N)r)rZrrrrr[] sz1_initialize_master_working_set..cSs |jddS)NT)r:)r)rrrrrn` sz0_initialize_master_working_set..F)rSN)rrr\r}rrTr~r!rr2rrrtrrUrVr)rr}rrr~rrrr_initialize_master_working_setB s   r)rr)rrr=)N)N)F)F)F)F)N)r __future__rrtrrrrEr[rr%rIrrpkgutilrirur4r email.parserrrJrrvr-rrrorimppkg_resources.externrpkg_resources.extern.six.movesrrrrr r r rr ros.pathr rimportlib.machinery machineryrrrrrrr version_info RuntimeErrorrDrGrHr}rrKrrrrQrrOrrPrTrWr\rbrdrgrjrkrl _sget_none _sset_noner|__all__ ExceptionrrrrrrrqrrrrrrrrwrrqrFrrrrrr~rrrrrrrrrXr3rrrrrrrrrrrrrrrrrrrrrrr&rrrrrr$r*r2r;r3r@r6r>rRr? ImpImporterrrUrrbr_rrrtrurr4rr5r]rrsrrG IGNORECASErrrrrrrrrryrrr<rrrrrrrfilterwarningsrrUrrrrrrs             "b          .   3    a  ' '            !!            g0 5