Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +4 -0
- evalkit_llava/bin/bzcat +3 -0
- evalkit_llava/lib/libbz2.so +3 -0
- evalkit_llava/lib/libformw.a +3 -0
- evalkit_llava/lib/liblzma.so.5 +3 -0
- evalkit_llava/lib/python3.10/idlelib/Icons/minusnode.gif +3 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_entry_points.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_imp.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_importlib.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_normalization.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_reqs.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/archive_util.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/depends.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/discovery.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/dist.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/extension.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/glob.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/installer.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/modified.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/package_index.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/sandbox.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/unicode_utils.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/version.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/warnings.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/wheel.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/windows_support.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/INSTALLER +1 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/LICENSE +17 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/METADATA +85 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/RECORD +10 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/REQUESTED +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/WHEEL +5 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/top_level.txt +1 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/INSTALLER +1 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/LICENSE +17 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/METADATA +75 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/RECORD +8 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/WHEEL +5 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/top_level.txt +1 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/__pycache__/context.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/__init__.py +1091 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/py.typed +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/context.py +361 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/__init__.py +633 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/__init__.pyi +125 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/py.typed +0 -0
- evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/text/Lorem ipsum.txt +2 -0
.gitattributes
CHANGED
|
@@ -100,3 +100,7 @@ evalkit_llava/lib/libncurses++w.a filter=lfs diff=lfs merge=lfs -text
|
|
| 100 |
evalkit_llava/bin/lzma filter=lfs diff=lfs merge=lfs -text
|
| 101 |
evalkit_llava/lib/libncurses++.a filter=lfs diff=lfs merge=lfs -text
|
| 102 |
evalkit_llava/lib/libform.a filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
evalkit_llava/bin/lzma filter=lfs diff=lfs merge=lfs -text
|
| 101 |
evalkit_llava/lib/libncurses++.a filter=lfs diff=lfs merge=lfs -text
|
| 102 |
evalkit_llava/lib/libform.a filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
evalkit_llava/lib/libformw.a filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
evalkit_llava/lib/liblzma.so.5 filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
evalkit_llava/bin/bzcat filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
evalkit_llava/lib/libbz2.so filter=lfs diff=lfs merge=lfs -text
|
evalkit_llava/bin/bzcat
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8a514cce807cb1656a3bcd59794401e7d63c9554267e9acc77097a406092a8ed
|
| 3 |
+
size 299464
|
evalkit_llava/lib/libbz2.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4979469ae49ac144f62202f75bbdd69b17197aedb879d633337c8cf7e4aba301
|
| 3 |
+
size 229016
|
evalkit_llava/lib/libformw.a
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e38c05b95a8311e56f3f585bf38e66c9af44a8d6085d39648a770d611a6ebeeb
|
| 3 |
+
size 185212
|
evalkit_llava/lib/liblzma.so.5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6b126e186cc43702dcacb626e0455f8aecf030d969d6d4a407ce4cc35293c503
|
| 3 |
+
size 218304
|
evalkit_llava/lib/python3.10/idlelib/Icons/minusnode.gif
ADDED
|
|
Git LFS Details
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_entry_points.cpython-310.pyc
ADDED
|
Binary file (3.23 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_imp.cpython-310.pyc
ADDED
|
Binary file (2.07 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_importlib.cpython-310.pyc
ADDED
|
Binary file (321 Bytes). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_normalization.cpython-310.pyc
ADDED
|
Binary file (4.62 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/_reqs.cpython-310.pyc
ADDED
|
Binary file (1.62 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/archive_util.cpython-310.pyc
ADDED
|
Binary file (6.18 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/depends.cpython-310.pyc
ADDED
|
Binary file (5.44 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/discovery.cpython-310.pyc
ADDED
|
Binary file (21.2 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/dist.cpython-310.pyc
ADDED
|
Binary file (32.6 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/extension.cpython-310.pyc
ADDED
|
Binary file (6.28 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/glob.cpython-310.pyc
ADDED
|
Binary file (5.1 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/installer.cpython-310.pyc
ADDED
|
Binary file (4.14 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/modified.cpython-310.pyc
ADDED
|
Binary file (408 Bytes). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/package_index.cpython-310.pyc
ADDED
|
Binary file (33.6 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/sandbox.cpython-310.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/unicode_utils.cpython-310.pyc
ADDED
|
Binary file (3.15 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/version.cpython-310.pyc
ADDED
|
Binary file (299 Bytes). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/warnings.cpython-310.pyc
ADDED
|
Binary file (3.96 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/wheel.cpython-310.pyc
ADDED
|
Binary file (7.77 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/__pycache__/windows_support.cpython-310.pyc
ADDED
|
Binary file (1.01 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
conda
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 2 |
+
of this software and associated documentation files (the "Software"), to
|
| 3 |
+
deal in the Software without restriction, including without limitation the
|
| 4 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 5 |
+
sell copies of the Software, and to permit persons to whom the Software is
|
| 6 |
+
furnished to do so, subject to the following conditions:
|
| 7 |
+
|
| 8 |
+
The above copyright notice and this permission notice shall be included in
|
| 9 |
+
all copies or substantial portions of the Software.
|
| 10 |
+
|
| 11 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 12 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 13 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 14 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 15 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 16 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 17 |
+
IN THE SOFTWARE.
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: jaraco.collections
|
| 3 |
+
Version: 5.1.0
|
| 4 |
+
Summary: Collection objects similar to those in stdlib by jaraco
|
| 5 |
+
Author-email: "Jason R. Coombs" <[email protected]>
|
| 6 |
+
Project-URL: Source, https://github.com/jaraco/jaraco.collections
|
| 7 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 8 |
+
Classifier: Intended Audience :: Developers
|
| 9 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 10 |
+
Classifier: Programming Language :: Python :: 3
|
| 11 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 12 |
+
Requires-Python: >=3.8
|
| 13 |
+
Description-Content-Type: text/x-rst
|
| 14 |
+
License-File: LICENSE
|
| 15 |
+
Requires-Dist: jaraco.text
|
| 16 |
+
Provides-Extra: check
|
| 17 |
+
Requires-Dist: pytest-checkdocs >=2.4 ; extra == 'check'
|
| 18 |
+
Requires-Dist: pytest-ruff >=0.2.1 ; (sys_platform != "cygwin") and extra == 'check'
|
| 19 |
+
Provides-Extra: cover
|
| 20 |
+
Requires-Dist: pytest-cov ; extra == 'cover'
|
| 21 |
+
Provides-Extra: doc
|
| 22 |
+
Requires-Dist: sphinx >=3.5 ; extra == 'doc'
|
| 23 |
+
Requires-Dist: jaraco.packaging >=9.3 ; extra == 'doc'
|
| 24 |
+
Requires-Dist: rst.linker >=1.9 ; extra == 'doc'
|
| 25 |
+
Requires-Dist: furo ; extra == 'doc'
|
| 26 |
+
Requires-Dist: sphinx-lint ; extra == 'doc'
|
| 27 |
+
Requires-Dist: jaraco.tidelift >=1.4 ; extra == 'doc'
|
| 28 |
+
Provides-Extra: enabler
|
| 29 |
+
Requires-Dist: pytest-enabler >=2.2 ; extra == 'enabler'
|
| 30 |
+
Provides-Extra: test
|
| 31 |
+
Requires-Dist: pytest !=8.1.*,>=6 ; extra == 'test'
|
| 32 |
+
Provides-Extra: type
|
| 33 |
+
Requires-Dist: pytest-mypy ; extra == 'type'
|
| 34 |
+
|
| 35 |
+
.. image:: https://img.shields.io/pypi/v/jaraco.collections.svg
|
| 36 |
+
:target: https://pypi.org/project/jaraco.collections
|
| 37 |
+
|
| 38 |
+
.. image:: https://img.shields.io/pypi/pyversions/jaraco.collections.svg
|
| 39 |
+
|
| 40 |
+
.. image:: https://github.com/jaraco/jaraco.collections/actions/workflows/main.yml/badge.svg
|
| 41 |
+
:target: https://github.com/jaraco/jaraco.collections/actions?query=workflow%3A%22tests%22
|
| 42 |
+
:alt: tests
|
| 43 |
+
|
| 44 |
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
|
| 45 |
+
:target: https://github.com/astral-sh/ruff
|
| 46 |
+
:alt: Ruff
|
| 47 |
+
|
| 48 |
+
.. image:: https://readthedocs.org/projects/jaracocollections/badge/?version=latest
|
| 49 |
+
:target: https://jaracocollections.readthedocs.io/en/latest/?badge=latest
|
| 50 |
+
|
| 51 |
+
.. image:: https://img.shields.io/badge/skeleton-2024-informational
|
| 52 |
+
:target: https://blog.jaraco.com/skeleton
|
| 53 |
+
|
| 54 |
+
.. image:: https://tidelift.com/badges/package/pypi/jaraco.collections
|
| 55 |
+
:target: https://tidelift.com/subscription/pkg/pypi-jaraco.collections?utm_source=pypi-jaraco.collections&utm_medium=readme
|
| 56 |
+
|
| 57 |
+
Models and classes to supplement the stdlib 'collections' module.
|
| 58 |
+
|
| 59 |
+
See the docs, linked above, for descriptions and usage examples.
|
| 60 |
+
|
| 61 |
+
Highlights include:
|
| 62 |
+
|
| 63 |
+
- RangeMap: A mapping that accepts a range of values for keys.
|
| 64 |
+
- Projection: A subset over an existing mapping.
|
| 65 |
+
- KeyTransformingDict: Generalized mapping with keys transformed by a function.
|
| 66 |
+
- FoldedCaseKeyedDict: A dict whose string keys are case-insensitive.
|
| 67 |
+
- BijectiveMap: A map where keys map to values and values back to their keys.
|
| 68 |
+
- ItemsAsAttributes: A mapping mix-in exposing items as attributes.
|
| 69 |
+
- IdentityOverrideMap: A map whose keys map by default to themselves unless overridden.
|
| 70 |
+
- FrozenDict: A hashable, immutable map.
|
| 71 |
+
- Enumeration: An object whose keys are enumerated.
|
| 72 |
+
- Everything: A container that contains all things.
|
| 73 |
+
- Least, Greatest: Objects that are always less than or greater than any other.
|
| 74 |
+
- pop_all: Return all items from the mutable sequence and remove them from that sequence.
|
| 75 |
+
- DictStack: A stack of dicts, great for sharing scopes.
|
| 76 |
+
- WeightedLookup: A specialized RangeMap for selecting an item by weights.
|
| 77 |
+
|
| 78 |
+
For Enterprise
|
| 79 |
+
==============
|
| 80 |
+
|
| 81 |
+
Available as part of the Tidelift Subscription.
|
| 82 |
+
|
| 83 |
+
This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.
|
| 84 |
+
|
| 85 |
+
`Learn more <https://tidelift.com/subscription/pkg/pypi-jaraco.collections?utm_source=pypi-jaraco.collections&utm_medium=referral&utm_campaign=github>`_.
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jaraco.collections-5.1.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
jaraco.collections-5.1.0.dist-info/LICENSE,sha256=htoPAa6uRjSKPD1GUZXcHOzN55956HdppkuNoEsqR0E,1023
|
| 3 |
+
jaraco.collections-5.1.0.dist-info/METADATA,sha256=IMUaliNsA5X1Ox9MXUWOagch5R4Wwb_3M7erp29dBtg,3933
|
| 4 |
+
jaraco.collections-5.1.0.dist-info/RECORD,,
|
| 5 |
+
jaraco.collections-5.1.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
jaraco.collections-5.1.0.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
|
| 7 |
+
jaraco.collections-5.1.0.dist-info/top_level.txt,sha256=0JnN3LfXH4LIRfXL-QFOGCJzQWZO3ELx4R1d_louoQM,7
|
| 8 |
+
jaraco/collections/__init__.py,sha256=Pc1-SqjWm81ad1P0-GttpkwO_LWlnaY6gUq8gcKh2v0,26640
|
| 9 |
+
jaraco/collections/__pycache__/__init__.cpython-312.pyc,,
|
| 10 |
+
jaraco/collections/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/REQUESTED
ADDED
|
File without changes
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (73.0.1)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.collections-5.1.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
jaraco
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
conda
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 2 |
+
of this software and associated documentation files (the "Software"), to
|
| 3 |
+
deal in the Software without restriction, including without limitation the
|
| 4 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 5 |
+
sell copies of the Software, and to permit persons to whom the Software is
|
| 6 |
+
furnished to do so, subject to the following conditions:
|
| 7 |
+
|
| 8 |
+
The above copyright notice and this permission notice shall be included in
|
| 9 |
+
all copies or substantial portions of the Software.
|
| 10 |
+
|
| 11 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 12 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 13 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 14 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 15 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 16 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 17 |
+
IN THE SOFTWARE.
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: jaraco.context
|
| 3 |
+
Version: 5.3.0
|
| 4 |
+
Summary: Useful decorators and context managers
|
| 5 |
+
Home-page: https://github.com/jaraco/jaraco.context
|
| 6 |
+
Author: Jason R. Coombs
|
| 7 |
+
Author-email: [email protected]
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Intended Audience :: Developers
|
| 10 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 11 |
+
Classifier: Programming Language :: Python :: 3
|
| 12 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 13 |
+
Requires-Python: >=3.8
|
| 14 |
+
License-File: LICENSE
|
| 15 |
+
Requires-Dist: backports.tarfile ; python_version < "3.12"
|
| 16 |
+
Provides-Extra: docs
|
| 17 |
+
Requires-Dist: sphinx >=3.5 ; extra == 'docs'
|
| 18 |
+
Requires-Dist: jaraco.packaging >=9.3 ; extra == 'docs'
|
| 19 |
+
Requires-Dist: rst.linker >=1.9 ; extra == 'docs'
|
| 20 |
+
Requires-Dist: furo ; extra == 'docs'
|
| 21 |
+
Requires-Dist: sphinx-lint ; extra == 'docs'
|
| 22 |
+
Requires-Dist: jaraco.tidelift >=1.4 ; extra == 'docs'
|
| 23 |
+
Provides-Extra: testing
|
| 24 |
+
Requires-Dist: pytest !=8.1.1,>=6 ; extra == 'testing'
|
| 25 |
+
Requires-Dist: pytest-checkdocs >=2.4 ; extra == 'testing'
|
| 26 |
+
Requires-Dist: pytest-cov ; extra == 'testing'
|
| 27 |
+
Requires-Dist: pytest-mypy ; extra == 'testing'
|
| 28 |
+
Requires-Dist: pytest-enabler >=2.2 ; extra == 'testing'
|
| 29 |
+
Requires-Dist: pytest-ruff >=0.2.1 ; extra == 'testing'
|
| 30 |
+
Requires-Dist: portend ; extra == 'testing'
|
| 31 |
+
|
| 32 |
+
.. image:: https://img.shields.io/pypi/v/jaraco.context.svg
|
| 33 |
+
:target: https://pypi.org/project/jaraco.context
|
| 34 |
+
|
| 35 |
+
.. image:: https://img.shields.io/pypi/pyversions/jaraco.context.svg
|
| 36 |
+
|
| 37 |
+
.. image:: https://github.com/jaraco/jaraco.context/actions/workflows/main.yml/badge.svg
|
| 38 |
+
:target: https://github.com/jaraco/jaraco.context/actions?query=workflow%3A%22tests%22
|
| 39 |
+
:alt: tests
|
| 40 |
+
|
| 41 |
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
|
| 42 |
+
:target: https://github.com/astral-sh/ruff
|
| 43 |
+
:alt: Ruff
|
| 44 |
+
|
| 45 |
+
.. image:: https://readthedocs.org/projects/jaracocontext/badge/?version=latest
|
| 46 |
+
:target: https://jaracocontext.readthedocs.io/en/latest/?badge=latest
|
| 47 |
+
|
| 48 |
+
.. image:: https://img.shields.io/badge/skeleton-2024-informational
|
| 49 |
+
:target: https://blog.jaraco.com/skeleton
|
| 50 |
+
|
| 51 |
+
.. image:: https://tidelift.com/badges/package/pypi/jaraco.context
|
| 52 |
+
:target: https://tidelift.com/subscription/pkg/pypi-jaraco.context?utm_source=pypi-jaraco.context&utm_medium=readme
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Highlights
|
| 56 |
+
==========
|
| 57 |
+
|
| 58 |
+
See the docs linked from the badge above for the full details, but here are some features that may be of interest.
|
| 59 |
+
|
| 60 |
+
- ``ExceptionTrap`` provides a general-purpose wrapper for trapping exceptions and then acting on the outcome. Includes ``passes`` and ``raises`` decorators to replace the result of a wrapped function by a boolean indicating the outcome of the exception trap. See `this keyring commit <https://github.com/jaraco/keyring/commit/a85a7cbc6c909f8121660ed1f7b487f99a1c2bf7>`_ for an example of it in production.
|
| 61 |
+
- ``suppress`` simply enables ``contextlib.suppress`` as a decorator.
|
| 62 |
+
- ``on_interrupt`` is a decorator used by CLI entry points to affect the handling of a ``KeyboardInterrupt``. Inspired by `Lucretiel/autocommand#18 <https://github.com/Lucretiel/autocommand/issues/18>`_.
|
| 63 |
+
- ``pushd`` is similar to pytest's ``monkeypatch.chdir`` or path's `default context <https://path.readthedocs.io/en/latest/api.html>`_, changes the current working directory for the duration of the context.
|
| 64 |
+
- ``tarball`` will download a tarball, extract it, change directory, yield, then clean up after. Convenient when working with web assets.
|
| 65 |
+
- ``null`` is there for those times when one code branch needs a context and the other doesn't; this null context provides symmetry across those branches.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
For Enterprise
|
| 69 |
+
==============
|
| 70 |
+
|
| 71 |
+
Available as part of the Tidelift Subscription.
|
| 72 |
+
|
| 73 |
+
This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.
|
| 74 |
+
|
| 75 |
+
`Learn more <https://tidelift.com/subscription/pkg/pypi-jaraco.context?utm_source=pypi-jaraco.context&utm_medium=referral&utm_campaign=github>`_.
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jaraco.context-5.3.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
jaraco.context-5.3.0.dist-info/LICENSE,sha256=htoPAa6uRjSKPD1GUZXcHOzN55956HdppkuNoEsqR0E,1023
|
| 3 |
+
jaraco.context-5.3.0.dist-info/METADATA,sha256=xDtguJej0tN9iEXCUvxEJh2a7xceIRVBEakBLSr__tY,4020
|
| 4 |
+
jaraco.context-5.3.0.dist-info/RECORD,,
|
| 5 |
+
jaraco.context-5.3.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
| 6 |
+
jaraco.context-5.3.0.dist-info/top_level.txt,sha256=0JnN3LfXH4LIRfXL-QFOGCJzQWZO3ELx4R1d_louoQM,7
|
| 7 |
+
jaraco/__pycache__/context.cpython-312.pyc,,
|
| 8 |
+
jaraco/context.py,sha256=REoLIxDkO5MfEYowt_WoupNCRoxBS5v7YX2PbW8lIcs,9552
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.43.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
jaraco
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/__pycache__/context.cpython-310.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/__init__.py
ADDED
|
@@ -0,0 +1,1091 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import collections.abc
|
| 4 |
+
import copy
|
| 5 |
+
import functools
|
| 6 |
+
import itertools
|
| 7 |
+
import operator
|
| 8 |
+
import random
|
| 9 |
+
import re
|
| 10 |
+
from collections.abc import Container, Iterable, Mapping
|
| 11 |
+
from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar, Union, overload
|
| 12 |
+
|
| 13 |
+
import jaraco.text
|
| 14 |
+
|
| 15 |
+
if TYPE_CHECKING:
|
| 16 |
+
from _operator import _SupportsComparison
|
| 17 |
+
|
| 18 |
+
from _typeshed import SupportsKeysAndGetItem
|
| 19 |
+
from typing_extensions import Self
|
| 20 |
+
|
| 21 |
+
_RangeMapKT = TypeVar('_RangeMapKT', bound=_SupportsComparison)
|
| 22 |
+
else:
|
| 23 |
+
# _SupportsComparison doesn't exist at runtime,
|
| 24 |
+
# but _RangeMapKT is used in RangeMap's superclass' type parameters
|
| 25 |
+
_RangeMapKT = TypeVar('_RangeMapKT')
|
| 26 |
+
|
| 27 |
+
_T = TypeVar('_T')
|
| 28 |
+
_VT = TypeVar('_VT')
|
| 29 |
+
|
| 30 |
+
_Matchable = Union[Callable, Container, Iterable, re.Pattern]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _dispatch(obj: _Matchable) -> Callable:
|
| 34 |
+
# can't rely on singledispatch for Union[Container, Iterable]
|
| 35 |
+
# due to ambiguity
|
| 36 |
+
# (https://peps.python.org/pep-0443/#abstract-base-classes).
|
| 37 |
+
if isinstance(obj, re.Pattern):
|
| 38 |
+
return obj.fullmatch
|
| 39 |
+
# mypy issue: https://github.com/python/mypy/issues/11071
|
| 40 |
+
if not isinstance(obj, Callable): # type: ignore[arg-type]
|
| 41 |
+
if not isinstance(obj, Container):
|
| 42 |
+
obj = set(obj) # type: ignore[arg-type]
|
| 43 |
+
obj = obj.__contains__
|
| 44 |
+
return obj # type: ignore[return-value]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class Projection(collections.abc.Mapping):
|
| 48 |
+
"""
|
| 49 |
+
Project a set of keys over a mapping
|
| 50 |
+
|
| 51 |
+
>>> sample = {'a': 1, 'b': 2, 'c': 3}
|
| 52 |
+
>>> prj = Projection(['a', 'c', 'd'], sample)
|
| 53 |
+
>>> dict(prj)
|
| 54 |
+
{'a': 1, 'c': 3}
|
| 55 |
+
|
| 56 |
+
Projection also accepts an iterable or callable or pattern.
|
| 57 |
+
|
| 58 |
+
>>> iter_prj = Projection(iter('acd'), sample)
|
| 59 |
+
>>> call_prj = Projection(lambda k: ord(k) in (97, 99, 100), sample)
|
| 60 |
+
>>> pat_prj = Projection(re.compile(r'[acd]'), sample)
|
| 61 |
+
>>> prj == iter_prj == call_prj == pat_prj
|
| 62 |
+
True
|
| 63 |
+
|
| 64 |
+
Keys should only appear if they were specified and exist in the space.
|
| 65 |
+
Order is retained.
|
| 66 |
+
|
| 67 |
+
>>> list(prj)
|
| 68 |
+
['a', 'c']
|
| 69 |
+
|
| 70 |
+
Attempting to access a key not in the projection
|
| 71 |
+
results in a KeyError.
|
| 72 |
+
|
| 73 |
+
>>> prj['b']
|
| 74 |
+
Traceback (most recent call last):
|
| 75 |
+
...
|
| 76 |
+
KeyError: 'b'
|
| 77 |
+
|
| 78 |
+
Use the projection to update another dict.
|
| 79 |
+
|
| 80 |
+
>>> target = {'a': 2, 'b': 2}
|
| 81 |
+
>>> target.update(prj)
|
| 82 |
+
>>> target
|
| 83 |
+
{'a': 1, 'b': 2, 'c': 3}
|
| 84 |
+
|
| 85 |
+
Projection keeps a reference to the original dict, so
|
| 86 |
+
modifying the original dict may modify the Projection.
|
| 87 |
+
|
| 88 |
+
>>> del sample['a']
|
| 89 |
+
>>> dict(prj)
|
| 90 |
+
{'c': 3}
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
def __init__(self, keys: _Matchable, space: Mapping):
|
| 94 |
+
self._match = _dispatch(keys)
|
| 95 |
+
self._space = space
|
| 96 |
+
|
| 97 |
+
def __getitem__(self, key):
|
| 98 |
+
if not self._match(key):
|
| 99 |
+
raise KeyError(key)
|
| 100 |
+
return self._space[key]
|
| 101 |
+
|
| 102 |
+
def _keys_resolved(self):
|
| 103 |
+
return filter(self._match, self._space)
|
| 104 |
+
|
| 105 |
+
def __iter__(self):
|
| 106 |
+
return self._keys_resolved()
|
| 107 |
+
|
| 108 |
+
def __len__(self):
|
| 109 |
+
return len(tuple(self._keys_resolved()))
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class Mask(Projection):
|
| 113 |
+
"""
|
| 114 |
+
The inverse of a :class:`Projection`, masking out keys.
|
| 115 |
+
|
| 116 |
+
>>> sample = {'a': 1, 'b': 2, 'c': 3}
|
| 117 |
+
>>> msk = Mask(['a', 'c', 'd'], sample)
|
| 118 |
+
>>> dict(msk)
|
| 119 |
+
{'b': 2}
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
def __init__(self, *args, **kwargs):
|
| 123 |
+
super().__init__(*args, **kwargs)
|
| 124 |
+
# self._match = compose(operator.not_, self._match)
|
| 125 |
+
self._match = lambda key, orig=self._match: not orig(key)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def dict_map(function, dictionary):
|
| 129 |
+
"""
|
| 130 |
+
Return a new dict with function applied to values of dictionary.
|
| 131 |
+
|
| 132 |
+
>>> dict_map(lambda x: x+1, dict(a=1, b=2))
|
| 133 |
+
{'a': 2, 'b': 3}
|
| 134 |
+
"""
|
| 135 |
+
return dict((key, function(value)) for key, value in dictionary.items())
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class RangeMap(Dict[_RangeMapKT, _VT]):
|
| 139 |
+
"""
|
| 140 |
+
A dictionary-like object that uses the keys as bounds for a range.
|
| 141 |
+
Inclusion of the value for that range is determined by the
|
| 142 |
+
key_match_comparator, which defaults to less-than-or-equal.
|
| 143 |
+
A value is returned for a key if it is the first key that matches in
|
| 144 |
+
the sorted list of keys.
|
| 145 |
+
|
| 146 |
+
One may supply keyword parameters to be passed to the sort function used
|
| 147 |
+
to sort keys (i.e. key, reverse) as sort_params.
|
| 148 |
+
|
| 149 |
+
Create a map that maps 1-3 -> 'a', 4-6 -> 'b'
|
| 150 |
+
|
| 151 |
+
>>> r = RangeMap({3: 'a', 6: 'b'}) # boy, that was easy
|
| 152 |
+
>>> r[1], r[2], r[3], r[4], r[5], r[6]
|
| 153 |
+
('a', 'a', 'a', 'b', 'b', 'b')
|
| 154 |
+
|
| 155 |
+
Even float values should work so long as the comparison operator
|
| 156 |
+
supports it.
|
| 157 |
+
|
| 158 |
+
>>> r[4.5]
|
| 159 |
+
'b'
|
| 160 |
+
|
| 161 |
+
Notice that the way rangemap is defined, it must be open-ended
|
| 162 |
+
on one side.
|
| 163 |
+
|
| 164 |
+
>>> r[0]
|
| 165 |
+
'a'
|
| 166 |
+
>>> r[-1]
|
| 167 |
+
'a'
|
| 168 |
+
|
| 169 |
+
One can close the open-end of the RangeMap by using undefined_value
|
| 170 |
+
|
| 171 |
+
>>> r = RangeMap({0: RangeMap.undefined_value, 3: 'a', 6: 'b'})
|
| 172 |
+
>>> r[0]
|
| 173 |
+
Traceback (most recent call last):
|
| 174 |
+
...
|
| 175 |
+
KeyError: 0
|
| 176 |
+
|
| 177 |
+
One can get the first or last elements in the range by using RangeMap.Item
|
| 178 |
+
|
| 179 |
+
>>> last_item = RangeMap.Item(-1)
|
| 180 |
+
>>> r[last_item]
|
| 181 |
+
'b'
|
| 182 |
+
|
| 183 |
+
.last_item is a shortcut for Item(-1)
|
| 184 |
+
|
| 185 |
+
>>> r[RangeMap.last_item]
|
| 186 |
+
'b'
|
| 187 |
+
|
| 188 |
+
Sometimes it's useful to find the bounds for a RangeMap
|
| 189 |
+
|
| 190 |
+
>>> r.bounds()
|
| 191 |
+
(0, 6)
|
| 192 |
+
|
| 193 |
+
RangeMap supports .get(key, default)
|
| 194 |
+
|
| 195 |
+
>>> r.get(0, 'not found')
|
| 196 |
+
'not found'
|
| 197 |
+
|
| 198 |
+
>>> r.get(7, 'not found')
|
| 199 |
+
'not found'
|
| 200 |
+
|
| 201 |
+
One often wishes to define the ranges by their left-most values,
|
| 202 |
+
which requires use of sort params and a key_match_comparator.
|
| 203 |
+
|
| 204 |
+
>>> r = RangeMap({1: 'a', 4: 'b'},
|
| 205 |
+
... sort_params=dict(reverse=True),
|
| 206 |
+
... key_match_comparator=operator.ge)
|
| 207 |
+
>>> r[1], r[2], r[3], r[4], r[5], r[6]
|
| 208 |
+
('a', 'a', 'a', 'b', 'b', 'b')
|
| 209 |
+
|
| 210 |
+
That wasn't nearly as easy as before, so an alternate constructor
|
| 211 |
+
is provided:
|
| 212 |
+
|
| 213 |
+
>>> r = RangeMap.left({1: 'a', 4: 'b', 7: RangeMap.undefined_value})
|
| 214 |
+
>>> r[1], r[2], r[3], r[4], r[5], r[6]
|
| 215 |
+
('a', 'a', 'a', 'b', 'b', 'b')
|
| 216 |
+
|
| 217 |
+
"""
|
| 218 |
+
|
| 219 |
+
def __init__(
|
| 220 |
+
self,
|
| 221 |
+
source: (
|
| 222 |
+
SupportsKeysAndGetItem[_RangeMapKT, _VT] | Iterable[tuple[_RangeMapKT, _VT]]
|
| 223 |
+
),
|
| 224 |
+
sort_params: Mapping[str, Any] = {},
|
| 225 |
+
key_match_comparator: Callable[[_RangeMapKT, _RangeMapKT], bool] = operator.le,
|
| 226 |
+
):
|
| 227 |
+
dict.__init__(self, source)
|
| 228 |
+
self.sort_params = sort_params
|
| 229 |
+
self.match = key_match_comparator
|
| 230 |
+
|
| 231 |
+
@classmethod
|
| 232 |
+
def left(
|
| 233 |
+
cls,
|
| 234 |
+
source: (
|
| 235 |
+
SupportsKeysAndGetItem[_RangeMapKT, _VT] | Iterable[tuple[_RangeMapKT, _VT]]
|
| 236 |
+
),
|
| 237 |
+
) -> Self:
|
| 238 |
+
return cls(
|
| 239 |
+
source, sort_params=dict(reverse=True), key_match_comparator=operator.ge
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
def __getitem__(self, item: _RangeMapKT) -> _VT:
|
| 243 |
+
sorted_keys = sorted(self.keys(), **self.sort_params)
|
| 244 |
+
if isinstance(item, RangeMap.Item):
|
| 245 |
+
result = self.__getitem__(sorted_keys[item])
|
| 246 |
+
else:
|
| 247 |
+
key = self._find_first_match_(sorted_keys, item)
|
| 248 |
+
result = dict.__getitem__(self, key)
|
| 249 |
+
if result is RangeMap.undefined_value:
|
| 250 |
+
raise KeyError(key)
|
| 251 |
+
return result
|
| 252 |
+
|
| 253 |
+
@overload # type: ignore[override] # Signature simplified over dict and Mapping
|
| 254 |
+
def get(self, key: _RangeMapKT, default: _T) -> _VT | _T: ...
|
| 255 |
+
@overload
|
| 256 |
+
def get(self, key: _RangeMapKT, default: None = None) -> _VT | None: ...
|
| 257 |
+
def get(self, key: _RangeMapKT, default: _T | None = None) -> _VT | _T | None:
|
| 258 |
+
"""
|
| 259 |
+
Return the value for key if key is in the dictionary, else default.
|
| 260 |
+
If default is not given, it defaults to None, so that this method
|
| 261 |
+
never raises a KeyError.
|
| 262 |
+
"""
|
| 263 |
+
try:
|
| 264 |
+
return self[key]
|
| 265 |
+
except KeyError:
|
| 266 |
+
return default
|
| 267 |
+
|
| 268 |
+
def _find_first_match_(
|
| 269 |
+
self, keys: Iterable[_RangeMapKT], item: _RangeMapKT
|
| 270 |
+
) -> _RangeMapKT:
|
| 271 |
+
is_match = functools.partial(self.match, item)
|
| 272 |
+
matches = filter(is_match, keys)
|
| 273 |
+
try:
|
| 274 |
+
return next(matches)
|
| 275 |
+
except StopIteration:
|
| 276 |
+
raise KeyError(item) from None
|
| 277 |
+
|
| 278 |
+
def bounds(self) -> tuple[_RangeMapKT, _RangeMapKT]:
|
| 279 |
+
sorted_keys = sorted(self.keys(), **self.sort_params)
|
| 280 |
+
return (sorted_keys[RangeMap.first_item], sorted_keys[RangeMap.last_item])
|
| 281 |
+
|
| 282 |
+
# some special values for the RangeMap
|
| 283 |
+
undefined_value = type('RangeValueUndefined', (), {})()
|
| 284 |
+
|
| 285 |
+
class Item(int):
|
| 286 |
+
"""RangeMap Item"""
|
| 287 |
+
|
| 288 |
+
first_item = Item(0)
|
| 289 |
+
last_item = Item(-1)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def __identity(x):
|
| 293 |
+
return x
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def sorted_items(d, key=__identity, reverse=False):
|
| 297 |
+
"""
|
| 298 |
+
Return the items of the dictionary sorted by the keys.
|
| 299 |
+
|
| 300 |
+
>>> sample = dict(foo=20, bar=42, baz=10)
|
| 301 |
+
>>> tuple(sorted_items(sample))
|
| 302 |
+
(('bar', 42), ('baz', 10), ('foo', 20))
|
| 303 |
+
|
| 304 |
+
>>> reverse_string = lambda s: ''.join(reversed(s))
|
| 305 |
+
>>> tuple(sorted_items(sample, key=reverse_string))
|
| 306 |
+
(('foo', 20), ('bar', 42), ('baz', 10))
|
| 307 |
+
|
| 308 |
+
>>> tuple(sorted_items(sample, reverse=True))
|
| 309 |
+
(('foo', 20), ('baz', 10), ('bar', 42))
|
| 310 |
+
"""
|
| 311 |
+
|
| 312 |
+
# wrap the key func so it operates on the first element of each item
|
| 313 |
+
def pairkey_key(item):
|
| 314 |
+
return key(item[0])
|
| 315 |
+
|
| 316 |
+
return sorted(d.items(), key=pairkey_key, reverse=reverse)
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class KeyTransformingDict(dict):
|
| 320 |
+
"""
|
| 321 |
+
A dict subclass that transforms the keys before they're used.
|
| 322 |
+
Subclasses may override the default transform_key to customize behavior.
|
| 323 |
+
"""
|
| 324 |
+
|
| 325 |
+
@staticmethod
|
| 326 |
+
def transform_key(key): # pragma: nocover
|
| 327 |
+
return key
|
| 328 |
+
|
| 329 |
+
def __init__(self, *args, **kargs):
|
| 330 |
+
super().__init__()
|
| 331 |
+
# build a dictionary using the default constructs
|
| 332 |
+
d = dict(*args, **kargs)
|
| 333 |
+
# build this dictionary using transformed keys.
|
| 334 |
+
for item in d.items():
|
| 335 |
+
self.__setitem__(*item)
|
| 336 |
+
|
| 337 |
+
def __setitem__(self, key, val):
|
| 338 |
+
key = self.transform_key(key)
|
| 339 |
+
super().__setitem__(key, val)
|
| 340 |
+
|
| 341 |
+
def __getitem__(self, key):
|
| 342 |
+
key = self.transform_key(key)
|
| 343 |
+
return super().__getitem__(key)
|
| 344 |
+
|
| 345 |
+
def __contains__(self, key):
|
| 346 |
+
key = self.transform_key(key)
|
| 347 |
+
return super().__contains__(key)
|
| 348 |
+
|
| 349 |
+
def __delitem__(self, key):
|
| 350 |
+
key = self.transform_key(key)
|
| 351 |
+
return super().__delitem__(key)
|
| 352 |
+
|
| 353 |
+
def get(self, key, *args, **kwargs):
|
| 354 |
+
key = self.transform_key(key)
|
| 355 |
+
return super().get(key, *args, **kwargs)
|
| 356 |
+
|
| 357 |
+
def setdefault(self, key, *args, **kwargs):
|
| 358 |
+
key = self.transform_key(key)
|
| 359 |
+
return super().setdefault(key, *args, **kwargs)
|
| 360 |
+
|
| 361 |
+
def pop(self, key, *args, **kwargs):
|
| 362 |
+
key = self.transform_key(key)
|
| 363 |
+
return super().pop(key, *args, **kwargs)
|
| 364 |
+
|
| 365 |
+
def matching_key_for(self, key):
|
| 366 |
+
"""
|
| 367 |
+
Given a key, return the actual key stored in self that matches.
|
| 368 |
+
Raise KeyError if the key isn't found.
|
| 369 |
+
"""
|
| 370 |
+
try:
|
| 371 |
+
return next(e_key for e_key in self.keys() if e_key == key)
|
| 372 |
+
except StopIteration as err:
|
| 373 |
+
raise KeyError(key) from err
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
class FoldedCaseKeyedDict(KeyTransformingDict):
|
| 377 |
+
"""
|
| 378 |
+
A case-insensitive dictionary (keys are compared as insensitive
|
| 379 |
+
if they are strings).
|
| 380 |
+
|
| 381 |
+
>>> d = FoldedCaseKeyedDict()
|
| 382 |
+
>>> d['heLlo'] = 'world'
|
| 383 |
+
>>> list(d.keys()) == ['heLlo']
|
| 384 |
+
True
|
| 385 |
+
>>> list(d.values()) == ['world']
|
| 386 |
+
True
|
| 387 |
+
>>> d['hello'] == 'world'
|
| 388 |
+
True
|
| 389 |
+
>>> 'hello' in d
|
| 390 |
+
True
|
| 391 |
+
>>> 'HELLO' in d
|
| 392 |
+
True
|
| 393 |
+
>>> print(repr(FoldedCaseKeyedDict({'heLlo': 'world'})))
|
| 394 |
+
{'heLlo': 'world'}
|
| 395 |
+
>>> d = FoldedCaseKeyedDict({'heLlo': 'world'})
|
| 396 |
+
>>> print(d['hello'])
|
| 397 |
+
world
|
| 398 |
+
>>> print(d['Hello'])
|
| 399 |
+
world
|
| 400 |
+
>>> list(d.keys())
|
| 401 |
+
['heLlo']
|
| 402 |
+
>>> d = FoldedCaseKeyedDict({'heLlo': 'world', 'Hello': 'world'})
|
| 403 |
+
>>> list(d.values())
|
| 404 |
+
['world']
|
| 405 |
+
>>> key, = d.keys()
|
| 406 |
+
>>> key in ['heLlo', 'Hello']
|
| 407 |
+
True
|
| 408 |
+
>>> del d['HELLO']
|
| 409 |
+
>>> d
|
| 410 |
+
{}
|
| 411 |
+
|
| 412 |
+
get should work
|
| 413 |
+
|
| 414 |
+
>>> d['Sumthin'] = 'else'
|
| 415 |
+
>>> d.get('SUMTHIN')
|
| 416 |
+
'else'
|
| 417 |
+
>>> d.get('OTHER', 'thing')
|
| 418 |
+
'thing'
|
| 419 |
+
>>> del d['sumthin']
|
| 420 |
+
|
| 421 |
+
setdefault should also work
|
| 422 |
+
|
| 423 |
+
>>> d['This'] = 'that'
|
| 424 |
+
>>> print(d.setdefault('this', 'other'))
|
| 425 |
+
that
|
| 426 |
+
>>> len(d)
|
| 427 |
+
1
|
| 428 |
+
>>> print(d['this'])
|
| 429 |
+
that
|
| 430 |
+
>>> print(d.setdefault('That', 'other'))
|
| 431 |
+
other
|
| 432 |
+
>>> print(d['THAT'])
|
| 433 |
+
other
|
| 434 |
+
|
| 435 |
+
Make it pop!
|
| 436 |
+
|
| 437 |
+
>>> print(d.pop('THAT'))
|
| 438 |
+
other
|
| 439 |
+
|
| 440 |
+
To retrieve the key in its originally-supplied form, use matching_key_for
|
| 441 |
+
|
| 442 |
+
>>> print(d.matching_key_for('this'))
|
| 443 |
+
This
|
| 444 |
+
|
| 445 |
+
>>> d.matching_key_for('missing')
|
| 446 |
+
Traceback (most recent call last):
|
| 447 |
+
...
|
| 448 |
+
KeyError: 'missing'
|
| 449 |
+
"""
|
| 450 |
+
|
| 451 |
+
@staticmethod
|
| 452 |
+
def transform_key(key):
|
| 453 |
+
return jaraco.text.FoldedCase(key)
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
class DictAdapter:
|
| 457 |
+
"""
|
| 458 |
+
Provide a getitem interface for attributes of an object.
|
| 459 |
+
|
| 460 |
+
Let's say you want to get at the string.lowercase property in a formatted
|
| 461 |
+
string. It's easy with DictAdapter.
|
| 462 |
+
|
| 463 |
+
>>> import string
|
| 464 |
+
>>> print("lowercase is %(ascii_lowercase)s" % DictAdapter(string))
|
| 465 |
+
lowercase is abcdefghijklmnopqrstuvwxyz
|
| 466 |
+
"""
|
| 467 |
+
|
| 468 |
+
def __init__(self, wrapped_ob):
|
| 469 |
+
self.object = wrapped_ob
|
| 470 |
+
|
| 471 |
+
def __getitem__(self, name):
|
| 472 |
+
return getattr(self.object, name)
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
class ItemsAsAttributes:
|
| 476 |
+
"""
|
| 477 |
+
Mix-in class to enable a mapping object to provide items as
|
| 478 |
+
attributes.
|
| 479 |
+
|
| 480 |
+
>>> C = type('C', (dict, ItemsAsAttributes), dict())
|
| 481 |
+
>>> i = C()
|
| 482 |
+
>>> i['foo'] = 'bar'
|
| 483 |
+
>>> i.foo
|
| 484 |
+
'bar'
|
| 485 |
+
|
| 486 |
+
Natural attribute access takes precedence
|
| 487 |
+
|
| 488 |
+
>>> i.foo = 'henry'
|
| 489 |
+
>>> i.foo
|
| 490 |
+
'henry'
|
| 491 |
+
|
| 492 |
+
But as you might expect, the mapping functionality is preserved.
|
| 493 |
+
|
| 494 |
+
>>> i['foo']
|
| 495 |
+
'bar'
|
| 496 |
+
|
| 497 |
+
A normal attribute error should be raised if an attribute is
|
| 498 |
+
requested that doesn't exist.
|
| 499 |
+
|
| 500 |
+
>>> i.missing
|
| 501 |
+
Traceback (most recent call last):
|
| 502 |
+
...
|
| 503 |
+
AttributeError: 'C' object has no attribute 'missing'
|
| 504 |
+
|
| 505 |
+
It also works on dicts that customize __getitem__
|
| 506 |
+
|
| 507 |
+
>>> missing_func = lambda self, key: 'missing item'
|
| 508 |
+
>>> C = type(
|
| 509 |
+
... 'C',
|
| 510 |
+
... (dict, ItemsAsAttributes),
|
| 511 |
+
... dict(__missing__ = missing_func),
|
| 512 |
+
... )
|
| 513 |
+
>>> i = C()
|
| 514 |
+
>>> i.missing
|
| 515 |
+
'missing item'
|
| 516 |
+
>>> i.foo
|
| 517 |
+
'missing item'
|
| 518 |
+
"""
|
| 519 |
+
|
| 520 |
+
def __getattr__(self, key):
|
| 521 |
+
try:
|
| 522 |
+
return getattr(super(), key)
|
| 523 |
+
except AttributeError as e:
|
| 524 |
+
# attempt to get the value from the mapping (return self[key])
|
| 525 |
+
# but be careful not to lose the original exception context.
|
| 526 |
+
noval = object()
|
| 527 |
+
|
| 528 |
+
def _safe_getitem(cont, key, missing_result):
|
| 529 |
+
try:
|
| 530 |
+
return cont[key]
|
| 531 |
+
except KeyError:
|
| 532 |
+
return missing_result
|
| 533 |
+
|
| 534 |
+
result = _safe_getitem(self, key, noval)
|
| 535 |
+
if result is not noval:
|
| 536 |
+
return result
|
| 537 |
+
# raise the original exception, but use the original class
|
| 538 |
+
# name, not 'super'.
|
| 539 |
+
(message,) = e.args
|
| 540 |
+
message = message.replace('super', self.__class__.__name__, 1)
|
| 541 |
+
e.args = (message,)
|
| 542 |
+
raise
|
| 543 |
+
|
| 544 |
+
|
| 545 |
+
def invert_map(map):
|
| 546 |
+
"""
|
| 547 |
+
Given a dictionary, return another dictionary with keys and values
|
| 548 |
+
switched. If any of the values resolve to the same key, raises
|
| 549 |
+
a ValueError.
|
| 550 |
+
|
| 551 |
+
>>> numbers = dict(a=1, b=2, c=3)
|
| 552 |
+
>>> letters = invert_map(numbers)
|
| 553 |
+
>>> letters[1]
|
| 554 |
+
'a'
|
| 555 |
+
>>> numbers['d'] = 3
|
| 556 |
+
>>> invert_map(numbers)
|
| 557 |
+
Traceback (most recent call last):
|
| 558 |
+
...
|
| 559 |
+
ValueError: Key conflict in inverted mapping
|
| 560 |
+
"""
|
| 561 |
+
res = dict((v, k) for k, v in map.items())
|
| 562 |
+
if not len(res) == len(map):
|
| 563 |
+
raise ValueError('Key conflict in inverted mapping')
|
| 564 |
+
return res
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
class IdentityOverrideMap(dict):
|
| 568 |
+
"""
|
| 569 |
+
A dictionary that by default maps each key to itself, but otherwise
|
| 570 |
+
acts like a normal dictionary.
|
| 571 |
+
|
| 572 |
+
>>> d = IdentityOverrideMap()
|
| 573 |
+
>>> d[42]
|
| 574 |
+
42
|
| 575 |
+
>>> d['speed'] = 'speedo'
|
| 576 |
+
>>> print(d['speed'])
|
| 577 |
+
speedo
|
| 578 |
+
"""
|
| 579 |
+
|
| 580 |
+
def __missing__(self, key):
|
| 581 |
+
return key
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
class DictStack(list, collections.abc.MutableMapping):
|
| 585 |
+
"""
|
| 586 |
+
A stack of dictionaries that behaves as a view on those dictionaries,
|
| 587 |
+
giving preference to the last.
|
| 588 |
+
|
| 589 |
+
>>> stack = DictStack([dict(a=1, c=2), dict(b=2, a=2)])
|
| 590 |
+
>>> stack['a']
|
| 591 |
+
2
|
| 592 |
+
>>> stack['b']
|
| 593 |
+
2
|
| 594 |
+
>>> stack['c']
|
| 595 |
+
2
|
| 596 |
+
>>> len(stack)
|
| 597 |
+
3
|
| 598 |
+
>>> stack.push(dict(a=3))
|
| 599 |
+
>>> stack['a']
|
| 600 |
+
3
|
| 601 |
+
>>> stack['a'] = 4
|
| 602 |
+
>>> set(stack.keys()) == set(['a', 'b', 'c'])
|
| 603 |
+
True
|
| 604 |
+
>>> set(stack.items()) == set([('a', 4), ('b', 2), ('c', 2)])
|
| 605 |
+
True
|
| 606 |
+
>>> dict(**stack) == dict(stack) == dict(a=4, c=2, b=2)
|
| 607 |
+
True
|
| 608 |
+
>>> d = stack.pop()
|
| 609 |
+
>>> stack['a']
|
| 610 |
+
2
|
| 611 |
+
>>> d = stack.pop()
|
| 612 |
+
>>> stack['a']
|
| 613 |
+
1
|
| 614 |
+
>>> stack.get('b', None)
|
| 615 |
+
>>> 'c' in stack
|
| 616 |
+
True
|
| 617 |
+
>>> del stack['c']
|
| 618 |
+
>>> dict(stack)
|
| 619 |
+
{'a': 1}
|
| 620 |
+
"""
|
| 621 |
+
|
| 622 |
+
def __iter__(self):
|
| 623 |
+
dicts = list.__iter__(self)
|
| 624 |
+
return iter(set(itertools.chain.from_iterable(c.keys() for c in dicts)))
|
| 625 |
+
|
| 626 |
+
def __getitem__(self, key):
|
| 627 |
+
for scope in reversed(tuple(list.__iter__(self))):
|
| 628 |
+
if key in scope:
|
| 629 |
+
return scope[key]
|
| 630 |
+
raise KeyError(key)
|
| 631 |
+
|
| 632 |
+
push = list.append
|
| 633 |
+
|
| 634 |
+
def __contains__(self, other):
|
| 635 |
+
return collections.abc.Mapping.__contains__(self, other)
|
| 636 |
+
|
| 637 |
+
def __len__(self):
|
| 638 |
+
return len(list(iter(self)))
|
| 639 |
+
|
| 640 |
+
def __setitem__(self, key, item):
|
| 641 |
+
last = list.__getitem__(self, -1)
|
| 642 |
+
return last.__setitem__(key, item)
|
| 643 |
+
|
| 644 |
+
def __delitem__(self, key):
|
| 645 |
+
last = list.__getitem__(self, -1)
|
| 646 |
+
return last.__delitem__(key)
|
| 647 |
+
|
| 648 |
+
# workaround for mypy confusion
|
| 649 |
+
def pop(self, *args, **kwargs):
|
| 650 |
+
return list.pop(self, *args, **kwargs)
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
class BijectiveMap(dict):
|
| 654 |
+
"""
|
| 655 |
+
A Bijective Map (two-way mapping).
|
| 656 |
+
|
| 657 |
+
Implemented as a simple dictionary of 2x the size, mapping values back
|
| 658 |
+
to keys.
|
| 659 |
+
|
| 660 |
+
Note, this implementation may be incomplete. If there's not a test for
|
| 661 |
+
your use case below, it's likely to fail, so please test and send pull
|
| 662 |
+
requests or patches for additional functionality needed.
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
>>> m = BijectiveMap()
|
| 666 |
+
>>> m['a'] = 'b'
|
| 667 |
+
>>> m == {'a': 'b', 'b': 'a'}
|
| 668 |
+
True
|
| 669 |
+
>>> print(m['b'])
|
| 670 |
+
a
|
| 671 |
+
|
| 672 |
+
>>> m['c'] = 'd'
|
| 673 |
+
>>> len(m)
|
| 674 |
+
2
|
| 675 |
+
|
| 676 |
+
Some weird things happen if you map an item to itself or overwrite a
|
| 677 |
+
single key of a pair, so it's disallowed.
|
| 678 |
+
|
| 679 |
+
>>> m['e'] = 'e'
|
| 680 |
+
Traceback (most recent call last):
|
| 681 |
+
ValueError: Key cannot map to itself
|
| 682 |
+
|
| 683 |
+
>>> m['d'] = 'e'
|
| 684 |
+
Traceback (most recent call last):
|
| 685 |
+
ValueError: Key/Value pairs may not overlap
|
| 686 |
+
|
| 687 |
+
>>> m['e'] = 'd'
|
| 688 |
+
Traceback (most recent call last):
|
| 689 |
+
ValueError: Key/Value pairs may not overlap
|
| 690 |
+
|
| 691 |
+
>>> print(m.pop('d'))
|
| 692 |
+
c
|
| 693 |
+
|
| 694 |
+
>>> 'c' in m
|
| 695 |
+
False
|
| 696 |
+
|
| 697 |
+
>>> m = BijectiveMap(dict(a='b'))
|
| 698 |
+
>>> len(m)
|
| 699 |
+
1
|
| 700 |
+
>>> print(m['b'])
|
| 701 |
+
a
|
| 702 |
+
|
| 703 |
+
>>> m = BijectiveMap()
|
| 704 |
+
>>> m.update(a='b')
|
| 705 |
+
>>> m['b']
|
| 706 |
+
'a'
|
| 707 |
+
|
| 708 |
+
>>> del m['b']
|
| 709 |
+
>>> len(m)
|
| 710 |
+
0
|
| 711 |
+
>>> 'a' in m
|
| 712 |
+
False
|
| 713 |
+
"""
|
| 714 |
+
|
| 715 |
+
def __init__(self, *args, **kwargs):
|
| 716 |
+
super().__init__()
|
| 717 |
+
self.update(*args, **kwargs)
|
| 718 |
+
|
| 719 |
+
def __setitem__(self, item, value):
|
| 720 |
+
if item == value:
|
| 721 |
+
raise ValueError("Key cannot map to itself")
|
| 722 |
+
overlap = (
|
| 723 |
+
item in self
|
| 724 |
+
and self[item] != value
|
| 725 |
+
or value in self
|
| 726 |
+
and self[value] != item
|
| 727 |
+
)
|
| 728 |
+
if overlap:
|
| 729 |
+
raise ValueError("Key/Value pairs may not overlap")
|
| 730 |
+
super().__setitem__(item, value)
|
| 731 |
+
super().__setitem__(value, item)
|
| 732 |
+
|
| 733 |
+
def __delitem__(self, item):
|
| 734 |
+
self.pop(item)
|
| 735 |
+
|
| 736 |
+
def __len__(self):
|
| 737 |
+
return super().__len__() // 2
|
| 738 |
+
|
| 739 |
+
def pop(self, key, *args, **kwargs):
|
| 740 |
+
mirror = self[key]
|
| 741 |
+
super().__delitem__(mirror)
|
| 742 |
+
return super().pop(key, *args, **kwargs)
|
| 743 |
+
|
| 744 |
+
def update(self, *args, **kwargs):
|
| 745 |
+
# build a dictionary using the default constructs
|
| 746 |
+
d = dict(*args, **kwargs)
|
| 747 |
+
# build this dictionary using transformed keys.
|
| 748 |
+
for item in d.items():
|
| 749 |
+
self.__setitem__(*item)
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
class FrozenDict(collections.abc.Mapping, collections.abc.Hashable):
|
| 753 |
+
"""
|
| 754 |
+
An immutable mapping.
|
| 755 |
+
|
| 756 |
+
>>> a = FrozenDict(a=1, b=2)
|
| 757 |
+
>>> b = FrozenDict(a=1, b=2)
|
| 758 |
+
>>> a == b
|
| 759 |
+
True
|
| 760 |
+
|
| 761 |
+
>>> a == dict(a=1, b=2)
|
| 762 |
+
True
|
| 763 |
+
>>> dict(a=1, b=2) == a
|
| 764 |
+
True
|
| 765 |
+
>>> 'a' in a
|
| 766 |
+
True
|
| 767 |
+
>>> type(hash(a)) is type(0)
|
| 768 |
+
True
|
| 769 |
+
>>> set(iter(a)) == {'a', 'b'}
|
| 770 |
+
True
|
| 771 |
+
>>> len(a)
|
| 772 |
+
2
|
| 773 |
+
>>> a['a'] == a.get('a') == 1
|
| 774 |
+
True
|
| 775 |
+
|
| 776 |
+
>>> a['c'] = 3
|
| 777 |
+
Traceback (most recent call last):
|
| 778 |
+
...
|
| 779 |
+
TypeError: 'FrozenDict' object does not support item assignment
|
| 780 |
+
|
| 781 |
+
>>> a.update(y=3)
|
| 782 |
+
Traceback (most recent call last):
|
| 783 |
+
...
|
| 784 |
+
AttributeError: 'FrozenDict' object has no attribute 'update'
|
| 785 |
+
|
| 786 |
+
Copies should compare equal
|
| 787 |
+
|
| 788 |
+
>>> copy.copy(a) == a
|
| 789 |
+
True
|
| 790 |
+
|
| 791 |
+
Copies should be the same type
|
| 792 |
+
|
| 793 |
+
>>> isinstance(copy.copy(a), FrozenDict)
|
| 794 |
+
True
|
| 795 |
+
|
| 796 |
+
FrozenDict supplies .copy(), even though
|
| 797 |
+
collections.abc.Mapping doesn't demand it.
|
| 798 |
+
|
| 799 |
+
>>> a.copy() == a
|
| 800 |
+
True
|
| 801 |
+
>>> a.copy() is not a
|
| 802 |
+
True
|
| 803 |
+
"""
|
| 804 |
+
|
| 805 |
+
__slots__ = ['__data']
|
| 806 |
+
|
| 807 |
+
def __new__(cls, *args, **kwargs):
|
| 808 |
+
self = super().__new__(cls)
|
| 809 |
+
self.__data = dict(*args, **kwargs)
|
| 810 |
+
return self
|
| 811 |
+
|
| 812 |
+
# Container
|
| 813 |
+
def __contains__(self, key):
|
| 814 |
+
return key in self.__data
|
| 815 |
+
|
| 816 |
+
# Hashable
|
| 817 |
+
def __hash__(self):
|
| 818 |
+
return hash(tuple(sorted(self.__data.items())))
|
| 819 |
+
|
| 820 |
+
# Mapping
|
| 821 |
+
def __iter__(self):
|
| 822 |
+
return iter(self.__data)
|
| 823 |
+
|
| 824 |
+
def __len__(self):
|
| 825 |
+
return len(self.__data)
|
| 826 |
+
|
| 827 |
+
def __getitem__(self, key):
|
| 828 |
+
return self.__data[key]
|
| 829 |
+
|
| 830 |
+
# override get for efficiency provided by dict
|
| 831 |
+
def get(self, *args, **kwargs):
|
| 832 |
+
return self.__data.get(*args, **kwargs)
|
| 833 |
+
|
| 834 |
+
# override eq to recognize underlying implementation
|
| 835 |
+
def __eq__(self, other):
|
| 836 |
+
if isinstance(other, FrozenDict):
|
| 837 |
+
other = other.__data
|
| 838 |
+
return self.__data.__eq__(other)
|
| 839 |
+
|
| 840 |
+
def copy(self):
|
| 841 |
+
"Return a shallow copy of self"
|
| 842 |
+
return copy.copy(self)
|
| 843 |
+
|
| 844 |
+
|
| 845 |
+
class Enumeration(ItemsAsAttributes, BijectiveMap):
|
| 846 |
+
"""
|
| 847 |
+
A convenient way to provide enumerated values
|
| 848 |
+
|
| 849 |
+
>>> e = Enumeration('a b c')
|
| 850 |
+
>>> e['a']
|
| 851 |
+
0
|
| 852 |
+
|
| 853 |
+
>>> e.a
|
| 854 |
+
0
|
| 855 |
+
|
| 856 |
+
>>> e[1]
|
| 857 |
+
'b'
|
| 858 |
+
|
| 859 |
+
>>> set(e.names) == set('abc')
|
| 860 |
+
True
|
| 861 |
+
|
| 862 |
+
>>> set(e.codes) == set(range(3))
|
| 863 |
+
True
|
| 864 |
+
|
| 865 |
+
>>> e.get('d') is None
|
| 866 |
+
True
|
| 867 |
+
|
| 868 |
+
Codes need not start with 0
|
| 869 |
+
|
| 870 |
+
>>> e = Enumeration('a b c', range(1, 4))
|
| 871 |
+
>>> e['a']
|
| 872 |
+
1
|
| 873 |
+
|
| 874 |
+
>>> e[3]
|
| 875 |
+
'c'
|
| 876 |
+
"""
|
| 877 |
+
|
| 878 |
+
def __init__(self, names, codes=None):
|
| 879 |
+
if isinstance(names, str):
|
| 880 |
+
names = names.split()
|
| 881 |
+
if codes is None:
|
| 882 |
+
codes = itertools.count()
|
| 883 |
+
super().__init__(zip(names, codes))
|
| 884 |
+
|
| 885 |
+
@property
|
| 886 |
+
def names(self):
|
| 887 |
+
return (key for key in self if isinstance(key, str))
|
| 888 |
+
|
| 889 |
+
@property
|
| 890 |
+
def codes(self):
|
| 891 |
+
return (self[name] for name in self.names)
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
class Everything:
|
| 895 |
+
"""
|
| 896 |
+
A collection "containing" every possible thing.
|
| 897 |
+
|
| 898 |
+
>>> 'foo' in Everything()
|
| 899 |
+
True
|
| 900 |
+
|
| 901 |
+
>>> import random
|
| 902 |
+
>>> random.randint(1, 999) in Everything()
|
| 903 |
+
True
|
| 904 |
+
|
| 905 |
+
>>> random.choice([None, 'foo', 42, ('a', 'b', 'c')]) in Everything()
|
| 906 |
+
True
|
| 907 |
+
"""
|
| 908 |
+
|
| 909 |
+
def __contains__(self, other):
|
| 910 |
+
return True
|
| 911 |
+
|
| 912 |
+
|
| 913 |
+
class InstrumentedDict(collections.UserDict):
|
| 914 |
+
"""
|
| 915 |
+
Instrument an existing dictionary with additional
|
| 916 |
+
functionality, but always reference and mutate
|
| 917 |
+
the original dictionary.
|
| 918 |
+
|
| 919 |
+
>>> orig = {'a': 1, 'b': 2}
|
| 920 |
+
>>> inst = InstrumentedDict(orig)
|
| 921 |
+
>>> inst['a']
|
| 922 |
+
1
|
| 923 |
+
>>> inst['c'] = 3
|
| 924 |
+
>>> orig['c']
|
| 925 |
+
3
|
| 926 |
+
>>> inst.keys() == orig.keys()
|
| 927 |
+
True
|
| 928 |
+
"""
|
| 929 |
+
|
| 930 |
+
def __init__(self, data):
|
| 931 |
+
super().__init__()
|
| 932 |
+
self.data = data
|
| 933 |
+
|
| 934 |
+
|
| 935 |
+
class Least:
|
| 936 |
+
"""
|
| 937 |
+
A value that is always lesser than any other
|
| 938 |
+
|
| 939 |
+
>>> least = Least()
|
| 940 |
+
>>> 3 < least
|
| 941 |
+
False
|
| 942 |
+
>>> 3 > least
|
| 943 |
+
True
|
| 944 |
+
>>> least < 3
|
| 945 |
+
True
|
| 946 |
+
>>> least <= 3
|
| 947 |
+
True
|
| 948 |
+
>>> least > 3
|
| 949 |
+
False
|
| 950 |
+
>>> 'x' > least
|
| 951 |
+
True
|
| 952 |
+
>>> None > least
|
| 953 |
+
True
|
| 954 |
+
"""
|
| 955 |
+
|
| 956 |
+
def __le__(self, other):
|
| 957 |
+
return True
|
| 958 |
+
|
| 959 |
+
__lt__ = __le__
|
| 960 |
+
|
| 961 |
+
def __ge__(self, other):
|
| 962 |
+
return False
|
| 963 |
+
|
| 964 |
+
__gt__ = __ge__
|
| 965 |
+
|
| 966 |
+
|
| 967 |
+
class Greatest:
|
| 968 |
+
"""
|
| 969 |
+
A value that is always greater than any other
|
| 970 |
+
|
| 971 |
+
>>> greatest = Greatest()
|
| 972 |
+
>>> 3 < greatest
|
| 973 |
+
True
|
| 974 |
+
>>> 3 > greatest
|
| 975 |
+
False
|
| 976 |
+
>>> greatest < 3
|
| 977 |
+
False
|
| 978 |
+
>>> greatest > 3
|
| 979 |
+
True
|
| 980 |
+
>>> greatest >= 3
|
| 981 |
+
True
|
| 982 |
+
>>> 'x' > greatest
|
| 983 |
+
False
|
| 984 |
+
>>> None > greatest
|
| 985 |
+
False
|
| 986 |
+
"""
|
| 987 |
+
|
| 988 |
+
def __ge__(self, other):
|
| 989 |
+
return True
|
| 990 |
+
|
| 991 |
+
__gt__ = __ge__
|
| 992 |
+
|
| 993 |
+
def __le__(self, other):
|
| 994 |
+
return False
|
| 995 |
+
|
| 996 |
+
__lt__ = __le__
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
def pop_all(items):
|
| 1000 |
+
"""
|
| 1001 |
+
Clear items in place and return a copy of items.
|
| 1002 |
+
|
| 1003 |
+
>>> items = [1, 2, 3]
|
| 1004 |
+
>>> popped = pop_all(items)
|
| 1005 |
+
>>> popped is items
|
| 1006 |
+
False
|
| 1007 |
+
>>> popped
|
| 1008 |
+
[1, 2, 3]
|
| 1009 |
+
>>> items
|
| 1010 |
+
[]
|
| 1011 |
+
"""
|
| 1012 |
+
result, items[:] = items[:], []
|
| 1013 |
+
return result
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
class FreezableDefaultDict(collections.defaultdict):
|
| 1017 |
+
"""
|
| 1018 |
+
Often it is desirable to prevent the mutation of
|
| 1019 |
+
a default dict after its initial construction, such
|
| 1020 |
+
as to prevent mutation during iteration.
|
| 1021 |
+
|
| 1022 |
+
>>> dd = FreezableDefaultDict(list)
|
| 1023 |
+
>>> dd[0].append('1')
|
| 1024 |
+
>>> dd.freeze()
|
| 1025 |
+
>>> dd[1]
|
| 1026 |
+
[]
|
| 1027 |
+
>>> len(dd)
|
| 1028 |
+
1
|
| 1029 |
+
"""
|
| 1030 |
+
|
| 1031 |
+
def __missing__(self, key):
|
| 1032 |
+
return getattr(self, '_frozen', super().__missing__)(key)
|
| 1033 |
+
|
| 1034 |
+
def freeze(self):
|
| 1035 |
+
self._frozen = lambda key: self.default_factory()
|
| 1036 |
+
|
| 1037 |
+
|
| 1038 |
+
class Accumulator:
|
| 1039 |
+
def __init__(self, initial=0):
|
| 1040 |
+
self.val = initial
|
| 1041 |
+
|
| 1042 |
+
def __call__(self, val):
|
| 1043 |
+
self.val += val
|
| 1044 |
+
return self.val
|
| 1045 |
+
|
| 1046 |
+
|
| 1047 |
+
class WeightedLookup(RangeMap):
|
| 1048 |
+
"""
|
| 1049 |
+
Given parameters suitable for a dict representing keys
|
| 1050 |
+
and a weighted proportion, return a RangeMap representing
|
| 1051 |
+
spans of values proportial to the weights:
|
| 1052 |
+
|
| 1053 |
+
>>> even = WeightedLookup(a=1, b=1)
|
| 1054 |
+
|
| 1055 |
+
[0, 1) -> a
|
| 1056 |
+
[1, 2) -> b
|
| 1057 |
+
|
| 1058 |
+
>>> lk = WeightedLookup(a=1, b=2)
|
| 1059 |
+
|
| 1060 |
+
[0, 1) -> a
|
| 1061 |
+
[1, 3) -> b
|
| 1062 |
+
|
| 1063 |
+
>>> lk[.5]
|
| 1064 |
+
'a'
|
| 1065 |
+
>>> lk[1.5]
|
| 1066 |
+
'b'
|
| 1067 |
+
|
| 1068 |
+
Adds ``.random()`` to select a random weighted value:
|
| 1069 |
+
|
| 1070 |
+
>>> lk.random() in ['a', 'b']
|
| 1071 |
+
True
|
| 1072 |
+
|
| 1073 |
+
>>> choices = [lk.random() for x in range(1000)]
|
| 1074 |
+
|
| 1075 |
+
Statistically speaking, choices should be .5 a:b
|
| 1076 |
+
>>> ratio = choices.count('a') / choices.count('b')
|
| 1077 |
+
>>> .4 < ratio < .6
|
| 1078 |
+
True
|
| 1079 |
+
"""
|
| 1080 |
+
|
| 1081 |
+
def __init__(self, *args, **kwargs):
|
| 1082 |
+
raw = dict(*args, **kwargs)
|
| 1083 |
+
|
| 1084 |
+
# allocate keys by weight
|
| 1085 |
+
indexes = map(Accumulator(), raw.values())
|
| 1086 |
+
super().__init__(zip(indexes, raw.keys()), key_match_comparator=operator.lt)
|
| 1087 |
+
|
| 1088 |
+
def random(self):
|
| 1089 |
+
lower, upper = self.bounds()
|
| 1090 |
+
selector = random.random() * upper
|
| 1091 |
+
return self[selector]
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (32.2 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/py.typed
ADDED
|
File without changes
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/context.py
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import functools
|
| 5 |
+
import operator
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import subprocess
|
| 9 |
+
import sys
|
| 10 |
+
import tempfile
|
| 11 |
+
import urllib.request
|
| 12 |
+
import warnings
|
| 13 |
+
from typing import Iterator
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
if sys.version_info < (3, 12):
|
| 17 |
+
from backports import tarfile
|
| 18 |
+
else:
|
| 19 |
+
import tarfile
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@contextlib.contextmanager
|
| 23 |
+
def pushd(dir: str | os.PathLike) -> Iterator[str | os.PathLike]:
|
| 24 |
+
"""
|
| 25 |
+
>>> tmp_path = getfixture('tmp_path')
|
| 26 |
+
>>> with pushd(tmp_path):
|
| 27 |
+
... assert os.getcwd() == os.fspath(tmp_path)
|
| 28 |
+
>>> assert os.getcwd() != os.fspath(tmp_path)
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
orig = os.getcwd()
|
| 32 |
+
os.chdir(dir)
|
| 33 |
+
try:
|
| 34 |
+
yield dir
|
| 35 |
+
finally:
|
| 36 |
+
os.chdir(orig)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@contextlib.contextmanager
|
| 40 |
+
def tarball(
|
| 41 |
+
url, target_dir: str | os.PathLike | None = None
|
| 42 |
+
) -> Iterator[str | os.PathLike]:
|
| 43 |
+
"""
|
| 44 |
+
Get a tarball, extract it, yield, then clean up.
|
| 45 |
+
|
| 46 |
+
>>> import urllib.request
|
| 47 |
+
>>> url = getfixture('tarfile_served')
|
| 48 |
+
>>> target = getfixture('tmp_path') / 'out'
|
| 49 |
+
>>> tb = tarball(url, target_dir=target)
|
| 50 |
+
>>> import pathlib
|
| 51 |
+
>>> with tb as extracted:
|
| 52 |
+
... contents = pathlib.Path(extracted, 'contents.txt').read_text(encoding='utf-8')
|
| 53 |
+
>>> assert not os.path.exists(extracted)
|
| 54 |
+
"""
|
| 55 |
+
if target_dir is None:
|
| 56 |
+
target_dir = os.path.basename(url).replace('.tar.gz', '').replace('.tgz', '')
|
| 57 |
+
# In the tar command, use --strip-components=1 to strip the first path and
|
| 58 |
+
# then
|
| 59 |
+
# use -C to cause the files to be extracted to {target_dir}. This ensures
|
| 60 |
+
# that we always know where the files were extracted.
|
| 61 |
+
os.mkdir(target_dir)
|
| 62 |
+
try:
|
| 63 |
+
req = urllib.request.urlopen(url)
|
| 64 |
+
with tarfile.open(fileobj=req, mode='r|*') as tf:
|
| 65 |
+
tf.extractall(path=target_dir, filter=strip_first_component)
|
| 66 |
+
yield target_dir
|
| 67 |
+
finally:
|
| 68 |
+
shutil.rmtree(target_dir)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def strip_first_component(
|
| 72 |
+
member: tarfile.TarInfo,
|
| 73 |
+
path,
|
| 74 |
+
) -> tarfile.TarInfo:
|
| 75 |
+
_, member.name = member.name.split('/', 1)
|
| 76 |
+
return member
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _compose(*cmgrs):
|
| 80 |
+
"""
|
| 81 |
+
Compose any number of dependent context managers into a single one.
|
| 82 |
+
|
| 83 |
+
The last, innermost context manager may take arbitrary arguments, but
|
| 84 |
+
each successive context manager should accept the result from the
|
| 85 |
+
previous as a single parameter.
|
| 86 |
+
|
| 87 |
+
Like :func:`jaraco.functools.compose`, behavior works from right to
|
| 88 |
+
left, so the context manager should be indicated from outermost to
|
| 89 |
+
innermost.
|
| 90 |
+
|
| 91 |
+
Example, to create a context manager to change to a temporary
|
| 92 |
+
directory:
|
| 93 |
+
|
| 94 |
+
>>> temp_dir_as_cwd = _compose(pushd, temp_dir)
|
| 95 |
+
>>> with temp_dir_as_cwd() as dir:
|
| 96 |
+
... assert os.path.samefile(os.getcwd(), dir)
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
def compose_two(inner, outer):
|
| 100 |
+
def composed(*args, **kwargs):
|
| 101 |
+
with inner(*args, **kwargs) as saved, outer(saved) as res:
|
| 102 |
+
yield res
|
| 103 |
+
|
| 104 |
+
return contextlib.contextmanager(composed)
|
| 105 |
+
|
| 106 |
+
return functools.reduce(compose_two, reversed(cmgrs))
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
tarball_cwd = _compose(pushd, tarball)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
@contextlib.contextmanager
|
| 113 |
+
def tarball_context(*args, **kwargs):
|
| 114 |
+
warnings.warn(
|
| 115 |
+
"tarball_context is deprecated. Use tarball or tarball_cwd instead.",
|
| 116 |
+
DeprecationWarning,
|
| 117 |
+
stacklevel=2,
|
| 118 |
+
)
|
| 119 |
+
pushd_ctx = kwargs.pop('pushd', pushd)
|
| 120 |
+
with tarball(*args, **kwargs) as tball, pushd_ctx(tball) as dir:
|
| 121 |
+
yield dir
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def infer_compression(url):
|
| 125 |
+
"""
|
| 126 |
+
Given a URL or filename, infer the compression code for tar.
|
| 127 |
+
|
| 128 |
+
>>> infer_compression('http://foo/bar.tar.gz')
|
| 129 |
+
'z'
|
| 130 |
+
>>> infer_compression('http://foo/bar.tgz')
|
| 131 |
+
'z'
|
| 132 |
+
>>> infer_compression('file.bz')
|
| 133 |
+
'j'
|
| 134 |
+
>>> infer_compression('file.xz')
|
| 135 |
+
'J'
|
| 136 |
+
"""
|
| 137 |
+
warnings.warn(
|
| 138 |
+
"infer_compression is deprecated with no replacement",
|
| 139 |
+
DeprecationWarning,
|
| 140 |
+
stacklevel=2,
|
| 141 |
+
)
|
| 142 |
+
# cheat and just assume it's the last two characters
|
| 143 |
+
compression_indicator = url[-2:]
|
| 144 |
+
mapping = dict(gz='z', bz='j', xz='J')
|
| 145 |
+
# Assume 'z' (gzip) if no match
|
| 146 |
+
return mapping.get(compression_indicator, 'z')
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@contextlib.contextmanager
|
| 150 |
+
def temp_dir(remover=shutil.rmtree):
|
| 151 |
+
"""
|
| 152 |
+
Create a temporary directory context. Pass a custom remover
|
| 153 |
+
to override the removal behavior.
|
| 154 |
+
|
| 155 |
+
>>> import pathlib
|
| 156 |
+
>>> with temp_dir() as the_dir:
|
| 157 |
+
... assert os.path.isdir(the_dir)
|
| 158 |
+
... _ = pathlib.Path(the_dir).joinpath('somefile').write_text('contents', encoding='utf-8')
|
| 159 |
+
>>> assert not os.path.exists(the_dir)
|
| 160 |
+
"""
|
| 161 |
+
temp_dir = tempfile.mkdtemp()
|
| 162 |
+
try:
|
| 163 |
+
yield temp_dir
|
| 164 |
+
finally:
|
| 165 |
+
remover(temp_dir)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
@contextlib.contextmanager
|
| 169 |
+
def repo_context(url, branch=None, quiet=True, dest_ctx=temp_dir):
|
| 170 |
+
"""
|
| 171 |
+
Check out the repo indicated by url.
|
| 172 |
+
|
| 173 |
+
If dest_ctx is supplied, it should be a context manager
|
| 174 |
+
to yield the target directory for the check out.
|
| 175 |
+
"""
|
| 176 |
+
exe = 'git' if 'git' in url else 'hg'
|
| 177 |
+
with dest_ctx() as repo_dir:
|
| 178 |
+
cmd = [exe, 'clone', url, repo_dir]
|
| 179 |
+
if branch:
|
| 180 |
+
cmd.extend(['--branch', branch])
|
| 181 |
+
devnull = open(os.path.devnull, 'w')
|
| 182 |
+
stdout = devnull if quiet else None
|
| 183 |
+
subprocess.check_call(cmd, stdout=stdout)
|
| 184 |
+
yield repo_dir
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def null():
|
| 188 |
+
"""
|
| 189 |
+
A null context suitable to stand in for a meaningful context.
|
| 190 |
+
|
| 191 |
+
>>> with null() as value:
|
| 192 |
+
... assert value is None
|
| 193 |
+
|
| 194 |
+
This context is most useful when dealing with two or more code
|
| 195 |
+
branches but only some need a context. Wrap the others in a null
|
| 196 |
+
context to provide symmetry across all options.
|
| 197 |
+
"""
|
| 198 |
+
warnings.warn(
|
| 199 |
+
"null is deprecated. Use contextlib.nullcontext",
|
| 200 |
+
DeprecationWarning,
|
| 201 |
+
stacklevel=2,
|
| 202 |
+
)
|
| 203 |
+
return contextlib.nullcontext()
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
class ExceptionTrap:
|
| 207 |
+
"""
|
| 208 |
+
A context manager that will catch certain exceptions and provide an
|
| 209 |
+
indication they occurred.
|
| 210 |
+
|
| 211 |
+
>>> with ExceptionTrap() as trap:
|
| 212 |
+
... raise Exception()
|
| 213 |
+
>>> bool(trap)
|
| 214 |
+
True
|
| 215 |
+
|
| 216 |
+
>>> with ExceptionTrap() as trap:
|
| 217 |
+
... pass
|
| 218 |
+
>>> bool(trap)
|
| 219 |
+
False
|
| 220 |
+
|
| 221 |
+
>>> with ExceptionTrap(ValueError) as trap:
|
| 222 |
+
... raise ValueError("1 + 1 is not 3")
|
| 223 |
+
>>> bool(trap)
|
| 224 |
+
True
|
| 225 |
+
>>> trap.value
|
| 226 |
+
ValueError('1 + 1 is not 3')
|
| 227 |
+
>>> trap.tb
|
| 228 |
+
<traceback object at ...>
|
| 229 |
+
|
| 230 |
+
>>> with ExceptionTrap(ValueError) as trap:
|
| 231 |
+
... raise Exception()
|
| 232 |
+
Traceback (most recent call last):
|
| 233 |
+
...
|
| 234 |
+
Exception
|
| 235 |
+
|
| 236 |
+
>>> bool(trap)
|
| 237 |
+
False
|
| 238 |
+
"""
|
| 239 |
+
|
| 240 |
+
exc_info = None, None, None
|
| 241 |
+
|
| 242 |
+
def __init__(self, exceptions=(Exception,)):
|
| 243 |
+
self.exceptions = exceptions
|
| 244 |
+
|
| 245 |
+
def __enter__(self):
|
| 246 |
+
return self
|
| 247 |
+
|
| 248 |
+
@property
|
| 249 |
+
def type(self):
|
| 250 |
+
return self.exc_info[0]
|
| 251 |
+
|
| 252 |
+
@property
|
| 253 |
+
def value(self):
|
| 254 |
+
return self.exc_info[1]
|
| 255 |
+
|
| 256 |
+
@property
|
| 257 |
+
def tb(self):
|
| 258 |
+
return self.exc_info[2]
|
| 259 |
+
|
| 260 |
+
def __exit__(self, *exc_info):
|
| 261 |
+
type = exc_info[0]
|
| 262 |
+
matches = type and issubclass(type, self.exceptions)
|
| 263 |
+
if matches:
|
| 264 |
+
self.exc_info = exc_info
|
| 265 |
+
return matches
|
| 266 |
+
|
| 267 |
+
def __bool__(self):
|
| 268 |
+
return bool(self.type)
|
| 269 |
+
|
| 270 |
+
def raises(self, func, *, _test=bool):
|
| 271 |
+
"""
|
| 272 |
+
Wrap func and replace the result with the truth
|
| 273 |
+
value of the trap (True if an exception occurred).
|
| 274 |
+
|
| 275 |
+
First, give the decorator an alias to support Python 3.8
|
| 276 |
+
Syntax.
|
| 277 |
+
|
| 278 |
+
>>> raises = ExceptionTrap(ValueError).raises
|
| 279 |
+
|
| 280 |
+
Now decorate a function that always fails.
|
| 281 |
+
|
| 282 |
+
>>> @raises
|
| 283 |
+
... def fail():
|
| 284 |
+
... raise ValueError('failed')
|
| 285 |
+
>>> fail()
|
| 286 |
+
True
|
| 287 |
+
"""
|
| 288 |
+
|
| 289 |
+
@functools.wraps(func)
|
| 290 |
+
def wrapper(*args, **kwargs):
|
| 291 |
+
with ExceptionTrap(self.exceptions) as trap:
|
| 292 |
+
func(*args, **kwargs)
|
| 293 |
+
return _test(trap)
|
| 294 |
+
|
| 295 |
+
return wrapper
|
| 296 |
+
|
| 297 |
+
def passes(self, func):
|
| 298 |
+
"""
|
| 299 |
+
Wrap func and replace the result with the truth
|
| 300 |
+
value of the trap (True if no exception).
|
| 301 |
+
|
| 302 |
+
First, give the decorator an alias to support Python 3.8
|
| 303 |
+
Syntax.
|
| 304 |
+
|
| 305 |
+
>>> passes = ExceptionTrap(ValueError).passes
|
| 306 |
+
|
| 307 |
+
Now decorate a function that always fails.
|
| 308 |
+
|
| 309 |
+
>>> @passes
|
| 310 |
+
... def fail():
|
| 311 |
+
... raise ValueError('failed')
|
| 312 |
+
|
| 313 |
+
>>> fail()
|
| 314 |
+
False
|
| 315 |
+
"""
|
| 316 |
+
return self.raises(func, _test=operator.not_)
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class suppress(contextlib.suppress, contextlib.ContextDecorator):
|
| 320 |
+
"""
|
| 321 |
+
A version of contextlib.suppress with decorator support.
|
| 322 |
+
|
| 323 |
+
>>> @suppress(KeyError)
|
| 324 |
+
... def key_error():
|
| 325 |
+
... {}['']
|
| 326 |
+
>>> key_error()
|
| 327 |
+
"""
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
class on_interrupt(contextlib.ContextDecorator):
|
| 331 |
+
"""
|
| 332 |
+
Replace a KeyboardInterrupt with SystemExit(1)
|
| 333 |
+
|
| 334 |
+
>>> def do_interrupt():
|
| 335 |
+
... raise KeyboardInterrupt()
|
| 336 |
+
>>> on_interrupt('error')(do_interrupt)()
|
| 337 |
+
Traceback (most recent call last):
|
| 338 |
+
...
|
| 339 |
+
SystemExit: 1
|
| 340 |
+
>>> on_interrupt('error', code=255)(do_interrupt)()
|
| 341 |
+
Traceback (most recent call last):
|
| 342 |
+
...
|
| 343 |
+
SystemExit: 255
|
| 344 |
+
>>> on_interrupt('suppress')(do_interrupt)()
|
| 345 |
+
>>> with __import__('pytest').raises(KeyboardInterrupt):
|
| 346 |
+
... on_interrupt('ignore')(do_interrupt)()
|
| 347 |
+
"""
|
| 348 |
+
|
| 349 |
+
def __init__(self, action='error', /, code=1):
|
| 350 |
+
self.action = action
|
| 351 |
+
self.code = code
|
| 352 |
+
|
| 353 |
+
def __enter__(self):
|
| 354 |
+
return self
|
| 355 |
+
|
| 356 |
+
def __exit__(self, exctype, excinst, exctb):
|
| 357 |
+
if exctype is not KeyboardInterrupt or self.action == 'ignore':
|
| 358 |
+
return
|
| 359 |
+
elif self.action == 'error':
|
| 360 |
+
raise SystemExit(self.code) from excinst
|
| 361 |
+
return self.action == 'suppress'
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jara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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections.abc
|
| 2 |
+
import functools
|
| 3 |
+
import inspect
|
| 4 |
+
import itertools
|
| 5 |
+
import operator
|
| 6 |
+
import time
|
| 7 |
+
import types
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
import more_itertools
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def compose(*funcs):
|
| 14 |
+
"""
|
| 15 |
+
Compose any number of unary functions into a single unary function.
|
| 16 |
+
|
| 17 |
+
>>> import textwrap
|
| 18 |
+
>>> expected = str.strip(textwrap.dedent(compose.__doc__))
|
| 19 |
+
>>> strip_and_dedent = compose(str.strip, textwrap.dedent)
|
| 20 |
+
>>> strip_and_dedent(compose.__doc__) == expected
|
| 21 |
+
True
|
| 22 |
+
|
| 23 |
+
Compose also allows the innermost function to take arbitrary arguments.
|
| 24 |
+
|
| 25 |
+
>>> round_three = lambda x: round(x, ndigits=3)
|
| 26 |
+
>>> f = compose(round_three, int.__truediv__)
|
| 27 |
+
>>> [f(3*x, x+1) for x in range(1,10)]
|
| 28 |
+
[1.5, 2.0, 2.25, 2.4, 2.5, 2.571, 2.625, 2.667, 2.7]
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def compose_two(f1, f2):
|
| 32 |
+
return lambda *args, **kwargs: f1(f2(*args, **kwargs))
|
| 33 |
+
|
| 34 |
+
return functools.reduce(compose_two, funcs)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def once(func):
|
| 38 |
+
"""
|
| 39 |
+
Decorate func so it's only ever called the first time.
|
| 40 |
+
|
| 41 |
+
This decorator can ensure that an expensive or non-idempotent function
|
| 42 |
+
will not be expensive on subsequent calls and is idempotent.
|
| 43 |
+
|
| 44 |
+
>>> add_three = once(lambda a: a+3)
|
| 45 |
+
>>> add_three(3)
|
| 46 |
+
6
|
| 47 |
+
>>> add_three(9)
|
| 48 |
+
6
|
| 49 |
+
>>> add_three('12')
|
| 50 |
+
6
|
| 51 |
+
|
| 52 |
+
To reset the stored value, simply clear the property ``saved_result``.
|
| 53 |
+
|
| 54 |
+
>>> del add_three.saved_result
|
| 55 |
+
>>> add_three(9)
|
| 56 |
+
12
|
| 57 |
+
>>> add_three(8)
|
| 58 |
+
12
|
| 59 |
+
|
| 60 |
+
Or invoke 'reset()' on it.
|
| 61 |
+
|
| 62 |
+
>>> add_three.reset()
|
| 63 |
+
>>> add_three(-3)
|
| 64 |
+
0
|
| 65 |
+
>>> add_three(0)
|
| 66 |
+
0
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
@functools.wraps(func)
|
| 70 |
+
def wrapper(*args, **kwargs):
|
| 71 |
+
if not hasattr(wrapper, 'saved_result'):
|
| 72 |
+
wrapper.saved_result = func(*args, **kwargs)
|
| 73 |
+
return wrapper.saved_result
|
| 74 |
+
|
| 75 |
+
wrapper.reset = lambda: vars(wrapper).__delitem__('saved_result')
|
| 76 |
+
return wrapper
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def method_cache(method, cache_wrapper=functools.lru_cache()):
|
| 80 |
+
"""
|
| 81 |
+
Wrap lru_cache to support storing the cache data in the object instances.
|
| 82 |
+
|
| 83 |
+
Abstracts the common paradigm where the method explicitly saves an
|
| 84 |
+
underscore-prefixed protected property on first call and returns that
|
| 85 |
+
subsequently.
|
| 86 |
+
|
| 87 |
+
>>> class MyClass:
|
| 88 |
+
... calls = 0
|
| 89 |
+
...
|
| 90 |
+
... @method_cache
|
| 91 |
+
... def method(self, value):
|
| 92 |
+
... self.calls += 1
|
| 93 |
+
... return value
|
| 94 |
+
|
| 95 |
+
>>> a = MyClass()
|
| 96 |
+
>>> a.method(3)
|
| 97 |
+
3
|
| 98 |
+
>>> for x in range(75):
|
| 99 |
+
... res = a.method(x)
|
| 100 |
+
>>> a.calls
|
| 101 |
+
75
|
| 102 |
+
|
| 103 |
+
Note that the apparent behavior will be exactly like that of lru_cache
|
| 104 |
+
except that the cache is stored on each instance, so values in one
|
| 105 |
+
instance will not flush values from another, and when an instance is
|
| 106 |
+
deleted, so are the cached values for that instance.
|
| 107 |
+
|
| 108 |
+
>>> b = MyClass()
|
| 109 |
+
>>> for x in range(35):
|
| 110 |
+
... res = b.method(x)
|
| 111 |
+
>>> b.calls
|
| 112 |
+
35
|
| 113 |
+
>>> a.method(0)
|
| 114 |
+
0
|
| 115 |
+
>>> a.calls
|
| 116 |
+
75
|
| 117 |
+
|
| 118 |
+
Note that if method had been decorated with ``functools.lru_cache()``,
|
| 119 |
+
a.calls would have been 76 (due to the cached value of 0 having been
|
| 120 |
+
flushed by the 'b' instance).
|
| 121 |
+
|
| 122 |
+
Clear the cache with ``.cache_clear()``
|
| 123 |
+
|
| 124 |
+
>>> a.method.cache_clear()
|
| 125 |
+
|
| 126 |
+
Same for a method that hasn't yet been called.
|
| 127 |
+
|
| 128 |
+
>>> c = MyClass()
|
| 129 |
+
>>> c.method.cache_clear()
|
| 130 |
+
|
| 131 |
+
Another cache wrapper may be supplied:
|
| 132 |
+
|
| 133 |
+
>>> cache = functools.lru_cache(maxsize=2)
|
| 134 |
+
>>> MyClass.method2 = method_cache(lambda self: 3, cache_wrapper=cache)
|
| 135 |
+
>>> a = MyClass()
|
| 136 |
+
>>> a.method2()
|
| 137 |
+
3
|
| 138 |
+
|
| 139 |
+
Caution - do not subsequently wrap the method with another decorator, such
|
| 140 |
+
as ``@property``, which changes the semantics of the function.
|
| 141 |
+
|
| 142 |
+
See also
|
| 143 |
+
http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/
|
| 144 |
+
for another implementation and additional justification.
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
def wrapper(self, *args, **kwargs):
|
| 148 |
+
# it's the first call, replace the method with a cached, bound method
|
| 149 |
+
bound_method = types.MethodType(method, self)
|
| 150 |
+
cached_method = cache_wrapper(bound_method)
|
| 151 |
+
setattr(self, method.__name__, cached_method)
|
| 152 |
+
return cached_method(*args, **kwargs)
|
| 153 |
+
|
| 154 |
+
# Support cache clear even before cache has been created.
|
| 155 |
+
wrapper.cache_clear = lambda: None
|
| 156 |
+
|
| 157 |
+
return _special_method_cache(method, cache_wrapper) or wrapper
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _special_method_cache(method, cache_wrapper):
|
| 161 |
+
"""
|
| 162 |
+
Because Python treats special methods differently, it's not
|
| 163 |
+
possible to use instance attributes to implement the cached
|
| 164 |
+
methods.
|
| 165 |
+
|
| 166 |
+
Instead, install the wrapper method under a different name
|
| 167 |
+
and return a simple proxy to that wrapper.
|
| 168 |
+
|
| 169 |
+
https://github.com/jaraco/jaraco.functools/issues/5
|
| 170 |
+
"""
|
| 171 |
+
name = method.__name__
|
| 172 |
+
special_names = '__getattr__', '__getitem__'
|
| 173 |
+
|
| 174 |
+
if name not in special_names:
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
wrapper_name = '__cached' + name
|
| 178 |
+
|
| 179 |
+
def proxy(self, /, *args, **kwargs):
|
| 180 |
+
if wrapper_name not in vars(self):
|
| 181 |
+
bound = types.MethodType(method, self)
|
| 182 |
+
cache = cache_wrapper(bound)
|
| 183 |
+
setattr(self, wrapper_name, cache)
|
| 184 |
+
else:
|
| 185 |
+
cache = getattr(self, wrapper_name)
|
| 186 |
+
return cache(*args, **kwargs)
|
| 187 |
+
|
| 188 |
+
return proxy
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def apply(transform):
|
| 192 |
+
"""
|
| 193 |
+
Decorate a function with a transform function that is
|
| 194 |
+
invoked on results returned from the decorated function.
|
| 195 |
+
|
| 196 |
+
>>> @apply(reversed)
|
| 197 |
+
... def get_numbers(start):
|
| 198 |
+
... "doc for get_numbers"
|
| 199 |
+
... return range(start, start+3)
|
| 200 |
+
>>> list(get_numbers(4))
|
| 201 |
+
[6, 5, 4]
|
| 202 |
+
>>> get_numbers.__doc__
|
| 203 |
+
'doc for get_numbers'
|
| 204 |
+
"""
|
| 205 |
+
|
| 206 |
+
def wrap(func):
|
| 207 |
+
return functools.wraps(func)(compose(transform, func))
|
| 208 |
+
|
| 209 |
+
return wrap
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def result_invoke(action):
|
| 213 |
+
r"""
|
| 214 |
+
Decorate a function with an action function that is
|
| 215 |
+
invoked on the results returned from the decorated
|
| 216 |
+
function (for its side effect), then return the original
|
| 217 |
+
result.
|
| 218 |
+
|
| 219 |
+
>>> @result_invoke(print)
|
| 220 |
+
... def add_two(a, b):
|
| 221 |
+
... return a + b
|
| 222 |
+
>>> x = add_two(2, 3)
|
| 223 |
+
5
|
| 224 |
+
>>> x
|
| 225 |
+
5
|
| 226 |
+
"""
|
| 227 |
+
|
| 228 |
+
def wrap(func):
|
| 229 |
+
@functools.wraps(func)
|
| 230 |
+
def wrapper(*args, **kwargs):
|
| 231 |
+
result = func(*args, **kwargs)
|
| 232 |
+
action(result)
|
| 233 |
+
return result
|
| 234 |
+
|
| 235 |
+
return wrapper
|
| 236 |
+
|
| 237 |
+
return wrap
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def invoke(f, /, *args, **kwargs):
|
| 241 |
+
"""
|
| 242 |
+
Call a function for its side effect after initialization.
|
| 243 |
+
|
| 244 |
+
The benefit of using the decorator instead of simply invoking a function
|
| 245 |
+
after defining it is that it makes explicit the author's intent for the
|
| 246 |
+
function to be called immediately. Whereas if one simply calls the
|
| 247 |
+
function immediately, it's less obvious if that was intentional or
|
| 248 |
+
incidental. It also avoids repeating the name - the two actions, defining
|
| 249 |
+
the function and calling it immediately are modeled separately, but linked
|
| 250 |
+
by the decorator construct.
|
| 251 |
+
|
| 252 |
+
The benefit of having a function construct (opposed to just invoking some
|
| 253 |
+
behavior inline) is to serve as a scope in which the behavior occurs. It
|
| 254 |
+
avoids polluting the global namespace with local variables, provides an
|
| 255 |
+
anchor on which to attach documentation (docstring), keeps the behavior
|
| 256 |
+
logically separated (instead of conceptually separated or not separated at
|
| 257 |
+
all), and provides potential to re-use the behavior for testing or other
|
| 258 |
+
purposes.
|
| 259 |
+
|
| 260 |
+
This function is named as a pithy way to communicate, "call this function
|
| 261 |
+
primarily for its side effect", or "while defining this function, also
|
| 262 |
+
take it aside and call it". It exists because there's no Python construct
|
| 263 |
+
for "define and call" (nor should there be, as decorators serve this need
|
| 264 |
+
just fine). The behavior happens immediately and synchronously.
|
| 265 |
+
|
| 266 |
+
>>> @invoke
|
| 267 |
+
... def func(): print("called")
|
| 268 |
+
called
|
| 269 |
+
>>> func()
|
| 270 |
+
called
|
| 271 |
+
|
| 272 |
+
Use functools.partial to pass parameters to the initial call
|
| 273 |
+
|
| 274 |
+
>>> @functools.partial(invoke, name='bingo')
|
| 275 |
+
... def func(name): print('called with', name)
|
| 276 |
+
called with bingo
|
| 277 |
+
"""
|
| 278 |
+
f(*args, **kwargs)
|
| 279 |
+
return f
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class Throttler:
|
| 283 |
+
"""Rate-limit a function (or other callable)."""
|
| 284 |
+
|
| 285 |
+
def __init__(self, func, max_rate=float('Inf')):
|
| 286 |
+
if isinstance(func, Throttler):
|
| 287 |
+
func = func.func
|
| 288 |
+
self.func = func
|
| 289 |
+
self.max_rate = max_rate
|
| 290 |
+
self.reset()
|
| 291 |
+
|
| 292 |
+
def reset(self):
|
| 293 |
+
self.last_called = 0
|
| 294 |
+
|
| 295 |
+
def __call__(self, *args, **kwargs):
|
| 296 |
+
self._wait()
|
| 297 |
+
return self.func(*args, **kwargs)
|
| 298 |
+
|
| 299 |
+
def _wait(self):
|
| 300 |
+
"""Ensure at least 1/max_rate seconds from last call."""
|
| 301 |
+
elapsed = time.time() - self.last_called
|
| 302 |
+
must_wait = 1 / self.max_rate - elapsed
|
| 303 |
+
time.sleep(max(0, must_wait))
|
| 304 |
+
self.last_called = time.time()
|
| 305 |
+
|
| 306 |
+
def __get__(self, obj, owner=None):
|
| 307 |
+
return first_invoke(self._wait, functools.partial(self.func, obj))
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def first_invoke(func1, func2):
|
| 311 |
+
"""
|
| 312 |
+
Return a function that when invoked will invoke func1 without
|
| 313 |
+
any parameters (for its side effect) and then invoke func2
|
| 314 |
+
with whatever parameters were passed, returning its result.
|
| 315 |
+
"""
|
| 316 |
+
|
| 317 |
+
def wrapper(*args, **kwargs):
|
| 318 |
+
func1()
|
| 319 |
+
return func2(*args, **kwargs)
|
| 320 |
+
|
| 321 |
+
return wrapper
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
method_caller = first_invoke(
|
| 325 |
+
lambda: warnings.warn(
|
| 326 |
+
'`jaraco.functools.method_caller` is deprecated, '
|
| 327 |
+
'use `operator.methodcaller` instead',
|
| 328 |
+
DeprecationWarning,
|
| 329 |
+
stacklevel=3,
|
| 330 |
+
),
|
| 331 |
+
operator.methodcaller,
|
| 332 |
+
)
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
def retry_call(func, cleanup=lambda: None, retries=0, trap=()):
|
| 336 |
+
"""
|
| 337 |
+
Given a callable func, trap the indicated exceptions
|
| 338 |
+
for up to 'retries' times, invoking cleanup on the
|
| 339 |
+
exception. On the final attempt, allow any exceptions
|
| 340 |
+
to propagate.
|
| 341 |
+
"""
|
| 342 |
+
attempts = itertools.count() if retries == float('inf') else range(retries)
|
| 343 |
+
for _ in attempts:
|
| 344 |
+
try:
|
| 345 |
+
return func()
|
| 346 |
+
except trap:
|
| 347 |
+
cleanup()
|
| 348 |
+
|
| 349 |
+
return func()
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def retry(*r_args, **r_kwargs):
|
| 353 |
+
"""
|
| 354 |
+
Decorator wrapper for retry_call. Accepts arguments to retry_call
|
| 355 |
+
except func and then returns a decorator for the decorated function.
|
| 356 |
+
|
| 357 |
+
Ex:
|
| 358 |
+
|
| 359 |
+
>>> @retry(retries=3)
|
| 360 |
+
... def my_func(a, b):
|
| 361 |
+
... "this is my funk"
|
| 362 |
+
... print(a, b)
|
| 363 |
+
>>> my_func.__doc__
|
| 364 |
+
'this is my funk'
|
| 365 |
+
"""
|
| 366 |
+
|
| 367 |
+
def decorate(func):
|
| 368 |
+
@functools.wraps(func)
|
| 369 |
+
def wrapper(*f_args, **f_kwargs):
|
| 370 |
+
bound = functools.partial(func, *f_args, **f_kwargs)
|
| 371 |
+
return retry_call(bound, *r_args, **r_kwargs)
|
| 372 |
+
|
| 373 |
+
return wrapper
|
| 374 |
+
|
| 375 |
+
return decorate
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def print_yielded(func):
|
| 379 |
+
"""
|
| 380 |
+
Convert a generator into a function that prints all yielded elements.
|
| 381 |
+
|
| 382 |
+
>>> @print_yielded
|
| 383 |
+
... def x():
|
| 384 |
+
... yield 3; yield None
|
| 385 |
+
>>> x()
|
| 386 |
+
3
|
| 387 |
+
None
|
| 388 |
+
"""
|
| 389 |
+
print_all = functools.partial(map, print)
|
| 390 |
+
print_results = compose(more_itertools.consume, print_all, func)
|
| 391 |
+
return functools.wraps(func)(print_results)
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
def pass_none(func):
|
| 395 |
+
"""
|
| 396 |
+
Wrap func so it's not called if its first param is None.
|
| 397 |
+
|
| 398 |
+
>>> print_text = pass_none(print)
|
| 399 |
+
>>> print_text('text')
|
| 400 |
+
text
|
| 401 |
+
>>> print_text(None)
|
| 402 |
+
"""
|
| 403 |
+
|
| 404 |
+
@functools.wraps(func)
|
| 405 |
+
def wrapper(param, /, *args, **kwargs):
|
| 406 |
+
if param is not None:
|
| 407 |
+
return func(param, *args, **kwargs)
|
| 408 |
+
return None
|
| 409 |
+
|
| 410 |
+
return wrapper
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def assign_params(func, namespace):
|
| 414 |
+
"""
|
| 415 |
+
Assign parameters from namespace where func solicits.
|
| 416 |
+
|
| 417 |
+
>>> def func(x, y=3):
|
| 418 |
+
... print(x, y)
|
| 419 |
+
>>> assigned = assign_params(func, dict(x=2, z=4))
|
| 420 |
+
>>> assigned()
|
| 421 |
+
2 3
|
| 422 |
+
|
| 423 |
+
The usual errors are raised if a function doesn't receive
|
| 424 |
+
its required parameters:
|
| 425 |
+
|
| 426 |
+
>>> assigned = assign_params(func, dict(y=3, z=4))
|
| 427 |
+
>>> assigned()
|
| 428 |
+
Traceback (most recent call last):
|
| 429 |
+
TypeError: func() ...argument...
|
| 430 |
+
|
| 431 |
+
It even works on methods:
|
| 432 |
+
|
| 433 |
+
>>> class Handler:
|
| 434 |
+
... def meth(self, arg):
|
| 435 |
+
... print(arg)
|
| 436 |
+
>>> assign_params(Handler().meth, dict(arg='crystal', foo='clear'))()
|
| 437 |
+
crystal
|
| 438 |
+
"""
|
| 439 |
+
sig = inspect.signature(func)
|
| 440 |
+
params = sig.parameters.keys()
|
| 441 |
+
call_ns = {k: namespace[k] for k in params if k in namespace}
|
| 442 |
+
return functools.partial(func, **call_ns)
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
def save_method_args(method):
|
| 446 |
+
"""
|
| 447 |
+
Wrap a method such that when it is called, the args and kwargs are
|
| 448 |
+
saved on the method.
|
| 449 |
+
|
| 450 |
+
>>> class MyClass:
|
| 451 |
+
... @save_method_args
|
| 452 |
+
... def method(self, a, b):
|
| 453 |
+
... print(a, b)
|
| 454 |
+
>>> my_ob = MyClass()
|
| 455 |
+
>>> my_ob.method(1, 2)
|
| 456 |
+
1 2
|
| 457 |
+
>>> my_ob._saved_method.args
|
| 458 |
+
(1, 2)
|
| 459 |
+
>>> my_ob._saved_method.kwargs
|
| 460 |
+
{}
|
| 461 |
+
>>> my_ob.method(a=3, b='foo')
|
| 462 |
+
3 foo
|
| 463 |
+
>>> my_ob._saved_method.args
|
| 464 |
+
()
|
| 465 |
+
>>> my_ob._saved_method.kwargs == dict(a=3, b='foo')
|
| 466 |
+
True
|
| 467 |
+
|
| 468 |
+
The arguments are stored on the instance, allowing for
|
| 469 |
+
different instance to save different args.
|
| 470 |
+
|
| 471 |
+
>>> your_ob = MyClass()
|
| 472 |
+
>>> your_ob.method({str('x'): 3}, b=[4])
|
| 473 |
+
{'x': 3} [4]
|
| 474 |
+
>>> your_ob._saved_method.args
|
| 475 |
+
({'x': 3},)
|
| 476 |
+
>>> my_ob._saved_method.args
|
| 477 |
+
()
|
| 478 |
+
"""
|
| 479 |
+
args_and_kwargs = collections.namedtuple('args_and_kwargs', 'args kwargs')
|
| 480 |
+
|
| 481 |
+
@functools.wraps(method)
|
| 482 |
+
def wrapper(self, /, *args, **kwargs):
|
| 483 |
+
attr_name = '_saved_' + method.__name__
|
| 484 |
+
attr = args_and_kwargs(args, kwargs)
|
| 485 |
+
setattr(self, attr_name, attr)
|
| 486 |
+
return method(self, *args, **kwargs)
|
| 487 |
+
|
| 488 |
+
return wrapper
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def except_(*exceptions, replace=None, use=None):
|
| 492 |
+
"""
|
| 493 |
+
Replace the indicated exceptions, if raised, with the indicated
|
| 494 |
+
literal replacement or evaluated expression (if present).
|
| 495 |
+
|
| 496 |
+
>>> safe_int = except_(ValueError)(int)
|
| 497 |
+
>>> safe_int('five')
|
| 498 |
+
>>> safe_int('5')
|
| 499 |
+
5
|
| 500 |
+
|
| 501 |
+
Specify a literal replacement with ``replace``.
|
| 502 |
+
|
| 503 |
+
>>> safe_int_r = except_(ValueError, replace=0)(int)
|
| 504 |
+
>>> safe_int_r('five')
|
| 505 |
+
0
|
| 506 |
+
|
| 507 |
+
Provide an expression to ``use`` to pass through particular parameters.
|
| 508 |
+
|
| 509 |
+
>>> safe_int_pt = except_(ValueError, use='args[0]')(int)
|
| 510 |
+
>>> safe_int_pt('five')
|
| 511 |
+
'five'
|
| 512 |
+
|
| 513 |
+
"""
|
| 514 |
+
|
| 515 |
+
def decorate(func):
|
| 516 |
+
@functools.wraps(func)
|
| 517 |
+
def wrapper(*args, **kwargs):
|
| 518 |
+
try:
|
| 519 |
+
return func(*args, **kwargs)
|
| 520 |
+
except exceptions:
|
| 521 |
+
try:
|
| 522 |
+
return eval(use)
|
| 523 |
+
except TypeError:
|
| 524 |
+
return replace
|
| 525 |
+
|
| 526 |
+
return wrapper
|
| 527 |
+
|
| 528 |
+
return decorate
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
def identity(x):
|
| 532 |
+
"""
|
| 533 |
+
Return the argument.
|
| 534 |
+
|
| 535 |
+
>>> o = object()
|
| 536 |
+
>>> identity(o) is o
|
| 537 |
+
True
|
| 538 |
+
"""
|
| 539 |
+
return x
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
def bypass_when(check, *, _op=identity):
|
| 543 |
+
"""
|
| 544 |
+
Decorate a function to return its parameter when ``check``.
|
| 545 |
+
|
| 546 |
+
>>> bypassed = [] # False
|
| 547 |
+
|
| 548 |
+
>>> @bypass_when(bypassed)
|
| 549 |
+
... def double(x):
|
| 550 |
+
... return x * 2
|
| 551 |
+
>>> double(2)
|
| 552 |
+
4
|
| 553 |
+
>>> bypassed[:] = [object()] # True
|
| 554 |
+
>>> double(2)
|
| 555 |
+
2
|
| 556 |
+
"""
|
| 557 |
+
|
| 558 |
+
def decorate(func):
|
| 559 |
+
@functools.wraps(func)
|
| 560 |
+
def wrapper(param, /):
|
| 561 |
+
return param if _op(check) else func(param)
|
| 562 |
+
|
| 563 |
+
return wrapper
|
| 564 |
+
|
| 565 |
+
return decorate
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def bypass_unless(check):
|
| 569 |
+
"""
|
| 570 |
+
Decorate a function to return its parameter unless ``check``.
|
| 571 |
+
|
| 572 |
+
>>> enabled = [object()] # True
|
| 573 |
+
|
| 574 |
+
>>> @bypass_unless(enabled)
|
| 575 |
+
... def double(x):
|
| 576 |
+
... return x * 2
|
| 577 |
+
>>> double(2)
|
| 578 |
+
4
|
| 579 |
+
>>> del enabled[:] # False
|
| 580 |
+
>>> double(2)
|
| 581 |
+
2
|
| 582 |
+
"""
|
| 583 |
+
return bypass_when(check, _op=operator.not_)
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
@functools.singledispatch
|
| 587 |
+
def _splat_inner(args, func):
|
| 588 |
+
"""Splat args to func."""
|
| 589 |
+
return func(*args)
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
@_splat_inner.register
|
| 593 |
+
def _(args: collections.abc.Mapping, func):
|
| 594 |
+
"""Splat kargs to func as kwargs."""
|
| 595 |
+
return func(**args)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def splat(func):
|
| 599 |
+
"""
|
| 600 |
+
Wrap func to expect its parameters to be passed positionally in a tuple.
|
| 601 |
+
|
| 602 |
+
Has a similar effect to that of ``itertools.starmap`` over
|
| 603 |
+
simple ``map``.
|
| 604 |
+
|
| 605 |
+
>>> pairs = [(-1, 1), (0, 2)]
|
| 606 |
+
>>> more_itertools.consume(itertools.starmap(print, pairs))
|
| 607 |
+
-1 1
|
| 608 |
+
0 2
|
| 609 |
+
>>> more_itertools.consume(map(splat(print), pairs))
|
| 610 |
+
-1 1
|
| 611 |
+
0 2
|
| 612 |
+
|
| 613 |
+
The approach generalizes to other iterators that don't have a "star"
|
| 614 |
+
equivalent, such as a "starfilter".
|
| 615 |
+
|
| 616 |
+
>>> list(filter(splat(operator.add), pairs))
|
| 617 |
+
[(0, 2)]
|
| 618 |
+
|
| 619 |
+
Splat also accepts a mapping argument.
|
| 620 |
+
|
| 621 |
+
>>> def is_nice(msg, code):
|
| 622 |
+
... return "smile" in msg or code == 0
|
| 623 |
+
>>> msgs = [
|
| 624 |
+
... dict(msg='smile!', code=20),
|
| 625 |
+
... dict(msg='error :(', code=1),
|
| 626 |
+
... dict(msg='unknown', code=0),
|
| 627 |
+
... ]
|
| 628 |
+
>>> for msg in filter(splat(is_nice), msgs):
|
| 629 |
+
... print(msg)
|
| 630 |
+
{'msg': 'smile!', 'code': 20}
|
| 631 |
+
{'msg': 'unknown', 'code': 0}
|
| 632 |
+
"""
|
| 633 |
+
return functools.wraps(func)(functools.partial(_splat_inner, func=func))
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/__init__.pyi
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable, Hashable, Iterator
|
| 2 |
+
from functools import partial
|
| 3 |
+
from operator import methodcaller
|
| 4 |
+
import sys
|
| 5 |
+
from typing import (
|
| 6 |
+
Any,
|
| 7 |
+
Generic,
|
| 8 |
+
Protocol,
|
| 9 |
+
TypeVar,
|
| 10 |
+
overload,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
if sys.version_info >= (3, 10):
|
| 14 |
+
from typing import Concatenate, ParamSpec
|
| 15 |
+
else:
|
| 16 |
+
from typing_extensions import Concatenate, ParamSpec
|
| 17 |
+
|
| 18 |
+
_P = ParamSpec('_P')
|
| 19 |
+
_R = TypeVar('_R')
|
| 20 |
+
_T = TypeVar('_T')
|
| 21 |
+
_R1 = TypeVar('_R1')
|
| 22 |
+
_R2 = TypeVar('_R2')
|
| 23 |
+
_V = TypeVar('_V')
|
| 24 |
+
_S = TypeVar('_S')
|
| 25 |
+
_R_co = TypeVar('_R_co', covariant=True)
|
| 26 |
+
|
| 27 |
+
class _OnceCallable(Protocol[_P, _R]):
|
| 28 |
+
saved_result: _R
|
| 29 |
+
reset: Callable[[], None]
|
| 30 |
+
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
|
| 31 |
+
|
| 32 |
+
class _ProxyMethodCacheWrapper(Protocol[_R_co]):
|
| 33 |
+
cache_clear: Callable[[], None]
|
| 34 |
+
def __call__(self, *args: Hashable, **kwargs: Hashable) -> _R_co: ...
|
| 35 |
+
|
| 36 |
+
class _MethodCacheWrapper(Protocol[_R_co]):
|
| 37 |
+
def cache_clear(self) -> None: ...
|
| 38 |
+
def __call__(self, *args: Hashable, **kwargs: Hashable) -> _R_co: ...
|
| 39 |
+
|
| 40 |
+
# `compose()` overloads below will cover most use cases.
|
| 41 |
+
|
| 42 |
+
@overload
|
| 43 |
+
def compose(
|
| 44 |
+
__func1: Callable[[_R], _T],
|
| 45 |
+
__func2: Callable[_P, _R],
|
| 46 |
+
/,
|
| 47 |
+
) -> Callable[_P, _T]: ...
|
| 48 |
+
@overload
|
| 49 |
+
def compose(
|
| 50 |
+
__func1: Callable[[_R], _T],
|
| 51 |
+
__func2: Callable[[_R1], _R],
|
| 52 |
+
__func3: Callable[_P, _R1],
|
| 53 |
+
/,
|
| 54 |
+
) -> Callable[_P, _T]: ...
|
| 55 |
+
@overload
|
| 56 |
+
def compose(
|
| 57 |
+
__func1: Callable[[_R], _T],
|
| 58 |
+
__func2: Callable[[_R2], _R],
|
| 59 |
+
__func3: Callable[[_R1], _R2],
|
| 60 |
+
__func4: Callable[_P, _R1],
|
| 61 |
+
/,
|
| 62 |
+
) -> Callable[_P, _T]: ...
|
| 63 |
+
def once(func: Callable[_P, _R]) -> _OnceCallable[_P, _R]: ...
|
| 64 |
+
def method_cache(
|
| 65 |
+
method: Callable[..., _R],
|
| 66 |
+
cache_wrapper: Callable[[Callable[..., _R]], _MethodCacheWrapper[_R]] = ...,
|
| 67 |
+
) -> _MethodCacheWrapper[_R] | _ProxyMethodCacheWrapper[_R]: ...
|
| 68 |
+
def apply(
|
| 69 |
+
transform: Callable[[_R], _T]
|
| 70 |
+
) -> Callable[[Callable[_P, _R]], Callable[_P, _T]]: ...
|
| 71 |
+
def result_invoke(
|
| 72 |
+
action: Callable[[_R], Any]
|
| 73 |
+
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
|
| 74 |
+
def invoke(
|
| 75 |
+
f: Callable[_P, _R], /, *args: _P.args, **kwargs: _P.kwargs
|
| 76 |
+
) -> Callable[_P, _R]: ...
|
| 77 |
+
|
| 78 |
+
class Throttler(Generic[_R]):
|
| 79 |
+
last_called: float
|
| 80 |
+
func: Callable[..., _R]
|
| 81 |
+
max_rate: float
|
| 82 |
+
def __init__(
|
| 83 |
+
self, func: Callable[..., _R] | Throttler[_R], max_rate: float = ...
|
| 84 |
+
) -> None: ...
|
| 85 |
+
def reset(self) -> None: ...
|
| 86 |
+
def __call__(self, *args: Any, **kwargs: Any) -> _R: ...
|
| 87 |
+
def __get__(self, obj: Any, owner: type[Any] | None = ...) -> Callable[..., _R]: ...
|
| 88 |
+
|
| 89 |
+
def first_invoke(
|
| 90 |
+
func1: Callable[..., Any], func2: Callable[_P, _R]
|
| 91 |
+
) -> Callable[_P, _R]: ...
|
| 92 |
+
|
| 93 |
+
method_caller: Callable[..., methodcaller]
|
| 94 |
+
|
| 95 |
+
def retry_call(
|
| 96 |
+
func: Callable[..., _R],
|
| 97 |
+
cleanup: Callable[..., None] = ...,
|
| 98 |
+
retries: int | float = ...,
|
| 99 |
+
trap: type[BaseException] | tuple[type[BaseException], ...] = ...,
|
| 100 |
+
) -> _R: ...
|
| 101 |
+
def retry(
|
| 102 |
+
cleanup: Callable[..., None] = ...,
|
| 103 |
+
retries: int | float = ...,
|
| 104 |
+
trap: type[BaseException] | tuple[type[BaseException], ...] = ...,
|
| 105 |
+
) -> Callable[[Callable[..., _R]], Callable[..., _R]]: ...
|
| 106 |
+
def print_yielded(func: Callable[_P, Iterator[Any]]) -> Callable[_P, None]: ...
|
| 107 |
+
def pass_none(
|
| 108 |
+
func: Callable[Concatenate[_T, _P], _R]
|
| 109 |
+
) -> Callable[Concatenate[_T, _P], _R]: ...
|
| 110 |
+
def assign_params(
|
| 111 |
+
func: Callable[..., _R], namespace: dict[str, Any]
|
| 112 |
+
) -> partial[_R]: ...
|
| 113 |
+
def save_method_args(
|
| 114 |
+
method: Callable[Concatenate[_S, _P], _R]
|
| 115 |
+
) -> Callable[Concatenate[_S, _P], _R]: ...
|
| 116 |
+
def except_(
|
| 117 |
+
*exceptions: type[BaseException], replace: Any = ..., use: Any = ...
|
| 118 |
+
) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ...
|
| 119 |
+
def identity(x: _T) -> _T: ...
|
| 120 |
+
def bypass_when(
|
| 121 |
+
check: _V, *, _op: Callable[[_V], Any] = ...
|
| 122 |
+
) -> Callable[[Callable[[_T], _R]], Callable[[_T], _T | _R]]: ...
|
| 123 |
+
def bypass_unless(
|
| 124 |
+
check: Any,
|
| 125 |
+
) -> Callable[[Callable[[_T], _R]], Callable[[_T], _T | _R]]: ...
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (19.2 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/functools/py.typed
ADDED
|
File without changes
|
evalkit_llava/lib/python3.10/site-packages/setuptools/_vendor/jaraco/text/Lorem ipsum.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
| 2 |
+
Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst.
|