rigid 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/rigid +4 -0
- data/rigid +16 -0
- data/vendor/PyYAML-3.12.dist-info/DESCRIPTION.rst +12 -0
- data/vendor/PyYAML-3.12.dist-info/INSTALLER +1 -0
- data/vendor/PyYAML-3.12.dist-info/METADATA +35 -0
- data/vendor/PyYAML-3.12.dist-info/RECORD +42 -0
- data/vendor/PyYAML-3.12.dist-info/WHEEL +5 -0
- data/vendor/PyYAML-3.12.dist-info/metadata.json +1 -0
- data/vendor/PyYAML-3.12.dist-info/top_level.txt +2 -0
- data/vendor/_yaml.so +0 -0
- data/vendor/click/__init__.py +98 -0
- data/vendor/click/__init__.pyc +0 -0
- data/vendor/click/_bashcomplete.py +83 -0
- data/vendor/click/_bashcomplete.pyc +0 -0
- data/vendor/click/_compat.py +642 -0
- data/vendor/click/_compat.pyc +0 -0
- data/vendor/click/_termui_impl.py +547 -0
- data/vendor/click/_termui_impl.pyc +0 -0
- data/vendor/click/_textwrap.py +38 -0
- data/vendor/click/_textwrap.pyc +0 -0
- data/vendor/click/_unicodefun.py +119 -0
- data/vendor/click/_unicodefun.pyc +0 -0
- data/vendor/click/_winconsole.py +273 -0
- data/vendor/click/_winconsole.pyc +0 -0
- data/vendor/click/core.py +1738 -0
- data/vendor/click/core.pyc +0 -0
- data/vendor/click/decorators.py +304 -0
- data/vendor/click/decorators.pyc +0 -0
- data/vendor/click/exceptions.py +201 -0
- data/vendor/click/exceptions.pyc +0 -0
- data/vendor/click/formatting.py +256 -0
- data/vendor/click/formatting.pyc +0 -0
- data/vendor/click/globals.py +48 -0
- data/vendor/click/globals.pyc +0 -0
- data/vendor/click/parser.py +426 -0
- data/vendor/click/parser.pyc +0 -0
- data/vendor/click/termui.py +539 -0
- data/vendor/click/termui.pyc +0 -0
- data/vendor/click/testing.py +322 -0
- data/vendor/click/testing.pyc +0 -0
- data/vendor/click/types.py +550 -0
- data/vendor/click/types.pyc +0 -0
- data/vendor/click/utils.py +415 -0
- data/vendor/click/utils.pyc +0 -0
- data/vendor/click-6.6.dist-info/DESCRIPTION.rst +3 -0
- data/vendor/click-6.6.dist-info/INSTALLER +1 -0
- data/vendor/click-6.6.dist-info/METADATA +16 -0
- data/vendor/click-6.6.dist-info/RECORD +41 -0
- data/vendor/click-6.6.dist-info/WHEEL +6 -0
- data/vendor/click-6.6.dist-info/metadata.json +1 -0
- data/vendor/click-6.6.dist-info/top_level.txt +1 -0
- data/vendor/easy_install.py +5 -0
- data/vendor/easy_install.pyc +0 -0
- data/vendor/pip-9.0.1.dist-info/DESCRIPTION.rst +39 -0
- data/vendor/pip-9.0.1.dist-info/INSTALLER +1 -0
- data/vendor/pip-9.0.1.dist-info/METADATA +69 -0
- data/vendor/pip-9.0.1.dist-info/RECORD +501 -0
- data/vendor/pip-9.0.1.dist-info/WHEEL +6 -0
- data/vendor/pip-9.0.1.dist-info/entry_points.txt +5 -0
- data/vendor/pip-9.0.1.dist-info/metadata.json +1 -0
- data/vendor/pip-9.0.1.dist-info/top_level.txt +1 -0
- data/vendor/pkg_resources/__init__.py +3051 -0
- data/vendor/pkg_resources/__init__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/__init__.py +0 -0
- data/vendor/pkg_resources/_vendor/__init__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/appdirs.py +552 -0
- data/vendor/pkg_resources/_vendor/appdirs.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/__about__.py +21 -0
- data/vendor/pkg_resources/_vendor/packaging/__about__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/__init__.py +14 -0
- data/vendor/pkg_resources/_vendor/packaging/__init__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/_compat.py +30 -0
- data/vendor/pkg_resources/_vendor/packaging/_compat.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/_structures.py +68 -0
- data/vendor/pkg_resources/_vendor/packaging/_structures.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/markers.py +287 -0
- data/vendor/pkg_resources/_vendor/packaging/markers.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/requirements.py +127 -0
- data/vendor/pkg_resources/_vendor/packaging/requirements.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/specifiers.py +774 -0
- data/vendor/pkg_resources/_vendor/packaging/specifiers.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/utils.py +14 -0
- data/vendor/pkg_resources/_vendor/packaging/utils.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/version.py +393 -0
- data/vendor/pkg_resources/_vendor/packaging/version.pyc +0 -0
- data/vendor/pkg_resources/_vendor/pyparsing.py +5696 -0
- data/vendor/pkg_resources/_vendor/pyparsing.pyc +0 -0
- data/vendor/pkg_resources/_vendor/six.py +868 -0
- data/vendor/pkg_resources/_vendor/six.pyc +0 -0
- data/vendor/pkg_resources/extern/__init__.py +73 -0
- data/vendor/pkg_resources/extern/__init__.pyc +0 -0
- data/vendor/requests/__init__.py +86 -0
- data/vendor/requests/__init__.pyc +0 -0
- data/vendor/requests/adapters.py +503 -0
- data/vendor/requests/adapters.pyc +0 -0
- data/vendor/requests/api.py +148 -0
- data/vendor/requests/api.pyc +0 -0
- data/vendor/requests/auth.py +252 -0
- data/vendor/requests/auth.pyc +0 -0
- data/vendor/requests/cacert.pem +5616 -0
- data/vendor/requests/certs.py +25 -0
- data/vendor/requests/certs.pyc +0 -0
- data/vendor/requests/compat.py +66 -0
- data/vendor/requests/compat.pyc +0 -0
- data/vendor/requests/cookies.py +540 -0
- data/vendor/requests/cookies.pyc +0 -0
- data/vendor/requests/exceptions.py +114 -0
- data/vendor/requests/exceptions.pyc +0 -0
- data/vendor/requests/hooks.py +34 -0
- data/vendor/requests/hooks.pyc +0 -0
- data/vendor/requests/models.py +873 -0
- data/vendor/requests/models.pyc +0 -0
- data/vendor/requests/packages/__init__.py +36 -0
- data/vendor/requests/packages/__init__.pyc +0 -0
- data/vendor/requests/packages/chardet/__init__.py +32 -0
- data/vendor/requests/packages/chardet/__init__.pyc +0 -0
- data/vendor/requests/packages/chardet/big5freq.py +925 -0
- data/vendor/requests/packages/chardet/big5freq.pyc +0 -0
- data/vendor/requests/packages/chardet/big5prober.py +42 -0
- data/vendor/requests/packages/chardet/big5prober.pyc +0 -0
- data/vendor/requests/packages/chardet/chardetect.py +80 -0
- data/vendor/requests/packages/chardet/chardetect.pyc +0 -0
- data/vendor/requests/packages/chardet/chardistribution.py +231 -0
- data/vendor/requests/packages/chardet/chardistribution.pyc +0 -0
- data/vendor/requests/packages/chardet/charsetgroupprober.py +106 -0
- data/vendor/requests/packages/chardet/charsetgroupprober.pyc +0 -0
- data/vendor/requests/packages/chardet/charsetprober.py +62 -0
- data/vendor/requests/packages/chardet/charsetprober.pyc +0 -0
- data/vendor/requests/packages/chardet/codingstatemachine.py +61 -0
- data/vendor/requests/packages/chardet/codingstatemachine.pyc +0 -0
- data/vendor/requests/packages/chardet/compat.py +34 -0
- data/vendor/requests/packages/chardet/compat.pyc +0 -0
- data/vendor/requests/packages/chardet/constants.py +39 -0
- data/vendor/requests/packages/chardet/constants.pyc +0 -0
- data/vendor/requests/packages/chardet/cp949prober.py +44 -0
- data/vendor/requests/packages/chardet/cp949prober.pyc +0 -0
- data/vendor/requests/packages/chardet/escprober.py +86 -0
- data/vendor/requests/packages/chardet/escprober.pyc +0 -0
- data/vendor/requests/packages/chardet/escsm.py +242 -0
- data/vendor/requests/packages/chardet/escsm.pyc +0 -0
- data/vendor/requests/packages/chardet/eucjpprober.py +90 -0
- data/vendor/requests/packages/chardet/eucjpprober.pyc +0 -0
- data/vendor/requests/packages/chardet/euckrfreq.py +596 -0
- data/vendor/requests/packages/chardet/euckrfreq.pyc +0 -0
- data/vendor/requests/packages/chardet/euckrprober.py +42 -0
- data/vendor/requests/packages/chardet/euckrprober.pyc +0 -0
- data/vendor/requests/packages/chardet/euctwfreq.py +428 -0
- data/vendor/requests/packages/chardet/euctwfreq.pyc +0 -0
- data/vendor/requests/packages/chardet/euctwprober.py +41 -0
- data/vendor/requests/packages/chardet/euctwprober.pyc +0 -0
- data/vendor/requests/packages/chardet/gb2312freq.py +472 -0
- data/vendor/requests/packages/chardet/gb2312freq.pyc +0 -0
- data/vendor/requests/packages/chardet/gb2312prober.py +41 -0
- data/vendor/requests/packages/chardet/gb2312prober.pyc +0 -0
- data/vendor/requests/packages/chardet/hebrewprober.py +283 -0
- data/vendor/requests/packages/chardet/hebrewprober.pyc +0 -0
- data/vendor/requests/packages/chardet/jisfreq.py +569 -0
- data/vendor/requests/packages/chardet/jisfreq.pyc +0 -0
- data/vendor/requests/packages/chardet/jpcntx.py +227 -0
- data/vendor/requests/packages/chardet/jpcntx.pyc +0 -0
- data/vendor/requests/packages/chardet/langbulgarianmodel.py +229 -0
- data/vendor/requests/packages/chardet/langbulgarianmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langcyrillicmodel.py +329 -0
- data/vendor/requests/packages/chardet/langcyrillicmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langgreekmodel.py +225 -0
- data/vendor/requests/packages/chardet/langgreekmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langhebrewmodel.py +201 -0
- data/vendor/requests/packages/chardet/langhebrewmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langhungarianmodel.py +225 -0
- data/vendor/requests/packages/chardet/langhungarianmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langthaimodel.py +200 -0
- data/vendor/requests/packages/chardet/langthaimodel.pyc +0 -0
- data/vendor/requests/packages/chardet/latin1prober.py +139 -0
- data/vendor/requests/packages/chardet/latin1prober.pyc +0 -0
- data/vendor/requests/packages/chardet/mbcharsetprober.py +86 -0
- data/vendor/requests/packages/chardet/mbcharsetprober.pyc +0 -0
- data/vendor/requests/packages/chardet/mbcsgroupprober.py +54 -0
- data/vendor/requests/packages/chardet/mbcsgroupprober.pyc +0 -0
- data/vendor/requests/packages/chardet/mbcssm.py +572 -0
- data/vendor/requests/packages/chardet/mbcssm.pyc +0 -0
- data/vendor/requests/packages/chardet/sbcharsetprober.py +120 -0
- data/vendor/requests/packages/chardet/sbcharsetprober.pyc +0 -0
- data/vendor/requests/packages/chardet/sbcsgroupprober.py +69 -0
- data/vendor/requests/packages/chardet/sbcsgroupprober.pyc +0 -0
- data/vendor/requests/packages/chardet/sjisprober.py +91 -0
- data/vendor/requests/packages/chardet/sjisprober.pyc +0 -0
- data/vendor/requests/packages/chardet/universaldetector.py +170 -0
- data/vendor/requests/packages/chardet/universaldetector.pyc +0 -0
- data/vendor/requests/packages/chardet/utf8prober.py +76 -0
- data/vendor/requests/packages/chardet/utf8prober.pyc +0 -0
- data/vendor/requests/packages/urllib3/__init__.py +96 -0
- data/vendor/requests/packages/urllib3/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/_collections.py +324 -0
- data/vendor/requests/packages/urllib3/_collections.pyc +0 -0
- data/vendor/requests/packages/urllib3/connection.py +330 -0
- data/vendor/requests/packages/urllib3/connection.pyc +0 -0
- data/vendor/requests/packages/urllib3/connectionpool.py +866 -0
- data/vendor/requests/packages/urllib3/connectionpool.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/__init__.py +0 -0
- data/vendor/requests/packages/urllib3/contrib/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/appengine.py +231 -0
- data/vendor/requests/packages/urllib3/contrib/appengine.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/ntlmpool.py +115 -0
- data/vendor/requests/packages/urllib3/contrib/ntlmpool.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/pyopenssl.py +358 -0
- data/vendor/requests/packages/urllib3/contrib/pyopenssl.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/socks.py +172 -0
- data/vendor/requests/packages/urllib3/contrib/socks.pyc +0 -0
- data/vendor/requests/packages/urllib3/exceptions.py +209 -0
- data/vendor/requests/packages/urllib3/exceptions.pyc +0 -0
- data/vendor/requests/packages/urllib3/fields.py +178 -0
- data/vendor/requests/packages/urllib3/fields.pyc +0 -0
- data/vendor/requests/packages/urllib3/filepost.py +94 -0
- data/vendor/requests/packages/urllib3/filepost.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/__init__.py +5 -0
- data/vendor/requests/packages/urllib3/packages/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/ordered_dict.py +259 -0
- data/vendor/requests/packages/urllib3/packages/ordered_dict.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/six.py +868 -0
- data/vendor/requests/packages/urllib3/packages/six.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py +13 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py +105 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.pyc +0 -0
- data/vendor/requests/packages/urllib3/poolmanager.py +367 -0
- data/vendor/requests/packages/urllib3/poolmanager.pyc +0 -0
- data/vendor/requests/packages/urllib3/request.py +151 -0
- data/vendor/requests/packages/urllib3/request.pyc +0 -0
- data/vendor/requests/packages/urllib3/response.py +530 -0
- data/vendor/requests/packages/urllib3/response.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/__init__.py +46 -0
- data/vendor/requests/packages/urllib3/util/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/connection.py +144 -0
- data/vendor/requests/packages/urllib3/util/connection.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/request.py +72 -0
- data/vendor/requests/packages/urllib3/util/request.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/response.py +74 -0
- data/vendor/requests/packages/urllib3/util/response.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/retry.py +300 -0
- data/vendor/requests/packages/urllib3/util/retry.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/ssl_.py +320 -0
- data/vendor/requests/packages/urllib3/util/ssl_.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/timeout.py +242 -0
- data/vendor/requests/packages/urllib3/util/timeout.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/url.py +217 -0
- data/vendor/requests/packages/urllib3/util/url.pyc +0 -0
- data/vendor/requests/sessions.py +712 -0
- data/vendor/requests/sessions.pyc +0 -0
- data/vendor/requests/status_codes.py +91 -0
- data/vendor/requests/status_codes.pyc +0 -0
- data/vendor/requests/structures.py +105 -0
- data/vendor/requests/structures.pyc +0 -0
- data/vendor/requests/utils.py +817 -0
- data/vendor/requests/utils.pyc +0 -0
- data/vendor/requests-2.11.1.dist-info/DESCRIPTION.rst +1294 -0
- data/vendor/requests-2.11.1.dist-info/INSTALLER +1 -0
- data/vendor/requests-2.11.1.dist-info/METADATA +1323 -0
- data/vendor/requests-2.11.1.dist-info/RECORD +170 -0
- data/vendor/requests-2.11.1.dist-info/WHEEL +6 -0
- data/vendor/requests-2.11.1.dist-info/metadata.json +1 -0
- data/vendor/requests-2.11.1.dist-info/top_level.txt +1 -0
- data/vendor/rigid/__init__.py +1 -0
- data/vendor/rigid/__init__.pyc +0 -0
- data/vendor/rigid/api.py +129 -0
- data/vendor/rigid/api.pyc +0 -0
- data/vendor/rigid/commands/__init__.py +260 -0
- data/vendor/rigid/commands/__init__.pyc +0 -0
- data/vendor/rigid/commands/deploy.py +0 -0
- data/vendor/rigid/commands/deploy.pyc +0 -0
- data/vendor/rigid/deploy.py +70 -0
- data/vendor/rigid/deploy.pyc +0 -0
- data/vendor/rigid/file_scanner.py +63 -0
- data/vendor/rigid/file_scanner.pyc +0 -0
- data/vendor/rigid/utils.py +17 -0
- data/vendor/rigid/utils.pyc +0 -0
- data/vendor/rigid-0.2.0.dist-info/DESCRIPTION.rst +3 -0
- data/vendor/rigid-0.2.0.dist-info/INSTALLER +1 -0
- data/vendor/rigid-0.2.0.dist-info/METADATA +23 -0
- data/vendor/rigid-0.2.0.dist-info/RECORD +49 -0
- data/vendor/rigid-0.2.0.dist-info/WHEEL +5 -0
- data/vendor/rigid-0.2.0.dist-info/entry_points.txt +3 -0
- data/vendor/rigid-0.2.0.dist-info/metadata.json +1 -0
- data/vendor/rigid-0.2.0.dist-info/top_level.txt +2 -0
- data/vendor/setuptools-28.8.0.dist-info/DESCRIPTION.rst +243 -0
- data/vendor/setuptools-28.8.0.dist-info/INSTALLER +1 -0
- data/vendor/setuptools-28.8.0.dist-info/METADATA +272 -0
- data/vendor/setuptools-28.8.0.dist-info/RECORD +143 -0
- data/vendor/setuptools-28.8.0.dist-info/WHEEL +6 -0
- data/vendor/setuptools-28.8.0.dist-info/dependency_links.txt +2 -0
- data/vendor/setuptools-28.8.0.dist-info/entry_points.txt +63 -0
- data/vendor/setuptools-28.8.0.dist-info/metadata.json +1 -0
- data/vendor/setuptools-28.8.0.dist-info/top_level.txt +3 -0
- data/vendor/setuptools-28.8.0.dist-info/zip-safe +1 -0
- data/vendor/tests/__init__.py +0 -0
- data/vendor/tests/__init__.pyc +0 -0
- data/vendor/tests/integration/__init__.py +0 -0
- data/vendor/tests/integration/__init__.pyc +0 -0
- data/vendor/tests/integration/test_app.py +63 -0
- data/vendor/tests/integration/test_app.pyc +0 -0
- data/vendor/tests/integration/test_apps.py +27 -0
- data/vendor/tests/integration/test_apps.pyc +0 -0
- data/vendor/tests/integration/test_deploy.py +128 -0
- data/vendor/tests/integration/test_deploy.pyc +0 -0
- data/vendor/tests/integration/test_domains.py +35 -0
- data/vendor/tests/integration/test_domains.pyc +0 -0
- data/vendor/tests/integration/test_login.py +37 -0
- data/vendor/tests/integration/test_login.pyc +0 -0
- data/vendor/tests/integration/test_promote.py +24 -0
- data/vendor/tests/integration/test_promote.pyc +0 -0
- data/vendor/tests/integration/test_token.py +33 -0
- data/vendor/tests/integration/test_token.pyc +0 -0
- data/vendor/tests/integration/test_whoami.py +24 -0
- data/vendor/tests/integration/test_whoami.pyc +0 -0
- data/vendor/tests/test_deploy.py +33 -0
- data/vendor/tests/test_deploy.pyc +0 -0
- data/vendor/tests/test_file_scanner.py +89 -0
- data/vendor/tests/test_file_scanner.pyc +0 -0
- data/vendor/tests/utils.py +78 -0
- data/vendor/tests/utils.pyc +0 -0
- data/vendor/wheel-0.30.0a0.dist-info/DESCRIPTION.rst +325 -0
- data/vendor/wheel-0.30.0a0.dist-info/INSTALLER +1 -0
- data/vendor/wheel-0.30.0a0.dist-info/LICENSE.txt +22 -0
- data/vendor/wheel-0.30.0a0.dist-info/METADATA +357 -0
- data/vendor/wheel-0.30.0a0.dist-info/RECORD +86 -0
- data/vendor/wheel-0.30.0a0.dist-info/WHEEL +6 -0
- data/vendor/wheel-0.30.0a0.dist-info/entry_points.txt +6 -0
- data/vendor/wheel-0.30.0a0.dist-info/metadata.json +1 -0
- data/vendor/wheel-0.30.0a0.dist-info/top_level.txt +1 -0
- data/vendor/yaml/__init__.py +315 -0
- data/vendor/yaml/__init__.pyc +0 -0
- data/vendor/yaml/composer.py +139 -0
- data/vendor/yaml/composer.pyc +0 -0
- data/vendor/yaml/constructor.py +675 -0
- data/vendor/yaml/constructor.pyc +0 -0
- data/vendor/yaml/cyaml.py +85 -0
- data/vendor/yaml/cyaml.pyc +0 -0
- data/vendor/yaml/dumper.py +62 -0
- data/vendor/yaml/dumper.pyc +0 -0
- data/vendor/yaml/emitter.py +1140 -0
- data/vendor/yaml/emitter.pyc +0 -0
- data/vendor/yaml/error.py +75 -0
- data/vendor/yaml/error.pyc +0 -0
- data/vendor/yaml/events.py +86 -0
- data/vendor/yaml/events.pyc +0 -0
- data/vendor/yaml/loader.py +40 -0
- data/vendor/yaml/loader.pyc +0 -0
- data/vendor/yaml/nodes.py +49 -0
- data/vendor/yaml/nodes.pyc +0 -0
- data/vendor/yaml/parser.py +589 -0
- data/vendor/yaml/parser.pyc +0 -0
- data/vendor/yaml/reader.py +190 -0
- data/vendor/yaml/reader.pyc +0 -0
- data/vendor/yaml/representer.py +486 -0
- data/vendor/yaml/representer.pyc +0 -0
- data/vendor/yaml/resolver.py +227 -0
- data/vendor/yaml/resolver.pyc +0 -0
- data/vendor/yaml/scanner.py +1453 -0
- data/vendor/yaml/scanner.pyc +0 -0
- data/vendor/yaml/serializer.py +111 -0
- data/vendor/yaml/serializer.pyc +0 -0
- data/vendor/yaml/tokens.py +104 -0
- data/vendor/yaml/tokens.pyc +0 -0
- metadata +407 -0
@@ -0,0 +1,3051 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
"""
|
3
|
+
Package resource API
|
4
|
+
--------------------
|
5
|
+
|
6
|
+
A resource is a logical file contained within a package, or a logical
|
7
|
+
subdirectory thereof. The package resource API expects resource names
|
8
|
+
to have their path parts separated with ``/``, *not* whatever the local
|
9
|
+
path separator is. Do not use os.path operations to manipulate resource
|
10
|
+
names being passed into the API.
|
11
|
+
|
12
|
+
The package resource API is designed to work with normal filesystem packages,
|
13
|
+
.egg files, and unpacked .egg files. It can also work in a limited way with
|
14
|
+
.zip files and with custom PEP 302 loaders that support the ``get_data()``
|
15
|
+
method.
|
16
|
+
"""
|
17
|
+
|
18
|
+
from __future__ import absolute_import
|
19
|
+
|
20
|
+
import sys
|
21
|
+
import os
|
22
|
+
import io
|
23
|
+
import time
|
24
|
+
import re
|
25
|
+
import types
|
26
|
+
import zipfile
|
27
|
+
import zipimport
|
28
|
+
import warnings
|
29
|
+
import stat
|
30
|
+
import functools
|
31
|
+
import pkgutil
|
32
|
+
import operator
|
33
|
+
import platform
|
34
|
+
import collections
|
35
|
+
import plistlib
|
36
|
+
import email.parser
|
37
|
+
import tempfile
|
38
|
+
import textwrap
|
39
|
+
import itertools
|
40
|
+
from pkgutil import get_importer
|
41
|
+
|
42
|
+
try:
|
43
|
+
import _imp
|
44
|
+
except ImportError:
|
45
|
+
# Python 3.2 compatibility
|
46
|
+
import imp as _imp
|
47
|
+
|
48
|
+
from pkg_resources.extern import six
|
49
|
+
from pkg_resources.extern.six.moves import urllib, map, filter
|
50
|
+
|
51
|
+
# capture these to bypass sandboxing
|
52
|
+
from os import utime
|
53
|
+
try:
|
54
|
+
from os import mkdir, rename, unlink
|
55
|
+
WRITE_SUPPORT = True
|
56
|
+
except ImportError:
|
57
|
+
# no write support, probably under GAE
|
58
|
+
WRITE_SUPPORT = False
|
59
|
+
|
60
|
+
from os import open as os_open
|
61
|
+
from os.path import isdir, split
|
62
|
+
|
63
|
+
try:
|
64
|
+
import importlib.machinery as importlib_machinery
|
65
|
+
# access attribute to force import under delayed import mechanisms.
|
66
|
+
importlib_machinery.__name__
|
67
|
+
except ImportError:
|
68
|
+
importlib_machinery = None
|
69
|
+
|
70
|
+
from pkg_resources.extern import appdirs
|
71
|
+
from pkg_resources.extern import packaging
|
72
|
+
__import__('pkg_resources.extern.packaging.version')
|
73
|
+
__import__('pkg_resources.extern.packaging.specifiers')
|
74
|
+
__import__('pkg_resources.extern.packaging.requirements')
|
75
|
+
__import__('pkg_resources.extern.packaging.markers')
|
76
|
+
|
77
|
+
if (3, 0) < sys.version_info < (3, 3):
|
78
|
+
msg = (
|
79
|
+
"Support for Python 3.0-3.2 has been dropped. Future versions "
|
80
|
+
"will fail here."
|
81
|
+
)
|
82
|
+
warnings.warn(msg)
|
83
|
+
|
84
|
+
# declare some globals that will be defined later to
|
85
|
+
# satisfy the linters.
|
86
|
+
require = None
|
87
|
+
working_set = None
|
88
|
+
|
89
|
+
|
90
|
+
class PEP440Warning(RuntimeWarning):
|
91
|
+
"""
|
92
|
+
Used when there is an issue with a version or specifier not complying with
|
93
|
+
PEP 440.
|
94
|
+
"""
|
95
|
+
|
96
|
+
|
97
|
+
class _SetuptoolsVersionMixin(object):
|
98
|
+
def __hash__(self):
|
99
|
+
return super(_SetuptoolsVersionMixin, self).__hash__()
|
100
|
+
|
101
|
+
def __lt__(self, other):
|
102
|
+
if isinstance(other, tuple):
|
103
|
+
return tuple(self) < other
|
104
|
+
else:
|
105
|
+
return super(_SetuptoolsVersionMixin, self).__lt__(other)
|
106
|
+
|
107
|
+
def __le__(self, other):
|
108
|
+
if isinstance(other, tuple):
|
109
|
+
return tuple(self) <= other
|
110
|
+
else:
|
111
|
+
return super(_SetuptoolsVersionMixin, self).__le__(other)
|
112
|
+
|
113
|
+
def __eq__(self, other):
|
114
|
+
if isinstance(other, tuple):
|
115
|
+
return tuple(self) == other
|
116
|
+
else:
|
117
|
+
return super(_SetuptoolsVersionMixin, self).__eq__(other)
|
118
|
+
|
119
|
+
def __ge__(self, other):
|
120
|
+
if isinstance(other, tuple):
|
121
|
+
return tuple(self) >= other
|
122
|
+
else:
|
123
|
+
return super(_SetuptoolsVersionMixin, self).__ge__(other)
|
124
|
+
|
125
|
+
def __gt__(self, other):
|
126
|
+
if isinstance(other, tuple):
|
127
|
+
return tuple(self) > other
|
128
|
+
else:
|
129
|
+
return super(_SetuptoolsVersionMixin, self).__gt__(other)
|
130
|
+
|
131
|
+
def __ne__(self, other):
|
132
|
+
if isinstance(other, tuple):
|
133
|
+
return tuple(self) != other
|
134
|
+
else:
|
135
|
+
return super(_SetuptoolsVersionMixin, self).__ne__(other)
|
136
|
+
|
137
|
+
def __getitem__(self, key):
|
138
|
+
return tuple(self)[key]
|
139
|
+
|
140
|
+
def __iter__(self):
|
141
|
+
component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE)
|
142
|
+
replace = {
|
143
|
+
'pre': 'c',
|
144
|
+
'preview': 'c',
|
145
|
+
'-': 'final-',
|
146
|
+
'rc': 'c',
|
147
|
+
'dev': '@',
|
148
|
+
}.get
|
149
|
+
|
150
|
+
def _parse_version_parts(s):
|
151
|
+
for part in component_re.split(s):
|
152
|
+
part = replace(part, part)
|
153
|
+
if not part or part == '.':
|
154
|
+
continue
|
155
|
+
if part[:1] in '0123456789':
|
156
|
+
# pad for numeric comparison
|
157
|
+
yield part.zfill(8)
|
158
|
+
else:
|
159
|
+
yield '*' + part
|
160
|
+
|
161
|
+
# ensure that alpha/beta/candidate are before final
|
162
|
+
yield '*final'
|
163
|
+
|
164
|
+
def old_parse_version(s):
|
165
|
+
parts = []
|
166
|
+
for part in _parse_version_parts(s.lower()):
|
167
|
+
if part.startswith('*'):
|
168
|
+
# remove '-' before a prerelease tag
|
169
|
+
if part < '*final':
|
170
|
+
while parts and parts[-1] == '*final-':
|
171
|
+
parts.pop()
|
172
|
+
# remove trailing zeros from each series of numeric parts
|
173
|
+
while parts and parts[-1] == '00000000':
|
174
|
+
parts.pop()
|
175
|
+
parts.append(part)
|
176
|
+
return tuple(parts)
|
177
|
+
|
178
|
+
# Warn for use of this function
|
179
|
+
warnings.warn(
|
180
|
+
"You have iterated over the result of "
|
181
|
+
"pkg_resources.parse_version. This is a legacy behavior which is "
|
182
|
+
"inconsistent with the new version class introduced in setuptools "
|
183
|
+
"8.0. In most cases, conversion to a tuple is unnecessary. For "
|
184
|
+
"comparison of versions, sort the Version instances directly. If "
|
185
|
+
"you have another use case requiring the tuple, please file a "
|
186
|
+
"bug with the setuptools project describing that need.",
|
187
|
+
RuntimeWarning,
|
188
|
+
stacklevel=1,
|
189
|
+
)
|
190
|
+
|
191
|
+
for part in old_parse_version(str(self)):
|
192
|
+
yield part
|
193
|
+
|
194
|
+
|
195
|
+
class SetuptoolsVersion(_SetuptoolsVersionMixin, packaging.version.Version):
|
196
|
+
pass
|
197
|
+
|
198
|
+
|
199
|
+
class SetuptoolsLegacyVersion(_SetuptoolsVersionMixin,
|
200
|
+
packaging.version.LegacyVersion):
|
201
|
+
pass
|
202
|
+
|
203
|
+
|
204
|
+
def parse_version(v):
|
205
|
+
try:
|
206
|
+
return SetuptoolsVersion(v)
|
207
|
+
except packaging.version.InvalidVersion:
|
208
|
+
return SetuptoolsLegacyVersion(v)
|
209
|
+
|
210
|
+
|
211
|
+
_state_vars = {}
|
212
|
+
|
213
|
+
|
214
|
+
def _declare_state(vartype, **kw):
|
215
|
+
globals().update(kw)
|
216
|
+
_state_vars.update(dict.fromkeys(kw, vartype))
|
217
|
+
|
218
|
+
|
219
|
+
def __getstate__():
|
220
|
+
state = {}
|
221
|
+
g = globals()
|
222
|
+
for k, v in _state_vars.items():
|
223
|
+
state[k] = g['_sget_' + v](g[k])
|
224
|
+
return state
|
225
|
+
|
226
|
+
|
227
|
+
def __setstate__(state):
|
228
|
+
g = globals()
|
229
|
+
for k, v in state.items():
|
230
|
+
g['_sset_' + _state_vars[k]](k, g[k], v)
|
231
|
+
return state
|
232
|
+
|
233
|
+
|
234
|
+
def _sget_dict(val):
|
235
|
+
return val.copy()
|
236
|
+
|
237
|
+
|
238
|
+
def _sset_dict(key, ob, state):
|
239
|
+
ob.clear()
|
240
|
+
ob.update(state)
|
241
|
+
|
242
|
+
|
243
|
+
def _sget_object(val):
|
244
|
+
return val.__getstate__()
|
245
|
+
|
246
|
+
|
247
|
+
def _sset_object(key, ob, state):
|
248
|
+
ob.__setstate__(state)
|
249
|
+
|
250
|
+
|
251
|
+
_sget_none = _sset_none = lambda *args: None
|
252
|
+
|
253
|
+
|
254
|
+
def get_supported_platform():
|
255
|
+
"""Return this platform's maximum compatible version.
|
256
|
+
|
257
|
+
distutils.util.get_platform() normally reports the minimum version
|
258
|
+
of Mac OS X that would be required to *use* extensions produced by
|
259
|
+
distutils. But what we want when checking compatibility is to know the
|
260
|
+
version of Mac OS X that we are *running*. To allow usage of packages that
|
261
|
+
explicitly require a newer version of Mac OS X, we must also know the
|
262
|
+
current version of the OS.
|
263
|
+
|
264
|
+
If this condition occurs for any other platform with a version in its
|
265
|
+
platform strings, this function should be extended accordingly.
|
266
|
+
"""
|
267
|
+
plat = get_build_platform()
|
268
|
+
m = macosVersionString.match(plat)
|
269
|
+
if m is not None and sys.platform == "darwin":
|
270
|
+
try:
|
271
|
+
plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
|
272
|
+
except ValueError:
|
273
|
+
# not Mac OS X
|
274
|
+
pass
|
275
|
+
return plat
|
276
|
+
|
277
|
+
|
278
|
+
__all__ = [
|
279
|
+
# Basic resource access and distribution/entry point discovery
|
280
|
+
'require', 'run_script', 'get_provider', 'get_distribution',
|
281
|
+
'load_entry_point', 'get_entry_map', 'get_entry_info',
|
282
|
+
'iter_entry_points',
|
283
|
+
'resource_string', 'resource_stream', 'resource_filename',
|
284
|
+
'resource_listdir', 'resource_exists', 'resource_isdir',
|
285
|
+
|
286
|
+
# Environmental control
|
287
|
+
'declare_namespace', 'working_set', 'add_activation_listener',
|
288
|
+
'find_distributions', 'set_extraction_path', 'cleanup_resources',
|
289
|
+
'get_default_cache',
|
290
|
+
|
291
|
+
# Primary implementation classes
|
292
|
+
'Environment', 'WorkingSet', 'ResourceManager',
|
293
|
+
'Distribution', 'Requirement', 'EntryPoint',
|
294
|
+
|
295
|
+
# Exceptions
|
296
|
+
'ResolutionError', 'VersionConflict', 'DistributionNotFound',
|
297
|
+
'UnknownExtra', 'ExtractionError',
|
298
|
+
|
299
|
+
# Warnings
|
300
|
+
'PEP440Warning',
|
301
|
+
|
302
|
+
# Parsing functions and string utilities
|
303
|
+
'parse_requirements', 'parse_version', 'safe_name', 'safe_version',
|
304
|
+
'get_platform', 'compatible_platforms', 'yield_lines', 'split_sections',
|
305
|
+
'safe_extra', 'to_filename', 'invalid_marker', 'evaluate_marker',
|
306
|
+
|
307
|
+
# filesystem utilities
|
308
|
+
'ensure_directory', 'normalize_path',
|
309
|
+
|
310
|
+
# Distribution "precedence" constants
|
311
|
+
'EGG_DIST', 'BINARY_DIST', 'SOURCE_DIST', 'CHECKOUT_DIST', 'DEVELOP_DIST',
|
312
|
+
|
313
|
+
# "Provider" interfaces, implementations, and registration/lookup APIs
|
314
|
+
'IMetadataProvider', 'IResourceProvider', 'FileMetadata',
|
315
|
+
'PathMetadata', 'EggMetadata', 'EmptyProvider', 'empty_provider',
|
316
|
+
'NullProvider', 'EggProvider', 'DefaultProvider', 'ZipProvider',
|
317
|
+
'register_finder', 'register_namespace_handler', 'register_loader_type',
|
318
|
+
'fixup_namespace_packages', 'get_importer',
|
319
|
+
|
320
|
+
# Deprecated/backward compatibility only
|
321
|
+
'run_main', 'AvailableDistributions',
|
322
|
+
]
|
323
|
+
|
324
|
+
|
325
|
+
class ResolutionError(Exception):
|
326
|
+
"""Abstract base for dependency resolution errors"""
|
327
|
+
|
328
|
+
def __repr__(self):
|
329
|
+
return self.__class__.__name__ + repr(self.args)
|
330
|
+
|
331
|
+
|
332
|
+
class VersionConflict(ResolutionError):
|
333
|
+
"""
|
334
|
+
An already-installed version conflicts with the requested version.
|
335
|
+
|
336
|
+
Should be initialized with the installed Distribution and the requested
|
337
|
+
Requirement.
|
338
|
+
"""
|
339
|
+
|
340
|
+
_template = "{self.dist} is installed but {self.req} is required"
|
341
|
+
|
342
|
+
@property
|
343
|
+
def dist(self):
|
344
|
+
return self.args[0]
|
345
|
+
|
346
|
+
@property
|
347
|
+
def req(self):
|
348
|
+
return self.args[1]
|
349
|
+
|
350
|
+
def report(self):
|
351
|
+
return self._template.format(**locals())
|
352
|
+
|
353
|
+
def with_context(self, required_by):
|
354
|
+
"""
|
355
|
+
If required_by is non-empty, return a version of self that is a
|
356
|
+
ContextualVersionConflict.
|
357
|
+
"""
|
358
|
+
if not required_by:
|
359
|
+
return self
|
360
|
+
args = self.args + (required_by,)
|
361
|
+
return ContextualVersionConflict(*args)
|
362
|
+
|
363
|
+
|
364
|
+
class ContextualVersionConflict(VersionConflict):
|
365
|
+
"""
|
366
|
+
A VersionConflict that accepts a third parameter, the set of the
|
367
|
+
requirements that required the installed Distribution.
|
368
|
+
"""
|
369
|
+
|
370
|
+
_template = VersionConflict._template + ' by {self.required_by}'
|
371
|
+
|
372
|
+
@property
|
373
|
+
def required_by(self):
|
374
|
+
return self.args[2]
|
375
|
+
|
376
|
+
|
377
|
+
class DistributionNotFound(ResolutionError):
|
378
|
+
"""A requested distribution was not found"""
|
379
|
+
|
380
|
+
_template = ("The '{self.req}' distribution was not found "
|
381
|
+
"and is required by {self.requirers_str}")
|
382
|
+
|
383
|
+
@property
|
384
|
+
def req(self):
|
385
|
+
return self.args[0]
|
386
|
+
|
387
|
+
@property
|
388
|
+
def requirers(self):
|
389
|
+
return self.args[1]
|
390
|
+
|
391
|
+
@property
|
392
|
+
def requirers_str(self):
|
393
|
+
if not self.requirers:
|
394
|
+
return 'the application'
|
395
|
+
return ', '.join(self.requirers)
|
396
|
+
|
397
|
+
def report(self):
|
398
|
+
return self._template.format(**locals())
|
399
|
+
|
400
|
+
def __str__(self):
|
401
|
+
return self.report()
|
402
|
+
|
403
|
+
|
404
|
+
class UnknownExtra(ResolutionError):
|
405
|
+
"""Distribution doesn't have an "extra feature" of the given name"""
|
406
|
+
|
407
|
+
|
408
|
+
_provider_factories = {}
|
409
|
+
|
410
|
+
PY_MAJOR = sys.version[:3]
|
411
|
+
EGG_DIST = 3
|
412
|
+
BINARY_DIST = 2
|
413
|
+
SOURCE_DIST = 1
|
414
|
+
CHECKOUT_DIST = 0
|
415
|
+
DEVELOP_DIST = -1
|
416
|
+
|
417
|
+
|
418
|
+
def register_loader_type(loader_type, provider_factory):
|
419
|
+
"""Register `provider_factory` to make providers for `loader_type`
|
420
|
+
|
421
|
+
`loader_type` is the type or class of a PEP 302 ``module.__loader__``,
|
422
|
+
and `provider_factory` is a function that, passed a *module* object,
|
423
|
+
returns an ``IResourceProvider`` for that module.
|
424
|
+
"""
|
425
|
+
_provider_factories[loader_type] = provider_factory
|
426
|
+
|
427
|
+
|
428
|
+
def get_provider(moduleOrReq):
|
429
|
+
"""Return an IResourceProvider for the named module or requirement"""
|
430
|
+
if isinstance(moduleOrReq, Requirement):
|
431
|
+
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
|
432
|
+
try:
|
433
|
+
module = sys.modules[moduleOrReq]
|
434
|
+
except KeyError:
|
435
|
+
__import__(moduleOrReq)
|
436
|
+
module = sys.modules[moduleOrReq]
|
437
|
+
loader = getattr(module, '__loader__', None)
|
438
|
+
return _find_adapter(_provider_factories, loader)(module)
|
439
|
+
|
440
|
+
|
441
|
+
def _macosx_vers(_cache=[]):
|
442
|
+
if not _cache:
|
443
|
+
version = platform.mac_ver()[0]
|
444
|
+
# fallback for MacPorts
|
445
|
+
if version == '':
|
446
|
+
plist = '/System/Library/CoreServices/SystemVersion.plist'
|
447
|
+
if os.path.exists(plist):
|
448
|
+
if hasattr(plistlib, 'readPlist'):
|
449
|
+
plist_content = plistlib.readPlist(plist)
|
450
|
+
if 'ProductVersion' in plist_content:
|
451
|
+
version = plist_content['ProductVersion']
|
452
|
+
|
453
|
+
_cache.append(version.split('.'))
|
454
|
+
return _cache[0]
|
455
|
+
|
456
|
+
|
457
|
+
def _macosx_arch(machine):
|
458
|
+
return {'PowerPC': 'ppc', 'Power_Macintosh': 'ppc'}.get(machine, machine)
|
459
|
+
|
460
|
+
|
461
|
+
def get_build_platform():
|
462
|
+
"""Return this platform's string for platform-specific distributions
|
463
|
+
|
464
|
+
XXX Currently this is the same as ``distutils.util.get_platform()``, but it
|
465
|
+
needs some hacks for Linux and Mac OS X.
|
466
|
+
"""
|
467
|
+
try:
|
468
|
+
# Python 2.7 or >=3.2
|
469
|
+
from sysconfig import get_platform
|
470
|
+
except ImportError:
|
471
|
+
from distutils.util import get_platform
|
472
|
+
|
473
|
+
plat = get_platform()
|
474
|
+
if sys.platform == "darwin" and not plat.startswith('macosx-'):
|
475
|
+
try:
|
476
|
+
version = _macosx_vers()
|
477
|
+
machine = os.uname()[4].replace(" ", "_")
|
478
|
+
return "macosx-%d.%d-%s" % (int(version[0]), int(version[1]),
|
479
|
+
_macosx_arch(machine))
|
480
|
+
except ValueError:
|
481
|
+
# if someone is running a non-Mac darwin system, this will fall
|
482
|
+
# through to the default implementation
|
483
|
+
pass
|
484
|
+
return plat
|
485
|
+
|
486
|
+
|
487
|
+
macosVersionString = re.compile(r"macosx-(\d+)\.(\d+)-(.*)")
|
488
|
+
darwinVersionString = re.compile(r"darwin-(\d+)\.(\d+)\.(\d+)-(.*)")
|
489
|
+
# XXX backward compat
|
490
|
+
get_platform = get_build_platform
|
491
|
+
|
492
|
+
|
493
|
+
def compatible_platforms(provided, required):
|
494
|
+
"""Can code for the `provided` platform run on the `required` platform?
|
495
|
+
|
496
|
+
Returns true if either platform is ``None``, or the platforms are equal.
|
497
|
+
|
498
|
+
XXX Needs compatibility checks for Linux and other unixy OSes.
|
499
|
+
"""
|
500
|
+
if provided is None or required is None or provided == required:
|
501
|
+
# easy case
|
502
|
+
return True
|
503
|
+
|
504
|
+
# Mac OS X special cases
|
505
|
+
reqMac = macosVersionString.match(required)
|
506
|
+
if reqMac:
|
507
|
+
provMac = macosVersionString.match(provided)
|
508
|
+
|
509
|
+
# is this a Mac package?
|
510
|
+
if not provMac:
|
511
|
+
# this is backwards compatibility for packages built before
|
512
|
+
# setuptools 0.6. All packages built after this point will
|
513
|
+
# use the new macosx designation.
|
514
|
+
provDarwin = darwinVersionString.match(provided)
|
515
|
+
if provDarwin:
|
516
|
+
dversion = int(provDarwin.group(1))
|
517
|
+
macosversion = "%s.%s" % (reqMac.group(1), reqMac.group(2))
|
518
|
+
if dversion == 7 and macosversion >= "10.3" or \
|
519
|
+
dversion == 8 and macosversion >= "10.4":
|
520
|
+
return True
|
521
|
+
# egg isn't macosx or legacy darwin
|
522
|
+
return False
|
523
|
+
|
524
|
+
# are they the same major version and machine type?
|
525
|
+
if provMac.group(1) != reqMac.group(1) or \
|
526
|
+
provMac.group(3) != reqMac.group(3):
|
527
|
+
return False
|
528
|
+
|
529
|
+
# is the required OS major update >= the provided one?
|
530
|
+
if int(provMac.group(2)) > int(reqMac.group(2)):
|
531
|
+
return False
|
532
|
+
|
533
|
+
return True
|
534
|
+
|
535
|
+
# XXX Linux and other platforms' special cases should go here
|
536
|
+
return False
|
537
|
+
|
538
|
+
|
539
|
+
def run_script(dist_spec, script_name):
|
540
|
+
"""Locate distribution `dist_spec` and run its `script_name` script"""
|
541
|
+
ns = sys._getframe(1).f_globals
|
542
|
+
name = ns['__name__']
|
543
|
+
ns.clear()
|
544
|
+
ns['__name__'] = name
|
545
|
+
require(dist_spec)[0].run_script(script_name, ns)
|
546
|
+
|
547
|
+
|
548
|
+
# backward compatibility
|
549
|
+
run_main = run_script
|
550
|
+
|
551
|
+
|
552
|
+
def get_distribution(dist):
|
553
|
+
"""Return a current distribution object for a Requirement or string"""
|
554
|
+
if isinstance(dist, six.string_types):
|
555
|
+
dist = Requirement.parse(dist)
|
556
|
+
if isinstance(dist, Requirement):
|
557
|
+
dist = get_provider(dist)
|
558
|
+
if not isinstance(dist, Distribution):
|
559
|
+
raise TypeError("Expected string, Requirement, or Distribution", dist)
|
560
|
+
return dist
|
561
|
+
|
562
|
+
|
563
|
+
def load_entry_point(dist, group, name):
|
564
|
+
"""Return `name` entry point of `group` for `dist` or raise ImportError"""
|
565
|
+
return get_distribution(dist).load_entry_point(group, name)
|
566
|
+
|
567
|
+
|
568
|
+
def get_entry_map(dist, group=None):
|
569
|
+
"""Return the entry point map for `group`, or the full entry map"""
|
570
|
+
return get_distribution(dist).get_entry_map(group)
|
571
|
+
|
572
|
+
|
573
|
+
def get_entry_info(dist, group, name):
|
574
|
+
"""Return the EntryPoint object for `group`+`name`, or ``None``"""
|
575
|
+
return get_distribution(dist).get_entry_info(group, name)
|
576
|
+
|
577
|
+
|
578
|
+
class IMetadataProvider:
|
579
|
+
def has_metadata(name):
|
580
|
+
"""Does the package's distribution contain the named metadata?"""
|
581
|
+
|
582
|
+
def get_metadata(name):
|
583
|
+
"""The named metadata resource as a string"""
|
584
|
+
|
585
|
+
def get_metadata_lines(name):
|
586
|
+
"""Yield named metadata resource as list of non-blank non-comment lines
|
587
|
+
|
588
|
+
Leading and trailing whitespace is stripped from each line, and lines
|
589
|
+
with ``#`` as the first non-blank character are omitted."""
|
590
|
+
|
591
|
+
def metadata_isdir(name):
|
592
|
+
"""Is the named metadata a directory? (like ``os.path.isdir()``)"""
|
593
|
+
|
594
|
+
def metadata_listdir(name):
|
595
|
+
"""List of metadata names in the directory (like ``os.listdir()``)"""
|
596
|
+
|
597
|
+
def run_script(script_name, namespace):
|
598
|
+
"""Execute the named script in the supplied namespace dictionary"""
|
599
|
+
|
600
|
+
|
601
|
+
class IResourceProvider(IMetadataProvider):
|
602
|
+
"""An object that provides access to package resources"""
|
603
|
+
|
604
|
+
def get_resource_filename(manager, resource_name):
|
605
|
+
"""Return a true filesystem path for `resource_name`
|
606
|
+
|
607
|
+
`manager` must be an ``IResourceManager``"""
|
608
|
+
|
609
|
+
def get_resource_stream(manager, resource_name):
|
610
|
+
"""Return a readable file-like object for `resource_name`
|
611
|
+
|
612
|
+
`manager` must be an ``IResourceManager``"""
|
613
|
+
|
614
|
+
def get_resource_string(manager, resource_name):
|
615
|
+
"""Return a string containing the contents of `resource_name`
|
616
|
+
|
617
|
+
`manager` must be an ``IResourceManager``"""
|
618
|
+
|
619
|
+
def has_resource(resource_name):
|
620
|
+
"""Does the package contain the named resource?"""
|
621
|
+
|
622
|
+
def resource_isdir(resource_name):
|
623
|
+
"""Is the named resource a directory? (like ``os.path.isdir()``)"""
|
624
|
+
|
625
|
+
def resource_listdir(resource_name):
|
626
|
+
"""List of resource names in the directory (like ``os.listdir()``)"""
|
627
|
+
|
628
|
+
|
629
|
+
class WorkingSet(object):
|
630
|
+
"""A collection of active distributions on sys.path (or a similar list)"""
|
631
|
+
|
632
|
+
def __init__(self, entries=None):
|
633
|
+
"""Create working set from list of path entries (default=sys.path)"""
|
634
|
+
self.entries = []
|
635
|
+
self.entry_keys = {}
|
636
|
+
self.by_key = {}
|
637
|
+
self.callbacks = []
|
638
|
+
|
639
|
+
if entries is None:
|
640
|
+
entries = sys.path
|
641
|
+
|
642
|
+
for entry in entries:
|
643
|
+
self.add_entry(entry)
|
644
|
+
|
645
|
+
@classmethod
|
646
|
+
def _build_master(cls):
|
647
|
+
"""
|
648
|
+
Prepare the master working set.
|
649
|
+
"""
|
650
|
+
ws = cls()
|
651
|
+
try:
|
652
|
+
from __main__ import __requires__
|
653
|
+
except ImportError:
|
654
|
+
# The main program does not list any requirements
|
655
|
+
return ws
|
656
|
+
|
657
|
+
# ensure the requirements are met
|
658
|
+
try:
|
659
|
+
ws.require(__requires__)
|
660
|
+
except VersionConflict:
|
661
|
+
return cls._build_from_requirements(__requires__)
|
662
|
+
|
663
|
+
return ws
|
664
|
+
|
665
|
+
@classmethod
|
666
|
+
def _build_from_requirements(cls, req_spec):
|
667
|
+
"""
|
668
|
+
Build a working set from a requirement spec. Rewrites sys.path.
|
669
|
+
"""
|
670
|
+
# try it without defaults already on sys.path
|
671
|
+
# by starting with an empty path
|
672
|
+
ws = cls([])
|
673
|
+
reqs = parse_requirements(req_spec)
|
674
|
+
dists = ws.resolve(reqs, Environment())
|
675
|
+
for dist in dists:
|
676
|
+
ws.add(dist)
|
677
|
+
|
678
|
+
# add any missing entries from sys.path
|
679
|
+
for entry in sys.path:
|
680
|
+
if entry not in ws.entries:
|
681
|
+
ws.add_entry(entry)
|
682
|
+
|
683
|
+
# then copy back to sys.path
|
684
|
+
sys.path[:] = ws.entries
|
685
|
+
return ws
|
686
|
+
|
687
|
+
def add_entry(self, entry):
|
688
|
+
"""Add a path item to ``.entries``, finding any distributions on it
|
689
|
+
|
690
|
+
``find_distributions(entry, True)`` is used to find distributions
|
691
|
+
corresponding to the path entry, and they are added. `entry` is
|
692
|
+
always appended to ``.entries``, even if it is already present.
|
693
|
+
(This is because ``sys.path`` can contain the same value more than
|
694
|
+
once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
|
695
|
+
equal ``sys.path``.)
|
696
|
+
"""
|
697
|
+
self.entry_keys.setdefault(entry, [])
|
698
|
+
self.entries.append(entry)
|
699
|
+
for dist in find_distributions(entry, True):
|
700
|
+
self.add(dist, entry, False)
|
701
|
+
|
702
|
+
def __contains__(self, dist):
|
703
|
+
"""True if `dist` is the active distribution for its project"""
|
704
|
+
return self.by_key.get(dist.key) == dist
|
705
|
+
|
706
|
+
def find(self, req):
|
707
|
+
"""Find a distribution matching requirement `req`
|
708
|
+
|
709
|
+
If there is an active distribution for the requested project, this
|
710
|
+
returns it as long as it meets the version requirement specified by
|
711
|
+
`req`. But, if there is an active distribution for the project and it
|
712
|
+
does *not* meet the `req` requirement, ``VersionConflict`` is raised.
|
713
|
+
If there is no active distribution for the requested project, ``None``
|
714
|
+
is returned.
|
715
|
+
"""
|
716
|
+
dist = self.by_key.get(req.key)
|
717
|
+
if dist is not None and dist not in req:
|
718
|
+
# XXX add more info
|
719
|
+
raise VersionConflict(dist, req)
|
720
|
+
return dist
|
721
|
+
|
722
|
+
def iter_entry_points(self, group, name=None):
|
723
|
+
"""Yield entry point objects from `group` matching `name`
|
724
|
+
|
725
|
+
If `name` is None, yields all entry points in `group` from all
|
726
|
+
distributions in the working set, otherwise only ones matching
|
727
|
+
both `group` and `name` are yielded (in distribution order).
|
728
|
+
"""
|
729
|
+
for dist in self:
|
730
|
+
entries = dist.get_entry_map(group)
|
731
|
+
if name is None:
|
732
|
+
for ep in entries.values():
|
733
|
+
yield ep
|
734
|
+
elif name in entries:
|
735
|
+
yield entries[name]
|
736
|
+
|
737
|
+
def run_script(self, requires, script_name):
|
738
|
+
"""Locate distribution for `requires` and run `script_name` script"""
|
739
|
+
ns = sys._getframe(1).f_globals
|
740
|
+
name = ns['__name__']
|
741
|
+
ns.clear()
|
742
|
+
ns['__name__'] = name
|
743
|
+
self.require(requires)[0].run_script(script_name, ns)
|
744
|
+
|
745
|
+
def __iter__(self):
|
746
|
+
"""Yield distributions for non-duplicate projects in the working set
|
747
|
+
|
748
|
+
The yield order is the order in which the items' path entries were
|
749
|
+
added to the working set.
|
750
|
+
"""
|
751
|
+
seen = {}
|
752
|
+
for item in self.entries:
|
753
|
+
if item not in self.entry_keys:
|
754
|
+
# workaround a cache issue
|
755
|
+
continue
|
756
|
+
|
757
|
+
for key in self.entry_keys[item]:
|
758
|
+
if key not in seen:
|
759
|
+
seen[key] = 1
|
760
|
+
yield self.by_key[key]
|
761
|
+
|
762
|
+
def add(self, dist, entry=None, insert=True, replace=False):
|
763
|
+
"""Add `dist` to working set, associated with `entry`
|
764
|
+
|
765
|
+
If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
|
766
|
+
On exit from this routine, `entry` is added to the end of the working
|
767
|
+
set's ``.entries`` (if it wasn't already present).
|
768
|
+
|
769
|
+
`dist` is only added to the working set if it's for a project that
|
770
|
+
doesn't already have a distribution in the set, unless `replace=True`.
|
771
|
+
If it's added, any callbacks registered with the ``subscribe()`` method
|
772
|
+
will be called.
|
773
|
+
"""
|
774
|
+
if insert:
|
775
|
+
dist.insert_on(self.entries, entry, replace=replace)
|
776
|
+
|
777
|
+
if entry is None:
|
778
|
+
entry = dist.location
|
779
|
+
keys = self.entry_keys.setdefault(entry, [])
|
780
|
+
keys2 = self.entry_keys.setdefault(dist.location, [])
|
781
|
+
if not replace and dist.key in self.by_key:
|
782
|
+
# ignore hidden distros
|
783
|
+
return
|
784
|
+
|
785
|
+
self.by_key[dist.key] = dist
|
786
|
+
if dist.key not in keys:
|
787
|
+
keys.append(dist.key)
|
788
|
+
if dist.key not in keys2:
|
789
|
+
keys2.append(dist.key)
|
790
|
+
self._added_new(dist)
|
791
|
+
|
792
|
+
def resolve(self, requirements, env=None, installer=None,
|
793
|
+
replace_conflicting=False):
|
794
|
+
"""List all distributions needed to (recursively) meet `requirements`
|
795
|
+
|
796
|
+
`requirements` must be a sequence of ``Requirement`` objects. `env`,
|
797
|
+
if supplied, should be an ``Environment`` instance. If
|
798
|
+
not supplied, it defaults to all distributions available within any
|
799
|
+
entry or distribution in the working set. `installer`, if supplied,
|
800
|
+
will be invoked with each requirement that cannot be met by an
|
801
|
+
already-installed distribution; it should return a ``Distribution`` or
|
802
|
+
``None``.
|
803
|
+
|
804
|
+
Unless `replace_conflicting=True`, raises a VersionConflict exception if
|
805
|
+
any requirements are found on the path that have the correct name but
|
806
|
+
the wrong version. Otherwise, if an `installer` is supplied it will be
|
807
|
+
invoked to obtain the correct version of the requirement and activate
|
808
|
+
it.
|
809
|
+
"""
|
810
|
+
|
811
|
+
# set up the stack
|
812
|
+
requirements = list(requirements)[::-1]
|
813
|
+
# set of processed requirements
|
814
|
+
processed = {}
|
815
|
+
# key -> dist
|
816
|
+
best = {}
|
817
|
+
to_activate = []
|
818
|
+
|
819
|
+
req_extras = _ReqExtras()
|
820
|
+
|
821
|
+
# Mapping of requirement to set of distributions that required it;
|
822
|
+
# useful for reporting info about conflicts.
|
823
|
+
required_by = collections.defaultdict(set)
|
824
|
+
|
825
|
+
while requirements:
|
826
|
+
# process dependencies breadth-first
|
827
|
+
req = requirements.pop(0)
|
828
|
+
if req in processed:
|
829
|
+
# Ignore cyclic or redundant dependencies
|
830
|
+
continue
|
831
|
+
|
832
|
+
if not req_extras.markers_pass(req):
|
833
|
+
continue
|
834
|
+
|
835
|
+
dist = best.get(req.key)
|
836
|
+
if dist is None:
|
837
|
+
# Find the best distribution and add it to the map
|
838
|
+
dist = self.by_key.get(req.key)
|
839
|
+
if dist is None or (dist not in req and replace_conflicting):
|
840
|
+
ws = self
|
841
|
+
if env is None:
|
842
|
+
if dist is None:
|
843
|
+
env = Environment(self.entries)
|
844
|
+
else:
|
845
|
+
# Use an empty environment and workingset to avoid
|
846
|
+
# any further conflicts with the conflicting
|
847
|
+
# distribution
|
848
|
+
env = Environment([])
|
849
|
+
ws = WorkingSet([])
|
850
|
+
dist = best[req.key] = env.best_match(req, ws, installer)
|
851
|
+
if dist is None:
|
852
|
+
requirers = required_by.get(req, None)
|
853
|
+
raise DistributionNotFound(req, requirers)
|
854
|
+
to_activate.append(dist)
|
855
|
+
if dist not in req:
|
856
|
+
# Oops, the "best" so far conflicts with a dependency
|
857
|
+
dependent_req = required_by[req]
|
858
|
+
raise VersionConflict(dist, req).with_context(dependent_req)
|
859
|
+
|
860
|
+
# push the new requirements onto the stack
|
861
|
+
new_requirements = dist.requires(req.extras)[::-1]
|
862
|
+
requirements.extend(new_requirements)
|
863
|
+
|
864
|
+
# Register the new requirements needed by req
|
865
|
+
for new_requirement in new_requirements:
|
866
|
+
required_by[new_requirement].add(req.project_name)
|
867
|
+
req_extras[new_requirement] = req.extras
|
868
|
+
|
869
|
+
processed[req] = True
|
870
|
+
|
871
|
+
# return list of distros to activate
|
872
|
+
return to_activate
|
873
|
+
|
874
|
+
def find_plugins(self, plugin_env, full_env=None, installer=None,
|
875
|
+
fallback=True):
|
876
|
+
"""Find all activatable distributions in `plugin_env`
|
877
|
+
|
878
|
+
Example usage::
|
879
|
+
|
880
|
+
distributions, errors = working_set.find_plugins(
|
881
|
+
Environment(plugin_dirlist)
|
882
|
+
)
|
883
|
+
# add plugins+libs to sys.path
|
884
|
+
map(working_set.add, distributions)
|
885
|
+
# display errors
|
886
|
+
print('Could not load', errors)
|
887
|
+
|
888
|
+
The `plugin_env` should be an ``Environment`` instance that contains
|
889
|
+
only distributions that are in the project's "plugin directory" or
|
890
|
+
directories. The `full_env`, if supplied, should be an ``Environment``
|
891
|
+
contains all currently-available distributions. If `full_env` is not
|
892
|
+
supplied, one is created automatically from the ``WorkingSet`` this
|
893
|
+
method is called on, which will typically mean that every directory on
|
894
|
+
``sys.path`` will be scanned for distributions.
|
895
|
+
|
896
|
+
`installer` is a standard installer callback as used by the
|
897
|
+
``resolve()`` method. The `fallback` flag indicates whether we should
|
898
|
+
attempt to resolve older versions of a plugin if the newest version
|
899
|
+
cannot be resolved.
|
900
|
+
|
901
|
+
This method returns a 2-tuple: (`distributions`, `error_info`), where
|
902
|
+
`distributions` is a list of the distributions found in `plugin_env`
|
903
|
+
that were loadable, along with any other distributions that are needed
|
904
|
+
to resolve their dependencies. `error_info` is a dictionary mapping
|
905
|
+
unloadable plugin distributions to an exception instance describing the
|
906
|
+
error that occurred. Usually this will be a ``DistributionNotFound`` or
|
907
|
+
``VersionConflict`` instance.
|
908
|
+
"""
|
909
|
+
|
910
|
+
plugin_projects = list(plugin_env)
|
911
|
+
# scan project names in alphabetic order
|
912
|
+
plugin_projects.sort()
|
913
|
+
|
914
|
+
error_info = {}
|
915
|
+
distributions = {}
|
916
|
+
|
917
|
+
if full_env is None:
|
918
|
+
env = Environment(self.entries)
|
919
|
+
env += plugin_env
|
920
|
+
else:
|
921
|
+
env = full_env + plugin_env
|
922
|
+
|
923
|
+
shadow_set = self.__class__([])
|
924
|
+
# put all our entries in shadow_set
|
925
|
+
list(map(shadow_set.add, self))
|
926
|
+
|
927
|
+
for project_name in plugin_projects:
|
928
|
+
|
929
|
+
for dist in plugin_env[project_name]:
|
930
|
+
|
931
|
+
req = [dist.as_requirement()]
|
932
|
+
|
933
|
+
try:
|
934
|
+
resolvees = shadow_set.resolve(req, env, installer)
|
935
|
+
|
936
|
+
except ResolutionError as v:
|
937
|
+
# save error info
|
938
|
+
error_info[dist] = v
|
939
|
+
if fallback:
|
940
|
+
# try the next older version of project
|
941
|
+
continue
|
942
|
+
else:
|
943
|
+
# give up on this project, keep going
|
944
|
+
break
|
945
|
+
|
946
|
+
else:
|
947
|
+
list(map(shadow_set.add, resolvees))
|
948
|
+
distributions.update(dict.fromkeys(resolvees))
|
949
|
+
|
950
|
+
# success, no need to try any more versions of this project
|
951
|
+
break
|
952
|
+
|
953
|
+
distributions = list(distributions)
|
954
|
+
distributions.sort()
|
955
|
+
|
956
|
+
return distributions, error_info
|
957
|
+
|
958
|
+
def require(self, *requirements):
|
959
|
+
"""Ensure that distributions matching `requirements` are activated
|
960
|
+
|
961
|
+
`requirements` must be a string or a (possibly-nested) sequence
|
962
|
+
thereof, specifying the distributions and versions required. The
|
963
|
+
return value is a sequence of the distributions that needed to be
|
964
|
+
activated to fulfill the requirements; all relevant distributions are
|
965
|
+
included, even if they were already activated in this working set.
|
966
|
+
"""
|
967
|
+
needed = self.resolve(parse_requirements(requirements))
|
968
|
+
|
969
|
+
for dist in needed:
|
970
|
+
self.add(dist)
|
971
|
+
|
972
|
+
return needed
|
973
|
+
|
974
|
+
def subscribe(self, callback, existing=True):
|
975
|
+
"""Invoke `callback` for all distributions
|
976
|
+
|
977
|
+
If `existing=True` (default),
|
978
|
+
call on all existing ones, as well.
|
979
|
+
"""
|
980
|
+
if callback in self.callbacks:
|
981
|
+
return
|
982
|
+
self.callbacks.append(callback)
|
983
|
+
if not existing:
|
984
|
+
return
|
985
|
+
for dist in self:
|
986
|
+
callback(dist)
|
987
|
+
|
988
|
+
def _added_new(self, dist):
|
989
|
+
for callback in self.callbacks:
|
990
|
+
callback(dist)
|
991
|
+
|
992
|
+
def __getstate__(self):
|
993
|
+
return (
|
994
|
+
self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
|
995
|
+
self.callbacks[:]
|
996
|
+
)
|
997
|
+
|
998
|
+
def __setstate__(self, e_k_b_c):
|
999
|
+
entries, keys, by_key, callbacks = e_k_b_c
|
1000
|
+
self.entries = entries[:]
|
1001
|
+
self.entry_keys = keys.copy()
|
1002
|
+
self.by_key = by_key.copy()
|
1003
|
+
self.callbacks = callbacks[:]
|
1004
|
+
|
1005
|
+
|
1006
|
+
class _ReqExtras(dict):
|
1007
|
+
"""
|
1008
|
+
Map each requirement to the extras that demanded it.
|
1009
|
+
"""
|
1010
|
+
|
1011
|
+
def markers_pass(self, req):
|
1012
|
+
"""
|
1013
|
+
Evaluate markers for req against each extra that
|
1014
|
+
demanded it.
|
1015
|
+
|
1016
|
+
Return False if the req has a marker and fails
|
1017
|
+
evaluation. Otherwise, return True.
|
1018
|
+
"""
|
1019
|
+
extra_evals = (
|
1020
|
+
req.marker.evaluate({'extra': extra})
|
1021
|
+
for extra in self.get(req, ()) + (None,)
|
1022
|
+
)
|
1023
|
+
return not req.marker or any(extra_evals)
|
1024
|
+
|
1025
|
+
|
1026
|
+
class Environment(object):
|
1027
|
+
"""Searchable snapshot of distributions on a search path"""
|
1028
|
+
|
1029
|
+
def __init__(self, search_path=None, platform=get_supported_platform(),
|
1030
|
+
python=PY_MAJOR):
|
1031
|
+
"""Snapshot distributions available on a search path
|
1032
|
+
|
1033
|
+
Any distributions found on `search_path` are added to the environment.
|
1034
|
+
`search_path` should be a sequence of ``sys.path`` items. If not
|
1035
|
+
supplied, ``sys.path`` is used.
|
1036
|
+
|
1037
|
+
`platform` is an optional string specifying the name of the platform
|
1038
|
+
that platform-specific distributions must be compatible with. If
|
1039
|
+
unspecified, it defaults to the current platform. `python` is an
|
1040
|
+
optional string naming the desired version of Python (e.g. ``'3.3'``);
|
1041
|
+
it defaults to the current version.
|
1042
|
+
|
1043
|
+
You may explicitly set `platform` (and/or `python`) to ``None`` if you
|
1044
|
+
wish to map *all* distributions, not just those compatible with the
|
1045
|
+
running platform or Python version.
|
1046
|
+
"""
|
1047
|
+
self._distmap = {}
|
1048
|
+
self.platform = platform
|
1049
|
+
self.python = python
|
1050
|
+
self.scan(search_path)
|
1051
|
+
|
1052
|
+
def can_add(self, dist):
|
1053
|
+
"""Is distribution `dist` acceptable for this environment?
|
1054
|
+
|
1055
|
+
The distribution must match the platform and python version
|
1056
|
+
requirements specified when this environment was created, or False
|
1057
|
+
is returned.
|
1058
|
+
"""
|
1059
|
+
return (self.python is None or dist.py_version is None
|
1060
|
+
or dist.py_version == self.python) \
|
1061
|
+
and compatible_platforms(dist.platform, self.platform)
|
1062
|
+
|
1063
|
+
def remove(self, dist):
|
1064
|
+
"""Remove `dist` from the environment"""
|
1065
|
+
self._distmap[dist.key].remove(dist)
|
1066
|
+
|
1067
|
+
def scan(self, search_path=None):
|
1068
|
+
"""Scan `search_path` for distributions usable in this environment
|
1069
|
+
|
1070
|
+
Any distributions found are added to the environment.
|
1071
|
+
`search_path` should be a sequence of ``sys.path`` items. If not
|
1072
|
+
supplied, ``sys.path`` is used. Only distributions conforming to
|
1073
|
+
the platform/python version defined at initialization are added.
|
1074
|
+
"""
|
1075
|
+
if search_path is None:
|
1076
|
+
search_path = sys.path
|
1077
|
+
|
1078
|
+
for item in search_path:
|
1079
|
+
for dist in find_distributions(item):
|
1080
|
+
self.add(dist)
|
1081
|
+
|
1082
|
+
def __getitem__(self, project_name):
|
1083
|
+
"""Return a newest-to-oldest list of distributions for `project_name`
|
1084
|
+
|
1085
|
+
Uses case-insensitive `project_name` comparison, assuming all the
|
1086
|
+
project's distributions use their project's name converted to all
|
1087
|
+
lowercase as their key.
|
1088
|
+
|
1089
|
+
"""
|
1090
|
+
distribution_key = project_name.lower()
|
1091
|
+
return self._distmap.get(distribution_key, [])
|
1092
|
+
|
1093
|
+
def add(self, dist):
|
1094
|
+
"""Add `dist` if we ``can_add()`` it and it has not already been added
|
1095
|
+
"""
|
1096
|
+
if self.can_add(dist) and dist.has_version():
|
1097
|
+
dists = self._distmap.setdefault(dist.key, [])
|
1098
|
+
if dist not in dists:
|
1099
|
+
dists.append(dist)
|
1100
|
+
dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
|
1101
|
+
|
1102
|
+
def best_match(self, req, working_set, installer=None):
|
1103
|
+
"""Find distribution best matching `req` and usable on `working_set`
|
1104
|
+
|
1105
|
+
This calls the ``find(req)`` method of the `working_set` to see if a
|
1106
|
+
suitable distribution is already active. (This may raise
|
1107
|
+
``VersionConflict`` if an unsuitable version of the project is already
|
1108
|
+
active in the specified `working_set`.) If a suitable distribution
|
1109
|
+
isn't active, this method returns the newest distribution in the
|
1110
|
+
environment that meets the ``Requirement`` in `req`. If no suitable
|
1111
|
+
distribution is found, and `installer` is supplied, then the result of
|
1112
|
+
calling the environment's ``obtain(req, installer)`` method will be
|
1113
|
+
returned.
|
1114
|
+
"""
|
1115
|
+
dist = working_set.find(req)
|
1116
|
+
if dist is not None:
|
1117
|
+
return dist
|
1118
|
+
for dist in self[req.key]:
|
1119
|
+
if dist in req:
|
1120
|
+
return dist
|
1121
|
+
# try to download/install
|
1122
|
+
return self.obtain(req, installer)
|
1123
|
+
|
1124
|
+
def obtain(self, requirement, installer=None):
|
1125
|
+
"""Obtain a distribution matching `requirement` (e.g. via download)
|
1126
|
+
|
1127
|
+
Obtain a distro that matches requirement (e.g. via download). In the
|
1128
|
+
base ``Environment`` class, this routine just returns
|
1129
|
+
``installer(requirement)``, unless `installer` is None, in which case
|
1130
|
+
None is returned instead. This method is a hook that allows subclasses
|
1131
|
+
to attempt other ways of obtaining a distribution before falling back
|
1132
|
+
to the `installer` argument."""
|
1133
|
+
if installer is not None:
|
1134
|
+
return installer(requirement)
|
1135
|
+
|
1136
|
+
def __iter__(self):
|
1137
|
+
"""Yield the unique project names of the available distributions"""
|
1138
|
+
for key in self._distmap.keys():
|
1139
|
+
if self[key]:
|
1140
|
+
yield key
|
1141
|
+
|
1142
|
+
def __iadd__(self, other):
|
1143
|
+
"""In-place addition of a distribution or environment"""
|
1144
|
+
if isinstance(other, Distribution):
|
1145
|
+
self.add(other)
|
1146
|
+
elif isinstance(other, Environment):
|
1147
|
+
for project in other:
|
1148
|
+
for dist in other[project]:
|
1149
|
+
self.add(dist)
|
1150
|
+
else:
|
1151
|
+
raise TypeError("Can't add %r to environment" % (other,))
|
1152
|
+
return self
|
1153
|
+
|
1154
|
+
def __add__(self, other):
|
1155
|
+
"""Add an environment or distribution to an environment"""
|
1156
|
+
new = self.__class__([], platform=None, python=None)
|
1157
|
+
for env in self, other:
|
1158
|
+
new += env
|
1159
|
+
return new
|
1160
|
+
|
1161
|
+
|
1162
|
+
# XXX backward compatibility
|
1163
|
+
AvailableDistributions = Environment
|
1164
|
+
|
1165
|
+
|
1166
|
+
class ExtractionError(RuntimeError):
|
1167
|
+
"""An error occurred extracting a resource
|
1168
|
+
|
1169
|
+
The following attributes are available from instances of this exception:
|
1170
|
+
|
1171
|
+
manager
|
1172
|
+
The resource manager that raised this exception
|
1173
|
+
|
1174
|
+
cache_path
|
1175
|
+
The base directory for resource extraction
|
1176
|
+
|
1177
|
+
original_error
|
1178
|
+
The exception instance that caused extraction to fail
|
1179
|
+
"""
|
1180
|
+
|
1181
|
+
|
1182
|
+
class ResourceManager:
|
1183
|
+
"""Manage resource extraction and packages"""
|
1184
|
+
extraction_path = None
|
1185
|
+
|
1186
|
+
def __init__(self):
|
1187
|
+
self.cached_files = {}
|
1188
|
+
|
1189
|
+
def resource_exists(self, package_or_requirement, resource_name):
|
1190
|
+
"""Does the named resource exist?"""
|
1191
|
+
return get_provider(package_or_requirement).has_resource(resource_name)
|
1192
|
+
|
1193
|
+
def resource_isdir(self, package_or_requirement, resource_name):
|
1194
|
+
"""Is the named resource an existing directory?"""
|
1195
|
+
return get_provider(package_or_requirement).resource_isdir(
|
1196
|
+
resource_name
|
1197
|
+
)
|
1198
|
+
|
1199
|
+
def resource_filename(self, package_or_requirement, resource_name):
|
1200
|
+
"""Return a true filesystem path for specified resource"""
|
1201
|
+
return get_provider(package_or_requirement).get_resource_filename(
|
1202
|
+
self, resource_name
|
1203
|
+
)
|
1204
|
+
|
1205
|
+
def resource_stream(self, package_or_requirement, resource_name):
|
1206
|
+
"""Return a readable file-like object for specified resource"""
|
1207
|
+
return get_provider(package_or_requirement).get_resource_stream(
|
1208
|
+
self, resource_name
|
1209
|
+
)
|
1210
|
+
|
1211
|
+
def resource_string(self, package_or_requirement, resource_name):
|
1212
|
+
"""Return specified resource as a string"""
|
1213
|
+
return get_provider(package_or_requirement).get_resource_string(
|
1214
|
+
self, resource_name
|
1215
|
+
)
|
1216
|
+
|
1217
|
+
def resource_listdir(self, package_or_requirement, resource_name):
|
1218
|
+
"""List the contents of the named resource directory"""
|
1219
|
+
return get_provider(package_or_requirement).resource_listdir(
|
1220
|
+
resource_name
|
1221
|
+
)
|
1222
|
+
|
1223
|
+
def extraction_error(self):
|
1224
|
+
"""Give an error message for problems extracting file(s)"""
|
1225
|
+
|
1226
|
+
old_exc = sys.exc_info()[1]
|
1227
|
+
cache_path = self.extraction_path or get_default_cache()
|
1228
|
+
|
1229
|
+
tmpl = textwrap.dedent("""
|
1230
|
+
Can't extract file(s) to egg cache
|
1231
|
+
|
1232
|
+
The following error occurred while trying to extract file(s) to the Python egg
|
1233
|
+
cache:
|
1234
|
+
|
1235
|
+
{old_exc}
|
1236
|
+
|
1237
|
+
The Python egg cache directory is currently set to:
|
1238
|
+
|
1239
|
+
{cache_path}
|
1240
|
+
|
1241
|
+
Perhaps your account does not have write access to this directory? You can
|
1242
|
+
change the cache directory by setting the PYTHON_EGG_CACHE environment
|
1243
|
+
variable to point to an accessible directory.
|
1244
|
+
""").lstrip()
|
1245
|
+
err = ExtractionError(tmpl.format(**locals()))
|
1246
|
+
err.manager = self
|
1247
|
+
err.cache_path = cache_path
|
1248
|
+
err.original_error = old_exc
|
1249
|
+
raise err
|
1250
|
+
|
1251
|
+
def get_cache_path(self, archive_name, names=()):
|
1252
|
+
"""Return absolute location in cache for `archive_name` and `names`
|
1253
|
+
|
1254
|
+
The parent directory of the resulting path will be created if it does
|
1255
|
+
not already exist. `archive_name` should be the base filename of the
|
1256
|
+
enclosing egg (which may not be the name of the enclosing zipfile!),
|
1257
|
+
including its ".egg" extension. `names`, if provided, should be a
|
1258
|
+
sequence of path name parts "under" the egg's extraction location.
|
1259
|
+
|
1260
|
+
This method should only be called by resource providers that need to
|
1261
|
+
obtain an extraction location, and only for names they intend to
|
1262
|
+
extract, as it tracks the generated names for possible cleanup later.
|
1263
|
+
"""
|
1264
|
+
extract_path = self.extraction_path or get_default_cache()
|
1265
|
+
target_path = os.path.join(extract_path, archive_name + '-tmp', *names)
|
1266
|
+
try:
|
1267
|
+
_bypass_ensure_directory(target_path)
|
1268
|
+
except:
|
1269
|
+
self.extraction_error()
|
1270
|
+
|
1271
|
+
self._warn_unsafe_extraction_path(extract_path)
|
1272
|
+
|
1273
|
+
self.cached_files[target_path] = 1
|
1274
|
+
return target_path
|
1275
|
+
|
1276
|
+
@staticmethod
|
1277
|
+
def _warn_unsafe_extraction_path(path):
|
1278
|
+
"""
|
1279
|
+
If the default extraction path is overridden and set to an insecure
|
1280
|
+
location, such as /tmp, it opens up an opportunity for an attacker to
|
1281
|
+
replace an extracted file with an unauthorized payload. Warn the user
|
1282
|
+
if a known insecure location is used.
|
1283
|
+
|
1284
|
+
See Distribute #375 for more details.
|
1285
|
+
"""
|
1286
|
+
if os.name == 'nt' and not path.startswith(os.environ['windir']):
|
1287
|
+
# On Windows, permissions are generally restrictive by default
|
1288
|
+
# and temp directories are not writable by other users, so
|
1289
|
+
# bypass the warning.
|
1290
|
+
return
|
1291
|
+
mode = os.stat(path).st_mode
|
1292
|
+
if mode & stat.S_IWOTH or mode & stat.S_IWGRP:
|
1293
|
+
msg = ("%s is writable by group/others and vulnerable to attack "
|
1294
|
+
"when "
|
1295
|
+
"used with get_resource_filename. Consider a more secure "
|
1296
|
+
"location (set with .set_extraction_path or the "
|
1297
|
+
"PYTHON_EGG_CACHE environment variable)." % path)
|
1298
|
+
warnings.warn(msg, UserWarning)
|
1299
|
+
|
1300
|
+
def postprocess(self, tempname, filename):
|
1301
|
+
"""Perform any platform-specific postprocessing of `tempname`
|
1302
|
+
|
1303
|
+
This is where Mac header rewrites should be done; other platforms don't
|
1304
|
+
have anything special they should do.
|
1305
|
+
|
1306
|
+
Resource providers should call this method ONLY after successfully
|
1307
|
+
extracting a compressed resource. They must NOT call it on resources
|
1308
|
+
that are already in the filesystem.
|
1309
|
+
|
1310
|
+
`tempname` is the current (temporary) name of the file, and `filename`
|
1311
|
+
is the name it will be renamed to by the caller after this routine
|
1312
|
+
returns.
|
1313
|
+
"""
|
1314
|
+
|
1315
|
+
if os.name == 'posix':
|
1316
|
+
# Make the resource executable
|
1317
|
+
mode = ((os.stat(tempname).st_mode) | 0o555) & 0o7777
|
1318
|
+
os.chmod(tempname, mode)
|
1319
|
+
|
1320
|
+
def set_extraction_path(self, path):
|
1321
|
+
"""Set the base path where resources will be extracted to, if needed.
|
1322
|
+
|
1323
|
+
If you do not call this routine before any extractions take place, the
|
1324
|
+
path defaults to the return value of ``get_default_cache()``. (Which
|
1325
|
+
is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
|
1326
|
+
platform-specific fallbacks. See that routine's documentation for more
|
1327
|
+
details.)
|
1328
|
+
|
1329
|
+
Resources are extracted to subdirectories of this path based upon
|
1330
|
+
information given by the ``IResourceProvider``. You may set this to a
|
1331
|
+
temporary directory, but then you must call ``cleanup_resources()`` to
|
1332
|
+
delete the extracted files when done. There is no guarantee that
|
1333
|
+
``cleanup_resources()`` will be able to remove all extracted files.
|
1334
|
+
|
1335
|
+
(Note: you may not change the extraction path for a given resource
|
1336
|
+
manager once resources have been extracted, unless you first call
|
1337
|
+
``cleanup_resources()``.)
|
1338
|
+
"""
|
1339
|
+
if self.cached_files:
|
1340
|
+
raise ValueError(
|
1341
|
+
"Can't change extraction path, files already extracted"
|
1342
|
+
)
|
1343
|
+
|
1344
|
+
self.extraction_path = path
|
1345
|
+
|
1346
|
+
def cleanup_resources(self, force=False):
|
1347
|
+
"""
|
1348
|
+
Delete all extracted resource files and directories, returning a list
|
1349
|
+
of the file and directory names that could not be successfully removed.
|
1350
|
+
This function does not have any concurrency protection, so it should
|
1351
|
+
generally only be called when the extraction path is a temporary
|
1352
|
+
directory exclusive to a single process. This method is not
|
1353
|
+
automatically called; you must call it explicitly or register it as an
|
1354
|
+
``atexit`` function if you wish to ensure cleanup of a temporary
|
1355
|
+
directory used for extractions.
|
1356
|
+
"""
|
1357
|
+
# XXX
|
1358
|
+
|
1359
|
+
|
1360
|
+
def get_default_cache():
|
1361
|
+
"""
|
1362
|
+
Return the ``PYTHON_EGG_CACHE`` environment variable
|
1363
|
+
or a platform-relevant user cache dir for an app
|
1364
|
+
named "Python-Eggs".
|
1365
|
+
"""
|
1366
|
+
return (
|
1367
|
+
os.environ.get('PYTHON_EGG_CACHE')
|
1368
|
+
or appdirs.user_cache_dir(appname='Python-Eggs')
|
1369
|
+
)
|
1370
|
+
|
1371
|
+
|
1372
|
+
def safe_name(name):
|
1373
|
+
"""Convert an arbitrary string to a standard distribution name
|
1374
|
+
|
1375
|
+
Any runs of non-alphanumeric/. characters are replaced with a single '-'.
|
1376
|
+
"""
|
1377
|
+
return re.sub('[^A-Za-z0-9.]+', '-', name)
|
1378
|
+
|
1379
|
+
|
1380
|
+
def safe_version(version):
|
1381
|
+
"""
|
1382
|
+
Convert an arbitrary string to a standard version string
|
1383
|
+
"""
|
1384
|
+
try:
|
1385
|
+
# normalize the version
|
1386
|
+
return str(packaging.version.Version(version))
|
1387
|
+
except packaging.version.InvalidVersion:
|
1388
|
+
version = version.replace(' ', '.')
|
1389
|
+
return re.sub('[^A-Za-z0-9.]+', '-', version)
|
1390
|
+
|
1391
|
+
|
1392
|
+
def safe_extra(extra):
|
1393
|
+
"""Convert an arbitrary string to a standard 'extra' name
|
1394
|
+
|
1395
|
+
Any runs of non-alphanumeric characters are replaced with a single '_',
|
1396
|
+
and the result is always lowercased.
|
1397
|
+
"""
|
1398
|
+
return re.sub('[^A-Za-z0-9.-]+', '_', extra).lower()
|
1399
|
+
|
1400
|
+
|
1401
|
+
def to_filename(name):
|
1402
|
+
"""Convert a project or version name to its filename-escaped form
|
1403
|
+
|
1404
|
+
Any '-' characters are currently replaced with '_'.
|
1405
|
+
"""
|
1406
|
+
return name.replace('-', '_')
|
1407
|
+
|
1408
|
+
|
1409
|
+
def invalid_marker(text):
|
1410
|
+
"""
|
1411
|
+
Validate text as a PEP 508 environment marker; return an exception
|
1412
|
+
if invalid or False otherwise.
|
1413
|
+
"""
|
1414
|
+
try:
|
1415
|
+
evaluate_marker(text)
|
1416
|
+
except SyntaxError as e:
|
1417
|
+
e.filename = None
|
1418
|
+
e.lineno = None
|
1419
|
+
return e
|
1420
|
+
return False
|
1421
|
+
|
1422
|
+
|
1423
|
+
def evaluate_marker(text, extra=None):
|
1424
|
+
"""
|
1425
|
+
Evaluate a PEP 508 environment marker.
|
1426
|
+
Return a boolean indicating the marker result in this environment.
|
1427
|
+
Raise SyntaxError if marker is invalid.
|
1428
|
+
|
1429
|
+
This implementation uses the 'pyparsing' module.
|
1430
|
+
"""
|
1431
|
+
try:
|
1432
|
+
marker = packaging.markers.Marker(text)
|
1433
|
+
return marker.evaluate()
|
1434
|
+
except packaging.markers.InvalidMarker as e:
|
1435
|
+
raise SyntaxError(e)
|
1436
|
+
|
1437
|
+
|
1438
|
+
class NullProvider:
|
1439
|
+
"""Try to implement resources and metadata for arbitrary PEP 302 loaders"""
|
1440
|
+
|
1441
|
+
egg_name = None
|
1442
|
+
egg_info = None
|
1443
|
+
loader = None
|
1444
|
+
|
1445
|
+
def __init__(self, module):
|
1446
|
+
self.loader = getattr(module, '__loader__', None)
|
1447
|
+
self.module_path = os.path.dirname(getattr(module, '__file__', ''))
|
1448
|
+
|
1449
|
+
def get_resource_filename(self, manager, resource_name):
|
1450
|
+
return self._fn(self.module_path, resource_name)
|
1451
|
+
|
1452
|
+
def get_resource_stream(self, manager, resource_name):
|
1453
|
+
return io.BytesIO(self.get_resource_string(manager, resource_name))
|
1454
|
+
|
1455
|
+
def get_resource_string(self, manager, resource_name):
|
1456
|
+
return self._get(self._fn(self.module_path, resource_name))
|
1457
|
+
|
1458
|
+
def has_resource(self, resource_name):
|
1459
|
+
return self._has(self._fn(self.module_path, resource_name))
|
1460
|
+
|
1461
|
+
def has_metadata(self, name):
|
1462
|
+
return self.egg_info and self._has(self._fn(self.egg_info, name))
|
1463
|
+
|
1464
|
+
def get_metadata(self, name):
|
1465
|
+
if not self.egg_info:
|
1466
|
+
return ""
|
1467
|
+
value = self._get(self._fn(self.egg_info, name))
|
1468
|
+
return value.decode('utf-8') if six.PY3 else value
|
1469
|
+
|
1470
|
+
def get_metadata_lines(self, name):
|
1471
|
+
return yield_lines(self.get_metadata(name))
|
1472
|
+
|
1473
|
+
def resource_isdir(self, resource_name):
|
1474
|
+
return self._isdir(self._fn(self.module_path, resource_name))
|
1475
|
+
|
1476
|
+
def metadata_isdir(self, name):
|
1477
|
+
return self.egg_info and self._isdir(self._fn(self.egg_info, name))
|
1478
|
+
|
1479
|
+
def resource_listdir(self, resource_name):
|
1480
|
+
return self._listdir(self._fn(self.module_path, resource_name))
|
1481
|
+
|
1482
|
+
def metadata_listdir(self, name):
|
1483
|
+
if self.egg_info:
|
1484
|
+
return self._listdir(self._fn(self.egg_info, name))
|
1485
|
+
return []
|
1486
|
+
|
1487
|
+
def run_script(self, script_name, namespace):
|
1488
|
+
script = 'scripts/' + script_name
|
1489
|
+
if not self.has_metadata(script):
|
1490
|
+
raise ResolutionError("No script named %r" % script_name)
|
1491
|
+
script_text = self.get_metadata(script).replace('\r\n', '\n')
|
1492
|
+
script_text = script_text.replace('\r', '\n')
|
1493
|
+
script_filename = self._fn(self.egg_info, script)
|
1494
|
+
namespace['__file__'] = script_filename
|
1495
|
+
if os.path.exists(script_filename):
|
1496
|
+
source = open(script_filename).read()
|
1497
|
+
code = compile(source, script_filename, 'exec')
|
1498
|
+
exec(code, namespace, namespace)
|
1499
|
+
else:
|
1500
|
+
from linecache import cache
|
1501
|
+
cache[script_filename] = (
|
1502
|
+
len(script_text), 0, script_text.split('\n'), script_filename
|
1503
|
+
)
|
1504
|
+
script_code = compile(script_text, script_filename, 'exec')
|
1505
|
+
exec(script_code, namespace, namespace)
|
1506
|
+
|
1507
|
+
def _has(self, path):
|
1508
|
+
raise NotImplementedError(
|
1509
|
+
"Can't perform this operation for unregistered loader type"
|
1510
|
+
)
|
1511
|
+
|
1512
|
+
def _isdir(self, path):
|
1513
|
+
raise NotImplementedError(
|
1514
|
+
"Can't perform this operation for unregistered loader type"
|
1515
|
+
)
|
1516
|
+
|
1517
|
+
def _listdir(self, path):
|
1518
|
+
raise NotImplementedError(
|
1519
|
+
"Can't perform this operation for unregistered loader type"
|
1520
|
+
)
|
1521
|
+
|
1522
|
+
def _fn(self, base, resource_name):
|
1523
|
+
if resource_name:
|
1524
|
+
return os.path.join(base, *resource_name.split('/'))
|
1525
|
+
return base
|
1526
|
+
|
1527
|
+
def _get(self, path):
|
1528
|
+
if hasattr(self.loader, 'get_data'):
|
1529
|
+
return self.loader.get_data(path)
|
1530
|
+
raise NotImplementedError(
|
1531
|
+
"Can't perform this operation for loaders without 'get_data()'"
|
1532
|
+
)
|
1533
|
+
|
1534
|
+
|
1535
|
+
register_loader_type(object, NullProvider)
|
1536
|
+
|
1537
|
+
|
1538
|
+
class EggProvider(NullProvider):
|
1539
|
+
"""Provider based on a virtual filesystem"""
|
1540
|
+
|
1541
|
+
def __init__(self, module):
|
1542
|
+
NullProvider.__init__(self, module)
|
1543
|
+
self._setup_prefix()
|
1544
|
+
|
1545
|
+
def _setup_prefix(self):
|
1546
|
+
# we assume here that our metadata may be nested inside a "basket"
|
1547
|
+
# of multiple eggs; that's why we use module_path instead of .archive
|
1548
|
+
path = self.module_path
|
1549
|
+
old = None
|
1550
|
+
while path != old:
|
1551
|
+
if _is_unpacked_egg(path):
|
1552
|
+
self.egg_name = os.path.basename(path)
|
1553
|
+
self.egg_info = os.path.join(path, 'EGG-INFO')
|
1554
|
+
self.egg_root = path
|
1555
|
+
break
|
1556
|
+
old = path
|
1557
|
+
path, base = os.path.split(path)
|
1558
|
+
|
1559
|
+
|
1560
|
+
class DefaultProvider(EggProvider):
|
1561
|
+
"""Provides access to package resources in the filesystem"""
|
1562
|
+
|
1563
|
+
def _has(self, path):
|
1564
|
+
return os.path.exists(path)
|
1565
|
+
|
1566
|
+
def _isdir(self, path):
|
1567
|
+
return os.path.isdir(path)
|
1568
|
+
|
1569
|
+
def _listdir(self, path):
|
1570
|
+
return os.listdir(path)
|
1571
|
+
|
1572
|
+
def get_resource_stream(self, manager, resource_name):
|
1573
|
+
return open(self._fn(self.module_path, resource_name), 'rb')
|
1574
|
+
|
1575
|
+
def _get(self, path):
|
1576
|
+
with open(path, 'rb') as stream:
|
1577
|
+
return stream.read()
|
1578
|
+
|
1579
|
+
@classmethod
|
1580
|
+
def _register(cls):
|
1581
|
+
loader_cls = getattr(importlib_machinery, 'SourceFileLoader',
|
1582
|
+
type(None))
|
1583
|
+
register_loader_type(loader_cls, cls)
|
1584
|
+
|
1585
|
+
|
1586
|
+
DefaultProvider._register()
|
1587
|
+
|
1588
|
+
|
1589
|
+
class EmptyProvider(NullProvider):
|
1590
|
+
"""Provider that returns nothing for all requests"""
|
1591
|
+
|
1592
|
+
_isdir = _has = lambda self, path: False
|
1593
|
+
_get = lambda self, path: ''
|
1594
|
+
_listdir = lambda self, path: []
|
1595
|
+
module_path = None
|
1596
|
+
|
1597
|
+
def __init__(self):
|
1598
|
+
pass
|
1599
|
+
|
1600
|
+
|
1601
|
+
empty_provider = EmptyProvider()
|
1602
|
+
|
1603
|
+
|
1604
|
+
class ZipManifests(dict):
|
1605
|
+
"""
|
1606
|
+
zip manifest builder
|
1607
|
+
"""
|
1608
|
+
|
1609
|
+
@classmethod
|
1610
|
+
def build(cls, path):
|
1611
|
+
"""
|
1612
|
+
Build a dictionary similar to the zipimport directory
|
1613
|
+
caches, except instead of tuples, store ZipInfo objects.
|
1614
|
+
|
1615
|
+
Use a platform-specific path separator (os.sep) for the path keys
|
1616
|
+
for compatibility with pypy on Windows.
|
1617
|
+
"""
|
1618
|
+
with ContextualZipFile(path) as zfile:
|
1619
|
+
items = (
|
1620
|
+
(
|
1621
|
+
name.replace('/', os.sep),
|
1622
|
+
zfile.getinfo(name),
|
1623
|
+
)
|
1624
|
+
for name in zfile.namelist()
|
1625
|
+
)
|
1626
|
+
return dict(items)
|
1627
|
+
|
1628
|
+
load = build
|
1629
|
+
|
1630
|
+
|
1631
|
+
class MemoizedZipManifests(ZipManifests):
|
1632
|
+
"""
|
1633
|
+
Memoized zipfile manifests.
|
1634
|
+
"""
|
1635
|
+
manifest_mod = collections.namedtuple('manifest_mod', 'manifest mtime')
|
1636
|
+
|
1637
|
+
def load(self, path):
|
1638
|
+
"""
|
1639
|
+
Load a manifest at path or return a suitable manifest already loaded.
|
1640
|
+
"""
|
1641
|
+
path = os.path.normpath(path)
|
1642
|
+
mtime = os.stat(path).st_mtime
|
1643
|
+
|
1644
|
+
if path not in self or self[path].mtime != mtime:
|
1645
|
+
manifest = self.build(path)
|
1646
|
+
self[path] = self.manifest_mod(manifest, mtime)
|
1647
|
+
|
1648
|
+
return self[path].manifest
|
1649
|
+
|
1650
|
+
|
1651
|
+
class ContextualZipFile(zipfile.ZipFile):
|
1652
|
+
"""
|
1653
|
+
Supplement ZipFile class to support context manager for Python 2.6
|
1654
|
+
"""
|
1655
|
+
|
1656
|
+
def __enter__(self):
|
1657
|
+
return self
|
1658
|
+
|
1659
|
+
def __exit__(self, type, value, traceback):
|
1660
|
+
self.close()
|
1661
|
+
|
1662
|
+
def __new__(cls, *args, **kwargs):
|
1663
|
+
"""
|
1664
|
+
Construct a ZipFile or ContextualZipFile as appropriate
|
1665
|
+
"""
|
1666
|
+
if hasattr(zipfile.ZipFile, '__exit__'):
|
1667
|
+
return zipfile.ZipFile(*args, **kwargs)
|
1668
|
+
return super(ContextualZipFile, cls).__new__(cls)
|
1669
|
+
|
1670
|
+
|
1671
|
+
class ZipProvider(EggProvider):
|
1672
|
+
"""Resource support for zips and eggs"""
|
1673
|
+
|
1674
|
+
eagers = None
|
1675
|
+
_zip_manifests = MemoizedZipManifests()
|
1676
|
+
|
1677
|
+
def __init__(self, module):
|
1678
|
+
EggProvider.__init__(self, module)
|
1679
|
+
self.zip_pre = self.loader.archive + os.sep
|
1680
|
+
|
1681
|
+
def _zipinfo_name(self, fspath):
|
1682
|
+
# Convert a virtual filename (full path to file) into a zipfile subpath
|
1683
|
+
# usable with the zipimport directory cache for our target archive
|
1684
|
+
if fspath.startswith(self.zip_pre):
|
1685
|
+
return fspath[len(self.zip_pre):]
|
1686
|
+
raise AssertionError(
|
1687
|
+
"%s is not a subpath of %s" % (fspath, self.zip_pre)
|
1688
|
+
)
|
1689
|
+
|
1690
|
+
def _parts(self, zip_path):
|
1691
|
+
# Convert a zipfile subpath into an egg-relative path part list.
|
1692
|
+
# pseudo-fs path
|
1693
|
+
fspath = self.zip_pre + zip_path
|
1694
|
+
if fspath.startswith(self.egg_root + os.sep):
|
1695
|
+
return fspath[len(self.egg_root) + 1:].split(os.sep)
|
1696
|
+
raise AssertionError(
|
1697
|
+
"%s is not a subpath of %s" % (fspath, self.egg_root)
|
1698
|
+
)
|
1699
|
+
|
1700
|
+
@property
|
1701
|
+
def zipinfo(self):
|
1702
|
+
return self._zip_manifests.load(self.loader.archive)
|
1703
|
+
|
1704
|
+
def get_resource_filename(self, manager, resource_name):
|
1705
|
+
if not self.egg_name:
|
1706
|
+
raise NotImplementedError(
|
1707
|
+
"resource_filename() only supported for .egg, not .zip"
|
1708
|
+
)
|
1709
|
+
# no need to lock for extraction, since we use temp names
|
1710
|
+
zip_path = self._resource_to_zip(resource_name)
|
1711
|
+
eagers = self._get_eager_resources()
|
1712
|
+
if '/'.join(self._parts(zip_path)) in eagers:
|
1713
|
+
for name in eagers:
|
1714
|
+
self._extract_resource(manager, self._eager_to_zip(name))
|
1715
|
+
return self._extract_resource(manager, zip_path)
|
1716
|
+
|
1717
|
+
@staticmethod
|
1718
|
+
def _get_date_and_size(zip_stat):
|
1719
|
+
size = zip_stat.file_size
|
1720
|
+
# ymdhms+wday, yday, dst
|
1721
|
+
date_time = zip_stat.date_time + (0, 0, -1)
|
1722
|
+
# 1980 offset already done
|
1723
|
+
timestamp = time.mktime(date_time)
|
1724
|
+
return timestamp, size
|
1725
|
+
|
1726
|
+
def _extract_resource(self, manager, zip_path):
|
1727
|
+
|
1728
|
+
if zip_path in self._index():
|
1729
|
+
for name in self._index()[zip_path]:
|
1730
|
+
last = self._extract_resource(
|
1731
|
+
manager, os.path.join(zip_path, name)
|
1732
|
+
)
|
1733
|
+
# return the extracted directory name
|
1734
|
+
return os.path.dirname(last)
|
1735
|
+
|
1736
|
+
timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
|
1737
|
+
|
1738
|
+
if not WRITE_SUPPORT:
|
1739
|
+
raise IOError('"os.rename" and "os.unlink" are not supported '
|
1740
|
+
'on this platform')
|
1741
|
+
try:
|
1742
|
+
|
1743
|
+
real_path = manager.get_cache_path(
|
1744
|
+
self.egg_name, self._parts(zip_path)
|
1745
|
+
)
|
1746
|
+
|
1747
|
+
if self._is_current(real_path, zip_path):
|
1748
|
+
return real_path
|
1749
|
+
|
1750
|
+
outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path))
|
1751
|
+
os.write(outf, self.loader.get_data(zip_path))
|
1752
|
+
os.close(outf)
|
1753
|
+
utime(tmpnam, (timestamp, timestamp))
|
1754
|
+
manager.postprocess(tmpnam, real_path)
|
1755
|
+
|
1756
|
+
try:
|
1757
|
+
rename(tmpnam, real_path)
|
1758
|
+
|
1759
|
+
except os.error:
|
1760
|
+
if os.path.isfile(real_path):
|
1761
|
+
if self._is_current(real_path, zip_path):
|
1762
|
+
# the file became current since it was checked above,
|
1763
|
+
# so proceed.
|
1764
|
+
return real_path
|
1765
|
+
# Windows, del old file and retry
|
1766
|
+
elif os.name == 'nt':
|
1767
|
+
unlink(real_path)
|
1768
|
+
rename(tmpnam, real_path)
|
1769
|
+
return real_path
|
1770
|
+
raise
|
1771
|
+
|
1772
|
+
except os.error:
|
1773
|
+
# report a user-friendly error
|
1774
|
+
manager.extraction_error()
|
1775
|
+
|
1776
|
+
return real_path
|
1777
|
+
|
1778
|
+
def _is_current(self, file_path, zip_path):
|
1779
|
+
"""
|
1780
|
+
Return True if the file_path is current for this zip_path
|
1781
|
+
"""
|
1782
|
+
timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
|
1783
|
+
if not os.path.isfile(file_path):
|
1784
|
+
return False
|
1785
|
+
stat = os.stat(file_path)
|
1786
|
+
if stat.st_size != size or stat.st_mtime != timestamp:
|
1787
|
+
return False
|
1788
|
+
# check that the contents match
|
1789
|
+
zip_contents = self.loader.get_data(zip_path)
|
1790
|
+
with open(file_path, 'rb') as f:
|
1791
|
+
file_contents = f.read()
|
1792
|
+
return zip_contents == file_contents
|
1793
|
+
|
1794
|
+
def _get_eager_resources(self):
|
1795
|
+
if self.eagers is None:
|
1796
|
+
eagers = []
|
1797
|
+
for name in ('native_libs.txt', 'eager_resources.txt'):
|
1798
|
+
if self.has_metadata(name):
|
1799
|
+
eagers.extend(self.get_metadata_lines(name))
|
1800
|
+
self.eagers = eagers
|
1801
|
+
return self.eagers
|
1802
|
+
|
1803
|
+
def _index(self):
|
1804
|
+
try:
|
1805
|
+
return self._dirindex
|
1806
|
+
except AttributeError:
|
1807
|
+
ind = {}
|
1808
|
+
for path in self.zipinfo:
|
1809
|
+
parts = path.split(os.sep)
|
1810
|
+
while parts:
|
1811
|
+
parent = os.sep.join(parts[:-1])
|
1812
|
+
if parent in ind:
|
1813
|
+
ind[parent].append(parts[-1])
|
1814
|
+
break
|
1815
|
+
else:
|
1816
|
+
ind[parent] = [parts.pop()]
|
1817
|
+
self._dirindex = ind
|
1818
|
+
return ind
|
1819
|
+
|
1820
|
+
def _has(self, fspath):
|
1821
|
+
zip_path = self._zipinfo_name(fspath)
|
1822
|
+
return zip_path in self.zipinfo or zip_path in self._index()
|
1823
|
+
|
1824
|
+
def _isdir(self, fspath):
|
1825
|
+
return self._zipinfo_name(fspath) in self._index()
|
1826
|
+
|
1827
|
+
def _listdir(self, fspath):
|
1828
|
+
return list(self._index().get(self._zipinfo_name(fspath), ()))
|
1829
|
+
|
1830
|
+
def _eager_to_zip(self, resource_name):
|
1831
|
+
return self._zipinfo_name(self._fn(self.egg_root, resource_name))
|
1832
|
+
|
1833
|
+
def _resource_to_zip(self, resource_name):
|
1834
|
+
return self._zipinfo_name(self._fn(self.module_path, resource_name))
|
1835
|
+
|
1836
|
+
|
1837
|
+
register_loader_type(zipimport.zipimporter, ZipProvider)
|
1838
|
+
|
1839
|
+
|
1840
|
+
class FileMetadata(EmptyProvider):
|
1841
|
+
"""Metadata handler for standalone PKG-INFO files
|
1842
|
+
|
1843
|
+
Usage::
|
1844
|
+
|
1845
|
+
metadata = FileMetadata("/path/to/PKG-INFO")
|
1846
|
+
|
1847
|
+
This provider rejects all data and metadata requests except for PKG-INFO,
|
1848
|
+
which is treated as existing, and will be the contents of the file at
|
1849
|
+
the provided location.
|
1850
|
+
"""
|
1851
|
+
|
1852
|
+
def __init__(self, path):
|
1853
|
+
self.path = path
|
1854
|
+
|
1855
|
+
def has_metadata(self, name):
|
1856
|
+
return name == 'PKG-INFO' and os.path.isfile(self.path)
|
1857
|
+
|
1858
|
+
def get_metadata(self, name):
|
1859
|
+
if name != 'PKG-INFO':
|
1860
|
+
raise KeyError("No metadata except PKG-INFO is available")
|
1861
|
+
|
1862
|
+
with io.open(self.path, encoding='utf-8', errors="replace") as f:
|
1863
|
+
metadata = f.read()
|
1864
|
+
self._warn_on_replacement(metadata)
|
1865
|
+
return metadata
|
1866
|
+
|
1867
|
+
def _warn_on_replacement(self, metadata):
|
1868
|
+
# Python 2.6 and 3.2 compat for: replacement_char = '�'
|
1869
|
+
replacement_char = b'\xef\xbf\xbd'.decode('utf-8')
|
1870
|
+
if replacement_char in metadata:
|
1871
|
+
tmpl = "{self.path} could not be properly decoded in UTF-8"
|
1872
|
+
msg = tmpl.format(**locals())
|
1873
|
+
warnings.warn(msg)
|
1874
|
+
|
1875
|
+
def get_metadata_lines(self, name):
|
1876
|
+
return yield_lines(self.get_metadata(name))
|
1877
|
+
|
1878
|
+
|
1879
|
+
class PathMetadata(DefaultProvider):
|
1880
|
+
"""Metadata provider for egg directories
|
1881
|
+
|
1882
|
+
Usage::
|
1883
|
+
|
1884
|
+
# Development eggs:
|
1885
|
+
|
1886
|
+
egg_info = "/path/to/PackageName.egg-info"
|
1887
|
+
base_dir = os.path.dirname(egg_info)
|
1888
|
+
metadata = PathMetadata(base_dir, egg_info)
|
1889
|
+
dist_name = os.path.splitext(os.path.basename(egg_info))[0]
|
1890
|
+
dist = Distribution(basedir, project_name=dist_name, metadata=metadata)
|
1891
|
+
|
1892
|
+
# Unpacked egg directories:
|
1893
|
+
|
1894
|
+
egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
|
1895
|
+
metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
|
1896
|
+
dist = Distribution.from_filename(egg_path, metadata=metadata)
|
1897
|
+
"""
|
1898
|
+
|
1899
|
+
def __init__(self, path, egg_info):
|
1900
|
+
self.module_path = path
|
1901
|
+
self.egg_info = egg_info
|
1902
|
+
|
1903
|
+
|
1904
|
+
class EggMetadata(ZipProvider):
|
1905
|
+
"""Metadata provider for .egg files"""
|
1906
|
+
|
1907
|
+
def __init__(self, importer):
|
1908
|
+
"""Create a metadata provider from a zipimporter"""
|
1909
|
+
|
1910
|
+
self.zip_pre = importer.archive + os.sep
|
1911
|
+
self.loader = importer
|
1912
|
+
if importer.prefix:
|
1913
|
+
self.module_path = os.path.join(importer.archive, importer.prefix)
|
1914
|
+
else:
|
1915
|
+
self.module_path = importer.archive
|
1916
|
+
self._setup_prefix()
|
1917
|
+
|
1918
|
+
|
1919
|
+
_declare_state('dict', _distribution_finders={})
|
1920
|
+
|
1921
|
+
|
1922
|
+
def register_finder(importer_type, distribution_finder):
|
1923
|
+
"""Register `distribution_finder` to find distributions in sys.path items
|
1924
|
+
|
1925
|
+
`importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
|
1926
|
+
handler), and `distribution_finder` is a callable that, passed a path
|
1927
|
+
item and the importer instance, yields ``Distribution`` instances found on
|
1928
|
+
that path item. See ``pkg_resources.find_on_path`` for an example."""
|
1929
|
+
_distribution_finders[importer_type] = distribution_finder
|
1930
|
+
|
1931
|
+
|
1932
|
+
def find_distributions(path_item, only=False):
|
1933
|
+
"""Yield distributions accessible via `path_item`"""
|
1934
|
+
importer = get_importer(path_item)
|
1935
|
+
finder = _find_adapter(_distribution_finders, importer)
|
1936
|
+
return finder(importer, path_item, only)
|
1937
|
+
|
1938
|
+
|
1939
|
+
def find_eggs_in_zip(importer, path_item, only=False):
|
1940
|
+
"""
|
1941
|
+
Find eggs in zip files; possibly multiple nested eggs.
|
1942
|
+
"""
|
1943
|
+
if importer.archive.endswith('.whl'):
|
1944
|
+
# wheels are not supported with this finder
|
1945
|
+
# they don't have PKG-INFO metadata, and won't ever contain eggs
|
1946
|
+
return
|
1947
|
+
metadata = EggMetadata(importer)
|
1948
|
+
if metadata.has_metadata('PKG-INFO'):
|
1949
|
+
yield Distribution.from_filename(path_item, metadata=metadata)
|
1950
|
+
if only:
|
1951
|
+
# don't yield nested distros
|
1952
|
+
return
|
1953
|
+
for subitem in metadata.resource_listdir('/'):
|
1954
|
+
if _is_unpacked_egg(subitem):
|
1955
|
+
subpath = os.path.join(path_item, subitem)
|
1956
|
+
for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath):
|
1957
|
+
yield dist
|
1958
|
+
|
1959
|
+
|
1960
|
+
register_finder(zipimport.zipimporter, find_eggs_in_zip)
|
1961
|
+
|
1962
|
+
|
1963
|
+
def find_nothing(importer, path_item, only=False):
|
1964
|
+
return ()
|
1965
|
+
|
1966
|
+
|
1967
|
+
register_finder(object, find_nothing)
|
1968
|
+
|
1969
|
+
|
1970
|
+
def _by_version_descending(names):
|
1971
|
+
"""
|
1972
|
+
Given a list of filenames, return them in descending order
|
1973
|
+
by version number.
|
1974
|
+
|
1975
|
+
>>> names = 'bar', 'foo', 'Python-2.7.10.egg', 'Python-2.7.2.egg'
|
1976
|
+
>>> _by_version_descending(names)
|
1977
|
+
['Python-2.7.10.egg', 'Python-2.7.2.egg', 'foo', 'bar']
|
1978
|
+
>>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.egg'
|
1979
|
+
>>> _by_version_descending(names)
|
1980
|
+
['Setuptools-1.2.3.egg', 'Setuptools-1.2.3b1.egg']
|
1981
|
+
>>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.post1.egg'
|
1982
|
+
>>> _by_version_descending(names)
|
1983
|
+
['Setuptools-1.2.3.post1.egg', 'Setuptools-1.2.3b1.egg']
|
1984
|
+
"""
|
1985
|
+
def _by_version(name):
|
1986
|
+
"""
|
1987
|
+
Parse each component of the filename
|
1988
|
+
"""
|
1989
|
+
name, ext = os.path.splitext(name)
|
1990
|
+
parts = itertools.chain(name.split('-'), [ext])
|
1991
|
+
return [packaging.version.parse(part) for part in parts]
|
1992
|
+
|
1993
|
+
return sorted(names, key=_by_version, reverse=True)
|
1994
|
+
|
1995
|
+
|
1996
|
+
def find_on_path(importer, path_item, only=False):
|
1997
|
+
"""Yield distributions accessible on a sys.path directory"""
|
1998
|
+
path_item = _normalize_cached(path_item)
|
1999
|
+
|
2000
|
+
if os.path.isdir(path_item) and os.access(path_item, os.R_OK):
|
2001
|
+
if _is_unpacked_egg(path_item):
|
2002
|
+
yield Distribution.from_filename(
|
2003
|
+
path_item, metadata=PathMetadata(
|
2004
|
+
path_item, os.path.join(path_item, 'EGG-INFO')
|
2005
|
+
)
|
2006
|
+
)
|
2007
|
+
else:
|
2008
|
+
# scan for .egg and .egg-info in directory
|
2009
|
+
path_item_entries = _by_version_descending(os.listdir(path_item))
|
2010
|
+
for entry in path_item_entries:
|
2011
|
+
lower = entry.lower()
|
2012
|
+
if lower.endswith('.egg-info') or lower.endswith('.dist-info'):
|
2013
|
+
fullpath = os.path.join(path_item, entry)
|
2014
|
+
if os.path.isdir(fullpath):
|
2015
|
+
# egg-info directory, allow getting metadata
|
2016
|
+
if len(os.listdir(fullpath)) == 0:
|
2017
|
+
# Empty egg directory, skip.
|
2018
|
+
continue
|
2019
|
+
metadata = PathMetadata(path_item, fullpath)
|
2020
|
+
else:
|
2021
|
+
metadata = FileMetadata(fullpath)
|
2022
|
+
yield Distribution.from_location(
|
2023
|
+
path_item, entry, metadata, precedence=DEVELOP_DIST
|
2024
|
+
)
|
2025
|
+
elif not only and _is_unpacked_egg(entry):
|
2026
|
+
dists = find_distributions(os.path.join(path_item, entry))
|
2027
|
+
for dist in dists:
|
2028
|
+
yield dist
|
2029
|
+
elif not only and lower.endswith('.egg-link'):
|
2030
|
+
with open(os.path.join(path_item, entry)) as entry_file:
|
2031
|
+
entry_lines = entry_file.readlines()
|
2032
|
+
for line in entry_lines:
|
2033
|
+
if not line.strip():
|
2034
|
+
continue
|
2035
|
+
path = os.path.join(path_item, line.rstrip())
|
2036
|
+
dists = find_distributions(path)
|
2037
|
+
for item in dists:
|
2038
|
+
yield item
|
2039
|
+
break
|
2040
|
+
|
2041
|
+
|
2042
|
+
register_finder(pkgutil.ImpImporter, find_on_path)
|
2043
|
+
|
2044
|
+
if hasattr(importlib_machinery, 'FileFinder'):
|
2045
|
+
register_finder(importlib_machinery.FileFinder, find_on_path)
|
2046
|
+
|
2047
|
+
_declare_state('dict', _namespace_handlers={})
|
2048
|
+
_declare_state('dict', _namespace_packages={})
|
2049
|
+
|
2050
|
+
|
2051
|
+
def register_namespace_handler(importer_type, namespace_handler):
|
2052
|
+
"""Register `namespace_handler` to declare namespace packages
|
2053
|
+
|
2054
|
+
`importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
|
2055
|
+
handler), and `namespace_handler` is a callable like this::
|
2056
|
+
|
2057
|
+
def namespace_handler(importer, path_entry, moduleName, module):
|
2058
|
+
# return a path_entry to use for child packages
|
2059
|
+
|
2060
|
+
Namespace handlers are only called if the importer object has already
|
2061
|
+
agreed that it can handle the relevant path item, and they should only
|
2062
|
+
return a subpath if the module __path__ does not already contain an
|
2063
|
+
equivalent subpath. For an example namespace handler, see
|
2064
|
+
``pkg_resources.file_ns_handler``.
|
2065
|
+
"""
|
2066
|
+
_namespace_handlers[importer_type] = namespace_handler
|
2067
|
+
|
2068
|
+
|
2069
|
+
def _handle_ns(packageName, path_item):
|
2070
|
+
"""Ensure that named package includes a subpath of path_item (if needed)"""
|
2071
|
+
|
2072
|
+
importer = get_importer(path_item)
|
2073
|
+
if importer is None:
|
2074
|
+
return None
|
2075
|
+
loader = importer.find_module(packageName)
|
2076
|
+
if loader is None:
|
2077
|
+
return None
|
2078
|
+
module = sys.modules.get(packageName)
|
2079
|
+
if module is None:
|
2080
|
+
module = sys.modules[packageName] = types.ModuleType(packageName)
|
2081
|
+
module.__path__ = []
|
2082
|
+
_set_parent_ns(packageName)
|
2083
|
+
elif not hasattr(module, '__path__'):
|
2084
|
+
raise TypeError("Not a package:", packageName)
|
2085
|
+
handler = _find_adapter(_namespace_handlers, importer)
|
2086
|
+
subpath = handler(importer, path_item, packageName, module)
|
2087
|
+
if subpath is not None:
|
2088
|
+
path = module.__path__
|
2089
|
+
path.append(subpath)
|
2090
|
+
loader.load_module(packageName)
|
2091
|
+
_rebuild_mod_path(path, packageName, module)
|
2092
|
+
return subpath
|
2093
|
+
|
2094
|
+
|
2095
|
+
def _rebuild_mod_path(orig_path, package_name, module):
|
2096
|
+
"""
|
2097
|
+
Rebuild module.__path__ ensuring that all entries are ordered
|
2098
|
+
corresponding to their sys.path order
|
2099
|
+
"""
|
2100
|
+
sys_path = [_normalize_cached(p) for p in sys.path]
|
2101
|
+
|
2102
|
+
def safe_sys_path_index(entry):
|
2103
|
+
"""
|
2104
|
+
Workaround for #520 and #513.
|
2105
|
+
"""
|
2106
|
+
try:
|
2107
|
+
return sys_path.index(entry)
|
2108
|
+
except ValueError:
|
2109
|
+
return float('inf')
|
2110
|
+
|
2111
|
+
def position_in_sys_path(path):
|
2112
|
+
"""
|
2113
|
+
Return the ordinal of the path based on its position in sys.path
|
2114
|
+
"""
|
2115
|
+
path_parts = path.split(os.sep)
|
2116
|
+
module_parts = package_name.count('.') + 1
|
2117
|
+
parts = path_parts[:-module_parts]
|
2118
|
+
return safe_sys_path_index(_normalize_cached(os.sep.join(parts)))
|
2119
|
+
|
2120
|
+
orig_path.sort(key=position_in_sys_path)
|
2121
|
+
module.__path__[:] = [_normalize_cached(p) for p in orig_path]
|
2122
|
+
|
2123
|
+
|
2124
|
+
def declare_namespace(packageName):
|
2125
|
+
"""Declare that package 'packageName' is a namespace package"""
|
2126
|
+
|
2127
|
+
_imp.acquire_lock()
|
2128
|
+
try:
|
2129
|
+
if packageName in _namespace_packages:
|
2130
|
+
return
|
2131
|
+
|
2132
|
+
path, parent = sys.path, None
|
2133
|
+
if '.' in packageName:
|
2134
|
+
parent = '.'.join(packageName.split('.')[:-1])
|
2135
|
+
declare_namespace(parent)
|
2136
|
+
if parent not in _namespace_packages:
|
2137
|
+
__import__(parent)
|
2138
|
+
try:
|
2139
|
+
path = sys.modules[parent].__path__
|
2140
|
+
except AttributeError:
|
2141
|
+
raise TypeError("Not a package:", parent)
|
2142
|
+
|
2143
|
+
# Track what packages are namespaces, so when new path items are added,
|
2144
|
+
# they can be updated
|
2145
|
+
_namespace_packages.setdefault(parent, []).append(packageName)
|
2146
|
+
_namespace_packages.setdefault(packageName, [])
|
2147
|
+
|
2148
|
+
for path_item in path:
|
2149
|
+
# Ensure all the parent's path items are reflected in the child,
|
2150
|
+
# if they apply
|
2151
|
+
_handle_ns(packageName, path_item)
|
2152
|
+
|
2153
|
+
finally:
|
2154
|
+
_imp.release_lock()
|
2155
|
+
|
2156
|
+
|
2157
|
+
def fixup_namespace_packages(path_item, parent=None):
|
2158
|
+
"""Ensure that previously-declared namespace packages include path_item"""
|
2159
|
+
_imp.acquire_lock()
|
2160
|
+
try:
|
2161
|
+
for package in _namespace_packages.get(parent, ()):
|
2162
|
+
subpath = _handle_ns(package, path_item)
|
2163
|
+
if subpath:
|
2164
|
+
fixup_namespace_packages(subpath, package)
|
2165
|
+
finally:
|
2166
|
+
_imp.release_lock()
|
2167
|
+
|
2168
|
+
|
2169
|
+
def file_ns_handler(importer, path_item, packageName, module):
|
2170
|
+
"""Compute an ns-package subpath for a filesystem or zipfile importer"""
|
2171
|
+
|
2172
|
+
subpath = os.path.join(path_item, packageName.split('.')[-1])
|
2173
|
+
normalized = _normalize_cached(subpath)
|
2174
|
+
for item in module.__path__:
|
2175
|
+
if _normalize_cached(item) == normalized:
|
2176
|
+
break
|
2177
|
+
else:
|
2178
|
+
# Only return the path if it's not already there
|
2179
|
+
return subpath
|
2180
|
+
|
2181
|
+
|
2182
|
+
register_namespace_handler(pkgutil.ImpImporter, file_ns_handler)
|
2183
|
+
register_namespace_handler(zipimport.zipimporter, file_ns_handler)
|
2184
|
+
|
2185
|
+
if hasattr(importlib_machinery, 'FileFinder'):
|
2186
|
+
register_namespace_handler(importlib_machinery.FileFinder, file_ns_handler)
|
2187
|
+
|
2188
|
+
|
2189
|
+
def null_ns_handler(importer, path_item, packageName, module):
|
2190
|
+
return None
|
2191
|
+
|
2192
|
+
|
2193
|
+
register_namespace_handler(object, null_ns_handler)
|
2194
|
+
|
2195
|
+
|
2196
|
+
def normalize_path(filename):
|
2197
|
+
"""Normalize a file/dir name for comparison purposes"""
|
2198
|
+
return os.path.normcase(os.path.realpath(filename))
|
2199
|
+
|
2200
|
+
|
2201
|
+
def _normalize_cached(filename, _cache={}):
|
2202
|
+
try:
|
2203
|
+
return _cache[filename]
|
2204
|
+
except KeyError:
|
2205
|
+
_cache[filename] = result = normalize_path(filename)
|
2206
|
+
return result
|
2207
|
+
|
2208
|
+
|
2209
|
+
def _is_unpacked_egg(path):
|
2210
|
+
"""
|
2211
|
+
Determine if given path appears to be an unpacked egg.
|
2212
|
+
"""
|
2213
|
+
return (
|
2214
|
+
path.lower().endswith('.egg')
|
2215
|
+
)
|
2216
|
+
|
2217
|
+
|
2218
|
+
def _set_parent_ns(packageName):
|
2219
|
+
parts = packageName.split('.')
|
2220
|
+
name = parts.pop()
|
2221
|
+
if parts:
|
2222
|
+
parent = '.'.join(parts)
|
2223
|
+
setattr(sys.modules[parent], name, sys.modules[packageName])
|
2224
|
+
|
2225
|
+
|
2226
|
+
def yield_lines(strs):
|
2227
|
+
"""Yield non-empty/non-comment lines of a string or sequence"""
|
2228
|
+
if isinstance(strs, six.string_types):
|
2229
|
+
for s in strs.splitlines():
|
2230
|
+
s = s.strip()
|
2231
|
+
# skip blank lines/comments
|
2232
|
+
if s and not s.startswith('#'):
|
2233
|
+
yield s
|
2234
|
+
else:
|
2235
|
+
for ss in strs:
|
2236
|
+
for s in yield_lines(ss):
|
2237
|
+
yield s
|
2238
|
+
|
2239
|
+
|
2240
|
+
MODULE = re.compile(r"\w+(\.\w+)*$").match
|
2241
|
+
EGG_NAME = re.compile(
|
2242
|
+
r"""
|
2243
|
+
(?P<name>[^-]+) (
|
2244
|
+
-(?P<ver>[^-]+) (
|
2245
|
+
-py(?P<pyver>[^-]+) (
|
2246
|
+
-(?P<plat>.+)
|
2247
|
+
)?
|
2248
|
+
)?
|
2249
|
+
)?
|
2250
|
+
""",
|
2251
|
+
re.VERBOSE | re.IGNORECASE,
|
2252
|
+
).match
|
2253
|
+
|
2254
|
+
|
2255
|
+
class EntryPoint(object):
|
2256
|
+
"""Object representing an advertised importable object"""
|
2257
|
+
|
2258
|
+
def __init__(self, name, module_name, attrs=(), extras=(), dist=None):
|
2259
|
+
if not MODULE(module_name):
|
2260
|
+
raise ValueError("Invalid module name", module_name)
|
2261
|
+
self.name = name
|
2262
|
+
self.module_name = module_name
|
2263
|
+
self.attrs = tuple(attrs)
|
2264
|
+
self.extras = Requirement.parse(("x[%s]" % ','.join(extras))).extras
|
2265
|
+
self.dist = dist
|
2266
|
+
|
2267
|
+
def __str__(self):
|
2268
|
+
s = "%s = %s" % (self.name, self.module_name)
|
2269
|
+
if self.attrs:
|
2270
|
+
s += ':' + '.'.join(self.attrs)
|
2271
|
+
if self.extras:
|
2272
|
+
s += ' [%s]' % ','.join(self.extras)
|
2273
|
+
return s
|
2274
|
+
|
2275
|
+
def __repr__(self):
|
2276
|
+
return "EntryPoint.parse(%r)" % str(self)
|
2277
|
+
|
2278
|
+
def load(self, require=True, *args, **kwargs):
|
2279
|
+
"""
|
2280
|
+
Require packages for this EntryPoint, then resolve it.
|
2281
|
+
"""
|
2282
|
+
if not require or args or kwargs:
|
2283
|
+
warnings.warn(
|
2284
|
+
"Parameters to load are deprecated. Call .resolve and "
|
2285
|
+
".require separately.",
|
2286
|
+
DeprecationWarning,
|
2287
|
+
stacklevel=2,
|
2288
|
+
)
|
2289
|
+
if require:
|
2290
|
+
self.require(*args, **kwargs)
|
2291
|
+
return self.resolve()
|
2292
|
+
|
2293
|
+
def resolve(self):
|
2294
|
+
"""
|
2295
|
+
Resolve the entry point from its module and attrs.
|
2296
|
+
"""
|
2297
|
+
module = __import__(self.module_name, fromlist=['__name__'], level=0)
|
2298
|
+
try:
|
2299
|
+
return functools.reduce(getattr, self.attrs, module)
|
2300
|
+
except AttributeError as exc:
|
2301
|
+
raise ImportError(str(exc))
|
2302
|
+
|
2303
|
+
def require(self, env=None, installer=None):
|
2304
|
+
if self.extras and not self.dist:
|
2305
|
+
raise UnknownExtra("Can't require() without a distribution", self)
|
2306
|
+
reqs = self.dist.requires(self.extras)
|
2307
|
+
items = working_set.resolve(reqs, env, installer)
|
2308
|
+
list(map(working_set.add, items))
|
2309
|
+
|
2310
|
+
pattern = re.compile(
|
2311
|
+
r'\s*'
|
2312
|
+
r'(?P<name>.+?)\s*'
|
2313
|
+
r'=\s*'
|
2314
|
+
r'(?P<module>[\w.]+)\s*'
|
2315
|
+
r'(:\s*(?P<attr>[\w.]+))?\s*'
|
2316
|
+
r'(?P<extras>\[.*\])?\s*$'
|
2317
|
+
)
|
2318
|
+
|
2319
|
+
@classmethod
|
2320
|
+
def parse(cls, src, dist=None):
|
2321
|
+
"""Parse a single entry point from string `src`
|
2322
|
+
|
2323
|
+
Entry point syntax follows the form::
|
2324
|
+
|
2325
|
+
name = some.module:some.attr [extra1, extra2]
|
2326
|
+
|
2327
|
+
The entry name and module name are required, but the ``:attrs`` and
|
2328
|
+
``[extras]`` parts are optional
|
2329
|
+
"""
|
2330
|
+
m = cls.pattern.match(src)
|
2331
|
+
if not m:
|
2332
|
+
msg = "EntryPoint must be in 'name=module:attrs [extras]' format"
|
2333
|
+
raise ValueError(msg, src)
|
2334
|
+
res = m.groupdict()
|
2335
|
+
extras = cls._parse_extras(res['extras'])
|
2336
|
+
attrs = res['attr'].split('.') if res['attr'] else ()
|
2337
|
+
return cls(res['name'], res['module'], attrs, extras, dist)
|
2338
|
+
|
2339
|
+
@classmethod
|
2340
|
+
def _parse_extras(cls, extras_spec):
|
2341
|
+
if not extras_spec:
|
2342
|
+
return ()
|
2343
|
+
req = Requirement.parse('x' + extras_spec)
|
2344
|
+
if req.specs:
|
2345
|
+
raise ValueError()
|
2346
|
+
return req.extras
|
2347
|
+
|
2348
|
+
@classmethod
|
2349
|
+
def parse_group(cls, group, lines, dist=None):
|
2350
|
+
"""Parse an entry point group"""
|
2351
|
+
if not MODULE(group):
|
2352
|
+
raise ValueError("Invalid group name", group)
|
2353
|
+
this = {}
|
2354
|
+
for line in yield_lines(lines):
|
2355
|
+
ep = cls.parse(line, dist)
|
2356
|
+
if ep.name in this:
|
2357
|
+
raise ValueError("Duplicate entry point", group, ep.name)
|
2358
|
+
this[ep.name] = ep
|
2359
|
+
return this
|
2360
|
+
|
2361
|
+
@classmethod
|
2362
|
+
def parse_map(cls, data, dist=None):
|
2363
|
+
"""Parse a map of entry point groups"""
|
2364
|
+
if isinstance(data, dict):
|
2365
|
+
data = data.items()
|
2366
|
+
else:
|
2367
|
+
data = split_sections(data)
|
2368
|
+
maps = {}
|
2369
|
+
for group, lines in data:
|
2370
|
+
if group is None:
|
2371
|
+
if not lines:
|
2372
|
+
continue
|
2373
|
+
raise ValueError("Entry points must be listed in groups")
|
2374
|
+
group = group.strip()
|
2375
|
+
if group in maps:
|
2376
|
+
raise ValueError("Duplicate group name", group)
|
2377
|
+
maps[group] = cls.parse_group(group, lines, dist)
|
2378
|
+
return maps
|
2379
|
+
|
2380
|
+
|
2381
|
+
def _remove_md5_fragment(location):
|
2382
|
+
if not location:
|
2383
|
+
return ''
|
2384
|
+
parsed = urllib.parse.urlparse(location)
|
2385
|
+
if parsed[-1].startswith('md5='):
|
2386
|
+
return urllib.parse.urlunparse(parsed[:-1] + ('',))
|
2387
|
+
return location
|
2388
|
+
|
2389
|
+
|
2390
|
+
def _version_from_file(lines):
|
2391
|
+
"""
|
2392
|
+
Given an iterable of lines from a Metadata file, return
|
2393
|
+
the value of the Version field, if present, or None otherwise.
|
2394
|
+
"""
|
2395
|
+
is_version_line = lambda line: line.lower().startswith('version:')
|
2396
|
+
version_lines = filter(is_version_line, lines)
|
2397
|
+
line = next(iter(version_lines), '')
|
2398
|
+
_, _, value = line.partition(':')
|
2399
|
+
return safe_version(value.strip()) or None
|
2400
|
+
|
2401
|
+
|
2402
|
+
class Distribution(object):
|
2403
|
+
"""Wrap an actual or potential sys.path entry w/metadata"""
|
2404
|
+
PKG_INFO = 'PKG-INFO'
|
2405
|
+
|
2406
|
+
def __init__(self, location=None, metadata=None, project_name=None,
|
2407
|
+
version=None, py_version=PY_MAJOR, platform=None,
|
2408
|
+
precedence=EGG_DIST):
|
2409
|
+
self.project_name = safe_name(project_name or 'Unknown')
|
2410
|
+
if version is not None:
|
2411
|
+
self._version = safe_version(version)
|
2412
|
+
self.py_version = py_version
|
2413
|
+
self.platform = platform
|
2414
|
+
self.location = location
|
2415
|
+
self.precedence = precedence
|
2416
|
+
self._provider = metadata or empty_provider
|
2417
|
+
|
2418
|
+
@classmethod
|
2419
|
+
def from_location(cls, location, basename, metadata=None, **kw):
|
2420
|
+
project_name, version, py_version, platform = [None] * 4
|
2421
|
+
basename, ext = os.path.splitext(basename)
|
2422
|
+
if ext.lower() in _distributionImpl:
|
2423
|
+
cls = _distributionImpl[ext.lower()]
|
2424
|
+
|
2425
|
+
match = EGG_NAME(basename)
|
2426
|
+
if match:
|
2427
|
+
project_name, version, py_version, platform = match.group(
|
2428
|
+
'name', 'ver', 'pyver', 'plat'
|
2429
|
+
)
|
2430
|
+
return cls(
|
2431
|
+
location, metadata, project_name=project_name, version=version,
|
2432
|
+
py_version=py_version, platform=platform, **kw
|
2433
|
+
)._reload_version()
|
2434
|
+
|
2435
|
+
def _reload_version(self):
|
2436
|
+
return self
|
2437
|
+
|
2438
|
+
@property
|
2439
|
+
def hashcmp(self):
|
2440
|
+
return (
|
2441
|
+
self.parsed_version,
|
2442
|
+
self.precedence,
|
2443
|
+
self.key,
|
2444
|
+
_remove_md5_fragment(self.location),
|
2445
|
+
self.py_version or '',
|
2446
|
+
self.platform or '',
|
2447
|
+
)
|
2448
|
+
|
2449
|
+
def __hash__(self):
|
2450
|
+
return hash(self.hashcmp)
|
2451
|
+
|
2452
|
+
def __lt__(self, other):
|
2453
|
+
return self.hashcmp < other.hashcmp
|
2454
|
+
|
2455
|
+
def __le__(self, other):
|
2456
|
+
return self.hashcmp <= other.hashcmp
|
2457
|
+
|
2458
|
+
def __gt__(self, other):
|
2459
|
+
return self.hashcmp > other.hashcmp
|
2460
|
+
|
2461
|
+
def __ge__(self, other):
|
2462
|
+
return self.hashcmp >= other.hashcmp
|
2463
|
+
|
2464
|
+
def __eq__(self, other):
|
2465
|
+
if not isinstance(other, self.__class__):
|
2466
|
+
# It's not a Distribution, so they are not equal
|
2467
|
+
return False
|
2468
|
+
return self.hashcmp == other.hashcmp
|
2469
|
+
|
2470
|
+
def __ne__(self, other):
|
2471
|
+
return not self == other
|
2472
|
+
|
2473
|
+
# These properties have to be lazy so that we don't have to load any
|
2474
|
+
# metadata until/unless it's actually needed. (i.e., some distributions
|
2475
|
+
# may not know their name or version without loading PKG-INFO)
|
2476
|
+
|
2477
|
+
@property
|
2478
|
+
def key(self):
|
2479
|
+
try:
|
2480
|
+
return self._key
|
2481
|
+
except AttributeError:
|
2482
|
+
self._key = key = self.project_name.lower()
|
2483
|
+
return key
|
2484
|
+
|
2485
|
+
@property
|
2486
|
+
def parsed_version(self):
|
2487
|
+
if not hasattr(self, "_parsed_version"):
|
2488
|
+
self._parsed_version = parse_version(self.version)
|
2489
|
+
|
2490
|
+
return self._parsed_version
|
2491
|
+
|
2492
|
+
def _warn_legacy_version(self):
|
2493
|
+
LV = packaging.version.LegacyVersion
|
2494
|
+
is_legacy = isinstance(self._parsed_version, LV)
|
2495
|
+
if not is_legacy:
|
2496
|
+
return
|
2497
|
+
|
2498
|
+
# While an empty version is technically a legacy version and
|
2499
|
+
# is not a valid PEP 440 version, it's also unlikely to
|
2500
|
+
# actually come from someone and instead it is more likely that
|
2501
|
+
# it comes from setuptools attempting to parse a filename and
|
2502
|
+
# including it in the list. So for that we'll gate this warning
|
2503
|
+
# on if the version is anything at all or not.
|
2504
|
+
if not self.version:
|
2505
|
+
return
|
2506
|
+
|
2507
|
+
tmpl = textwrap.dedent("""
|
2508
|
+
'{project_name} ({version})' is being parsed as a legacy,
|
2509
|
+
non PEP 440,
|
2510
|
+
version. You may find odd behavior and sort order.
|
2511
|
+
In particular it will be sorted as less than 0.0. It
|
2512
|
+
is recommended to migrate to PEP 440 compatible
|
2513
|
+
versions.
|
2514
|
+
""").strip().replace('\n', ' ')
|
2515
|
+
|
2516
|
+
warnings.warn(tmpl.format(**vars(self)), PEP440Warning)
|
2517
|
+
|
2518
|
+
@property
|
2519
|
+
def version(self):
|
2520
|
+
try:
|
2521
|
+
return self._version
|
2522
|
+
except AttributeError:
|
2523
|
+
version = _version_from_file(self._get_metadata(self.PKG_INFO))
|
2524
|
+
if version is None:
|
2525
|
+
tmpl = "Missing 'Version:' header and/or %s file"
|
2526
|
+
raise ValueError(tmpl % self.PKG_INFO, self)
|
2527
|
+
return version
|
2528
|
+
|
2529
|
+
@property
|
2530
|
+
def _dep_map(self):
|
2531
|
+
try:
|
2532
|
+
return self.__dep_map
|
2533
|
+
except AttributeError:
|
2534
|
+
dm = self.__dep_map = {None: []}
|
2535
|
+
for name in 'requires.txt', 'depends.txt':
|
2536
|
+
for extra, reqs in split_sections(self._get_metadata(name)):
|
2537
|
+
if extra:
|
2538
|
+
if ':' in extra:
|
2539
|
+
extra, marker = extra.split(':', 1)
|
2540
|
+
if invalid_marker(marker):
|
2541
|
+
# XXX warn
|
2542
|
+
reqs = []
|
2543
|
+
elif not evaluate_marker(marker):
|
2544
|
+
reqs = []
|
2545
|
+
extra = safe_extra(extra) or None
|
2546
|
+
dm.setdefault(extra, []).extend(parse_requirements(reqs))
|
2547
|
+
return dm
|
2548
|
+
|
2549
|
+
def requires(self, extras=()):
|
2550
|
+
"""List of Requirements needed for this distro if `extras` are used"""
|
2551
|
+
dm = self._dep_map
|
2552
|
+
deps = []
|
2553
|
+
deps.extend(dm.get(None, ()))
|
2554
|
+
for ext in extras:
|
2555
|
+
try:
|
2556
|
+
deps.extend(dm[safe_extra(ext)])
|
2557
|
+
except KeyError:
|
2558
|
+
raise UnknownExtra(
|
2559
|
+
"%s has no such extra feature %r" % (self, ext)
|
2560
|
+
)
|
2561
|
+
return deps
|
2562
|
+
|
2563
|
+
def _get_metadata(self, name):
|
2564
|
+
if self.has_metadata(name):
|
2565
|
+
for line in self.get_metadata_lines(name):
|
2566
|
+
yield line
|
2567
|
+
|
2568
|
+
def activate(self, path=None, replace=False):
|
2569
|
+
"""Ensure distribution is importable on `path` (default=sys.path)"""
|
2570
|
+
if path is None:
|
2571
|
+
path = sys.path
|
2572
|
+
self.insert_on(path, replace=replace)
|
2573
|
+
if path is sys.path:
|
2574
|
+
fixup_namespace_packages(self.location)
|
2575
|
+
for pkg in self._get_metadata('namespace_packages.txt'):
|
2576
|
+
if pkg in sys.modules:
|
2577
|
+
declare_namespace(pkg)
|
2578
|
+
|
2579
|
+
def egg_name(self):
|
2580
|
+
"""Return what this distribution's standard .egg filename should be"""
|
2581
|
+
filename = "%s-%s-py%s" % (
|
2582
|
+
to_filename(self.project_name), to_filename(self.version),
|
2583
|
+
self.py_version or PY_MAJOR
|
2584
|
+
)
|
2585
|
+
|
2586
|
+
if self.platform:
|
2587
|
+
filename += '-' + self.platform
|
2588
|
+
return filename
|
2589
|
+
|
2590
|
+
def __repr__(self):
|
2591
|
+
if self.location:
|
2592
|
+
return "%s (%s)" % (self, self.location)
|
2593
|
+
else:
|
2594
|
+
return str(self)
|
2595
|
+
|
2596
|
+
def __str__(self):
|
2597
|
+
try:
|
2598
|
+
version = getattr(self, 'version', None)
|
2599
|
+
except ValueError:
|
2600
|
+
version = None
|
2601
|
+
version = version or "[unknown version]"
|
2602
|
+
return "%s %s" % (self.project_name, version)
|
2603
|
+
|
2604
|
+
def __getattr__(self, attr):
|
2605
|
+
"""Delegate all unrecognized public attributes to .metadata provider"""
|
2606
|
+
if attr.startswith('_'):
|
2607
|
+
raise AttributeError(attr)
|
2608
|
+
return getattr(self._provider, attr)
|
2609
|
+
|
2610
|
+
@classmethod
|
2611
|
+
def from_filename(cls, filename, metadata=None, **kw):
|
2612
|
+
return cls.from_location(
|
2613
|
+
_normalize_cached(filename), os.path.basename(filename), metadata,
|
2614
|
+
**kw
|
2615
|
+
)
|
2616
|
+
|
2617
|
+
def as_requirement(self):
|
2618
|
+
"""Return a ``Requirement`` that matches this distribution exactly"""
|
2619
|
+
if isinstance(self.parsed_version, packaging.version.Version):
|
2620
|
+
spec = "%s==%s" % (self.project_name, self.parsed_version)
|
2621
|
+
else:
|
2622
|
+
spec = "%s===%s" % (self.project_name, self.parsed_version)
|
2623
|
+
|
2624
|
+
return Requirement.parse(spec)
|
2625
|
+
|
2626
|
+
def load_entry_point(self, group, name):
|
2627
|
+
"""Return the `name` entry point of `group` or raise ImportError"""
|
2628
|
+
ep = self.get_entry_info(group, name)
|
2629
|
+
if ep is None:
|
2630
|
+
raise ImportError("Entry point %r not found" % ((group, name),))
|
2631
|
+
return ep.load()
|
2632
|
+
|
2633
|
+
def get_entry_map(self, group=None):
|
2634
|
+
"""Return the entry point map for `group`, or the full entry map"""
|
2635
|
+
try:
|
2636
|
+
ep_map = self._ep_map
|
2637
|
+
except AttributeError:
|
2638
|
+
ep_map = self._ep_map = EntryPoint.parse_map(
|
2639
|
+
self._get_metadata('entry_points.txt'), self
|
2640
|
+
)
|
2641
|
+
if group is not None:
|
2642
|
+
return ep_map.get(group, {})
|
2643
|
+
return ep_map
|
2644
|
+
|
2645
|
+
def get_entry_info(self, group, name):
|
2646
|
+
"""Return the EntryPoint object for `group`+`name`, or ``None``"""
|
2647
|
+
return self.get_entry_map(group).get(name)
|
2648
|
+
|
2649
|
+
def insert_on(self, path, loc=None, replace=False):
|
2650
|
+
"""Ensure self.location is on path
|
2651
|
+
|
2652
|
+
If replace=False (default):
|
2653
|
+
- If location is already in path anywhere, do nothing.
|
2654
|
+
- Else:
|
2655
|
+
- If it's an egg and its parent directory is on path,
|
2656
|
+
insert just ahead of the parent.
|
2657
|
+
- Else: add to the end of path.
|
2658
|
+
If replace=True:
|
2659
|
+
- If location is already on path anywhere (not eggs)
|
2660
|
+
or higher priority than its parent (eggs)
|
2661
|
+
do nothing.
|
2662
|
+
- Else:
|
2663
|
+
- If it's an egg and its parent directory is on path,
|
2664
|
+
insert just ahead of the parent,
|
2665
|
+
removing any lower-priority entries.
|
2666
|
+
- Else: add it to the front of path.
|
2667
|
+
"""
|
2668
|
+
|
2669
|
+
loc = loc or self.location
|
2670
|
+
if not loc:
|
2671
|
+
return
|
2672
|
+
|
2673
|
+
nloc = _normalize_cached(loc)
|
2674
|
+
bdir = os.path.dirname(nloc)
|
2675
|
+
npath = [(p and _normalize_cached(p) or p) for p in path]
|
2676
|
+
|
2677
|
+
for p, item in enumerate(npath):
|
2678
|
+
if item == nloc:
|
2679
|
+
if replace:
|
2680
|
+
break
|
2681
|
+
else:
|
2682
|
+
# don't modify path (even removing duplicates) if found and not replace
|
2683
|
+
return
|
2684
|
+
elif item == bdir and self.precedence == EGG_DIST:
|
2685
|
+
# if it's an .egg, give it precedence over its directory
|
2686
|
+
# UNLESS it's already been added to sys.path and replace=False
|
2687
|
+
if (not replace) and nloc in npath[p:]:
|
2688
|
+
return
|
2689
|
+
if path is sys.path:
|
2690
|
+
self.check_version_conflict()
|
2691
|
+
path.insert(p, loc)
|
2692
|
+
npath.insert(p, nloc)
|
2693
|
+
break
|
2694
|
+
else:
|
2695
|
+
if path is sys.path:
|
2696
|
+
self.check_version_conflict()
|
2697
|
+
if replace:
|
2698
|
+
path.insert(0, loc)
|
2699
|
+
else:
|
2700
|
+
path.append(loc)
|
2701
|
+
return
|
2702
|
+
|
2703
|
+
# p is the spot where we found or inserted loc; now remove duplicates
|
2704
|
+
while True:
|
2705
|
+
try:
|
2706
|
+
np = npath.index(nloc, p + 1)
|
2707
|
+
except ValueError:
|
2708
|
+
break
|
2709
|
+
else:
|
2710
|
+
del npath[np], path[np]
|
2711
|
+
# ha!
|
2712
|
+
p = np
|
2713
|
+
|
2714
|
+
return
|
2715
|
+
|
2716
|
+
def check_version_conflict(self):
|
2717
|
+
if self.key == 'setuptools':
|
2718
|
+
# ignore the inevitable setuptools self-conflicts :(
|
2719
|
+
return
|
2720
|
+
|
2721
|
+
nsp = dict.fromkeys(self._get_metadata('namespace_packages.txt'))
|
2722
|
+
loc = normalize_path(self.location)
|
2723
|
+
for modname in self._get_metadata('top_level.txt'):
|
2724
|
+
if (modname not in sys.modules or modname in nsp
|
2725
|
+
or modname in _namespace_packages):
|
2726
|
+
continue
|
2727
|
+
if modname in ('pkg_resources', 'setuptools', 'site'):
|
2728
|
+
continue
|
2729
|
+
fn = getattr(sys.modules[modname], '__file__', None)
|
2730
|
+
if fn and (normalize_path(fn).startswith(loc) or
|
2731
|
+
fn.startswith(self.location)):
|
2732
|
+
continue
|
2733
|
+
issue_warning(
|
2734
|
+
"Module %s was already imported from %s, but %s is being added"
|
2735
|
+
" to sys.path" % (modname, fn, self.location),
|
2736
|
+
)
|
2737
|
+
|
2738
|
+
def has_version(self):
|
2739
|
+
try:
|
2740
|
+
self.version
|
2741
|
+
except ValueError:
|
2742
|
+
issue_warning("Unbuilt egg for " + repr(self))
|
2743
|
+
return False
|
2744
|
+
return True
|
2745
|
+
|
2746
|
+
def clone(self, **kw):
|
2747
|
+
"""Copy this distribution, substituting in any changed keyword args"""
|
2748
|
+
names = 'project_name version py_version platform location precedence'
|
2749
|
+
for attr in names.split():
|
2750
|
+
kw.setdefault(attr, getattr(self, attr, None))
|
2751
|
+
kw.setdefault('metadata', self._provider)
|
2752
|
+
return self.__class__(**kw)
|
2753
|
+
|
2754
|
+
@property
|
2755
|
+
def extras(self):
|
2756
|
+
return [dep for dep in self._dep_map if dep]
|
2757
|
+
|
2758
|
+
|
2759
|
+
class EggInfoDistribution(Distribution):
|
2760
|
+
def _reload_version(self):
|
2761
|
+
"""
|
2762
|
+
Packages installed by distutils (e.g. numpy or scipy),
|
2763
|
+
which uses an old safe_version, and so
|
2764
|
+
their version numbers can get mangled when
|
2765
|
+
converted to filenames (e.g., 1.11.0.dev0+2329eae to
|
2766
|
+
1.11.0.dev0_2329eae). These distributions will not be
|
2767
|
+
parsed properly
|
2768
|
+
downstream by Distribution and safe_version, so
|
2769
|
+
take an extra step and try to get the version number from
|
2770
|
+
the metadata file itself instead of the filename.
|
2771
|
+
"""
|
2772
|
+
md_version = _version_from_file(self._get_metadata(self.PKG_INFO))
|
2773
|
+
if md_version:
|
2774
|
+
self._version = md_version
|
2775
|
+
return self
|
2776
|
+
|
2777
|
+
|
2778
|
+
class DistInfoDistribution(Distribution):
|
2779
|
+
"""Wrap an actual or potential sys.path entry w/metadata, .dist-info style"""
|
2780
|
+
PKG_INFO = 'METADATA'
|
2781
|
+
EQEQ = re.compile(r"([\(,])\s*(\d.*?)\s*([,\)])")
|
2782
|
+
|
2783
|
+
@property
|
2784
|
+
def _parsed_pkg_info(self):
|
2785
|
+
"""Parse and cache metadata"""
|
2786
|
+
try:
|
2787
|
+
return self._pkg_info
|
2788
|
+
except AttributeError:
|
2789
|
+
metadata = self.get_metadata(self.PKG_INFO)
|
2790
|
+
self._pkg_info = email.parser.Parser().parsestr(metadata)
|
2791
|
+
return self._pkg_info
|
2792
|
+
|
2793
|
+
@property
|
2794
|
+
def _dep_map(self):
|
2795
|
+
try:
|
2796
|
+
return self.__dep_map
|
2797
|
+
except AttributeError:
|
2798
|
+
self.__dep_map = self._compute_dependencies()
|
2799
|
+
return self.__dep_map
|
2800
|
+
|
2801
|
+
def _compute_dependencies(self):
|
2802
|
+
"""Recompute this distribution's dependencies."""
|
2803
|
+
dm = self.__dep_map = {None: []}
|
2804
|
+
|
2805
|
+
reqs = []
|
2806
|
+
# Including any condition expressions
|
2807
|
+
for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
|
2808
|
+
reqs.extend(parse_requirements(req))
|
2809
|
+
|
2810
|
+
def reqs_for_extra(extra):
|
2811
|
+
for req in reqs:
|
2812
|
+
if not req.marker or req.marker.evaluate({'extra': extra}):
|
2813
|
+
yield req
|
2814
|
+
|
2815
|
+
common = frozenset(reqs_for_extra(None))
|
2816
|
+
dm[None].extend(common)
|
2817
|
+
|
2818
|
+
for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
|
2819
|
+
s_extra = safe_extra(extra.strip())
|
2820
|
+
dm[s_extra] = list(frozenset(reqs_for_extra(extra)) - common)
|
2821
|
+
|
2822
|
+
return dm
|
2823
|
+
|
2824
|
+
|
2825
|
+
_distributionImpl = {
|
2826
|
+
'.egg': Distribution,
|
2827
|
+
'.egg-info': EggInfoDistribution,
|
2828
|
+
'.dist-info': DistInfoDistribution,
|
2829
|
+
}
|
2830
|
+
|
2831
|
+
|
2832
|
+
def issue_warning(*args, **kw):
|
2833
|
+
level = 1
|
2834
|
+
g = globals()
|
2835
|
+
try:
|
2836
|
+
# find the first stack frame that is *not* code in
|
2837
|
+
# the pkg_resources module, to use for the warning
|
2838
|
+
while sys._getframe(level).f_globals is g:
|
2839
|
+
level += 1
|
2840
|
+
except ValueError:
|
2841
|
+
pass
|
2842
|
+
warnings.warn(stacklevel=level + 1, *args, **kw)
|
2843
|
+
|
2844
|
+
|
2845
|
+
class RequirementParseError(ValueError):
|
2846
|
+
def __str__(self):
|
2847
|
+
return ' '.join(self.args)
|
2848
|
+
|
2849
|
+
|
2850
|
+
def parse_requirements(strs):
|
2851
|
+
"""Yield ``Requirement`` objects for each specification in `strs`
|
2852
|
+
|
2853
|
+
`strs` must be a string, or a (possibly-nested) iterable thereof.
|
2854
|
+
"""
|
2855
|
+
# create a steppable iterator, so we can handle \-continuations
|
2856
|
+
lines = iter(yield_lines(strs))
|
2857
|
+
|
2858
|
+
for line in lines:
|
2859
|
+
# Drop comments -- a hash without a space may be in a URL.
|
2860
|
+
if ' #' in line:
|
2861
|
+
line = line[:line.find(' #')]
|
2862
|
+
# If there is a line continuation, drop it, and append the next line.
|
2863
|
+
if line.endswith('\\'):
|
2864
|
+
line = line[:-2].strip()
|
2865
|
+
line += next(lines)
|
2866
|
+
yield Requirement(line)
|
2867
|
+
|
2868
|
+
|
2869
|
+
class Requirement(packaging.requirements.Requirement):
|
2870
|
+
def __init__(self, requirement_string):
|
2871
|
+
"""DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
|
2872
|
+
try:
|
2873
|
+
super(Requirement, self).__init__(requirement_string)
|
2874
|
+
except packaging.requirements.InvalidRequirement as e:
|
2875
|
+
raise RequirementParseError(str(e))
|
2876
|
+
self.unsafe_name = self.name
|
2877
|
+
project_name = safe_name(self.name)
|
2878
|
+
self.project_name, self.key = project_name, project_name.lower()
|
2879
|
+
self.specs = [
|
2880
|
+
(spec.operator, spec.version) for spec in self.specifier]
|
2881
|
+
self.extras = tuple(map(safe_extra, self.extras))
|
2882
|
+
self.hashCmp = (
|
2883
|
+
self.key,
|
2884
|
+
self.specifier,
|
2885
|
+
frozenset(self.extras),
|
2886
|
+
str(self.marker) if self.marker else None,
|
2887
|
+
)
|
2888
|
+
self.__hash = hash(self.hashCmp)
|
2889
|
+
|
2890
|
+
def __eq__(self, other):
|
2891
|
+
return (
|
2892
|
+
isinstance(other, Requirement) and
|
2893
|
+
self.hashCmp == other.hashCmp
|
2894
|
+
)
|
2895
|
+
|
2896
|
+
def __ne__(self, other):
|
2897
|
+
return not self == other
|
2898
|
+
|
2899
|
+
def __contains__(self, item):
|
2900
|
+
if isinstance(item, Distribution):
|
2901
|
+
if item.key != self.key:
|
2902
|
+
return False
|
2903
|
+
|
2904
|
+
item = item.version
|
2905
|
+
|
2906
|
+
# Allow prereleases always in order to match the previous behavior of
|
2907
|
+
# this method. In the future this should be smarter and follow PEP 440
|
2908
|
+
# more accurately.
|
2909
|
+
return self.specifier.contains(item, prereleases=True)
|
2910
|
+
|
2911
|
+
def __hash__(self):
|
2912
|
+
return self.__hash
|
2913
|
+
|
2914
|
+
def __repr__(self): return "Requirement.parse(%r)" % str(self)
|
2915
|
+
|
2916
|
+
@staticmethod
|
2917
|
+
def parse(s):
|
2918
|
+
req, = parse_requirements(s)
|
2919
|
+
return req
|
2920
|
+
|
2921
|
+
|
2922
|
+
def _get_mro(cls):
|
2923
|
+
"""Get an mro for a type or classic class"""
|
2924
|
+
if not isinstance(cls, type):
|
2925
|
+
|
2926
|
+
class cls(cls, object):
|
2927
|
+
pass
|
2928
|
+
|
2929
|
+
return cls.__mro__[1:]
|
2930
|
+
return cls.__mro__
|
2931
|
+
|
2932
|
+
|
2933
|
+
def _find_adapter(registry, ob):
|
2934
|
+
"""Return an adapter factory for `ob` from `registry`"""
|
2935
|
+
for t in _get_mro(getattr(ob, '__class__', type(ob))):
|
2936
|
+
if t in registry:
|
2937
|
+
return registry[t]
|
2938
|
+
|
2939
|
+
|
2940
|
+
def ensure_directory(path):
|
2941
|
+
"""Ensure that the parent directory of `path` exists"""
|
2942
|
+
dirname = os.path.dirname(path)
|
2943
|
+
if not os.path.isdir(dirname):
|
2944
|
+
os.makedirs(dirname)
|
2945
|
+
|
2946
|
+
|
2947
|
+
def _bypass_ensure_directory(path):
|
2948
|
+
"""Sandbox-bypassing version of ensure_directory()"""
|
2949
|
+
if not WRITE_SUPPORT:
|
2950
|
+
raise IOError('"os.mkdir" not supported on this platform.')
|
2951
|
+
dirname, filename = split(path)
|
2952
|
+
if dirname and filename and not isdir(dirname):
|
2953
|
+
_bypass_ensure_directory(dirname)
|
2954
|
+
mkdir(dirname, 0o755)
|
2955
|
+
|
2956
|
+
|
2957
|
+
def split_sections(s):
|
2958
|
+
"""Split a string or iterable thereof into (section, content) pairs
|
2959
|
+
|
2960
|
+
Each ``section`` is a stripped version of the section header ("[section]")
|
2961
|
+
and each ``content`` is a list of stripped lines excluding blank lines and
|
2962
|
+
comment-only lines. If there are any such lines before the first section
|
2963
|
+
header, they're returned in a first ``section`` of ``None``.
|
2964
|
+
"""
|
2965
|
+
section = None
|
2966
|
+
content = []
|
2967
|
+
for line in yield_lines(s):
|
2968
|
+
if line.startswith("["):
|
2969
|
+
if line.endswith("]"):
|
2970
|
+
if section or content:
|
2971
|
+
yield section, content
|
2972
|
+
section = line[1:-1].strip()
|
2973
|
+
content = []
|
2974
|
+
else:
|
2975
|
+
raise ValueError("Invalid section heading", line)
|
2976
|
+
else:
|
2977
|
+
content.append(line)
|
2978
|
+
|
2979
|
+
# wrap up last segment
|
2980
|
+
yield section, content
|
2981
|
+
|
2982
|
+
|
2983
|
+
def _mkstemp(*args, **kw):
|
2984
|
+
old_open = os.open
|
2985
|
+
try:
|
2986
|
+
# temporarily bypass sandboxing
|
2987
|
+
os.open = os_open
|
2988
|
+
return tempfile.mkstemp(*args, **kw)
|
2989
|
+
finally:
|
2990
|
+
# and then put it back
|
2991
|
+
os.open = old_open
|
2992
|
+
|
2993
|
+
|
2994
|
+
# Silence the PEP440Warning by default, so that end users don't get hit by it
|
2995
|
+
# randomly just because they use pkg_resources. We want to append the rule
|
2996
|
+
# because we want earlier uses of filterwarnings to take precedence over this
|
2997
|
+
# one.
|
2998
|
+
warnings.filterwarnings("ignore", category=PEP440Warning, append=True)
|
2999
|
+
|
3000
|
+
|
3001
|
+
# from jaraco.functools 1.3
|
3002
|
+
def _call_aside(f, *args, **kwargs):
|
3003
|
+
f(*args, **kwargs)
|
3004
|
+
return f
|
3005
|
+
|
3006
|
+
|
3007
|
+
@_call_aside
|
3008
|
+
def _initialize(g=globals()):
|
3009
|
+
"Set up global resource manager (deliberately not state-saved)"
|
3010
|
+
manager = ResourceManager()
|
3011
|
+
g['_manager'] = manager
|
3012
|
+
for name in dir(manager):
|
3013
|
+
if not name.startswith('_'):
|
3014
|
+
g[name] = getattr(manager, name)
|
3015
|
+
|
3016
|
+
|
3017
|
+
@_call_aside
|
3018
|
+
def _initialize_master_working_set():
|
3019
|
+
"""
|
3020
|
+
Prepare the master working set and make the ``require()``
|
3021
|
+
API available.
|
3022
|
+
|
3023
|
+
This function has explicit effects on the global state
|
3024
|
+
of pkg_resources. It is intended to be invoked once at
|
3025
|
+
the initialization of this module.
|
3026
|
+
|
3027
|
+
Invocation by other packages is unsupported and done
|
3028
|
+
at their own risk.
|
3029
|
+
"""
|
3030
|
+
working_set = WorkingSet._build_master()
|
3031
|
+
_declare_state('object', working_set=working_set)
|
3032
|
+
|
3033
|
+
require = working_set.require
|
3034
|
+
iter_entry_points = working_set.iter_entry_points
|
3035
|
+
add_activation_listener = working_set.subscribe
|
3036
|
+
run_script = working_set.run_script
|
3037
|
+
# backward compatibility
|
3038
|
+
run_main = run_script
|
3039
|
+
# Activate all distributions already on sys.path with replace=False and
|
3040
|
+
# ensure that all distributions added to the working set in the future
|
3041
|
+
# (e.g. by calling ``require()``) will get activated as well,
|
3042
|
+
# with higher priority (replace=True).
|
3043
|
+
dist = None # ensure dist is defined for del dist below
|
3044
|
+
for dist in working_set:
|
3045
|
+
dist.activate(replace=False)
|
3046
|
+
del dist
|
3047
|
+
add_activation_listener(lambda dist: dist.activate(replace=True), existing=False)
|
3048
|
+
working_set.entries = []
|
3049
|
+
# match order
|
3050
|
+
list(map(working_set.add_entry, sys.path))
|
3051
|
+
globals().update(locals())
|