Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- python/Lib/site-packages/setuptools/__pycache__/__init__.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_core_metadata.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_discovery.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_entry_points.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_imp.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_importlib.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_itertools.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_normalization.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_path.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_reqs.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_scripts.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_shutil.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/_static.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/version.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/warnings.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/wheel.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/__pycache__/windows_support.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/INSTALLER +1 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/LICENSE +166 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/METADATA +420 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/RECORD +13 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/REQUESTED +0 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/WHEEL +5 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/top_level.txt +1 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand/__init__.py +27 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand/autoasync.py +142 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand/autocommand.py +70 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand/automain.py +59 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand/autoparse.py +333 -0
- python/Lib/site-packages/setuptools/_vendor/autocommand/errors.py +23 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/INSTALLER +1 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/LICENSE +17 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/METADATA +46 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/RECORD +12 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/REQUESTED +0 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/WHEEL +5 -0
- python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/top_level.txt +1 -0
- python/Lib/site-packages/setuptools/_vendor/backports/__init__.py +1 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/INSTALLER +1 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/METADATA +133 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/RECORD +21 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/REQUESTED +0 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/WHEEL +5 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/top_level.txt +1 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata/__init__.py +1191 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_adapters.py +136 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_collections.py +34 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_compat.py +56 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_functools.py +135 -0
- python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_itertools.py +171 -0
python/Lib/site-packages/setuptools/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (11.9 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_core_metadata.cpython-313.pyc
ADDED
|
Binary file (15.1 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_discovery.cpython-313.pyc
ADDED
|
Binary file (1.7 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_entry_points.cpython-313.pyc
ADDED
|
Binary file (4.74 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_imp.cpython-313.pyc
ADDED
|
Binary file (3.71 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_importlib.cpython-313.pyc
ADDED
|
Binary file (385 Bytes). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_itertools.cpython-313.pyc
ADDED
|
Binary file (1.01 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_normalization.cpython-313.pyc
ADDED
|
Binary file (7.22 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_path.cpython-313.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_reqs.cpython-313.pyc
ADDED
|
Binary file (1.89 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_scripts.cpython-313.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_shutil.cpython-313.pyc
ADDED
|
Binary file (2.59 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/_static.cpython-313.pyc
ADDED
|
Binary file (5.95 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/version.cpython-313.pyc
ADDED
|
Binary file (415 Bytes). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/warnings.cpython-313.pyc
ADDED
|
Binary file (5.39 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/wheel.cpython-313.pyc
ADDED
|
Binary file (15.6 kB). View file
|
|
|
python/Lib/site-packages/setuptools/__pycache__/windows_support.cpython-313.pyc
ADDED
|
Binary file (1.44 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU LESSER GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 29 June 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
This version of the GNU Lesser General Public License incorporates
|
| 10 |
+
the terms and conditions of version 3 of the GNU General Public
|
| 11 |
+
License, supplemented by the additional permissions listed below.
|
| 12 |
+
|
| 13 |
+
0. Additional Definitions.
|
| 14 |
+
|
| 15 |
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
| 16 |
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
| 17 |
+
General Public License.
|
| 18 |
+
|
| 19 |
+
"The Library" refers to a covered work governed by this License,
|
| 20 |
+
other than an Application or a Combined Work as defined below.
|
| 21 |
+
|
| 22 |
+
An "Application" is any work that makes use of an interface provided
|
| 23 |
+
by the Library, but which is not otherwise based on the Library.
|
| 24 |
+
Defining a subclass of a class defined by the Library is deemed a mode
|
| 25 |
+
of using an interface provided by the Library.
|
| 26 |
+
|
| 27 |
+
A "Combined Work" is a work produced by combining or linking an
|
| 28 |
+
Application with the Library. The particular version of the Library
|
| 29 |
+
with which the Combined Work was made is also called the "Linked
|
| 30 |
+
Version".
|
| 31 |
+
|
| 32 |
+
The "Minimal Corresponding Source" for a Combined Work means the
|
| 33 |
+
Corresponding Source for the Combined Work, excluding any source code
|
| 34 |
+
for portions of the Combined Work that, considered in isolation, are
|
| 35 |
+
based on the Application, and not on the Linked Version.
|
| 36 |
+
|
| 37 |
+
The "Corresponding Application Code" for a Combined Work means the
|
| 38 |
+
object code and/or source code for the Application, including any data
|
| 39 |
+
and utility programs needed for reproducing the Combined Work from the
|
| 40 |
+
Application, but excluding the System Libraries of the Combined Work.
|
| 41 |
+
|
| 42 |
+
1. Exception to Section 3 of the GNU GPL.
|
| 43 |
+
|
| 44 |
+
You may convey a covered work under sections 3 and 4 of this License
|
| 45 |
+
without being bound by section 3 of the GNU GPL.
|
| 46 |
+
|
| 47 |
+
2. Conveying Modified Versions.
|
| 48 |
+
|
| 49 |
+
If you modify a copy of the Library, and, in your modifications, a
|
| 50 |
+
facility refers to a function or data to be supplied by an Application
|
| 51 |
+
that uses the facility (other than as an argument passed when the
|
| 52 |
+
facility is invoked), then you may convey a copy of the modified
|
| 53 |
+
version:
|
| 54 |
+
|
| 55 |
+
a) under this License, provided that you make a good faith effort to
|
| 56 |
+
ensure that, in the event an Application does not supply the
|
| 57 |
+
function or data, the facility still operates, and performs
|
| 58 |
+
whatever part of its purpose remains meaningful, or
|
| 59 |
+
|
| 60 |
+
b) under the GNU GPL, with none of the additional permissions of
|
| 61 |
+
this License applicable to that copy.
|
| 62 |
+
|
| 63 |
+
3. Object Code Incorporating Material from Library Header Files.
|
| 64 |
+
|
| 65 |
+
The object code form of an Application may incorporate material from
|
| 66 |
+
a header file that is part of the Library. You may convey such object
|
| 67 |
+
code under terms of your choice, provided that, if the incorporated
|
| 68 |
+
material is not limited to numerical parameters, data structure
|
| 69 |
+
layouts and accessors, or small macros, inline functions and templates
|
| 70 |
+
(ten or fewer lines in length), you do both of the following:
|
| 71 |
+
|
| 72 |
+
a) Give prominent notice with each copy of the object code that the
|
| 73 |
+
Library is used in it and that the Library and its use are
|
| 74 |
+
covered by this License.
|
| 75 |
+
|
| 76 |
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
| 77 |
+
document.
|
| 78 |
+
|
| 79 |
+
4. Combined Works.
|
| 80 |
+
|
| 81 |
+
You may convey a Combined Work under terms of your choice that,
|
| 82 |
+
taken together, effectively do not restrict modification of the
|
| 83 |
+
portions of the Library contained in the Combined Work and reverse
|
| 84 |
+
engineering for debugging such modifications, if you also do each of
|
| 85 |
+
the following:
|
| 86 |
+
|
| 87 |
+
a) Give prominent notice with each copy of the Combined Work that
|
| 88 |
+
the Library is used in it and that the Library and its use are
|
| 89 |
+
covered by this License.
|
| 90 |
+
|
| 91 |
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
| 92 |
+
document.
|
| 93 |
+
|
| 94 |
+
c) For a Combined Work that displays copyright notices during
|
| 95 |
+
execution, include the copyright notice for the Library among
|
| 96 |
+
these notices, as well as a reference directing the user to the
|
| 97 |
+
copies of the GNU GPL and this license document.
|
| 98 |
+
|
| 99 |
+
d) Do one of the following:
|
| 100 |
+
|
| 101 |
+
0) Convey the Minimal Corresponding Source under the terms of this
|
| 102 |
+
License, and the Corresponding Application Code in a form
|
| 103 |
+
suitable for, and under terms that permit, the user to
|
| 104 |
+
recombine or relink the Application with a modified version of
|
| 105 |
+
the Linked Version to produce a modified Combined Work, in the
|
| 106 |
+
manner specified by section 6 of the GNU GPL for conveying
|
| 107 |
+
Corresponding Source.
|
| 108 |
+
|
| 109 |
+
1) Use a suitable shared library mechanism for linking with the
|
| 110 |
+
Library. A suitable mechanism is one that (a) uses at run time
|
| 111 |
+
a copy of the Library already present on the user's computer
|
| 112 |
+
system, and (b) will operate properly with a modified version
|
| 113 |
+
of the Library that is interface-compatible with the Linked
|
| 114 |
+
Version.
|
| 115 |
+
|
| 116 |
+
e) Provide Installation Information, but only if you would otherwise
|
| 117 |
+
be required to provide such information under section 6 of the
|
| 118 |
+
GNU GPL, and only to the extent that such information is
|
| 119 |
+
necessary to install and execute a modified version of the
|
| 120 |
+
Combined Work produced by recombining or relinking the
|
| 121 |
+
Application with a modified version of the Linked Version. (If
|
| 122 |
+
you use option 4d0, the Installation Information must accompany
|
| 123 |
+
the Minimal Corresponding Source and Corresponding Application
|
| 124 |
+
Code. If you use option 4d1, you must provide the Installation
|
| 125 |
+
Information in the manner specified by section 6 of the GNU GPL
|
| 126 |
+
for conveying Corresponding Source.)
|
| 127 |
+
|
| 128 |
+
5. Combined Libraries.
|
| 129 |
+
|
| 130 |
+
You may place library facilities that are a work based on the
|
| 131 |
+
Library side by side in a single library together with other library
|
| 132 |
+
facilities that are not Applications and are not covered by this
|
| 133 |
+
License, and convey such a combined library under terms of your
|
| 134 |
+
choice, if you do both of the following:
|
| 135 |
+
|
| 136 |
+
a) Accompany the combined library with a copy of the same work based
|
| 137 |
+
on the Library, uncombined with any other library facilities,
|
| 138 |
+
conveyed under the terms of this License.
|
| 139 |
+
|
| 140 |
+
b) Give prominent notice with the combined library that part of it
|
| 141 |
+
is a work based on the Library, and explaining where to find the
|
| 142 |
+
accompanying uncombined form of the same work.
|
| 143 |
+
|
| 144 |
+
6. Revised Versions of the GNU Lesser General Public License.
|
| 145 |
+
|
| 146 |
+
The Free Software Foundation may publish revised and/or new versions
|
| 147 |
+
of the GNU Lesser General Public License from time to time. Such new
|
| 148 |
+
versions will be similar in spirit to the present version, but may
|
| 149 |
+
differ in detail to address new problems or concerns.
|
| 150 |
+
|
| 151 |
+
Each version is given a distinguishing version number. If the
|
| 152 |
+
Library as you received it specifies that a certain numbered version
|
| 153 |
+
of the GNU Lesser General Public License "or any later version"
|
| 154 |
+
applies to it, you have the option of following the terms and
|
| 155 |
+
conditions either of that published version or of any later version
|
| 156 |
+
published by the Free Software Foundation. If the Library as you
|
| 157 |
+
received it does not specify a version number of the GNU Lesser
|
| 158 |
+
General Public License, you may choose any version of the GNU Lesser
|
| 159 |
+
General Public License ever published by the Free Software Foundation.
|
| 160 |
+
|
| 161 |
+
If the Library as you received it specifies that a proxy can decide
|
| 162 |
+
whether future versions of the GNU Lesser General Public License shall
|
| 163 |
+
apply, that proxy's public statement of acceptance of any version is
|
| 164 |
+
permanent authorization for you to choose that version for the
|
| 165 |
+
Library.
|
| 166 |
+
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/METADATA
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: autocommand
|
| 3 |
+
Version: 2.2.2
|
| 4 |
+
Summary: A library to create a command-line program from a function
|
| 5 |
+
Home-page: https://github.com/Lucretiel/autocommand
|
| 6 |
+
Author: Nathan West
|
| 7 |
+
License: LGPLv3
|
| 8 |
+
Project-URL: Homepage, https://github.com/Lucretiel/autocommand
|
| 9 |
+
Project-URL: Bug Tracker, https://github.com/Lucretiel/autocommand/issues
|
| 10 |
+
Platform: any
|
| 11 |
+
Classifier: Development Status :: 6 - Mature
|
| 12 |
+
Classifier: Intended Audience :: Developers
|
| 13 |
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
| 14 |
+
Classifier: Programming Language :: Python
|
| 15 |
+
Classifier: Programming Language :: Python :: 3
|
| 16 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 17 |
+
Classifier: Topic :: Software Development
|
| 18 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 19 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 20 |
+
Requires-Python: >=3.7
|
| 21 |
+
Description-Content-Type: text/markdown
|
| 22 |
+
License-File: LICENSE
|
| 23 |
+
|
| 24 |
+
[](https://badge.fury.io/py/autocommand)
|
| 25 |
+
|
| 26 |
+
# autocommand
|
| 27 |
+
|
| 28 |
+
A library to automatically generate and run simple argparse parsers from function signatures.
|
| 29 |
+
|
| 30 |
+
## Installation
|
| 31 |
+
|
| 32 |
+
Autocommand is installed via pip:
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
$ pip install autocommand
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Usage
|
| 39 |
+
|
| 40 |
+
Autocommand turns a function into a command-line program. It converts the function's parameter signature into command-line arguments, and automatically runs the function if the module was called as `__main__`. In effect, it lets your create a smart main function.
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from autocommand import autocommand
|
| 44 |
+
|
| 45 |
+
# This program takes exactly one argument and echos it.
|
| 46 |
+
@autocommand(__name__)
|
| 47 |
+
def echo(thing):
|
| 48 |
+
print(thing)
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
$ python echo.py hello
|
| 53 |
+
hello
|
| 54 |
+
$ python echo.py -h
|
| 55 |
+
usage: echo [-h] thing
|
| 56 |
+
|
| 57 |
+
positional arguments:
|
| 58 |
+
thing
|
| 59 |
+
|
| 60 |
+
optional arguments:
|
| 61 |
+
-h, --help show this help message and exit
|
| 62 |
+
$ python echo.py hello world # too many arguments
|
| 63 |
+
usage: echo.py [-h] thing
|
| 64 |
+
echo.py: error: unrecognized arguments: world
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
As you can see, autocommand converts the signature of the function into an argument spec. When you run the file as a program, autocommand collects the command-line arguments and turns them into function arguments. The function is executed with these arguments, and then the program exits with the return value of the function, via `sys.exit`. Autocommand also automatically creates a usage message, which can be invoked with `-h` or `--help`, and automatically prints an error message when provided with invalid arguments.
|
| 68 |
+
|
| 69 |
+
### Types
|
| 70 |
+
|
| 71 |
+
You can use a type annotation to give an argument a type. Any type (or in fact any callable) that returns an object when given a string argument can be used, though there are a few special cases that are described later.
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
@autocommand(__name__)
|
| 75 |
+
def net_client(host, port: int):
|
| 76 |
+
...
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Autocommand will catch `TypeErrors` raised by the type during argument parsing, so you can supply a callable and do some basic argument validation as well.
|
| 80 |
+
|
| 81 |
+
### Trailing Arguments
|
| 82 |
+
|
| 83 |
+
You can add a `*args` parameter to your function to give it trailing arguments. The command will collect 0 or more trailing arguments and supply them to `args` as a tuple. If a type annotation is supplied, the type is applied to each argument.
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
# Write the contents of each file, one by one
|
| 87 |
+
@autocommand(__name__)
|
| 88 |
+
def cat(*files):
|
| 89 |
+
for filename in files:
|
| 90 |
+
with open(filename) as file:
|
| 91 |
+
for line in file:
|
| 92 |
+
print(line.rstrip())
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
```
|
| 96 |
+
$ python cat.py -h
|
| 97 |
+
usage: ipython [-h] [file [file ...]]
|
| 98 |
+
|
| 99 |
+
positional arguments:
|
| 100 |
+
file
|
| 101 |
+
|
| 102 |
+
optional arguments:
|
| 103 |
+
-h, --help show this help message and exit
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### Options
|
| 107 |
+
|
| 108 |
+
To create `--option` switches, just assign a default. Autocommand will automatically create `--long` and `-s`hort switches.
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
@autocommand(__name__)
|
| 112 |
+
def do_with_config(argument, config='~/foo.conf'):
|
| 113 |
+
pass
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
$ python example.py -h
|
| 118 |
+
usage: example.py [-h] [-c CONFIG] argument
|
| 119 |
+
|
| 120 |
+
positional arguments:
|
| 121 |
+
argument
|
| 122 |
+
|
| 123 |
+
optional arguments:
|
| 124 |
+
-h, --help show this help message and exit
|
| 125 |
+
-c CONFIG, --config CONFIG
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
The option's type is automatically deduced from the default, unless one is explicitly given in an annotation:
|
| 129 |
+
|
| 130 |
+
```python
|
| 131 |
+
@autocommand(__name__)
|
| 132 |
+
def http_connect(host, port=80):
|
| 133 |
+
print('{}:{}'.format(host, port))
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
```
|
| 137 |
+
$ python http.py -h
|
| 138 |
+
usage: http.py [-h] [-p PORT] host
|
| 139 |
+
|
| 140 |
+
positional arguments:
|
| 141 |
+
host
|
| 142 |
+
|
| 143 |
+
optional arguments:
|
| 144 |
+
-h, --help show this help message and exit
|
| 145 |
+
-p PORT, --port PORT
|
| 146 |
+
$ python http.py localhost
|
| 147 |
+
localhost:80
|
| 148 |
+
$ python http.py localhost -p 8080
|
| 149 |
+
localhost:8080
|
| 150 |
+
$ python http.py localhost -p blah
|
| 151 |
+
usage: http.py [-h] [-p PORT] host
|
| 152 |
+
http.py: error: argument -p/--port: invalid int value: 'blah'
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
#### None
|
| 156 |
+
|
| 157 |
+
If an option is given a default value of `None`, it reads in a value as normal, but supplies `None` if the option isn't provided.
|
| 158 |
+
|
| 159 |
+
#### Switches
|
| 160 |
+
|
| 161 |
+
If an argument is given a default value of `True` or `False`, or
|
| 162 |
+
given an explicit `bool` type, it becomes an option switch.
|
| 163 |
+
|
| 164 |
+
```python
|
| 165 |
+
@autocommand(__name__)
|
| 166 |
+
def example(verbose=False, quiet=False):
|
| 167 |
+
pass
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
```
|
| 171 |
+
$ python example.py -h
|
| 172 |
+
usage: example.py [-h] [-v] [-q]
|
| 173 |
+
|
| 174 |
+
optional arguments:
|
| 175 |
+
-h, --help show this help message and exit
|
| 176 |
+
-v, --verbose
|
| 177 |
+
-q, --quiet
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
Autocommand attempts to do the "correct thing" in these cases- if the default is `True`, then supplying the switch makes the argument `False`; if the type is `bool` and the default is some other `True` value, then supplying the switch makes the argument `False`, while not supplying the switch makes the argument the default value.
|
| 181 |
+
|
| 182 |
+
Autocommand also supports the creation of switch inverters. Pass `add_nos=True` to `autocommand` to enable this.
|
| 183 |
+
|
| 184 |
+
```
|
| 185 |
+
@autocommand(__name__, add_nos=True)
|
| 186 |
+
def example(verbose=False):
|
| 187 |
+
pass
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
```
|
| 191 |
+
$ python example.py -h
|
| 192 |
+
usage: ipython [-h] [-v] [--no-verbose]
|
| 193 |
+
|
| 194 |
+
optional arguments:
|
| 195 |
+
-h, --help show this help message and exit
|
| 196 |
+
-v, --verbose
|
| 197 |
+
--no-verbose
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
Using the `--no-` version of a switch will pass the opposite value in as a function argument. If multiple switches are present, the last one takes precedence.
|
| 201 |
+
|
| 202 |
+
#### Files
|
| 203 |
+
|
| 204 |
+
If the default value is a file object, such as `sys.stdout`, then autocommand just looks for a string, for a file path. It doesn't do any special checking on the string, though (such as checking if the file exists); it's better to let the client decide how to handle errors in this case. Instead, it provides a special context manager called `smart_open`, which behaves exactly like `open` if a filename or other openable type is provided, but also lets you use already open files:
|
| 205 |
+
|
| 206 |
+
```python
|
| 207 |
+
from autocommand import autocommand, smart_open
|
| 208 |
+
import sys
|
| 209 |
+
|
| 210 |
+
# Write the contents of stdin, or a file, to stdout
|
| 211 |
+
@autocommand(__name__)
|
| 212 |
+
def write_out(infile=sys.stdin):
|
| 213 |
+
with smart_open(infile) as f:
|
| 214 |
+
for line in f:
|
| 215 |
+
print(line.rstrip())
|
| 216 |
+
# If a file was opened, it is closed here. If it was just stdin, it is untouched.
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
```
|
| 220 |
+
$ echo "Hello World!" | python write_out.py | tee hello.txt
|
| 221 |
+
Hello World!
|
| 222 |
+
$ python write_out.py --infile hello.txt
|
| 223 |
+
Hello World!
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
### Descriptions and docstrings
|
| 227 |
+
|
| 228 |
+
The `autocommand` decorator accepts `description` and `epilog` kwargs, corresponding to the `description <https://docs.python.org/3/library/argparse.html#description>`_ and `epilog <https://docs.python.org/3/library/argparse.html#epilog>`_ of the `ArgumentParser`. If no description is given, but the decorated function has a docstring, then it is taken as the `description` for the `ArgumentParser`. You can also provide both the description and epilog in the docstring by splitting it into two sections with 4 or more - characters.
|
| 229 |
+
|
| 230 |
+
```python
|
| 231 |
+
@autocommand(__name__)
|
| 232 |
+
def copy(infile=sys.stdin, outfile=sys.stdout):
|
| 233 |
+
'''
|
| 234 |
+
Copy an the contents of a file (or stdin) to another file (or stdout)
|
| 235 |
+
----------
|
| 236 |
+
Some extra documentation in the epilog
|
| 237 |
+
'''
|
| 238 |
+
with smart_open(infile) as istr:
|
| 239 |
+
with smart_open(outfile, 'w') as ostr:
|
| 240 |
+
for line in istr:
|
| 241 |
+
ostr.write(line)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
```
|
| 245 |
+
$ python copy.py -h
|
| 246 |
+
usage: copy.py [-h] [-i INFILE] [-o OUTFILE]
|
| 247 |
+
|
| 248 |
+
Copy an the contents of a file (or stdin) to another file (or stdout)
|
| 249 |
+
|
| 250 |
+
optional arguments:
|
| 251 |
+
-h, --help show this help message and exit
|
| 252 |
+
-i INFILE, --infile INFILE
|
| 253 |
+
-o OUTFILE, --outfile OUTFILE
|
| 254 |
+
|
| 255 |
+
Some extra documentation in the epilog
|
| 256 |
+
$ echo "Hello World" | python copy.py --outfile hello.txt
|
| 257 |
+
$ python copy.py --infile hello.txt --outfile hello2.txt
|
| 258 |
+
$ python copy.py --infile hello2.txt
|
| 259 |
+
Hello World
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
### Parameter descriptions
|
| 263 |
+
|
| 264 |
+
You can also attach description text to individual parameters in the annotation. To attach both a type and a description, supply them both in any order in a tuple
|
| 265 |
+
|
| 266 |
+
```python
|
| 267 |
+
@autocommand(__name__)
|
| 268 |
+
def copy_net(
|
| 269 |
+
infile: 'The name of the file to send',
|
| 270 |
+
host: 'The host to send the file to',
|
| 271 |
+
port: (int, 'The port to connect to')):
|
| 272 |
+
|
| 273 |
+
'''
|
| 274 |
+
Copy a file over raw TCP to a remote destination.
|
| 275 |
+
'''
|
| 276 |
+
# Left as an exercise to the reader
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
### Decorators and wrappers
|
| 280 |
+
|
| 281 |
+
Autocommand automatically follows wrapper chains created by `@functools.wraps`. This means that you can apply other wrapping decorators to your main function, and autocommand will still correctly detect the signature.
|
| 282 |
+
|
| 283 |
+
```python
|
| 284 |
+
from functools import wraps
|
| 285 |
+
from autocommand import autocommand
|
| 286 |
+
|
| 287 |
+
def print_yielded(func):
|
| 288 |
+
'''
|
| 289 |
+
Convert a generator into a function that prints all yielded elements
|
| 290 |
+
'''
|
| 291 |
+
@wraps(func)
|
| 292 |
+
def wrapper(*args, **kwargs):
|
| 293 |
+
for thing in func(*args, **kwargs):
|
| 294 |
+
print(thing)
|
| 295 |
+
return wrapper
|
| 296 |
+
|
| 297 |
+
@autocommand(__name__,
|
| 298 |
+
description= 'Print all the values from START to STOP, inclusive, in steps of STEP',
|
| 299 |
+
epilog= 'STOP and STEP default to 1')
|
| 300 |
+
@print_yielded
|
| 301 |
+
def seq(stop, start=1, step=1):
|
| 302 |
+
for i in range(start, stop + 1, step):
|
| 303 |
+
yield i
|
| 304 |
+
```
|
| 305 |
+
|
| 306 |
+
```
|
| 307 |
+
$ seq.py -h
|
| 308 |
+
usage: seq.py [-h] [-s START] [-S STEP] stop
|
| 309 |
+
|
| 310 |
+
Print all the values from START to STOP, inclusive, in steps of STEP
|
| 311 |
+
|
| 312 |
+
positional arguments:
|
| 313 |
+
stop
|
| 314 |
+
|
| 315 |
+
optional arguments:
|
| 316 |
+
-h, --help show this help message and exit
|
| 317 |
+
-s START, --start START
|
| 318 |
+
-S STEP, --step STEP
|
| 319 |
+
|
| 320 |
+
STOP and STEP default to 1
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
Even though autocommand is being applied to the `wrapper` returned by `print_yielded`, it still retreives the signature of the underlying `seq` function to create the argument parsing.
|
| 324 |
+
|
| 325 |
+
### Custom Parser
|
| 326 |
+
|
| 327 |
+
While autocommand's automatic parser generator is a powerful convenience, it doesn't cover all of the different features that argparse provides. If you need these features, you can provide your own parser as a kwarg to `autocommand`:
|
| 328 |
+
|
| 329 |
+
```python
|
| 330 |
+
from argparse import ArgumentParser
|
| 331 |
+
from autocommand import autocommand
|
| 332 |
+
|
| 333 |
+
parser = ArgumentParser()
|
| 334 |
+
# autocommand can't do optional positonal parameters
|
| 335 |
+
parser.add_argument('arg', nargs='?')
|
| 336 |
+
# or mutually exclusive options
|
| 337 |
+
group = parser.add_mutually_exclusive_group()
|
| 338 |
+
group.add_argument('-v', '--verbose', action='store_true')
|
| 339 |
+
group.add_argument('-q', '--quiet', action='store_true')
|
| 340 |
+
|
| 341 |
+
@autocommand(__name__, parser=parser)
|
| 342 |
+
def main(arg, verbose, quiet):
|
| 343 |
+
print(arg, verbose, quiet)
|
| 344 |
+
```
|
| 345 |
+
|
| 346 |
+
```
|
| 347 |
+
$ python parser.py -h
|
| 348 |
+
usage: write_file.py [-h] [-v | -q] [arg]
|
| 349 |
+
|
| 350 |
+
positional arguments:
|
| 351 |
+
arg
|
| 352 |
+
|
| 353 |
+
optional arguments:
|
| 354 |
+
-h, --help show this help message and exit
|
| 355 |
+
-v, --verbose
|
| 356 |
+
-q, --quiet
|
| 357 |
+
$ python parser.py
|
| 358 |
+
None False False
|
| 359 |
+
$ python parser.py hello
|
| 360 |
+
hello False False
|
| 361 |
+
$ python parser.py -v
|
| 362 |
+
None True False
|
| 363 |
+
$ python parser.py -q
|
| 364 |
+
None False True
|
| 365 |
+
$ python parser.py -vq
|
| 366 |
+
usage: parser.py [-h] [-v | -q] [arg]
|
| 367 |
+
parser.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
|
| 368 |
+
```
|
| 369 |
+
|
| 370 |
+
Any parser should work fine, so long as each of the parser's arguments has a corresponding parameter in the decorated main function. The order of parameters doesn't matter, as long as they are all present. Note that when using a custom parser, autocommand doesn't modify the parser or the retrieved arguments. This means that no description/epilog will be added, and the function's type annotations and defaults (if present) will be ignored.
|
| 371 |
+
|
| 372 |
+
## Testing and Library use
|
| 373 |
+
|
| 374 |
+
The decorated function is only called and exited from if the first argument to `autocommand` is `'__main__'` or `True`. If it is neither of these values, or no argument is given, then a new main function is created by the decorator. This function has the signature `main(argv=None)`, and is intended to be called with arguments as if via `main(sys.argv[1:])`. The function has the attributes `parser` and `main`, which are the generated `ArgumentParser` and the original main function that was decorated. This is to facilitate testing and library use of your main. Calling the function triggers a `parse_args()` with the supplied arguments, and returns the result of the main function. Note that, while it returns instead of calling `sys.exit`, the `parse_args()` function will raise a `SystemExit` in the event of a parsing error or `-h/--help` argument.
|
| 375 |
+
|
| 376 |
+
```python
|
| 377 |
+
@autocommand()
|
| 378 |
+
def test_prog(arg1, arg2: int, quiet=False, verbose=False):
|
| 379 |
+
if not quiet:
|
| 380 |
+
print(arg1, arg2)
|
| 381 |
+
if verbose:
|
| 382 |
+
print("LOUD NOISES")
|
| 383 |
+
|
| 384 |
+
return 0
|
| 385 |
+
|
| 386 |
+
print(test_prog(['-v', 'hello', '80']))
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
```
|
| 390 |
+
$ python test_prog.py
|
| 391 |
+
hello 80
|
| 392 |
+
LOUD NOISES
|
| 393 |
+
0
|
| 394 |
+
```
|
| 395 |
+
|
| 396 |
+
If the function is called with no arguments, `sys.argv[1:]` is used. This is to allow the autocommand function to be used as a setuptools entry point.
|
| 397 |
+
|
| 398 |
+
## Exceptions and limitations
|
| 399 |
+
|
| 400 |
+
- There are a few possible exceptions that `autocommand` can raise. All of them derive from `autocommand.AutocommandError`.
|
| 401 |
+
|
| 402 |
+
- If an invalid annotation is given (that is, it isn't a `type`, `str`, `(type, str)`, or `(str, type)`, an `AnnotationError` is raised. The `type` may be any callable, as described in the `Types`_ section.
|
| 403 |
+
- If the function has a `**kwargs` parameter, a `KWargError` is raised.
|
| 404 |
+
- If, somehow, the function has a positional-only parameter, a `PositionalArgError` is raised. This means that the argument doesn't have a name, which is currently not possible with a plain `def` or `lambda`, though many built-in functions have this kind of parameter.
|
| 405 |
+
|
| 406 |
+
- There are a few argparse features that are not supported by autocommand.
|
| 407 |
+
|
| 408 |
+
- It isn't possible to have an optional positional argument (as opposed to a `--option`). POSIX thinks this is bad form anyway.
|
| 409 |
+
- It isn't possible to have mutually exclusive arguments or options
|
| 410 |
+
- It isn't possible to have subcommands or subparsers, though I'm working on a few solutions involving classes or nested function definitions to allow this.
|
| 411 |
+
|
| 412 |
+
## Development
|
| 413 |
+
|
| 414 |
+
Autocommand cannot be important from the project root; this is to enforce separation of concerns and prevent accidental importing of `setup.py` or tests. To develop, install the project in editable mode:
|
| 415 |
+
|
| 416 |
+
```
|
| 417 |
+
$ python setup.py develop
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
This will create a link to the source files in the deployment directory, so that any source changes are reflected when it is imported.
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/RECORD
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
autocommand-2.2.2.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
autocommand-2.2.2.dist-info/LICENSE,sha256=reeNBJgtaZctREqOFKlPh6IzTdOFXMgDSOqOJAqg3y0,7634
|
| 3 |
+
autocommand-2.2.2.dist-info/METADATA,sha256=OADZuR3O6iBlpu1ieTgzYul6w4uOVrk0P0BO5TGGAJk,15006
|
| 4 |
+
autocommand-2.2.2.dist-info/RECORD,,
|
| 5 |
+
autocommand-2.2.2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
autocommand-2.2.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
| 7 |
+
autocommand-2.2.2.dist-info/top_level.txt,sha256=AzfhgKKS8EdAwWUTSF8mgeVQbXOY9kokHB6kSqwwqu0,12
|
| 8 |
+
autocommand/__init__.py,sha256=zko5Rnvolvb-UXjCx_2ArPTGBWwUK5QY4LIQIKYR7As,1037
|
| 9 |
+
autocommand/autoasync.py,sha256=AMdyrxNS4pqWJfP_xuoOcImOHWD-qT7x06wmKN1Vp-U,5680
|
| 10 |
+
autocommand/autocommand.py,sha256=hmkEmQ72HtL55gnURVjDOnsfYlGd5lLXbvT4KG496Qw,2505
|
| 11 |
+
autocommand/automain.py,sha256=A2b8i754Mxc_DjU9WFr6vqYDWlhz0cn8miu8d8EsxV8,2076
|
| 12 |
+
autocommand/autoparse.py,sha256=WVWmZJPcbzUKXP40raQw_0HD8qPJ2V9VG1eFFmmnFxw,11642
|
| 13 |
+
autocommand/errors.py,sha256=7aa3roh9Herd6nIKpQHNWEslWE8oq7GiHYVUuRqORnA,886
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/REQUESTED
ADDED
|
File without changes
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.38.4)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
python/Lib/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
autocommand
|
python/Lib/site-packages/setuptools/_vendor/autocommand/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2014-2016 Nathan West
|
| 2 |
+
#
|
| 3 |
+
# This file is part of autocommand.
|
| 4 |
+
#
|
| 5 |
+
# autocommand is free software: you can redistribute it and/or modify
|
| 6 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
# (at your option) any later version.
|
| 9 |
+
#
|
| 10 |
+
# autocommand is distributed in the hope that it will be useful,
|
| 11 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
# GNU Lesser General Public License for more details.
|
| 14 |
+
#
|
| 15 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
# along with autocommand. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
# flake8 flags all these imports as unused, hence the NOQAs everywhere.
|
| 19 |
+
|
| 20 |
+
from .automain import automain # NOQA
|
| 21 |
+
from .autoparse import autoparse, smart_open # NOQA
|
| 22 |
+
from .autocommand import autocommand # NOQA
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
from .autoasync import autoasync # NOQA
|
| 26 |
+
except ImportError: # pragma: no cover
|
| 27 |
+
pass
|
python/Lib/site-packages/setuptools/_vendor/autocommand/autoasync.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2014-2015 Nathan West
|
| 2 |
+
#
|
| 3 |
+
# This file is part of autocommand.
|
| 4 |
+
#
|
| 5 |
+
# autocommand is free software: you can redistribute it and/or modify
|
| 6 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
# (at your option) any later version.
|
| 9 |
+
#
|
| 10 |
+
# autocommand is distributed in the hope that it will be useful,
|
| 11 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
# GNU Lesser General Public License for more details.
|
| 14 |
+
#
|
| 15 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
# along with autocommand. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
from asyncio import get_event_loop, iscoroutine
|
| 19 |
+
from functools import wraps
|
| 20 |
+
from inspect import signature
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
async def _run_forever_coro(coro, args, kwargs, loop):
|
| 24 |
+
'''
|
| 25 |
+
This helper function launches an async main function that was tagged with
|
| 26 |
+
forever=True. There are two possibilities:
|
| 27 |
+
|
| 28 |
+
- The function is a normal function, which handles initializing the event
|
| 29 |
+
loop, which is then run forever
|
| 30 |
+
- The function is a coroutine, which needs to be scheduled in the event
|
| 31 |
+
loop, which is then run forever
|
| 32 |
+
- There is also the possibility that the function is a normal function
|
| 33 |
+
wrapping a coroutine function
|
| 34 |
+
|
| 35 |
+
The function is therefore called unconditionally and scheduled in the event
|
| 36 |
+
loop if the return value is a coroutine object.
|
| 37 |
+
|
| 38 |
+
The reason this is a separate function is to make absolutely sure that all
|
| 39 |
+
the objects created are garbage collected after all is said and done; we
|
| 40 |
+
do this to ensure that any exceptions raised in the tasks are collected
|
| 41 |
+
ASAP.
|
| 42 |
+
'''
|
| 43 |
+
|
| 44 |
+
# Personal note: I consider this an antipattern, as it relies on the use of
|
| 45 |
+
# unowned resources. The setup function dumps some stuff into the event
|
| 46 |
+
# loop where it just whirls in the ether without a well defined owner or
|
| 47 |
+
# lifetime. For this reason, there's a good chance I'll remove the
|
| 48 |
+
# forever=True feature from autoasync at some point in the future.
|
| 49 |
+
thing = coro(*args, **kwargs)
|
| 50 |
+
if iscoroutine(thing):
|
| 51 |
+
await thing
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def autoasync(coro=None, *, loop=None, forever=False, pass_loop=False):
|
| 55 |
+
'''
|
| 56 |
+
Convert an asyncio coroutine into a function which, when called, is
|
| 57 |
+
evaluted in an event loop, and the return value returned. This is intented
|
| 58 |
+
to make it easy to write entry points into asyncio coroutines, which
|
| 59 |
+
otherwise need to be explictly evaluted with an event loop's
|
| 60 |
+
run_until_complete.
|
| 61 |
+
|
| 62 |
+
If `loop` is given, it is used as the event loop to run the coro in. If it
|
| 63 |
+
is None (the default), the loop is retreived using asyncio.get_event_loop.
|
| 64 |
+
This call is defered until the decorated function is called, so that
|
| 65 |
+
callers can install custom event loops or event loop policies after
|
| 66 |
+
@autoasync is applied.
|
| 67 |
+
|
| 68 |
+
If `forever` is True, the loop is run forever after the decorated coroutine
|
| 69 |
+
is finished. Use this for servers created with asyncio.start_server and the
|
| 70 |
+
like.
|
| 71 |
+
|
| 72 |
+
If `pass_loop` is True, the event loop object is passed into the coroutine
|
| 73 |
+
as the `loop` kwarg when the wrapper function is called. In this case, the
|
| 74 |
+
wrapper function's __signature__ is updated to remove this parameter, so
|
| 75 |
+
that autoparse can still be used on it without generating a parameter for
|
| 76 |
+
`loop`.
|
| 77 |
+
|
| 78 |
+
This coroutine can be called with ( @autoasync(...) ) or without
|
| 79 |
+
( @autoasync ) arguments.
|
| 80 |
+
|
| 81 |
+
Examples:
|
| 82 |
+
|
| 83 |
+
@autoasync
|
| 84 |
+
def get_file(host, port):
|
| 85 |
+
reader, writer = yield from asyncio.open_connection(host, port)
|
| 86 |
+
data = reader.read()
|
| 87 |
+
sys.stdout.write(data.decode())
|
| 88 |
+
|
| 89 |
+
get_file(host, port)
|
| 90 |
+
|
| 91 |
+
@autoasync(forever=True, pass_loop=True)
|
| 92 |
+
def server(host, port, loop):
|
| 93 |
+
yield_from loop.create_server(Proto, host, port)
|
| 94 |
+
|
| 95 |
+
server('localhost', 8899)
|
| 96 |
+
|
| 97 |
+
'''
|
| 98 |
+
if coro is None:
|
| 99 |
+
return lambda c: autoasync(
|
| 100 |
+
c, loop=loop,
|
| 101 |
+
forever=forever,
|
| 102 |
+
pass_loop=pass_loop)
|
| 103 |
+
|
| 104 |
+
# The old and new signatures are required to correctly bind the loop
|
| 105 |
+
# parameter in 100% of cases, even if it's a positional parameter.
|
| 106 |
+
# NOTE: A future release will probably require the loop parameter to be
|
| 107 |
+
# a kwonly parameter.
|
| 108 |
+
if pass_loop:
|
| 109 |
+
old_sig = signature(coro)
|
| 110 |
+
new_sig = old_sig.replace(parameters=(
|
| 111 |
+
param for name, param in old_sig.parameters.items()
|
| 112 |
+
if name != "loop"))
|
| 113 |
+
|
| 114 |
+
@wraps(coro)
|
| 115 |
+
def autoasync_wrapper(*args, **kwargs):
|
| 116 |
+
# Defer the call to get_event_loop so that, if a custom policy is
|
| 117 |
+
# installed after the autoasync decorator, it is respected at call time
|
| 118 |
+
local_loop = get_event_loop() if loop is None else loop
|
| 119 |
+
|
| 120 |
+
# Inject the 'loop' argument. We have to use this signature binding to
|
| 121 |
+
# ensure it's injected in the correct place (positional, keyword, etc)
|
| 122 |
+
if pass_loop:
|
| 123 |
+
bound_args = old_sig.bind_partial()
|
| 124 |
+
bound_args.arguments.update(
|
| 125 |
+
loop=local_loop,
|
| 126 |
+
**new_sig.bind(*args, **kwargs).arguments)
|
| 127 |
+
args, kwargs = bound_args.args, bound_args.kwargs
|
| 128 |
+
|
| 129 |
+
if forever:
|
| 130 |
+
local_loop.create_task(_run_forever_coro(
|
| 131 |
+
coro, args, kwargs, local_loop
|
| 132 |
+
))
|
| 133 |
+
local_loop.run_forever()
|
| 134 |
+
else:
|
| 135 |
+
return local_loop.run_until_complete(coro(*args, **kwargs))
|
| 136 |
+
|
| 137 |
+
# Attach the updated signature. This allows 'pass_loop' to be used with
|
| 138 |
+
# autoparse
|
| 139 |
+
if pass_loop:
|
| 140 |
+
autoasync_wrapper.__signature__ = new_sig
|
| 141 |
+
|
| 142 |
+
return autoasync_wrapper
|
python/Lib/site-packages/setuptools/_vendor/autocommand/autocommand.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2014-2015 Nathan West
|
| 2 |
+
#
|
| 3 |
+
# This file is part of autocommand.
|
| 4 |
+
#
|
| 5 |
+
# autocommand is free software: you can redistribute it and/or modify
|
| 6 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
# (at your option) any later version.
|
| 9 |
+
#
|
| 10 |
+
# autocommand is distributed in the hope that it will be useful,
|
| 11 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
# GNU Lesser General Public License for more details.
|
| 14 |
+
#
|
| 15 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
# along with autocommand. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
from .autoparse import autoparse
|
| 19 |
+
from .automain import automain
|
| 20 |
+
try:
|
| 21 |
+
from .autoasync import autoasync
|
| 22 |
+
except ImportError: # pragma: no cover
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def autocommand(
|
| 27 |
+
module, *,
|
| 28 |
+
description=None,
|
| 29 |
+
epilog=None,
|
| 30 |
+
add_nos=False,
|
| 31 |
+
parser=None,
|
| 32 |
+
loop=None,
|
| 33 |
+
forever=False,
|
| 34 |
+
pass_loop=False):
|
| 35 |
+
|
| 36 |
+
if callable(module):
|
| 37 |
+
raise TypeError('autocommand requires a module name argument')
|
| 38 |
+
|
| 39 |
+
def autocommand_decorator(func):
|
| 40 |
+
# Step 1: if requested, run it all in an asyncio event loop. autoasync
|
| 41 |
+
# patches the __signature__ of the decorated function, so that in the
|
| 42 |
+
# event that pass_loop is True, the `loop` parameter of the original
|
| 43 |
+
# function will *not* be interpreted as a command-line argument by
|
| 44 |
+
# autoparse
|
| 45 |
+
if loop is not None or forever or pass_loop:
|
| 46 |
+
func = autoasync(
|
| 47 |
+
func,
|
| 48 |
+
loop=None if loop is True else loop,
|
| 49 |
+
pass_loop=pass_loop,
|
| 50 |
+
forever=forever)
|
| 51 |
+
|
| 52 |
+
# Step 2: create parser. We do this second so that the arguments are
|
| 53 |
+
# parsed and passed *before* entering the asyncio event loop, if it
|
| 54 |
+
# exists. This simplifies the stack trace and ensures errors are
|
| 55 |
+
# reported earlier. It also ensures that errors raised during parsing &
|
| 56 |
+
# passing are still raised if `forever` is True.
|
| 57 |
+
func = autoparse(
|
| 58 |
+
func,
|
| 59 |
+
description=description,
|
| 60 |
+
epilog=epilog,
|
| 61 |
+
add_nos=add_nos,
|
| 62 |
+
parser=parser)
|
| 63 |
+
|
| 64 |
+
# Step 3: call the function automatically if __name__ == '__main__' (or
|
| 65 |
+
# if True was provided)
|
| 66 |
+
func = automain(module)(func)
|
| 67 |
+
|
| 68 |
+
return func
|
| 69 |
+
|
| 70 |
+
return autocommand_decorator
|
python/Lib/site-packages/setuptools/_vendor/autocommand/automain.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2014-2015 Nathan West
|
| 2 |
+
#
|
| 3 |
+
# This file is part of autocommand.
|
| 4 |
+
#
|
| 5 |
+
# autocommand is free software: you can redistribute it and/or modify
|
| 6 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
# (at your option) any later version.
|
| 9 |
+
#
|
| 10 |
+
# autocommand is distributed in the hope that it will be useful,
|
| 11 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
# GNU Lesser General Public License for more details.
|
| 14 |
+
#
|
| 15 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
# along with autocommand. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
import sys
|
| 19 |
+
from .errors import AutocommandError
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class AutomainRequiresModuleError(AutocommandError, TypeError):
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def automain(module, *, args=(), kwargs=None):
|
| 27 |
+
'''
|
| 28 |
+
This decorator automatically invokes a function if the module is being run
|
| 29 |
+
as the "__main__" module. Optionally, provide args or kwargs with which to
|
| 30 |
+
call the function. If `module` is "__main__", the function is called, and
|
| 31 |
+
the program is `sys.exit`ed with the return value. You can also pass `True`
|
| 32 |
+
to cause the function to be called unconditionally. If the function is not
|
| 33 |
+
called, it is returned unchanged by the decorator.
|
| 34 |
+
|
| 35 |
+
Usage:
|
| 36 |
+
|
| 37 |
+
@automain(__name__) # Pass __name__ to check __name__=="__main__"
|
| 38 |
+
def main():
|
| 39 |
+
...
|
| 40 |
+
|
| 41 |
+
If __name__ is "__main__" here, the main function is called, and then
|
| 42 |
+
sys.exit called with the return value.
|
| 43 |
+
'''
|
| 44 |
+
|
| 45 |
+
# Check that @automain(...) was called, rather than @automain
|
| 46 |
+
if callable(module):
|
| 47 |
+
raise AutomainRequiresModuleError(module)
|
| 48 |
+
|
| 49 |
+
if module == '__main__' or module is True:
|
| 50 |
+
if kwargs is None:
|
| 51 |
+
kwargs = {}
|
| 52 |
+
|
| 53 |
+
# Use a function definition instead of a lambda for a neater traceback
|
| 54 |
+
def automain_decorator(main):
|
| 55 |
+
sys.exit(main(*args, **kwargs))
|
| 56 |
+
|
| 57 |
+
return automain_decorator
|
| 58 |
+
else:
|
| 59 |
+
return lambda main: main
|
python/Lib/site-packages/setuptools/_vendor/autocommand/autoparse.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
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+
# This file is part of autocommand.
|
| 4 |
+
#
|
| 5 |
+
# autocommand is free software: you can redistribute it and/or modify
|
| 6 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
# (at your option) any later version.
|
| 9 |
+
#
|
| 10 |
+
# autocommand is distributed in the hope that it will be useful,
|
| 11 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
# GNU Lesser General Public License for more details.
|
| 14 |
+
#
|
| 15 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
# along with autocommand. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
import sys
|
| 19 |
+
from re import compile as compile_regex
|
| 20 |
+
from inspect import signature, getdoc, Parameter
|
| 21 |
+
from argparse import ArgumentParser
|
| 22 |
+
from contextlib import contextmanager
|
| 23 |
+
from functools import wraps
|
| 24 |
+
from io import IOBase
|
| 25 |
+
from autocommand.errors import AutocommandError
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
_empty = Parameter.empty
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class AnnotationError(AutocommandError):
|
| 32 |
+
'''Annotation error: annotation must be a string, type, or tuple of both'''
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class PositionalArgError(AutocommandError):
|
| 36 |
+
'''
|
| 37 |
+
Postional Arg Error: autocommand can't handle postional-only parameters
|
| 38 |
+
'''
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class KWArgError(AutocommandError):
|
| 42 |
+
'''kwarg Error: autocommand can't handle a **kwargs parameter'''
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class DocstringError(AutocommandError):
|
| 46 |
+
'''Docstring error'''
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class TooManySplitsError(DocstringError):
|
| 50 |
+
'''
|
| 51 |
+
The docstring had too many ---- section splits. Currently we only support
|
| 52 |
+
using up to a single split, to split the docstring into description and
|
| 53 |
+
epilog parts.
|
| 54 |
+
'''
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _get_type_description(annotation):
|
| 58 |
+
'''
|
| 59 |
+
Given an annotation, return the (type, description) for the parameter.
|
| 60 |
+
If you provide an annotation that is somehow both a string and a callable,
|
| 61 |
+
the behavior is undefined.
|
| 62 |
+
'''
|
| 63 |
+
if annotation is _empty:
|
| 64 |
+
return None, None
|
| 65 |
+
elif callable(annotation):
|
| 66 |
+
return annotation, None
|
| 67 |
+
elif isinstance(annotation, str):
|
| 68 |
+
return None, annotation
|
| 69 |
+
elif isinstance(annotation, tuple):
|
| 70 |
+
try:
|
| 71 |
+
arg1, arg2 = annotation
|
| 72 |
+
except ValueError as e:
|
| 73 |
+
raise AnnotationError(annotation) from e
|
| 74 |
+
else:
|
| 75 |
+
if callable(arg1) and isinstance(arg2, str):
|
| 76 |
+
return arg1, arg2
|
| 77 |
+
elif isinstance(arg1, str) and callable(arg2):
|
| 78 |
+
return arg2, arg1
|
| 79 |
+
|
| 80 |
+
raise AnnotationError(annotation)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _add_arguments(param, parser, used_char_args, add_nos):
|
| 84 |
+
'''
|
| 85 |
+
Add the argument(s) to an ArgumentParser (using add_argument) for a given
|
| 86 |
+
parameter. used_char_args is the set of -short options currently already in
|
| 87 |
+
use, and is updated (if necessary) by this function. If add_nos is True,
|
| 88 |
+
this will also add an inverse switch for all boolean options. For
|
| 89 |
+
instance, for the boolean parameter "verbose", this will create --verbose
|
| 90 |
+
and --no-verbose.
|
| 91 |
+
'''
|
| 92 |
+
|
| 93 |
+
# Impl note: This function is kept separate from make_parser because it's
|
| 94 |
+
# already very long and I wanted to separate out as much as possible into
|
| 95 |
+
# its own call scope, to prevent even the possibility of suble mutation
|
| 96 |
+
# bugs.
|
| 97 |
+
if param.kind is param.POSITIONAL_ONLY:
|
| 98 |
+
raise PositionalArgError(param)
|
| 99 |
+
elif param.kind is param.VAR_KEYWORD:
|
| 100 |
+
raise KWArgError(param)
|
| 101 |
+
|
| 102 |
+
# These are the kwargs for the add_argument function.
|
| 103 |
+
arg_spec = {}
|
| 104 |
+
is_option = False
|
| 105 |
+
|
| 106 |
+
# Get the type and default from the annotation.
|
| 107 |
+
arg_type, description = _get_type_description(param.annotation)
|
| 108 |
+
|
| 109 |
+
# Get the default value
|
| 110 |
+
default = param.default
|
| 111 |
+
|
| 112 |
+
# If there is no explicit type, and the default is present and not None,
|
| 113 |
+
# infer the type from the default.
|
| 114 |
+
if arg_type is None and default not in {_empty, None}:
|
| 115 |
+
arg_type = type(default)
|
| 116 |
+
|
| 117 |
+
# Add default. The presence of a default means this is an option, not an
|
| 118 |
+
# argument.
|
| 119 |
+
if default is not _empty:
|
| 120 |
+
arg_spec['default'] = default
|
| 121 |
+
is_option = True
|
| 122 |
+
|
| 123 |
+
# Add the type
|
| 124 |
+
if arg_type is not None:
|
| 125 |
+
# Special case for bool: make it just a --switch
|
| 126 |
+
if arg_type is bool:
|
| 127 |
+
if not default or default is _empty:
|
| 128 |
+
arg_spec['action'] = 'store_true'
|
| 129 |
+
else:
|
| 130 |
+
arg_spec['action'] = 'store_false'
|
| 131 |
+
|
| 132 |
+
# Switches are always options
|
| 133 |
+
is_option = True
|
| 134 |
+
|
| 135 |
+
# Special case for file types: make it a string type, for filename
|
| 136 |
+
elif isinstance(default, IOBase):
|
| 137 |
+
arg_spec['type'] = str
|
| 138 |
+
|
| 139 |
+
# TODO: special case for list type.
|
| 140 |
+
# - How to specificy type of list members?
|
| 141 |
+
# - param: [int]
|
| 142 |
+
# - param: int =[]
|
| 143 |
+
# - action='append' vs nargs='*'
|
| 144 |
+
|
| 145 |
+
else:
|
| 146 |
+
arg_spec['type'] = arg_type
|
| 147 |
+
|
| 148 |
+
# nargs: if the signature includes *args, collect them as trailing CLI
|
| 149 |
+
# arguments in a list. *args can't have a default value, so it can never be
|
| 150 |
+
# an option.
|
| 151 |
+
if param.kind is param.VAR_POSITIONAL:
|
| 152 |
+
# TODO: consider depluralizing metavar/name here.
|
| 153 |
+
arg_spec['nargs'] = '*'
|
| 154 |
+
|
| 155 |
+
# Add description.
|
| 156 |
+
if description is not None:
|
| 157 |
+
arg_spec['help'] = description
|
| 158 |
+
|
| 159 |
+
# Get the --flags
|
| 160 |
+
flags = []
|
| 161 |
+
name = param.name
|
| 162 |
+
|
| 163 |
+
if is_option:
|
| 164 |
+
# Add the first letter as a -short option.
|
| 165 |
+
for letter in name[0], name[0].swapcase():
|
| 166 |
+
if letter not in used_char_args:
|
| 167 |
+
used_char_args.add(letter)
|
| 168 |
+
flags.append('-{}'.format(letter))
|
| 169 |
+
break
|
| 170 |
+
|
| 171 |
+
# If the parameter is a --long option, or is a -short option that
|
| 172 |
+
# somehow failed to get a flag, add it.
|
| 173 |
+
if len(name) > 1 or not flags:
|
| 174 |
+
flags.append('--{}'.format(name))
|
| 175 |
+
|
| 176 |
+
arg_spec['dest'] = name
|
| 177 |
+
else:
|
| 178 |
+
flags.append(name)
|
| 179 |
+
|
| 180 |
+
parser.add_argument(*flags, **arg_spec)
|
| 181 |
+
|
| 182 |
+
# Create the --no- version for boolean switches
|
| 183 |
+
if add_nos and arg_type is bool:
|
| 184 |
+
parser.add_argument(
|
| 185 |
+
'--no-{}'.format(name),
|
| 186 |
+
action='store_const',
|
| 187 |
+
dest=name,
|
| 188 |
+
const=default if default is not _empty else False)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def make_parser(func_sig, description, epilog, add_nos):
|
| 192 |
+
'''
|
| 193 |
+
Given the signature of a function, create an ArgumentParser
|
| 194 |
+
'''
|
| 195 |
+
parser = ArgumentParser(description=description, epilog=epilog)
|
| 196 |
+
|
| 197 |
+
used_char_args = {'h'}
|
| 198 |
+
|
| 199 |
+
# Arange the params so that single-character arguments are first. This
|
| 200 |
+
# esnures they don't have to get --long versions. sorted is stable, so the
|
| 201 |
+
# parameters will otherwise still be in relative order.
|
| 202 |
+
params = sorted(
|
| 203 |
+
func_sig.parameters.values(),
|
| 204 |
+
key=lambda param: len(param.name) > 1)
|
| 205 |
+
|
| 206 |
+
for param in params:
|
| 207 |
+
_add_arguments(param, parser, used_char_args, add_nos)
|
| 208 |
+
|
| 209 |
+
return parser
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
_DOCSTRING_SPLIT = compile_regex(r'\n\s*-{4,}\s*\n')
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def parse_docstring(docstring):
|
| 216 |
+
'''
|
| 217 |
+
Given a docstring, parse it into a description and epilog part
|
| 218 |
+
'''
|
| 219 |
+
if docstring is None:
|
| 220 |
+
return '', ''
|
| 221 |
+
|
| 222 |
+
parts = _DOCSTRING_SPLIT.split(docstring)
|
| 223 |
+
|
| 224 |
+
if len(parts) == 1:
|
| 225 |
+
return docstring, ''
|
| 226 |
+
elif len(parts) == 2:
|
| 227 |
+
return parts[0], parts[1]
|
| 228 |
+
else:
|
| 229 |
+
raise TooManySplitsError()
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def autoparse(
|
| 233 |
+
func=None, *,
|
| 234 |
+
description=None,
|
| 235 |
+
epilog=None,
|
| 236 |
+
add_nos=False,
|
| 237 |
+
parser=None):
|
| 238 |
+
'''
|
| 239 |
+
This decorator converts a function that takes normal arguments into a
|
| 240 |
+
function which takes a single optional argument, argv, parses it using an
|
| 241 |
+
argparse.ArgumentParser, and calls the underlying function with the parsed
|
| 242 |
+
arguments. If it is not given, sys.argv[1:] is used. This is so that the
|
| 243 |
+
function can be used as a setuptools entry point, as well as a normal main
|
| 244 |
+
function. sys.argv[1:] is not evaluated until the function is called, to
|
| 245 |
+
allow injecting different arguments for testing.
|
| 246 |
+
|
| 247 |
+
It uses the argument signature of the function to create an
|
| 248 |
+
ArgumentParser. Parameters without defaults become positional parameters,
|
| 249 |
+
while parameters *with* defaults become --options. Use annotations to set
|
| 250 |
+
the type of the parameter.
|
| 251 |
+
|
| 252 |
+
The `desctiption` and `epilog` parameters corrospond to the same respective
|
| 253 |
+
argparse parameters. If no description is given, it defaults to the
|
| 254 |
+
decorated functions's docstring, if present.
|
| 255 |
+
|
| 256 |
+
If add_nos is True, every boolean option (that is, every parameter with a
|
| 257 |
+
default of True/False or a type of bool) will have a --no- version created
|
| 258 |
+
as well, which inverts the option. For instance, the --verbose option will
|
| 259 |
+
have a --no-verbose counterpart. These are not mutually exclusive-
|
| 260 |
+
whichever one appears last in the argument list will have precedence.
|
| 261 |
+
|
| 262 |
+
If a parser is given, it is used instead of one generated from the function
|
| 263 |
+
signature. In this case, no parser is created; instead, the given parser is
|
| 264 |
+
used to parse the argv argument. The parser's results' argument names must
|
| 265 |
+
match up with the parameter names of the decorated function.
|
| 266 |
+
|
| 267 |
+
The decorated function is attached to the result as the `func` attribute,
|
| 268 |
+
and the parser is attached as the `parser` attribute.
|
| 269 |
+
'''
|
| 270 |
+
|
| 271 |
+
# If @autoparse(...) is used instead of @autoparse
|
| 272 |
+
if func is None:
|
| 273 |
+
return lambda f: autoparse(
|
| 274 |
+
f, description=description,
|
| 275 |
+
epilog=epilog,
|
| 276 |
+
add_nos=add_nos,
|
| 277 |
+
parser=parser)
|
| 278 |
+
|
| 279 |
+
func_sig = signature(func)
|
| 280 |
+
|
| 281 |
+
docstr_description, docstr_epilog = parse_docstring(getdoc(func))
|
| 282 |
+
|
| 283 |
+
if parser is None:
|
| 284 |
+
parser = make_parser(
|
| 285 |
+
func_sig,
|
| 286 |
+
description or docstr_description,
|
| 287 |
+
epilog or docstr_epilog,
|
| 288 |
+
add_nos)
|
| 289 |
+
|
| 290 |
+
@wraps(func)
|
| 291 |
+
def autoparse_wrapper(argv=None):
|
| 292 |
+
if argv is None:
|
| 293 |
+
argv = sys.argv[1:]
|
| 294 |
+
|
| 295 |
+
# Get empty argument binding, to fill with parsed arguments. This
|
| 296 |
+
# object does all the heavy lifting of turning named arguments into
|
| 297 |
+
# into correctly bound *args and **kwargs.
|
| 298 |
+
parsed_args = func_sig.bind_partial()
|
| 299 |
+
parsed_args.arguments.update(vars(parser.parse_args(argv)))
|
| 300 |
+
|
| 301 |
+
return func(*parsed_args.args, **parsed_args.kwargs)
|
| 302 |
+
|
| 303 |
+
# TODO: attach an updated __signature__ to autoparse_wrapper, just in case.
|
| 304 |
+
|
| 305 |
+
# Attach the wrapped function and parser, and return the wrapper.
|
| 306 |
+
autoparse_wrapper.func = func
|
| 307 |
+
autoparse_wrapper.parser = parser
|
| 308 |
+
return autoparse_wrapper
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
@contextmanager
|
| 312 |
+
def smart_open(filename_or_file, *args, **kwargs):
|
| 313 |
+
'''
|
| 314 |
+
This context manager allows you to open a filename, if you want to default
|
| 315 |
+
some already-existing file object, like sys.stdout, which shouldn't be
|
| 316 |
+
closed at the end of the context. If the filename argument is a str, bytes,
|
| 317 |
+
or int, the file object is created via a call to open with the given *args
|
| 318 |
+
and **kwargs, sent to the context, and closed at the end of the context,
|
| 319 |
+
just like "with open(filename) as f:". If it isn't one of the openable
|
| 320 |
+
types, the object simply sent to the context unchanged, and left unclosed
|
| 321 |
+
at the end of the context. Example:
|
| 322 |
+
|
| 323 |
+
def work_with_file(name=sys.stdout):
|
| 324 |
+
with smart_open(name) as f:
|
| 325 |
+
# Works correctly if name is a str filename or sys.stdout
|
| 326 |
+
print("Some stuff", file=f)
|
| 327 |
+
# If it was a filename, f is closed at the end here.
|
| 328 |
+
'''
|
| 329 |
+
if isinstance(filename_or_file, (str, bytes, int)):
|
| 330 |
+
with open(filename_or_file, *args, **kwargs) as file:
|
| 331 |
+
yield file
|
| 332 |
+
else:
|
| 333 |
+
yield filename_or_file
|
python/Lib/site-packages/setuptools/_vendor/autocommand/errors.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2014-2016 Nathan West
|
| 2 |
+
#
|
| 3 |
+
# This file is part of autocommand.
|
| 4 |
+
#
|
| 5 |
+
# autocommand is free software: you can redistribute it and/or modify
|
| 6 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
# (at your option) any later version.
|
| 9 |
+
#
|
| 10 |
+
# autocommand is distributed in the hope that it will be useful,
|
| 11 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
# GNU Lesser General Public License for more details.
|
| 14 |
+
#
|
| 15 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
# along with autocommand. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class AutocommandError(Exception):
|
| 20 |
+
'''Base class for autocommand exceptions'''
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
# Individual modules will define errors specific to that module.
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.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.
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: backports.tarfile
|
| 3 |
+
Version: 1.2.0
|
| 4 |
+
Summary: Backport of CPython tarfile module
|
| 5 |
+
Author-email: "Jason R. Coombs" <jaraco@jaraco.com>
|
| 6 |
+
Project-URL: Homepage, https://github.com/jaraco/backports.tarfile
|
| 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 |
+
Provides-Extra: docs
|
| 16 |
+
Requires-Dist: sphinx >=3.5 ; extra == 'docs'
|
| 17 |
+
Requires-Dist: jaraco.packaging >=9.3 ; extra == 'docs'
|
| 18 |
+
Requires-Dist: rst.linker >=1.9 ; extra == 'docs'
|
| 19 |
+
Requires-Dist: furo ; extra == 'docs'
|
| 20 |
+
Requires-Dist: sphinx-lint ; extra == 'docs'
|
| 21 |
+
Provides-Extra: testing
|
| 22 |
+
Requires-Dist: pytest !=8.1.*,>=6 ; extra == 'testing'
|
| 23 |
+
Requires-Dist: pytest-checkdocs >=2.4 ; extra == 'testing'
|
| 24 |
+
Requires-Dist: pytest-cov ; extra == 'testing'
|
| 25 |
+
Requires-Dist: pytest-enabler >=2.2 ; extra == 'testing'
|
| 26 |
+
Requires-Dist: jaraco.test ; extra == 'testing'
|
| 27 |
+
Requires-Dist: pytest !=8.0.* ; extra == 'testing'
|
| 28 |
+
|
| 29 |
+
.. image:: https://img.shields.io/pypi/v/backports.tarfile.svg
|
| 30 |
+
:target: https://pypi.org/project/backports.tarfile
|
| 31 |
+
|
| 32 |
+
.. image:: https://img.shields.io/pypi/pyversions/backports.tarfile.svg
|
| 33 |
+
|
| 34 |
+
.. image:: https://github.com/jaraco/backports.tarfile/actions/workflows/main.yml/badge.svg
|
| 35 |
+
:target: https://github.com/jaraco/backports.tarfile/actions?query=workflow%3A%22tests%22
|
| 36 |
+
:alt: tests
|
| 37 |
+
|
| 38 |
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
|
| 39 |
+
:target: https://github.com/astral-sh/ruff
|
| 40 |
+
:alt: Ruff
|
| 41 |
+
|
| 42 |
+
.. .. image:: https://readthedocs.org/projects/backportstarfile/badge/?version=latest
|
| 43 |
+
.. :target: https://backportstarfile.readthedocs.io/en/latest/?badge=latest
|
| 44 |
+
|
| 45 |
+
.. image:: https://img.shields.io/badge/skeleton-2024-informational
|
| 46 |
+
:target: https://blog.jaraco.com/skeleton
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
backports.tarfile-1.2.0.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
backports.tarfile-1.2.0.dist-info/LICENSE,sha256=htoPAa6uRjSKPD1GUZXcHOzN55956HdppkuNoEsqR0E,1023
|
| 3 |
+
backports.tarfile-1.2.0.dist-info/METADATA,sha256=ghXFTq132dxaEIolxr3HK1mZqm9iyUmaRANZQSr6WlE,2020
|
| 4 |
+
backports.tarfile-1.2.0.dist-info/RECORD,,
|
| 5 |
+
backports.tarfile-1.2.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
backports.tarfile-1.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
| 7 |
+
backports.tarfile-1.2.0.dist-info/top_level.txt,sha256=cGjaLMOoBR1FK0ApojtzWVmViTtJ7JGIK_HwXiEsvtU,10
|
| 8 |
+
backports/__init__.py,sha256=iOEMwnlORWezdO8-2vxBIPSR37D7JGjluZ8f55vzxls,81
|
| 9 |
+
backports/tarfile/__init__.py,sha256=Pwf2qUIfB0SolJPCKcx3vz3UEu_aids4g4sAfxy94qg,108491
|
| 10 |
+
backports/tarfile/__main__.py,sha256=Yw2oGT1afrz2eBskzdPYL8ReB_3liApmhFkN2EbDmc4,59
|
| 11 |
+
backports/tarfile/compat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 12 |
+
backports/tarfile/compat/py38.py,sha256=iYkyt_gvWjLzGUTJD9TuTfMMjOk-ersXZmRlvQYN2qE,568
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/REQUESTED
ADDED
|
File without changes
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.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 |
+
|
python/Lib/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
backports
|
python/Lib/site-packages/setuptools/_vendor/backports/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/METADATA
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: importlib_metadata
|
| 3 |
+
Version: 8.7.1
|
| 4 |
+
Summary: Read metadata from Python packages
|
| 5 |
+
Author-email: "Jason R. Coombs" <jaraco@jaraco.com>
|
| 6 |
+
License-Expression: Apache-2.0
|
| 7 |
+
Project-URL: Source, https://github.com/python/importlib_metadata
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Intended Audience :: Developers
|
| 10 |
+
Classifier: Programming Language :: Python :: 3
|
| 11 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 12 |
+
Requires-Python: >=3.9
|
| 13 |
+
Description-Content-Type: text/x-rst
|
| 14 |
+
License-File: LICENSE
|
| 15 |
+
Requires-Dist: zipp>=3.20
|
| 16 |
+
Provides-Extra: test
|
| 17 |
+
Requires-Dist: pytest!=8.1.*,>=6; extra == "test"
|
| 18 |
+
Requires-Dist: packaging; extra == "test"
|
| 19 |
+
Requires-Dist: pyfakefs; extra == "test"
|
| 20 |
+
Requires-Dist: flufl.flake8; extra == "test"
|
| 21 |
+
Requires-Dist: pytest-perf>=0.9.2; extra == "test"
|
| 22 |
+
Requires-Dist: jaraco.test>=5.4; extra == "test"
|
| 23 |
+
Provides-Extra: doc
|
| 24 |
+
Requires-Dist: sphinx>=3.5; extra == "doc"
|
| 25 |
+
Requires-Dist: jaraco.packaging>=9.3; extra == "doc"
|
| 26 |
+
Requires-Dist: rst.linker>=1.9; extra == "doc"
|
| 27 |
+
Requires-Dist: furo; extra == "doc"
|
| 28 |
+
Requires-Dist: sphinx-lint; extra == "doc"
|
| 29 |
+
Requires-Dist: jaraco.tidelift>=1.4; extra == "doc"
|
| 30 |
+
Provides-Extra: perf
|
| 31 |
+
Requires-Dist: ipython; extra == "perf"
|
| 32 |
+
Provides-Extra: check
|
| 33 |
+
Requires-Dist: pytest-checkdocs>=2.4; extra == "check"
|
| 34 |
+
Requires-Dist: pytest-ruff>=0.2.1; sys_platform != "cygwin" and extra == "check"
|
| 35 |
+
Provides-Extra: cover
|
| 36 |
+
Requires-Dist: pytest-cov; extra == "cover"
|
| 37 |
+
Provides-Extra: enabler
|
| 38 |
+
Requires-Dist: pytest-enabler>=3.4; extra == "enabler"
|
| 39 |
+
Provides-Extra: type
|
| 40 |
+
Requires-Dist: pytest-mypy>=1.0.1; extra == "type"
|
| 41 |
+
Requires-Dist: mypy<1.19; platform_python_implementation == "PyPy" and extra == "type"
|
| 42 |
+
Dynamic: license-file
|
| 43 |
+
|
| 44 |
+
.. image:: https://img.shields.io/pypi/v/importlib_metadata.svg
|
| 45 |
+
:target: https://pypi.org/project/importlib_metadata
|
| 46 |
+
|
| 47 |
+
.. image:: https://img.shields.io/pypi/pyversions/importlib_metadata.svg
|
| 48 |
+
|
| 49 |
+
.. image:: https://github.com/python/importlib_metadata/actions/workflows/main.yml/badge.svg
|
| 50 |
+
:target: https://github.com/python/importlib_metadata/actions?query=workflow%3A%22tests%22
|
| 51 |
+
:alt: tests
|
| 52 |
+
|
| 53 |
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
|
| 54 |
+
:target: https://github.com/astral-sh/ruff
|
| 55 |
+
:alt: Ruff
|
| 56 |
+
|
| 57 |
+
.. image:: https://readthedocs.org/projects/importlib-metadata/badge/?version=latest
|
| 58 |
+
:target: https://importlib-metadata.readthedocs.io/en/latest/?badge=latest
|
| 59 |
+
|
| 60 |
+
.. image:: https://img.shields.io/badge/skeleton-2025-informational
|
| 61 |
+
:target: https://blog.jaraco.com/skeleton
|
| 62 |
+
|
| 63 |
+
.. image:: https://tidelift.com/badges/package/pypi/importlib-metadata
|
| 64 |
+
:target: https://tidelift.com/subscription/pkg/pypi-importlib-metadata?utm_source=pypi-importlib-metadata&utm_medium=readme
|
| 65 |
+
|
| 66 |
+
Library to access the metadata for a Python package.
|
| 67 |
+
|
| 68 |
+
This package supplies third-party access to the functionality of
|
| 69 |
+
`importlib.metadata <https://docs.python.org/3/library/importlib.metadata.html>`_
|
| 70 |
+
including improvements added to subsequent Python versions.
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Compatibility
|
| 74 |
+
=============
|
| 75 |
+
|
| 76 |
+
New features are introduced in this third-party library and later merged
|
| 77 |
+
into CPython. The following table indicates which versions of this library
|
| 78 |
+
were contributed to different versions in the standard library:
|
| 79 |
+
|
| 80 |
+
.. list-table::
|
| 81 |
+
:header-rows: 1
|
| 82 |
+
|
| 83 |
+
* - importlib_metadata
|
| 84 |
+
- stdlib
|
| 85 |
+
* - 7.0
|
| 86 |
+
- 3.13
|
| 87 |
+
* - 6.5
|
| 88 |
+
- 3.12
|
| 89 |
+
* - 4.13
|
| 90 |
+
- 3.11
|
| 91 |
+
* - 4.6
|
| 92 |
+
- 3.10
|
| 93 |
+
* - 1.4
|
| 94 |
+
- 3.8
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
Usage
|
| 98 |
+
=====
|
| 99 |
+
|
| 100 |
+
See the `online documentation <https://importlib-metadata.readthedocs.io/>`_
|
| 101 |
+
for usage details.
|
| 102 |
+
|
| 103 |
+
`Finder authors
|
| 104 |
+
<https://docs.python.org/3/reference/import.html#finders-and-loaders>`_ can
|
| 105 |
+
also add support for custom package installers. See the above documentation
|
| 106 |
+
for details.
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
Caveats
|
| 110 |
+
=======
|
| 111 |
+
|
| 112 |
+
This project primarily supports third-party packages installed by PyPA
|
| 113 |
+
tools (or other conforming packages). It does not support:
|
| 114 |
+
|
| 115 |
+
- Packages in the stdlib.
|
| 116 |
+
- Packages installed without metadata.
|
| 117 |
+
|
| 118 |
+
Project details
|
| 119 |
+
===============
|
| 120 |
+
|
| 121 |
+
* Project home: https://github.com/python/importlib_metadata
|
| 122 |
+
* Report bugs at: https://github.com/python/importlib_metadata/issues
|
| 123 |
+
* Code hosting: https://github.com/python/importlib_metadata
|
| 124 |
+
* Documentation: https://importlib-metadata.readthedocs.io/
|
| 125 |
+
|
| 126 |
+
For Enterprise
|
| 127 |
+
==============
|
| 128 |
+
|
| 129 |
+
Available as part of the Tidelift Subscription.
|
| 130 |
+
|
| 131 |
+
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.
|
| 132 |
+
|
| 133 |
+
`Learn more <https://tidelift.com/subscription/pkg/pypi-importlib-metadata?utm_source=pypi-importlib-metadata&utm_medium=referral&utm_campaign=github>`_.
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/RECORD
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
importlib_metadata-8.7.1.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
importlib_metadata-8.7.1.dist-info/METADATA,sha256=o-OLnuQyYonUhkcE8w4pnudp4jCc6fSnXw3hpQrQo1Y,4670
|
| 3 |
+
importlib_metadata-8.7.1.dist-info/RECORD,,
|
| 4 |
+
importlib_metadata-8.7.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 5 |
+
importlib_metadata-8.7.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
| 6 |
+
importlib_metadata-8.7.1.dist-info/licenses/LICENSE,sha256=RYUC4S2Xu_ZEOGBqIARKqF6wX7CoqAe7NdvsJT_R_AQ,10278
|
| 7 |
+
importlib_metadata-8.7.1.dist-info/top_level.txt,sha256=CO3fD9yylANiXkrMo4qHLV_mqXL2sC5JFKgt1yWAT-A,19
|
| 8 |
+
importlib_metadata/__init__.py,sha256=u7Ew4-UkpzNY-ka6k-WRkDhQZS1akkLMfWs2eEnUmGo,37734
|
| 9 |
+
importlib_metadata/_adapters.py,sha256=r5i8XLrKT6xmrpoREZhZrfczOYDmrVZeJBW5u0HzIGU,3797
|
| 10 |
+
importlib_metadata/_collections.py,sha256=CxAhzlF3g1rwu_fMiB53JtRQiUFh0RgiMpoOvmK_ocg,760
|
| 11 |
+
importlib_metadata/_compat.py,sha256=VC5ZDLlT-BcshauCShdFJvMNLntJJfZzNK1meGa-enw,1313
|
| 12 |
+
importlib_metadata/_functools.py,sha256=0pA2OoiVK6wnsGq8HvVIzgdkvLiZ0nfnfw7IsndjoHk,3510
|
| 13 |
+
importlib_metadata/_itertools.py,sha256=nMvp9SfHAQ_JYwK4L2i64lr3GRXGlYlikGTVzWbys_E,5351
|
| 14 |
+
importlib_metadata/_meta.py,sha256=EtHyiJ5kGzWFDfKyQ2XQp6Vu113CeadKW1Vf6aGc1B4,1765
|
| 15 |
+
importlib_metadata/_text.py,sha256=HCsFksZpJLeTP3NEk_ngrAeXVRRtTrtyh9eOABoRP4A,2166
|
| 16 |
+
importlib_metadata/_typing.py,sha256=EQKhhsEgz_Sa-FnePI-faC72rNOOQwopjA1i5pG8FDU,367
|
| 17 |
+
importlib_metadata/compat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 18 |
+
importlib_metadata/compat/py311.py,sha256=uqm-K-uohyj1042TH4a9Er_I5o7667DvulcD-gC_fSA,608
|
| 19 |
+
importlib_metadata/compat/py39.py,sha256=J3W7PUVRPNYMmcvT12RF8ndBU9e8_T0Ac4U87Bsrq70,1187
|
| 20 |
+
importlib_metadata/diagnose.py,sha256=nkSRMiowlmkhLYhKhvCg9glmt_11Cox-EmLzEbqYTa8,379
|
| 21 |
+
importlib_metadata/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/REQUESTED
ADDED
|
File without changes
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (80.9.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
importlib_metadata
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
APIs exposing metadata from third-party Python packages.
|
| 3 |
+
|
| 4 |
+
This codebase is shared between importlib.metadata in the stdlib
|
| 5 |
+
and importlib_metadata in PyPI. See
|
| 6 |
+
https://github.com/python/importlib_metadata/wiki/Development-Methodology
|
| 7 |
+
for more detail.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import abc
|
| 13 |
+
import collections
|
| 14 |
+
import email
|
| 15 |
+
import functools
|
| 16 |
+
import itertools
|
| 17 |
+
import operator
|
| 18 |
+
import os
|
| 19 |
+
import pathlib
|
| 20 |
+
import posixpath
|
| 21 |
+
import re
|
| 22 |
+
import sys
|
| 23 |
+
import textwrap
|
| 24 |
+
import types
|
| 25 |
+
from collections.abc import Iterable, Mapping
|
| 26 |
+
from contextlib import suppress
|
| 27 |
+
from importlib import import_module
|
| 28 |
+
from importlib.abc import MetaPathFinder
|
| 29 |
+
from itertools import starmap
|
| 30 |
+
from typing import Any
|
| 31 |
+
|
| 32 |
+
from . import _meta
|
| 33 |
+
from ._collections import FreezableDefaultDict, Pair
|
| 34 |
+
from ._compat import (
|
| 35 |
+
NullFinder,
|
| 36 |
+
install,
|
| 37 |
+
)
|
| 38 |
+
from ._functools import method_cache, noop, pass_none, passthrough
|
| 39 |
+
from ._itertools import always_iterable, bucket, unique_everseen
|
| 40 |
+
from ._meta import PackageMetadata, SimplePath
|
| 41 |
+
from ._typing import md_none
|
| 42 |
+
from .compat import py39, py311
|
| 43 |
+
|
| 44 |
+
__all__ = [
|
| 45 |
+
'Distribution',
|
| 46 |
+
'DistributionFinder',
|
| 47 |
+
'PackageMetadata',
|
| 48 |
+
'PackageNotFoundError',
|
| 49 |
+
'SimplePath',
|
| 50 |
+
'distribution',
|
| 51 |
+
'distributions',
|
| 52 |
+
'entry_points',
|
| 53 |
+
'files',
|
| 54 |
+
'metadata',
|
| 55 |
+
'packages_distributions',
|
| 56 |
+
'requires',
|
| 57 |
+
'version',
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class PackageNotFoundError(ModuleNotFoundError):
|
| 62 |
+
"""The package was not found."""
|
| 63 |
+
|
| 64 |
+
def __str__(self) -> str:
|
| 65 |
+
return f"No package metadata was found for {self.name}"
|
| 66 |
+
|
| 67 |
+
@property
|
| 68 |
+
def name(self) -> str: # type: ignore[override] # make readonly
|
| 69 |
+
(name,) = self.args
|
| 70 |
+
return name
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class Sectioned:
|
| 74 |
+
"""
|
| 75 |
+
A simple entry point config parser for performance
|
| 76 |
+
|
| 77 |
+
>>> for item in Sectioned.read(Sectioned._sample):
|
| 78 |
+
... print(item)
|
| 79 |
+
Pair(name='sec1', value='# comments ignored')
|
| 80 |
+
Pair(name='sec1', value='a = 1')
|
| 81 |
+
Pair(name='sec1', value='b = 2')
|
| 82 |
+
Pair(name='sec2', value='a = 2')
|
| 83 |
+
|
| 84 |
+
>>> res = Sectioned.section_pairs(Sectioned._sample)
|
| 85 |
+
>>> item = next(res)
|
| 86 |
+
>>> item.name
|
| 87 |
+
'sec1'
|
| 88 |
+
>>> item.value
|
| 89 |
+
Pair(name='a', value='1')
|
| 90 |
+
>>> item = next(res)
|
| 91 |
+
>>> item.value
|
| 92 |
+
Pair(name='b', value='2')
|
| 93 |
+
>>> item = next(res)
|
| 94 |
+
>>> item.name
|
| 95 |
+
'sec2'
|
| 96 |
+
>>> item.value
|
| 97 |
+
Pair(name='a', value='2')
|
| 98 |
+
>>> list(res)
|
| 99 |
+
[]
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
_sample = textwrap.dedent(
|
| 103 |
+
"""
|
| 104 |
+
[sec1]
|
| 105 |
+
# comments ignored
|
| 106 |
+
a = 1
|
| 107 |
+
b = 2
|
| 108 |
+
|
| 109 |
+
[sec2]
|
| 110 |
+
a = 2
|
| 111 |
+
"""
|
| 112 |
+
).lstrip()
|
| 113 |
+
|
| 114 |
+
@classmethod
|
| 115 |
+
def section_pairs(cls, text):
|
| 116 |
+
return (
|
| 117 |
+
section._replace(value=Pair.parse(section.value))
|
| 118 |
+
for section in cls.read(text, filter_=cls.valid)
|
| 119 |
+
if section.name is not None
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
@staticmethod
|
| 123 |
+
def read(text, filter_=None):
|
| 124 |
+
lines = filter(filter_, map(str.strip, text.splitlines()))
|
| 125 |
+
name = None
|
| 126 |
+
for value in lines:
|
| 127 |
+
section_match = value.startswith('[') and value.endswith(']')
|
| 128 |
+
if section_match:
|
| 129 |
+
name = value.strip('[]')
|
| 130 |
+
continue
|
| 131 |
+
yield Pair(name, value)
|
| 132 |
+
|
| 133 |
+
@staticmethod
|
| 134 |
+
def valid(line: str):
|
| 135 |
+
return line and not line.startswith('#')
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class _EntryPointMatch(types.SimpleNamespace):
|
| 139 |
+
module: str
|
| 140 |
+
attr: str
|
| 141 |
+
extras: str
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class EntryPoint:
|
| 145 |
+
"""An entry point as defined by Python packaging conventions.
|
| 146 |
+
|
| 147 |
+
See `the packaging docs on entry points
|
| 148 |
+
<https://packaging.python.org/specifications/entry-points/>`_
|
| 149 |
+
for more information.
|
| 150 |
+
|
| 151 |
+
>>> ep = EntryPoint(
|
| 152 |
+
... name=None, group=None, value='package.module:attr [extra1, extra2]')
|
| 153 |
+
>>> ep.module
|
| 154 |
+
'package.module'
|
| 155 |
+
>>> ep.attr
|
| 156 |
+
'attr'
|
| 157 |
+
>>> ep.extras
|
| 158 |
+
['extra1', 'extra2']
|
| 159 |
+
|
| 160 |
+
If the value package or module are not valid identifiers, a
|
| 161 |
+
ValueError is raised on access.
|
| 162 |
+
|
| 163 |
+
>>> EntryPoint(name=None, group=None, value='invalid-name').module
|
| 164 |
+
Traceback (most recent call last):
|
| 165 |
+
...
|
| 166 |
+
ValueError: ('Invalid object reference...invalid-name...
|
| 167 |
+
>>> EntryPoint(name=None, group=None, value='invalid-name').attr
|
| 168 |
+
Traceback (most recent call last):
|
| 169 |
+
...
|
| 170 |
+
ValueError: ('Invalid object reference...invalid-name...
|
| 171 |
+
>>> EntryPoint(name=None, group=None, value='invalid-name').extras
|
| 172 |
+
Traceback (most recent call last):
|
| 173 |
+
...
|
| 174 |
+
ValueError: ('Invalid object reference...invalid-name...
|
| 175 |
+
|
| 176 |
+
The same thing happens on construction.
|
| 177 |
+
|
| 178 |
+
>>> EntryPoint(name=None, group=None, value='invalid-name')
|
| 179 |
+
Traceback (most recent call last):
|
| 180 |
+
...
|
| 181 |
+
ValueError: ('Invalid object reference...invalid-name...
|
| 182 |
+
|
| 183 |
+
"""
|
| 184 |
+
|
| 185 |
+
pattern = re.compile(
|
| 186 |
+
r'(?P<module>[\w.]+)\s*'
|
| 187 |
+
r'(:\s*(?P<attr>[\w.]+)\s*)?'
|
| 188 |
+
r'((?P<extras>\[.*\])\s*)?$'
|
| 189 |
+
)
|
| 190 |
+
"""
|
| 191 |
+
A regular expression describing the syntax for an entry point,
|
| 192 |
+
which might look like:
|
| 193 |
+
|
| 194 |
+
- module
|
| 195 |
+
- package.module
|
| 196 |
+
- package.module:attribute
|
| 197 |
+
- package.module:object.attribute
|
| 198 |
+
- package.module:attr [extra1, extra2]
|
| 199 |
+
|
| 200 |
+
Other combinations are possible as well.
|
| 201 |
+
|
| 202 |
+
The expression is lenient about whitespace around the ':',
|
| 203 |
+
following the attr, and following any extras.
|
| 204 |
+
"""
|
| 205 |
+
|
| 206 |
+
name: str
|
| 207 |
+
value: str
|
| 208 |
+
group: str
|
| 209 |
+
|
| 210 |
+
dist: Distribution | None = None
|
| 211 |
+
|
| 212 |
+
def __init__(self, name: str, value: str, group: str) -> None:
|
| 213 |
+
vars(self).update(name=name, value=value, group=group)
|
| 214 |
+
self.module
|
| 215 |
+
|
| 216 |
+
def load(self) -> Any:
|
| 217 |
+
"""Load the entry point from its definition. If only a module
|
| 218 |
+
is indicated by the value, return that module. Otherwise,
|
| 219 |
+
return the named object.
|
| 220 |
+
"""
|
| 221 |
+
module = import_module(self.module)
|
| 222 |
+
attrs = filter(None, (self.attr or '').split('.'))
|
| 223 |
+
return functools.reduce(getattr, attrs, module)
|
| 224 |
+
|
| 225 |
+
@property
|
| 226 |
+
def module(self) -> str:
|
| 227 |
+
return self._match.module
|
| 228 |
+
|
| 229 |
+
@property
|
| 230 |
+
def attr(self) -> str:
|
| 231 |
+
return self._match.attr
|
| 232 |
+
|
| 233 |
+
@property
|
| 234 |
+
def extras(self) -> list[str]:
|
| 235 |
+
return re.findall(r'\w+', self._match.extras or '')
|
| 236 |
+
|
| 237 |
+
@functools.cached_property
|
| 238 |
+
def _match(self) -> _EntryPointMatch:
|
| 239 |
+
match = self.pattern.match(self.value)
|
| 240 |
+
if not match:
|
| 241 |
+
raise ValueError(
|
| 242 |
+
'Invalid object reference. '
|
| 243 |
+
'See https://packaging.python.org'
|
| 244 |
+
'/en/latest/specifications/entry-points/#data-model',
|
| 245 |
+
self.value,
|
| 246 |
+
)
|
| 247 |
+
return _EntryPointMatch(**match.groupdict())
|
| 248 |
+
|
| 249 |
+
def _for(self, dist):
|
| 250 |
+
vars(self).update(dist=dist)
|
| 251 |
+
return self
|
| 252 |
+
|
| 253 |
+
def matches(self, **params):
|
| 254 |
+
"""
|
| 255 |
+
EntryPoint matches the given parameters.
|
| 256 |
+
|
| 257 |
+
>>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]')
|
| 258 |
+
>>> ep.matches(group='foo')
|
| 259 |
+
True
|
| 260 |
+
>>> ep.matches(name='bar', value='bing:bong [extra1, extra2]')
|
| 261 |
+
True
|
| 262 |
+
>>> ep.matches(group='foo', name='other')
|
| 263 |
+
False
|
| 264 |
+
>>> ep.matches()
|
| 265 |
+
True
|
| 266 |
+
>>> ep.matches(extras=['extra1', 'extra2'])
|
| 267 |
+
True
|
| 268 |
+
>>> ep.matches(module='bing')
|
| 269 |
+
True
|
| 270 |
+
>>> ep.matches(attr='bong')
|
| 271 |
+
True
|
| 272 |
+
"""
|
| 273 |
+
self._disallow_dist(params)
|
| 274 |
+
attrs = (getattr(self, param) for param in params)
|
| 275 |
+
return all(map(operator.eq, params.values(), attrs))
|
| 276 |
+
|
| 277 |
+
@staticmethod
|
| 278 |
+
def _disallow_dist(params):
|
| 279 |
+
"""
|
| 280 |
+
Querying by dist is not allowed (dist objects are not comparable).
|
| 281 |
+
>>> EntryPoint(name='fan', value='fav', group='fag').matches(dist='foo')
|
| 282 |
+
Traceback (most recent call last):
|
| 283 |
+
...
|
| 284 |
+
ValueError: "dist" is not suitable for matching...
|
| 285 |
+
"""
|
| 286 |
+
if "dist" in params:
|
| 287 |
+
raise ValueError(
|
| 288 |
+
'"dist" is not suitable for matching. '
|
| 289 |
+
"Instead, use Distribution.entry_points.select() on a "
|
| 290 |
+
"located distribution."
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
def _key(self):
|
| 294 |
+
return self.name, self.value, self.group
|
| 295 |
+
|
| 296 |
+
def __lt__(self, other):
|
| 297 |
+
return self._key() < other._key()
|
| 298 |
+
|
| 299 |
+
def __eq__(self, other):
|
| 300 |
+
return self._key() == other._key()
|
| 301 |
+
|
| 302 |
+
def __setattr__(self, name, value):
|
| 303 |
+
raise AttributeError("EntryPoint objects are immutable.")
|
| 304 |
+
|
| 305 |
+
def __repr__(self):
|
| 306 |
+
return (
|
| 307 |
+
f'EntryPoint(name={self.name!r}, value={self.value!r}, '
|
| 308 |
+
f'group={self.group!r})'
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
def __hash__(self) -> int:
|
| 312 |
+
return hash(self._key())
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
class EntryPoints(tuple):
|
| 316 |
+
"""
|
| 317 |
+
An immutable collection of selectable EntryPoint objects.
|
| 318 |
+
"""
|
| 319 |
+
|
| 320 |
+
__slots__ = ()
|
| 321 |
+
|
| 322 |
+
def __getitem__(self, name: str) -> EntryPoint: # type: ignore[override] # Work with str instead of int
|
| 323 |
+
"""
|
| 324 |
+
Get the EntryPoint in self matching name.
|
| 325 |
+
"""
|
| 326 |
+
try:
|
| 327 |
+
return next(iter(self.select(name=name)))
|
| 328 |
+
except StopIteration:
|
| 329 |
+
raise KeyError(name)
|
| 330 |
+
|
| 331 |
+
def __repr__(self):
|
| 332 |
+
"""
|
| 333 |
+
Repr with classname and tuple constructor to
|
| 334 |
+
signal that we deviate from regular tuple behavior.
|
| 335 |
+
"""
|
| 336 |
+
return '%s(%r)' % (self.__class__.__name__, tuple(self))
|
| 337 |
+
|
| 338 |
+
def select(self, **params) -> EntryPoints:
|
| 339 |
+
"""
|
| 340 |
+
Select entry points from self that match the
|
| 341 |
+
given parameters (typically group and/or name).
|
| 342 |
+
"""
|
| 343 |
+
return EntryPoints(ep for ep in self if py39.ep_matches(ep, **params))
|
| 344 |
+
|
| 345 |
+
@property
|
| 346 |
+
def names(self) -> set[str]:
|
| 347 |
+
"""
|
| 348 |
+
Return the set of all names of all entry points.
|
| 349 |
+
"""
|
| 350 |
+
return {ep.name for ep in self}
|
| 351 |
+
|
| 352 |
+
@property
|
| 353 |
+
def groups(self) -> set[str]:
|
| 354 |
+
"""
|
| 355 |
+
Return the set of all groups of all entry points.
|
| 356 |
+
"""
|
| 357 |
+
return {ep.group for ep in self}
|
| 358 |
+
|
| 359 |
+
@classmethod
|
| 360 |
+
def _from_text_for(cls, text, dist):
|
| 361 |
+
return cls(ep._for(dist) for ep in cls._from_text(text))
|
| 362 |
+
|
| 363 |
+
@staticmethod
|
| 364 |
+
def _from_text(text):
|
| 365 |
+
return (
|
| 366 |
+
EntryPoint(name=item.value.name, value=item.value.value, group=item.name)
|
| 367 |
+
for item in Sectioned.section_pairs(text or '')
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
class PackagePath(pathlib.PurePosixPath):
|
| 372 |
+
"""A reference to a path in a package"""
|
| 373 |
+
|
| 374 |
+
hash: FileHash | None
|
| 375 |
+
size: int
|
| 376 |
+
dist: Distribution
|
| 377 |
+
|
| 378 |
+
def read_text(self, encoding: str = 'utf-8') -> str:
|
| 379 |
+
return self.locate().read_text(encoding=encoding)
|
| 380 |
+
|
| 381 |
+
def read_binary(self) -> bytes:
|
| 382 |
+
return self.locate().read_bytes()
|
| 383 |
+
|
| 384 |
+
def locate(self) -> SimplePath:
|
| 385 |
+
"""Return a path-like object for this path"""
|
| 386 |
+
return self.dist.locate_file(self)
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
class FileHash:
|
| 390 |
+
def __init__(self, spec: str) -> None:
|
| 391 |
+
self.mode, _, self.value = spec.partition('=')
|
| 392 |
+
|
| 393 |
+
def __repr__(self) -> str:
|
| 394 |
+
return f'<FileHash mode: {self.mode} value: {self.value}>'
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
class Distribution(metaclass=abc.ABCMeta):
|
| 398 |
+
"""
|
| 399 |
+
An abstract Python distribution package.
|
| 400 |
+
|
| 401 |
+
Custom providers may derive from this class and define
|
| 402 |
+
the abstract methods to provide a concrete implementation
|
| 403 |
+
for their environment. Some providers may opt to override
|
| 404 |
+
the default implementation of some properties to bypass
|
| 405 |
+
the file-reading mechanism.
|
| 406 |
+
"""
|
| 407 |
+
|
| 408 |
+
@abc.abstractmethod
|
| 409 |
+
def read_text(self, filename) -> str | None:
|
| 410 |
+
"""Attempt to load metadata file given by the name.
|
| 411 |
+
|
| 412 |
+
Python distribution metadata is organized by blobs of text
|
| 413 |
+
typically represented as "files" in the metadata directory
|
| 414 |
+
(e.g. package-1.0.dist-info). These files include things
|
| 415 |
+
like:
|
| 416 |
+
|
| 417 |
+
- METADATA: The distribution metadata including fields
|
| 418 |
+
like Name and Version and Description.
|
| 419 |
+
- entry_points.txt: A series of entry points as defined in
|
| 420 |
+
`the entry points spec <https://packaging.python.org/en/latest/specifications/entry-points/#file-format>`_.
|
| 421 |
+
- RECORD: A record of files according to
|
| 422 |
+
`this recording spec <https://packaging.python.org/en/latest/specifications/recording-installed-packages/#the-record-file>`_.
|
| 423 |
+
|
| 424 |
+
A package may provide any set of files, including those
|
| 425 |
+
not listed here or none at all.
|
| 426 |
+
|
| 427 |
+
:param filename: The name of the file in the distribution info.
|
| 428 |
+
:return: The text if found, otherwise None.
|
| 429 |
+
"""
|
| 430 |
+
|
| 431 |
+
@abc.abstractmethod
|
| 432 |
+
def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
|
| 433 |
+
"""
|
| 434 |
+
Given a path to a file in this distribution, return a SimplePath
|
| 435 |
+
to it.
|
| 436 |
+
|
| 437 |
+
This method is used by callers of ``Distribution.files()`` to
|
| 438 |
+
locate files within the distribution. If it's possible for a
|
| 439 |
+
Distribution to represent files in the distribution as
|
| 440 |
+
``SimplePath`` objects, it should implement this method
|
| 441 |
+
to resolve such objects.
|
| 442 |
+
|
| 443 |
+
Some Distribution providers may elect not to resolve SimplePath
|
| 444 |
+
objects within the distribution by raising a
|
| 445 |
+
NotImplementedError, but consumers of such a Distribution would
|
| 446 |
+
be unable to invoke ``Distribution.files()``.
|
| 447 |
+
"""
|
| 448 |
+
|
| 449 |
+
@classmethod
|
| 450 |
+
def from_name(cls, name: str) -> Distribution:
|
| 451 |
+
"""Return the Distribution for the given package name.
|
| 452 |
+
|
| 453 |
+
:param name: The name of the distribution package to search for.
|
| 454 |
+
:return: The Distribution instance (or subclass thereof) for the named
|
| 455 |
+
package, if found.
|
| 456 |
+
:raises PackageNotFoundError: When the named package's distribution
|
| 457 |
+
metadata cannot be found.
|
| 458 |
+
:raises ValueError: When an invalid value is supplied for name.
|
| 459 |
+
"""
|
| 460 |
+
if not name:
|
| 461 |
+
raise ValueError("A distribution name is required.")
|
| 462 |
+
try:
|
| 463 |
+
return next(iter(cls._prefer_valid(cls.discover(name=name))))
|
| 464 |
+
except StopIteration:
|
| 465 |
+
raise PackageNotFoundError(name)
|
| 466 |
+
|
| 467 |
+
@classmethod
|
| 468 |
+
def discover(
|
| 469 |
+
cls, *, context: DistributionFinder.Context | None = None, **kwargs
|
| 470 |
+
) -> Iterable[Distribution]:
|
| 471 |
+
"""Return an iterable of Distribution objects for all packages.
|
| 472 |
+
|
| 473 |
+
Pass a ``context`` or pass keyword arguments for constructing
|
| 474 |
+
a context.
|
| 475 |
+
|
| 476 |
+
:context: A ``DistributionFinder.Context`` object.
|
| 477 |
+
:return: Iterable of Distribution objects for packages matching
|
| 478 |
+
the context.
|
| 479 |
+
"""
|
| 480 |
+
if context and kwargs:
|
| 481 |
+
raise ValueError("cannot accept context and kwargs")
|
| 482 |
+
context = context or DistributionFinder.Context(**kwargs)
|
| 483 |
+
return itertools.chain.from_iterable(
|
| 484 |
+
resolver(context) for resolver in cls._discover_resolvers()
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
@staticmethod
|
| 488 |
+
def _prefer_valid(dists: Iterable[Distribution]) -> Iterable[Distribution]:
|
| 489 |
+
"""
|
| 490 |
+
Prefer (move to the front) distributions that have metadata.
|
| 491 |
+
|
| 492 |
+
Ref python/importlib_resources#489.
|
| 493 |
+
"""
|
| 494 |
+
buckets = bucket(dists, lambda dist: bool(dist.metadata))
|
| 495 |
+
return itertools.chain(buckets[True], buckets[False])
|
| 496 |
+
|
| 497 |
+
@staticmethod
|
| 498 |
+
def at(path: str | os.PathLike[str]) -> Distribution:
|
| 499 |
+
"""Return a Distribution for the indicated metadata path.
|
| 500 |
+
|
| 501 |
+
:param path: a string or path-like object
|
| 502 |
+
:return: a concrete Distribution instance for the path
|
| 503 |
+
"""
|
| 504 |
+
return PathDistribution(pathlib.Path(path))
|
| 505 |
+
|
| 506 |
+
@staticmethod
|
| 507 |
+
def _discover_resolvers():
|
| 508 |
+
"""Search the meta_path for resolvers (MetadataPathFinders)."""
|
| 509 |
+
declared = (
|
| 510 |
+
getattr(finder, 'find_distributions', None) for finder in sys.meta_path
|
| 511 |
+
)
|
| 512 |
+
return filter(None, declared)
|
| 513 |
+
|
| 514 |
+
@property
|
| 515 |
+
def metadata(self) -> _meta.PackageMetadata | None:
|
| 516 |
+
"""Return the parsed metadata for this Distribution.
|
| 517 |
+
|
| 518 |
+
The returned object will have keys that name the various bits of
|
| 519 |
+
metadata per the
|
| 520 |
+
`Core metadata specifications <https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata>`_.
|
| 521 |
+
|
| 522 |
+
Custom providers may provide the METADATA file or override this
|
| 523 |
+
property.
|
| 524 |
+
"""
|
| 525 |
+
|
| 526 |
+
text = (
|
| 527 |
+
self.read_text('METADATA')
|
| 528 |
+
or self.read_text('PKG-INFO')
|
| 529 |
+
# This last clause is here to support old egg-info files. Its
|
| 530 |
+
# effect is to just end up using the PathDistribution's self._path
|
| 531 |
+
# (which points to the egg-info file) attribute unchanged.
|
| 532 |
+
or self.read_text('')
|
| 533 |
+
)
|
| 534 |
+
return self._assemble_message(text)
|
| 535 |
+
|
| 536 |
+
@staticmethod
|
| 537 |
+
@pass_none
|
| 538 |
+
def _assemble_message(text: str) -> _meta.PackageMetadata:
|
| 539 |
+
# deferred for performance (python/cpython#109829)
|
| 540 |
+
from . import _adapters
|
| 541 |
+
|
| 542 |
+
return _adapters.Message(email.message_from_string(text))
|
| 543 |
+
|
| 544 |
+
@property
|
| 545 |
+
def name(self) -> str:
|
| 546 |
+
"""Return the 'Name' metadata for the distribution package."""
|
| 547 |
+
return md_none(self.metadata)['Name']
|
| 548 |
+
|
| 549 |
+
@property
|
| 550 |
+
def _normalized_name(self):
|
| 551 |
+
"""Return a normalized version of the name."""
|
| 552 |
+
return Prepared.normalize(self.name)
|
| 553 |
+
|
| 554 |
+
@property
|
| 555 |
+
def version(self) -> str:
|
| 556 |
+
"""Return the 'Version' metadata for the distribution package."""
|
| 557 |
+
return md_none(self.metadata)['Version']
|
| 558 |
+
|
| 559 |
+
@property
|
| 560 |
+
def entry_points(self) -> EntryPoints:
|
| 561 |
+
"""
|
| 562 |
+
Return EntryPoints for this distribution.
|
| 563 |
+
|
| 564 |
+
Custom providers may provide the ``entry_points.txt`` file
|
| 565 |
+
or override this property.
|
| 566 |
+
"""
|
| 567 |
+
return EntryPoints._from_text_for(self.read_text('entry_points.txt'), self)
|
| 568 |
+
|
| 569 |
+
@property
|
| 570 |
+
def files(self) -> list[PackagePath] | None:
|
| 571 |
+
"""Files in this distribution.
|
| 572 |
+
|
| 573 |
+
:return: List of PackagePath for this distribution or None
|
| 574 |
+
|
| 575 |
+
Result is `None` if the metadata file that enumerates files
|
| 576 |
+
(i.e. RECORD for dist-info, or installed-files.txt or
|
| 577 |
+
SOURCES.txt for egg-info) is missing.
|
| 578 |
+
Result may be empty if the metadata exists but is empty.
|
| 579 |
+
|
| 580 |
+
Custom providers are recommended to provide a "RECORD" file (in
|
| 581 |
+
``read_text``) or override this property to allow for callers to be
|
| 582 |
+
able to resolve filenames provided by the package.
|
| 583 |
+
"""
|
| 584 |
+
|
| 585 |
+
def make_file(name, hash=None, size_str=None):
|
| 586 |
+
result = PackagePath(name)
|
| 587 |
+
result.hash = FileHash(hash) if hash else None
|
| 588 |
+
result.size = int(size_str) if size_str else None
|
| 589 |
+
result.dist = self
|
| 590 |
+
return result
|
| 591 |
+
|
| 592 |
+
@pass_none
|
| 593 |
+
def make_files(lines):
|
| 594 |
+
# Delay csv import, since Distribution.files is not as widely used
|
| 595 |
+
# as other parts of importlib.metadata
|
| 596 |
+
import csv
|
| 597 |
+
|
| 598 |
+
return starmap(make_file, csv.reader(lines))
|
| 599 |
+
|
| 600 |
+
@pass_none
|
| 601 |
+
def skip_missing_files(package_paths):
|
| 602 |
+
return list(filter(lambda path: path.locate().exists(), package_paths))
|
| 603 |
+
|
| 604 |
+
return skip_missing_files(
|
| 605 |
+
make_files(
|
| 606 |
+
self._read_files_distinfo()
|
| 607 |
+
or self._read_files_egginfo_installed()
|
| 608 |
+
or self._read_files_egginfo_sources()
|
| 609 |
+
)
|
| 610 |
+
)
|
| 611 |
+
|
| 612 |
+
def _read_files_distinfo(self):
|
| 613 |
+
"""
|
| 614 |
+
Read the lines of RECORD.
|
| 615 |
+
"""
|
| 616 |
+
text = self.read_text('RECORD')
|
| 617 |
+
return text and text.splitlines()
|
| 618 |
+
|
| 619 |
+
def _read_files_egginfo_installed(self):
|
| 620 |
+
"""
|
| 621 |
+
Read installed-files.txt and return lines in a similar
|
| 622 |
+
CSV-parsable format as RECORD: each file must be placed
|
| 623 |
+
relative to the site-packages directory and must also be
|
| 624 |
+
quoted (since file names can contain literal commas).
|
| 625 |
+
|
| 626 |
+
This file is written when the package is installed by pip,
|
| 627 |
+
but it might not be written for other installation methods.
|
| 628 |
+
Assume the file is accurate if it exists.
|
| 629 |
+
"""
|
| 630 |
+
text = self.read_text('installed-files.txt')
|
| 631 |
+
# Prepend the .egg-info/ subdir to the lines in this file.
|
| 632 |
+
# But this subdir is only available from PathDistribution's
|
| 633 |
+
# self._path.
|
| 634 |
+
subdir = getattr(self, '_path', None)
|
| 635 |
+
if not text or not subdir:
|
| 636 |
+
return
|
| 637 |
+
|
| 638 |
+
paths = (
|
| 639 |
+
py311
|
| 640 |
+
.relative_fix((subdir / name).resolve())
|
| 641 |
+
.relative_to(self.locate_file('').resolve(), walk_up=True)
|
| 642 |
+
.as_posix()
|
| 643 |
+
for name in text.splitlines()
|
| 644 |
+
)
|
| 645 |
+
return map('"{}"'.format, paths)
|
| 646 |
+
|
| 647 |
+
def _read_files_egginfo_sources(self):
|
| 648 |
+
"""
|
| 649 |
+
Read SOURCES.txt and return lines in a similar CSV-parsable
|
| 650 |
+
format as RECORD: each file name must be quoted (since it
|
| 651 |
+
might contain literal commas).
|
| 652 |
+
|
| 653 |
+
Note that SOURCES.txt is not a reliable source for what
|
| 654 |
+
files are installed by a package. This file is generated
|
| 655 |
+
for a source archive, and the files that are present
|
| 656 |
+
there (e.g. setup.py) may not correctly reflect the files
|
| 657 |
+
that are present after the package has been installed.
|
| 658 |
+
"""
|
| 659 |
+
text = self.read_text('SOURCES.txt')
|
| 660 |
+
return text and map('"{}"'.format, text.splitlines())
|
| 661 |
+
|
| 662 |
+
@property
|
| 663 |
+
def requires(self) -> list[str] | None:
|
| 664 |
+
"""Generated requirements specified for this Distribution"""
|
| 665 |
+
reqs = self._read_dist_info_reqs() or self._read_egg_info_reqs()
|
| 666 |
+
return reqs and list(reqs)
|
| 667 |
+
|
| 668 |
+
def _read_dist_info_reqs(self):
|
| 669 |
+
return self.metadata.get_all('Requires-Dist')
|
| 670 |
+
|
| 671 |
+
def _read_egg_info_reqs(self):
|
| 672 |
+
source = self.read_text('requires.txt')
|
| 673 |
+
return pass_none(self._deps_from_requires_text)(source)
|
| 674 |
+
|
| 675 |
+
@classmethod
|
| 676 |
+
def _deps_from_requires_text(cls, source):
|
| 677 |
+
return cls._convert_egg_info_reqs_to_simple_reqs(Sectioned.read(source))
|
| 678 |
+
|
| 679 |
+
@staticmethod
|
| 680 |
+
def _convert_egg_info_reqs_to_simple_reqs(sections):
|
| 681 |
+
"""
|
| 682 |
+
Historically, setuptools would solicit and store 'extra'
|
| 683 |
+
requirements, including those with environment markers,
|
| 684 |
+
in separate sections. More modern tools expect each
|
| 685 |
+
dependency to be defined separately, with any relevant
|
| 686 |
+
extras and environment markers attached directly to that
|
| 687 |
+
requirement. This method converts the former to the
|
| 688 |
+
latter. See _test_deps_from_requires_text for an example.
|
| 689 |
+
"""
|
| 690 |
+
|
| 691 |
+
def make_condition(name):
|
| 692 |
+
return name and f'extra == "{name}"'
|
| 693 |
+
|
| 694 |
+
def quoted_marker(section):
|
| 695 |
+
section = section or ''
|
| 696 |
+
extra, sep, markers = section.partition(':')
|
| 697 |
+
if extra and markers:
|
| 698 |
+
markers = f'({markers})'
|
| 699 |
+
conditions = list(filter(None, [markers, make_condition(extra)]))
|
| 700 |
+
return '; ' + ' and '.join(conditions) if conditions else ''
|
| 701 |
+
|
| 702 |
+
def url_req_space(req):
|
| 703 |
+
"""
|
| 704 |
+
PEP 508 requires a space between the url_spec and the quoted_marker.
|
| 705 |
+
Ref python/importlib_metadata#357.
|
| 706 |
+
"""
|
| 707 |
+
# '@' is uniquely indicative of a url_req.
|
| 708 |
+
return ' ' * ('@' in req)
|
| 709 |
+
|
| 710 |
+
for section in sections:
|
| 711 |
+
space = url_req_space(section.value)
|
| 712 |
+
yield section.value + space + quoted_marker(section.name)
|
| 713 |
+
|
| 714 |
+
@property
|
| 715 |
+
def origin(self):
|
| 716 |
+
return self._load_json('direct_url.json')
|
| 717 |
+
|
| 718 |
+
def _load_json(self, filename):
|
| 719 |
+
# Deferred for performance (python/importlib_metadata#503)
|
| 720 |
+
import json
|
| 721 |
+
|
| 722 |
+
return pass_none(json.loads)(
|
| 723 |
+
self.read_text(filename),
|
| 724 |
+
object_hook=lambda data: types.SimpleNamespace(**data),
|
| 725 |
+
)
|
| 726 |
+
|
| 727 |
+
|
| 728 |
+
class DistributionFinder(MetaPathFinder):
|
| 729 |
+
"""
|
| 730 |
+
A MetaPathFinder capable of discovering installed distributions.
|
| 731 |
+
|
| 732 |
+
Custom providers should implement this interface in order to
|
| 733 |
+
supply metadata.
|
| 734 |
+
"""
|
| 735 |
+
|
| 736 |
+
class Context:
|
| 737 |
+
"""
|
| 738 |
+
Keyword arguments presented by the caller to
|
| 739 |
+
``distributions()`` or ``Distribution.discover()``
|
| 740 |
+
to narrow the scope of a search for distributions
|
| 741 |
+
in all DistributionFinders.
|
| 742 |
+
|
| 743 |
+
Each DistributionFinder may expect any parameters
|
| 744 |
+
and should attempt to honor the canonical
|
| 745 |
+
parameters defined below when appropriate.
|
| 746 |
+
|
| 747 |
+
This mechanism gives a custom provider a means to
|
| 748 |
+
solicit additional details from the caller beyond
|
| 749 |
+
"name" and "path" when searching distributions.
|
| 750 |
+
For example, imagine a provider that exposes suites
|
| 751 |
+
of packages in either a "public" or "private" ``realm``.
|
| 752 |
+
A caller may wish to query only for distributions in
|
| 753 |
+
a particular realm and could call
|
| 754 |
+
``distributions(realm="private")`` to signal to the
|
| 755 |
+
custom provider to only include distributions from that
|
| 756 |
+
realm.
|
| 757 |
+
"""
|
| 758 |
+
|
| 759 |
+
name = None
|
| 760 |
+
"""
|
| 761 |
+
Specific name for which a distribution finder should match.
|
| 762 |
+
A name of ``None`` matches all distributions.
|
| 763 |
+
"""
|
| 764 |
+
|
| 765 |
+
def __init__(self, **kwargs):
|
| 766 |
+
vars(self).update(kwargs)
|
| 767 |
+
|
| 768 |
+
@property
|
| 769 |
+
def path(self) -> list[str]:
|
| 770 |
+
"""
|
| 771 |
+
The sequence of directory path that a distribution finder
|
| 772 |
+
should search.
|
| 773 |
+
|
| 774 |
+
Typically refers to Python installed package paths such as
|
| 775 |
+
"site-packages" directories and defaults to ``sys.path``.
|
| 776 |
+
"""
|
| 777 |
+
return vars(self).get('path', sys.path)
|
| 778 |
+
|
| 779 |
+
@abc.abstractmethod
|
| 780 |
+
def find_distributions(self, context=Context()) -> Iterable[Distribution]:
|
| 781 |
+
"""
|
| 782 |
+
Find distributions.
|
| 783 |
+
|
| 784 |
+
Return an iterable of all Distribution instances capable of
|
| 785 |
+
loading the metadata for packages matching the ``context``,
|
| 786 |
+
a DistributionFinder.Context instance.
|
| 787 |
+
"""
|
| 788 |
+
|
| 789 |
+
|
| 790 |
+
@passthrough
|
| 791 |
+
def _clear_after_fork(cached):
|
| 792 |
+
"""Ensure ``func`` clears cached state after ``fork`` when supported.
|
| 793 |
+
|
| 794 |
+
``FastPath`` caches zip-backed ``pathlib.Path`` objects that retain a
|
| 795 |
+
reference to the parent's open ``ZipFile`` handle. Re-using a cached
|
| 796 |
+
instance in a forked child can therefore resurrect invalid file pointers
|
| 797 |
+
and trigger ``BadZipFile``/``OSError`` failures (python/importlib_metadata#520).
|
| 798 |
+
Registering ``cache_clear`` with ``os.register_at_fork`` keeps each process
|
| 799 |
+
on its own cache.
|
| 800 |
+
"""
|
| 801 |
+
getattr(os, 'register_at_fork', noop)(after_in_child=cached.cache_clear)
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
class FastPath:
|
| 805 |
+
"""
|
| 806 |
+
Micro-optimized class for searching a root for children.
|
| 807 |
+
|
| 808 |
+
Root is a path on the file system that may contain metadata
|
| 809 |
+
directories either as natural directories or within a zip file.
|
| 810 |
+
|
| 811 |
+
>>> FastPath('').children()
|
| 812 |
+
['...']
|
| 813 |
+
|
| 814 |
+
FastPath objects are cached and recycled for any given root.
|
| 815 |
+
|
| 816 |
+
>>> FastPath('foobar') is FastPath('foobar')
|
| 817 |
+
True
|
| 818 |
+
"""
|
| 819 |
+
|
| 820 |
+
@_clear_after_fork # type: ignore[misc]
|
| 821 |
+
@functools.lru_cache()
|
| 822 |
+
def __new__(cls, root):
|
| 823 |
+
return super().__new__(cls)
|
| 824 |
+
|
| 825 |
+
def __init__(self, root):
|
| 826 |
+
self.root = root
|
| 827 |
+
|
| 828 |
+
def joinpath(self, child):
|
| 829 |
+
return pathlib.Path(self.root, child)
|
| 830 |
+
|
| 831 |
+
def children(self):
|
| 832 |
+
with suppress(Exception):
|
| 833 |
+
return os.listdir(self.root or '.')
|
| 834 |
+
with suppress(Exception):
|
| 835 |
+
return self.zip_children()
|
| 836 |
+
return []
|
| 837 |
+
|
| 838 |
+
def zip_children(self):
|
| 839 |
+
# deferred for performance (python/importlib_metadata#502)
|
| 840 |
+
from zipp.compat.overlay import zipfile
|
| 841 |
+
|
| 842 |
+
zip_path = zipfile.Path(self.root)
|
| 843 |
+
names = zip_path.root.namelist()
|
| 844 |
+
self.joinpath = zip_path.joinpath
|
| 845 |
+
|
| 846 |
+
return dict.fromkeys(child.split(posixpath.sep, 1)[0] for child in names)
|
| 847 |
+
|
| 848 |
+
def search(self, name):
|
| 849 |
+
return self.lookup(self.mtime).search(name)
|
| 850 |
+
|
| 851 |
+
@property
|
| 852 |
+
def mtime(self):
|
| 853 |
+
with suppress(OSError):
|
| 854 |
+
return os.stat(self.root).st_mtime
|
| 855 |
+
self.lookup.cache_clear()
|
| 856 |
+
|
| 857 |
+
@method_cache
|
| 858 |
+
def lookup(self, mtime):
|
| 859 |
+
return Lookup(self)
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
class Lookup:
|
| 863 |
+
"""
|
| 864 |
+
A micro-optimized class for searching a (fast) path for metadata.
|
| 865 |
+
"""
|
| 866 |
+
|
| 867 |
+
def __init__(self, path: FastPath):
|
| 868 |
+
"""
|
| 869 |
+
Calculate all of the children representing metadata.
|
| 870 |
+
|
| 871 |
+
From the children in the path, calculate early all of the
|
| 872 |
+
children that appear to represent metadata (infos) or legacy
|
| 873 |
+
metadata (eggs).
|
| 874 |
+
"""
|
| 875 |
+
|
| 876 |
+
base = os.path.basename(path.root).lower()
|
| 877 |
+
base_is_egg = base.endswith(".egg")
|
| 878 |
+
self.infos = FreezableDefaultDict(list)
|
| 879 |
+
self.eggs = FreezableDefaultDict(list)
|
| 880 |
+
|
| 881 |
+
for child in path.children():
|
| 882 |
+
low = child.lower()
|
| 883 |
+
if low.endswith((".dist-info", ".egg-info")):
|
| 884 |
+
# rpartition is faster than splitext and suitable for this purpose.
|
| 885 |
+
name = low.rpartition(".")[0].partition("-")[0]
|
| 886 |
+
normalized = Prepared.normalize(name)
|
| 887 |
+
self.infos[normalized].append(path.joinpath(child))
|
| 888 |
+
elif base_is_egg and low == "egg-info":
|
| 889 |
+
name = base.rpartition(".")[0].partition("-")[0]
|
| 890 |
+
legacy_normalized = Prepared.legacy_normalize(name)
|
| 891 |
+
self.eggs[legacy_normalized].append(path.joinpath(child))
|
| 892 |
+
|
| 893 |
+
self.infos.freeze()
|
| 894 |
+
self.eggs.freeze()
|
| 895 |
+
|
| 896 |
+
def search(self, prepared: Prepared):
|
| 897 |
+
"""
|
| 898 |
+
Yield all infos and eggs matching the Prepared query.
|
| 899 |
+
"""
|
| 900 |
+
infos = (
|
| 901 |
+
self.infos[prepared.normalized]
|
| 902 |
+
if prepared
|
| 903 |
+
else itertools.chain.from_iterable(self.infos.values())
|
| 904 |
+
)
|
| 905 |
+
eggs = (
|
| 906 |
+
self.eggs[prepared.legacy_normalized]
|
| 907 |
+
if prepared
|
| 908 |
+
else itertools.chain.from_iterable(self.eggs.values())
|
| 909 |
+
)
|
| 910 |
+
return itertools.chain(infos, eggs)
|
| 911 |
+
|
| 912 |
+
|
| 913 |
+
class Prepared:
|
| 914 |
+
"""
|
| 915 |
+
A prepared search query for metadata on a possibly-named package.
|
| 916 |
+
|
| 917 |
+
Pre-calculates the normalization to prevent repeated operations.
|
| 918 |
+
|
| 919 |
+
>>> none = Prepared(None)
|
| 920 |
+
>>> none.normalized
|
| 921 |
+
>>> none.legacy_normalized
|
| 922 |
+
>>> bool(none)
|
| 923 |
+
False
|
| 924 |
+
>>> sample = Prepared('Sample__Pkg-name.foo')
|
| 925 |
+
>>> sample.normalized
|
| 926 |
+
'sample_pkg_name_foo'
|
| 927 |
+
>>> sample.legacy_normalized
|
| 928 |
+
'sample__pkg_name.foo'
|
| 929 |
+
>>> bool(sample)
|
| 930 |
+
True
|
| 931 |
+
"""
|
| 932 |
+
|
| 933 |
+
normalized = None
|
| 934 |
+
legacy_normalized = None
|
| 935 |
+
|
| 936 |
+
def __init__(self, name: str | None):
|
| 937 |
+
self.name = name
|
| 938 |
+
if name is None:
|
| 939 |
+
return
|
| 940 |
+
self.normalized = self.normalize(name)
|
| 941 |
+
self.legacy_normalized = self.legacy_normalize(name)
|
| 942 |
+
|
| 943 |
+
@staticmethod
|
| 944 |
+
def normalize(name):
|
| 945 |
+
"""
|
| 946 |
+
PEP 503 normalization plus dashes as underscores.
|
| 947 |
+
"""
|
| 948 |
+
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
|
| 949 |
+
|
| 950 |
+
@staticmethod
|
| 951 |
+
def legacy_normalize(name):
|
| 952 |
+
"""
|
| 953 |
+
Normalize the package name as found in the convention in
|
| 954 |
+
older packaging tools versions and specs.
|
| 955 |
+
"""
|
| 956 |
+
return name.lower().replace('-', '_')
|
| 957 |
+
|
| 958 |
+
def __bool__(self):
|
| 959 |
+
return bool(self.name)
|
| 960 |
+
|
| 961 |
+
|
| 962 |
+
@install
|
| 963 |
+
class MetadataPathFinder(NullFinder, DistributionFinder):
|
| 964 |
+
"""A degenerate finder for distribution packages on the file system.
|
| 965 |
+
|
| 966 |
+
This finder supplies only a find_distributions() method for versions
|
| 967 |
+
of Python that do not have a PathFinder find_distributions().
|
| 968 |
+
"""
|
| 969 |
+
|
| 970 |
+
@classmethod
|
| 971 |
+
def find_distributions(
|
| 972 |
+
cls, context=DistributionFinder.Context()
|
| 973 |
+
) -> Iterable[PathDistribution]:
|
| 974 |
+
"""
|
| 975 |
+
Find distributions.
|
| 976 |
+
|
| 977 |
+
Return an iterable of all Distribution instances capable of
|
| 978 |
+
loading the metadata for packages matching ``context.name``
|
| 979 |
+
(or all names if ``None`` indicated) along the paths in the list
|
| 980 |
+
of directories ``context.path``.
|
| 981 |
+
"""
|
| 982 |
+
found = cls._search_paths(context.name, context.path)
|
| 983 |
+
return map(PathDistribution, found)
|
| 984 |
+
|
| 985 |
+
@classmethod
|
| 986 |
+
def _search_paths(cls, name, paths):
|
| 987 |
+
"""Find metadata directories in paths heuristically."""
|
| 988 |
+
prepared = Prepared(name)
|
| 989 |
+
return itertools.chain.from_iterable(
|
| 990 |
+
path.search(prepared) for path in map(FastPath, paths)
|
| 991 |
+
)
|
| 992 |
+
|
| 993 |
+
@classmethod
|
| 994 |
+
def invalidate_caches(cls) -> None:
|
| 995 |
+
FastPath.__new__.cache_clear()
|
| 996 |
+
|
| 997 |
+
|
| 998 |
+
class PathDistribution(Distribution):
|
| 999 |
+
def __init__(self, path: SimplePath) -> None:
|
| 1000 |
+
"""Construct a distribution.
|
| 1001 |
+
|
| 1002 |
+
:param path: SimplePath indicating the metadata directory.
|
| 1003 |
+
"""
|
| 1004 |
+
self._path = path
|
| 1005 |
+
|
| 1006 |
+
def read_text(self, filename: str | os.PathLike[str]) -> str | None:
|
| 1007 |
+
with suppress(
|
| 1008 |
+
FileNotFoundError,
|
| 1009 |
+
IsADirectoryError,
|
| 1010 |
+
KeyError,
|
| 1011 |
+
NotADirectoryError,
|
| 1012 |
+
PermissionError,
|
| 1013 |
+
):
|
| 1014 |
+
return self._path.joinpath(filename).read_text(encoding='utf-8')
|
| 1015 |
+
|
| 1016 |
+
return None
|
| 1017 |
+
|
| 1018 |
+
read_text.__doc__ = Distribution.read_text.__doc__
|
| 1019 |
+
|
| 1020 |
+
def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
|
| 1021 |
+
return self._path.parent / path
|
| 1022 |
+
|
| 1023 |
+
@property
|
| 1024 |
+
def _normalized_name(self):
|
| 1025 |
+
"""
|
| 1026 |
+
Performance optimization: where possible, resolve the
|
| 1027 |
+
normalized name from the file system path.
|
| 1028 |
+
"""
|
| 1029 |
+
stem = os.path.basename(str(self._path))
|
| 1030 |
+
return (
|
| 1031 |
+
pass_none(Prepared.normalize)(self._name_from_stem(stem))
|
| 1032 |
+
or super()._normalized_name
|
| 1033 |
+
)
|
| 1034 |
+
|
| 1035 |
+
@staticmethod
|
| 1036 |
+
def _name_from_stem(stem):
|
| 1037 |
+
"""
|
| 1038 |
+
>>> PathDistribution._name_from_stem('foo-3.0.egg-info')
|
| 1039 |
+
'foo'
|
| 1040 |
+
>>> PathDistribution._name_from_stem('CherryPy-3.0.dist-info')
|
| 1041 |
+
'CherryPy'
|
| 1042 |
+
>>> PathDistribution._name_from_stem('face.egg-info')
|
| 1043 |
+
'face'
|
| 1044 |
+
>>> PathDistribution._name_from_stem('foo.bar')
|
| 1045 |
+
"""
|
| 1046 |
+
filename, ext = os.path.splitext(stem)
|
| 1047 |
+
if ext not in ('.dist-info', '.egg-info'):
|
| 1048 |
+
return
|
| 1049 |
+
name, sep, rest = filename.partition('-')
|
| 1050 |
+
return name
|
| 1051 |
+
|
| 1052 |
+
|
| 1053 |
+
def distribution(distribution_name: str) -> Distribution:
|
| 1054 |
+
"""Get the ``Distribution`` instance for the named package.
|
| 1055 |
+
|
| 1056 |
+
:param distribution_name: The name of the distribution package as a string.
|
| 1057 |
+
:return: A ``Distribution`` instance (or subclass thereof).
|
| 1058 |
+
"""
|
| 1059 |
+
return Distribution.from_name(distribution_name)
|
| 1060 |
+
|
| 1061 |
+
|
| 1062 |
+
def distributions(**kwargs) -> Iterable[Distribution]:
|
| 1063 |
+
"""Get all ``Distribution`` instances in the current environment.
|
| 1064 |
+
|
| 1065 |
+
:return: An iterable of ``Distribution`` instances.
|
| 1066 |
+
"""
|
| 1067 |
+
return Distribution.discover(**kwargs)
|
| 1068 |
+
|
| 1069 |
+
|
| 1070 |
+
def metadata(distribution_name: str) -> _meta.PackageMetadata | None:
|
| 1071 |
+
"""Get the metadata for the named package.
|
| 1072 |
+
|
| 1073 |
+
:param distribution_name: The name of the distribution package to query.
|
| 1074 |
+
:return: A PackageMetadata containing the parsed metadata.
|
| 1075 |
+
"""
|
| 1076 |
+
return Distribution.from_name(distribution_name).metadata
|
| 1077 |
+
|
| 1078 |
+
|
| 1079 |
+
def version(distribution_name: str) -> str:
|
| 1080 |
+
"""Get the version string for the named package.
|
| 1081 |
+
|
| 1082 |
+
:param distribution_name: The name of the distribution package to query.
|
| 1083 |
+
:return: The version string for the package as defined in the package's
|
| 1084 |
+
"Version" metadata key.
|
| 1085 |
+
"""
|
| 1086 |
+
return distribution(distribution_name).version
|
| 1087 |
+
|
| 1088 |
+
|
| 1089 |
+
_unique = functools.partial(
|
| 1090 |
+
unique_everseen,
|
| 1091 |
+
key=py39.normalized_name,
|
| 1092 |
+
)
|
| 1093 |
+
"""
|
| 1094 |
+
Wrapper for ``distributions`` to return unique distributions by name.
|
| 1095 |
+
"""
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
def entry_points(**params) -> EntryPoints:
|
| 1099 |
+
"""Return EntryPoint objects for all installed packages.
|
| 1100 |
+
|
| 1101 |
+
Pass selection parameters (group or name) to filter the
|
| 1102 |
+
result to entry points matching those properties (see
|
| 1103 |
+
EntryPoints.select()).
|
| 1104 |
+
|
| 1105 |
+
:return: EntryPoints for all installed packages.
|
| 1106 |
+
"""
|
| 1107 |
+
eps = itertools.chain.from_iterable(
|
| 1108 |
+
dist.entry_points for dist in _unique(distributions())
|
| 1109 |
+
)
|
| 1110 |
+
return EntryPoints(eps).select(**params)
|
| 1111 |
+
|
| 1112 |
+
|
| 1113 |
+
def files(distribution_name: str) -> list[PackagePath] | None:
|
| 1114 |
+
"""Return a list of files for the named package.
|
| 1115 |
+
|
| 1116 |
+
:param distribution_name: The name of the distribution package to query.
|
| 1117 |
+
:return: List of files composing the distribution.
|
| 1118 |
+
"""
|
| 1119 |
+
return distribution(distribution_name).files
|
| 1120 |
+
|
| 1121 |
+
|
| 1122 |
+
def requires(distribution_name: str) -> list[str] | None:
|
| 1123 |
+
"""
|
| 1124 |
+
Return a list of requirements for the named package.
|
| 1125 |
+
|
| 1126 |
+
:return: An iterable of requirements, suitable for
|
| 1127 |
+
packaging.requirement.Requirement.
|
| 1128 |
+
"""
|
| 1129 |
+
return distribution(distribution_name).requires
|
| 1130 |
+
|
| 1131 |
+
|
| 1132 |
+
def packages_distributions() -> Mapping[str, list[str]]:
|
| 1133 |
+
"""
|
| 1134 |
+
Return a mapping of top-level packages to their
|
| 1135 |
+
distributions.
|
| 1136 |
+
|
| 1137 |
+
>>> import collections.abc
|
| 1138 |
+
>>> pkgs = packages_distributions()
|
| 1139 |
+
>>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values())
|
| 1140 |
+
True
|
| 1141 |
+
"""
|
| 1142 |
+
pkg_to_dist = collections.defaultdict(list)
|
| 1143 |
+
for dist in distributions():
|
| 1144 |
+
for pkg in _top_level_declared(dist) or _top_level_inferred(dist):
|
| 1145 |
+
pkg_to_dist[pkg].append(md_none(dist.metadata)['Name'])
|
| 1146 |
+
return dict(pkg_to_dist)
|
| 1147 |
+
|
| 1148 |
+
|
| 1149 |
+
def _top_level_declared(dist):
|
| 1150 |
+
return (dist.read_text('top_level.txt') or '').split()
|
| 1151 |
+
|
| 1152 |
+
|
| 1153 |
+
def _topmost(name: PackagePath) -> str | None:
|
| 1154 |
+
"""
|
| 1155 |
+
Return the top-most parent as long as there is a parent.
|
| 1156 |
+
"""
|
| 1157 |
+
top, *rest = name.parts
|
| 1158 |
+
return top if rest else None
|
| 1159 |
+
|
| 1160 |
+
|
| 1161 |
+
def _get_toplevel_name(name: PackagePath) -> str:
|
| 1162 |
+
"""
|
| 1163 |
+
Infer a possibly importable module name from a name presumed on
|
| 1164 |
+
sys.path.
|
| 1165 |
+
|
| 1166 |
+
>>> _get_toplevel_name(PackagePath('foo.py'))
|
| 1167 |
+
'foo'
|
| 1168 |
+
>>> _get_toplevel_name(PackagePath('foo'))
|
| 1169 |
+
'foo'
|
| 1170 |
+
>>> _get_toplevel_name(PackagePath('foo.pyc'))
|
| 1171 |
+
'foo'
|
| 1172 |
+
>>> _get_toplevel_name(PackagePath('foo/__init__.py'))
|
| 1173 |
+
'foo'
|
| 1174 |
+
>>> _get_toplevel_name(PackagePath('foo.pth'))
|
| 1175 |
+
'foo.pth'
|
| 1176 |
+
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
|
| 1177 |
+
'foo.dist-info'
|
| 1178 |
+
"""
|
| 1179 |
+
# Defer import of inspect for performance (python/cpython#118761)
|
| 1180 |
+
import inspect
|
| 1181 |
+
|
| 1182 |
+
return _topmost(name) or inspect.getmodulename(name) or str(name)
|
| 1183 |
+
|
| 1184 |
+
|
| 1185 |
+
def _top_level_inferred(dist):
|
| 1186 |
+
opt_names = set(map(_get_toplevel_name, always_iterable(dist.files)))
|
| 1187 |
+
|
| 1188 |
+
def importable_name(name):
|
| 1189 |
+
return '.' not in name
|
| 1190 |
+
|
| 1191 |
+
return filter(importable_name, opt_names)
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_adapters.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import email.message
|
| 2 |
+
import email.policy
|
| 3 |
+
import re
|
| 4 |
+
import textwrap
|
| 5 |
+
|
| 6 |
+
from ._text import FoldedCase
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class RawPolicy(email.policy.EmailPolicy):
|
| 10 |
+
def fold(self, name, value):
|
| 11 |
+
folded = self.linesep.join(
|
| 12 |
+
textwrap
|
| 13 |
+
.indent(value, prefix=' ' * 8, predicate=lambda line: True)
|
| 14 |
+
.lstrip()
|
| 15 |
+
.splitlines()
|
| 16 |
+
)
|
| 17 |
+
return f'{name}: {folded}{self.linesep}'
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Message(email.message.Message):
|
| 21 |
+
r"""
|
| 22 |
+
Specialized Message subclass to handle metadata naturally.
|
| 23 |
+
|
| 24 |
+
Reads values that may have newlines in them and converts the
|
| 25 |
+
payload to the Description.
|
| 26 |
+
|
| 27 |
+
>>> msg_text = textwrap.dedent('''
|
| 28 |
+
... Name: Foo
|
| 29 |
+
... Version: 3.0
|
| 30 |
+
... License: blah
|
| 31 |
+
... de-blah
|
| 32 |
+
... <BLANKLINE>
|
| 33 |
+
... First line of description.
|
| 34 |
+
... Second line of description.
|
| 35 |
+
... <BLANKLINE>
|
| 36 |
+
... Fourth line!
|
| 37 |
+
... ''').lstrip().replace('<BLANKLINE>', '')
|
| 38 |
+
>>> msg = Message(email.message_from_string(msg_text))
|
| 39 |
+
>>> msg['Description']
|
| 40 |
+
'First line of description.\nSecond line of description.\n\nFourth line!\n'
|
| 41 |
+
|
| 42 |
+
Message should render even if values contain newlines.
|
| 43 |
+
|
| 44 |
+
>>> print(msg)
|
| 45 |
+
Name: Foo
|
| 46 |
+
Version: 3.0
|
| 47 |
+
License: blah
|
| 48 |
+
de-blah
|
| 49 |
+
Description: First line of description.
|
| 50 |
+
Second line of description.
|
| 51 |
+
<BLANKLINE>
|
| 52 |
+
Fourth line!
|
| 53 |
+
<BLANKLINE>
|
| 54 |
+
<BLANKLINE>
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
multiple_use_keys = set(
|
| 58 |
+
map(
|
| 59 |
+
FoldedCase,
|
| 60 |
+
[
|
| 61 |
+
'Classifier',
|
| 62 |
+
'Obsoletes-Dist',
|
| 63 |
+
'Platform',
|
| 64 |
+
'Project-URL',
|
| 65 |
+
'Provides-Dist',
|
| 66 |
+
'Provides-Extra',
|
| 67 |
+
'Requires-Dist',
|
| 68 |
+
'Requires-External',
|
| 69 |
+
'Supported-Platform',
|
| 70 |
+
'Dynamic',
|
| 71 |
+
],
|
| 72 |
+
)
|
| 73 |
+
)
|
| 74 |
+
"""
|
| 75 |
+
Keys that may be indicated multiple times per PEP 566.
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
def __new__(cls, orig: email.message.Message):
|
| 79 |
+
res = super().__new__(cls)
|
| 80 |
+
vars(res).update(vars(orig))
|
| 81 |
+
return res
|
| 82 |
+
|
| 83 |
+
def __init__(self, *args, **kwargs):
|
| 84 |
+
self._headers = self._repair_headers()
|
| 85 |
+
|
| 86 |
+
# suppress spurious error from mypy
|
| 87 |
+
def __iter__(self):
|
| 88 |
+
return super().__iter__()
|
| 89 |
+
|
| 90 |
+
def __getitem__(self, item):
|
| 91 |
+
"""
|
| 92 |
+
Override parent behavior to typical dict behavior.
|
| 93 |
+
|
| 94 |
+
``email.message.Message`` will emit None values for missing
|
| 95 |
+
keys. Typical mappings, including this ``Message``, will raise
|
| 96 |
+
a key error for missing keys.
|
| 97 |
+
|
| 98 |
+
Ref python/importlib_metadata#371.
|
| 99 |
+
"""
|
| 100 |
+
res = super().__getitem__(item)
|
| 101 |
+
if res is None:
|
| 102 |
+
raise KeyError(item)
|
| 103 |
+
return res
|
| 104 |
+
|
| 105 |
+
def _repair_headers(self):
|
| 106 |
+
def redent(value):
|
| 107 |
+
"Correct for RFC822 indentation"
|
| 108 |
+
indent = ' ' * 8
|
| 109 |
+
if not value or '\n' + indent not in value:
|
| 110 |
+
return value
|
| 111 |
+
return textwrap.dedent(indent + value)
|
| 112 |
+
|
| 113 |
+
headers = [(key, redent(value)) for key, value in vars(self)['_headers']]
|
| 114 |
+
if self._payload:
|
| 115 |
+
headers.append(('Description', self.get_payload()))
|
| 116 |
+
self.set_payload('')
|
| 117 |
+
return headers
|
| 118 |
+
|
| 119 |
+
def as_string(self):
|
| 120 |
+
return super().as_string(policy=RawPolicy())
|
| 121 |
+
|
| 122 |
+
@property
|
| 123 |
+
def json(self):
|
| 124 |
+
"""
|
| 125 |
+
Convert PackageMetadata to a JSON-compatible format
|
| 126 |
+
per PEP 0566.
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
def transform(key):
|
| 130 |
+
value = self.get_all(key) if key in self.multiple_use_keys else self[key]
|
| 131 |
+
if key == 'Keywords':
|
| 132 |
+
value = re.split(r'\s+', value)
|
| 133 |
+
tk = key.lower().replace('-', '_')
|
| 134 |
+
return tk, value
|
| 135 |
+
|
| 136 |
+
return dict(map(transform, map(FoldedCase, self)))
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_collections.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
import typing
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# from jaraco.collections 3.3
|
| 6 |
+
class FreezableDefaultDict(collections.defaultdict):
|
| 7 |
+
"""
|
| 8 |
+
Often it is desirable to prevent the mutation of
|
| 9 |
+
a default dict after its initial construction, such
|
| 10 |
+
as to prevent mutation during iteration.
|
| 11 |
+
|
| 12 |
+
>>> dd = FreezableDefaultDict(list)
|
| 13 |
+
>>> dd[0].append('1')
|
| 14 |
+
>>> dd.freeze()
|
| 15 |
+
>>> dd[1]
|
| 16 |
+
[]
|
| 17 |
+
>>> len(dd)
|
| 18 |
+
1
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def __missing__(self, key):
|
| 22 |
+
return getattr(self, '_frozen', super().__missing__)(key)
|
| 23 |
+
|
| 24 |
+
def freeze(self):
|
| 25 |
+
self._frozen = lambda key: self.default_factory()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Pair(typing.NamedTuple):
|
| 29 |
+
name: str
|
| 30 |
+
value: str
|
| 31 |
+
|
| 32 |
+
@classmethod
|
| 33 |
+
def parse(cls, text):
|
| 34 |
+
return cls(*map(str.strip, text.split("=", 1)))
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_compat.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
__all__ = ['install', 'NullFinder']
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def install(cls):
|
| 8 |
+
"""
|
| 9 |
+
Class decorator for installation on sys.meta_path.
|
| 10 |
+
|
| 11 |
+
Adds the backport DistributionFinder to sys.meta_path and
|
| 12 |
+
attempts to disable the finder functionality of the stdlib
|
| 13 |
+
DistributionFinder.
|
| 14 |
+
"""
|
| 15 |
+
sys.meta_path.append(cls())
|
| 16 |
+
disable_stdlib_finder()
|
| 17 |
+
return cls
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def disable_stdlib_finder():
|
| 21 |
+
"""
|
| 22 |
+
Give the backport primacy for discovering path-based distributions
|
| 23 |
+
by monkey-patching the stdlib O_O.
|
| 24 |
+
|
| 25 |
+
See #91 for more background for rationale on this sketchy
|
| 26 |
+
behavior.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def matches(finder):
|
| 30 |
+
return getattr(
|
| 31 |
+
finder, '__module__', None
|
| 32 |
+
) == '_frozen_importlib_external' and hasattr(finder, 'find_distributions')
|
| 33 |
+
|
| 34 |
+
for finder in filter(matches, sys.meta_path): # pragma: nocover
|
| 35 |
+
del finder.find_distributions
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class NullFinder:
|
| 39 |
+
"""
|
| 40 |
+
A "Finder" (aka "MetaPathFinder") that never finds any modules,
|
| 41 |
+
but may find distributions.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
@staticmethod
|
| 45 |
+
def find_spec(*args, **kwargs):
|
| 46 |
+
return None
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def pypy_partial(val):
|
| 50 |
+
"""
|
| 51 |
+
Adjust for variable stacklevel on partial under PyPy.
|
| 52 |
+
|
| 53 |
+
Workaround for #327.
|
| 54 |
+
"""
|
| 55 |
+
is_pypy = platform.python_implementation() == 'PyPy'
|
| 56 |
+
return val + is_pypy
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_functools.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import types
|
| 3 |
+
from typing import Callable, TypeVar
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# from jaraco.functools 3.3
|
| 7 |
+
def method_cache(method, cache_wrapper=None):
|
| 8 |
+
"""
|
| 9 |
+
Wrap lru_cache to support storing the cache data in the object instances.
|
| 10 |
+
|
| 11 |
+
Abstracts the common paradigm where the method explicitly saves an
|
| 12 |
+
underscore-prefixed protected property on first call and returns that
|
| 13 |
+
subsequently.
|
| 14 |
+
|
| 15 |
+
>>> class MyClass:
|
| 16 |
+
... calls = 0
|
| 17 |
+
...
|
| 18 |
+
... @method_cache
|
| 19 |
+
... def method(self, value):
|
| 20 |
+
... self.calls += 1
|
| 21 |
+
... return value
|
| 22 |
+
|
| 23 |
+
>>> a = MyClass()
|
| 24 |
+
>>> a.method(3)
|
| 25 |
+
3
|
| 26 |
+
>>> for x in range(75):
|
| 27 |
+
... res = a.method(x)
|
| 28 |
+
>>> a.calls
|
| 29 |
+
75
|
| 30 |
+
|
| 31 |
+
Note that the apparent behavior will be exactly like that of lru_cache
|
| 32 |
+
except that the cache is stored on each instance, so values in one
|
| 33 |
+
instance will not flush values from another, and when an instance is
|
| 34 |
+
deleted, so are the cached values for that instance.
|
| 35 |
+
|
| 36 |
+
>>> b = MyClass()
|
| 37 |
+
>>> for x in range(35):
|
| 38 |
+
... res = b.method(x)
|
| 39 |
+
>>> b.calls
|
| 40 |
+
35
|
| 41 |
+
>>> a.method(0)
|
| 42 |
+
0
|
| 43 |
+
>>> a.calls
|
| 44 |
+
75
|
| 45 |
+
|
| 46 |
+
Note that if method had been decorated with ``functools.lru_cache()``,
|
| 47 |
+
a.calls would have been 76 (due to the cached value of 0 having been
|
| 48 |
+
flushed by the 'b' instance).
|
| 49 |
+
|
| 50 |
+
Clear the cache with ``.cache_clear()``
|
| 51 |
+
|
| 52 |
+
>>> a.method.cache_clear()
|
| 53 |
+
|
| 54 |
+
Same for a method that hasn't yet been called.
|
| 55 |
+
|
| 56 |
+
>>> c = MyClass()
|
| 57 |
+
>>> c.method.cache_clear()
|
| 58 |
+
|
| 59 |
+
Another cache wrapper may be supplied:
|
| 60 |
+
|
| 61 |
+
>>> cache = functools.lru_cache(maxsize=2)
|
| 62 |
+
>>> MyClass.method2 = method_cache(lambda self: 3, cache_wrapper=cache)
|
| 63 |
+
>>> a = MyClass()
|
| 64 |
+
>>> a.method2()
|
| 65 |
+
3
|
| 66 |
+
|
| 67 |
+
Caution - do not subsequently wrap the method with another decorator, such
|
| 68 |
+
as ``@property``, which changes the semantics of the function.
|
| 69 |
+
|
| 70 |
+
See also
|
| 71 |
+
http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/
|
| 72 |
+
for another implementation and additional justification.
|
| 73 |
+
"""
|
| 74 |
+
cache_wrapper = cache_wrapper or functools.lru_cache()
|
| 75 |
+
|
| 76 |
+
def wrapper(self, *args, **kwargs):
|
| 77 |
+
# it's the first call, replace the method with a cached, bound method
|
| 78 |
+
bound_method = types.MethodType(method, self)
|
| 79 |
+
cached_method = cache_wrapper(bound_method)
|
| 80 |
+
setattr(self, method.__name__, cached_method)
|
| 81 |
+
return cached_method(*args, **kwargs)
|
| 82 |
+
|
| 83 |
+
# Support cache clear even before cache has been created.
|
| 84 |
+
wrapper.cache_clear = lambda: None
|
| 85 |
+
|
| 86 |
+
return wrapper
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# From jaraco.functools 3.3
|
| 90 |
+
def pass_none(func):
|
| 91 |
+
"""
|
| 92 |
+
Wrap func so it's not called if its first param is None
|
| 93 |
+
|
| 94 |
+
>>> print_text = pass_none(print)
|
| 95 |
+
>>> print_text('text')
|
| 96 |
+
text
|
| 97 |
+
>>> print_text(None)
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
@functools.wraps(func)
|
| 101 |
+
def wrapper(param, *args, **kwargs):
|
| 102 |
+
if param is not None:
|
| 103 |
+
return func(param, *args, **kwargs)
|
| 104 |
+
|
| 105 |
+
return wrapper
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# From jaraco.functools 4.4
|
| 109 |
+
def noop(*args, **kwargs):
|
| 110 |
+
"""
|
| 111 |
+
A no-operation function that does nothing.
|
| 112 |
+
|
| 113 |
+
>>> noop(1, 2, three=3)
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
_T = TypeVar('_T')
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# From jaraco.functools 4.4
|
| 121 |
+
def passthrough(func: Callable[..., object]) -> Callable[[_T], _T]:
|
| 122 |
+
"""
|
| 123 |
+
Wrap the function to always return the first parameter.
|
| 124 |
+
|
| 125 |
+
>>> passthrough(print)('3')
|
| 126 |
+
3
|
| 127 |
+
'3'
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
@functools.wraps(func)
|
| 131 |
+
def wrapper(first: _T, *args, **kwargs) -> _T:
|
| 132 |
+
func(first, *args, **kwargs)
|
| 133 |
+
return first
|
| 134 |
+
|
| 135 |
+
return wrapper # type: ignore[return-value]
|
python/Lib/site-packages/setuptools/_vendor/importlib_metadata/_itertools.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
|
| 4 |
+
|
| 5 |
+
def unique_everseen(iterable, key=None):
|
| 6 |
+
"List unique elements, preserving order. Remember all elements ever seen."
|
| 7 |
+
# unique_everseen('AAAABBBCCDAABBB') --> A B C D
|
| 8 |
+
# unique_everseen('ABBCcAD', str.lower) --> A B C D
|
| 9 |
+
seen = set()
|
| 10 |
+
seen_add = seen.add
|
| 11 |
+
if key is None:
|
| 12 |
+
for element in filterfalse(seen.__contains__, iterable):
|
| 13 |
+
seen_add(element)
|
| 14 |
+
yield element
|
| 15 |
+
else:
|
| 16 |
+
for element in iterable:
|
| 17 |
+
k = key(element)
|
| 18 |
+
if k not in seen:
|
| 19 |
+
seen_add(k)
|
| 20 |
+
yield element
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# copied from more_itertools 8.8
|
| 24 |
+
def always_iterable(obj, base_type=(str, bytes)):
|
| 25 |
+
"""If *obj* is iterable, return an iterator over its items::
|
| 26 |
+
|
| 27 |
+
>>> obj = (1, 2, 3)
|
| 28 |
+
>>> list(always_iterable(obj))
|
| 29 |
+
[1, 2, 3]
|
| 30 |
+
|
| 31 |
+
If *obj* is not iterable, return a one-item iterable containing *obj*::
|
| 32 |
+
|
| 33 |
+
>>> obj = 1
|
| 34 |
+
>>> list(always_iterable(obj))
|
| 35 |
+
[1]
|
| 36 |
+
|
| 37 |
+
If *obj* is ``None``, return an empty iterable:
|
| 38 |
+
|
| 39 |
+
>>> obj = None
|
| 40 |
+
>>> list(always_iterable(None))
|
| 41 |
+
[]
|
| 42 |
+
|
| 43 |
+
By default, binary and text strings are not considered iterable::
|
| 44 |
+
|
| 45 |
+
>>> obj = 'foo'
|
| 46 |
+
>>> list(always_iterable(obj))
|
| 47 |
+
['foo']
|
| 48 |
+
|
| 49 |
+
If *base_type* is set, objects for which ``isinstance(obj, base_type)``
|
| 50 |
+
returns ``True`` won't be considered iterable.
|
| 51 |
+
|
| 52 |
+
>>> obj = {'a': 1}
|
| 53 |
+
>>> list(always_iterable(obj)) # Iterate over the dict's keys
|
| 54 |
+
['a']
|
| 55 |
+
>>> list(always_iterable(obj, base_type=dict)) # Treat dicts as a unit
|
| 56 |
+
[{'a': 1}]
|
| 57 |
+
|
| 58 |
+
Set *base_type* to ``None`` to avoid any special handling and treat objects
|
| 59 |
+
Python considers iterable as iterable:
|
| 60 |
+
|
| 61 |
+
>>> obj = 'foo'
|
| 62 |
+
>>> list(always_iterable(obj, base_type=None))
|
| 63 |
+
['f', 'o', 'o']
|
| 64 |
+
"""
|
| 65 |
+
if obj is None:
|
| 66 |
+
return iter(())
|
| 67 |
+
|
| 68 |
+
if (base_type is not None) and isinstance(obj, base_type):
|
| 69 |
+
return iter((obj,))
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
return iter(obj)
|
| 73 |
+
except TypeError:
|
| 74 |
+
return iter((obj,))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# Copied from more_itertools 10.3
|
| 78 |
+
class bucket:
|
| 79 |
+
"""Wrap *iterable* and return an object that buckets the iterable into
|
| 80 |
+
child iterables based on a *key* function.
|
| 81 |
+
|
| 82 |
+
>>> iterable = ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', 'b3']
|
| 83 |
+
>>> s = bucket(iterable, key=lambda x: x[0]) # Bucket by 1st character
|
| 84 |
+
>>> sorted(list(s)) # Get the keys
|
| 85 |
+
['a', 'b', 'c']
|
| 86 |
+
>>> a_iterable = s['a']
|
| 87 |
+
>>> next(a_iterable)
|
| 88 |
+
'a1'
|
| 89 |
+
>>> next(a_iterable)
|
| 90 |
+
'a2'
|
| 91 |
+
>>> list(s['b'])
|
| 92 |
+
['b1', 'b2', 'b3']
|
| 93 |
+
|
| 94 |
+
The original iterable will be advanced and its items will be cached until
|
| 95 |
+
they are used by the child iterables. This may require significant storage.
|
| 96 |
+
|
| 97 |
+
By default, attempting to select a bucket to which no items belong will
|
| 98 |
+
exhaust the iterable and cache all values.
|
| 99 |
+
If you specify a *validator* function, selected buckets will instead be
|
| 100 |
+
checked against it.
|
| 101 |
+
|
| 102 |
+
>>> from itertools import count
|
| 103 |
+
>>> it = count(1, 2) # Infinite sequence of odd numbers
|
| 104 |
+
>>> key = lambda x: x % 10 # Bucket by last digit
|
| 105 |
+
>>> validator = lambda x: x in {1, 3, 5, 7, 9} # Odd digits only
|
| 106 |
+
>>> s = bucket(it, key=key, validator=validator)
|
| 107 |
+
>>> 2 in s
|
| 108 |
+
False
|
| 109 |
+
>>> list(s[2])
|
| 110 |
+
[]
|
| 111 |
+
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
def __init__(self, iterable, key, validator=None):
|
| 115 |
+
self._it = iter(iterable)
|
| 116 |
+
self._key = key
|
| 117 |
+
self._cache = defaultdict(deque)
|
| 118 |
+
self._validator = validator or (lambda x: True)
|
| 119 |
+
|
| 120 |
+
def __contains__(self, value):
|
| 121 |
+
if not self._validator(value):
|
| 122 |
+
return False
|
| 123 |
+
|
| 124 |
+
try:
|
| 125 |
+
item = next(self[value])
|
| 126 |
+
except StopIteration:
|
| 127 |
+
return False
|
| 128 |
+
else:
|
| 129 |
+
self._cache[value].appendleft(item)
|
| 130 |
+
|
| 131 |
+
return True
|
| 132 |
+
|
| 133 |
+
def _get_values(self, value):
|
| 134 |
+
"""
|
| 135 |
+
Helper to yield items from the parent iterator that match *value*.
|
| 136 |
+
Items that don't match are stored in the local cache as they
|
| 137 |
+
are encountered.
|
| 138 |
+
"""
|
| 139 |
+
while True:
|
| 140 |
+
# If we've cached some items that match the target value, emit
|
| 141 |
+
# the first one and evict it from the cache.
|
| 142 |
+
if self._cache[value]:
|
| 143 |
+
yield self._cache[value].popleft()
|
| 144 |
+
# Otherwise we need to advance the parent iterator to search for
|
| 145 |
+
# a matching item, caching the rest.
|
| 146 |
+
else:
|
| 147 |
+
while True:
|
| 148 |
+
try:
|
| 149 |
+
item = next(self._it)
|
| 150 |
+
except StopIteration:
|
| 151 |
+
return
|
| 152 |
+
item_value = self._key(item)
|
| 153 |
+
if item_value == value:
|
| 154 |
+
yield item
|
| 155 |
+
break
|
| 156 |
+
elif self._validator(item_value):
|
| 157 |
+
self._cache[item_value].append(item)
|
| 158 |
+
|
| 159 |
+
def __iter__(self):
|
| 160 |
+
for item in self._it:
|
| 161 |
+
item_value = self._key(item)
|
| 162 |
+
if self._validator(item_value):
|
| 163 |
+
self._cache[item_value].append(item)
|
| 164 |
+
|
| 165 |
+
yield from self._cache.keys()
|
| 166 |
+
|
| 167 |
+
def __getitem__(self, value):
|
| 168 |
+
if not self._validator(value):
|
| 169 |
+
return iter(())
|
| 170 |
+
|
| 171 |
+
return self._get_values(value)
|